Main repository of MikuMikuStudio
Revisión | cf33becd9e3950bd1b7b8d22ae6b4d94ec3ac0c0 (tree) |
---|---|
Tiempo | 2013-07-07 07:14:41 |
Autor | kobayasi <kobayasi@pscn...> |
Commiter | kobayasi |
merge from jme10694
@@ -47,6 +47,7 @@ import com.jme3.renderer.Camera; | ||
47 | 47 | import com.jme3.renderer.RenderManager; |
48 | 48 | import com.jme3.scene.CameraNode; |
49 | 49 | import com.jme3.scene.Node; |
50 | +import com.jme3.scene.control.CameraControl; | |
50 | 51 | import com.jme3.scene.control.CameraControl.ControlDirection; |
51 | 52 | import de.lessvoid.nifty.Nifty; |
52 | 53 | import java.io.IOException; |
@@ -277,7 +278,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { | ||
277 | 278 | public CameraNode bindCamera(String cameraName, Camera cam) { |
278 | 279 | CameraNode node = new CameraNode(cameraName, cam); |
279 | 280 | node.setControlDir(ControlDirection.SpatialToCamera); |
280 | - node.getControl(0).setEnabled(false); | |
281 | + node.getControl(CameraControl.class).setEnabled(false); | |
281 | 282 | cameras.put(cameraName, node); |
282 | 283 | scene.attachChild(node); |
283 | 284 | return node; |
@@ -289,7 +290,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { | ||
289 | 290 | |
290 | 291 | private void enableCurrentCam(boolean enabled) { |
291 | 292 | if (currentCam != null) { |
292 | - currentCam.getControl(0).setEnabled(enabled); | |
293 | + currentCam.getControl(CameraControl.class).setEnabled(enabled); | |
293 | 294 | } |
294 | 295 | } |
295 | 296 |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (c) 2009-2010 jMonkeyEngine | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -29,12 +29,11 @@ | ||
29 | 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | 31 | */ |
32 | - | |
33 | 32 | package com.jme3.scene.control; |
34 | 33 | |
34 | +import com.jme3.export.InputCapsule; | |
35 | 35 | import com.jme3.export.JmeExporter; |
36 | 36 | import com.jme3.export.JmeImporter; |
37 | -import com.jme3.export.InputCapsule; | |
38 | 37 | import com.jme3.export.OutputCapsule; |
39 | 38 | import com.jme3.renderer.RenderManager; |
40 | 39 | import com.jme3.renderer.ViewPort; |
@@ -55,7 +54,7 @@ public abstract class AbstractControl implements Control { | ||
55 | 54 | } |
56 | 55 | |
57 | 56 | public void setSpatial(Spatial spatial) { |
58 | - if (this.spatial != null && spatial != null) { | |
57 | + if (this.spatial != null && spatial != null && spatial != this.spatial) { | |
59 | 58 | throw new IllegalStateException("This control has already been added to a Spatial"); |
60 | 59 | } |
61 | 60 | this.spatial = spatial; |
@@ -83,6 +82,29 @@ public abstract class AbstractControl implements Control { | ||
83 | 82 | */ |
84 | 83 | protected abstract void controlRender(RenderManager rm, ViewPort vp); |
85 | 84 | |
85 | + /** | |
86 | + * Default implementation of cloneForSpatial() that | |
87 | + * simply clones the control and sets the spatial. | |
88 | + * <pre> | |
89 | + * AbstractControl c = clone(); | |
90 | + * c.spatial = null; | |
91 | + * c.setSpatial(spatial); | |
92 | + * </pre> | |
93 | + * | |
94 | + * Controls that wish to be persisted must be Cloneable. | |
95 | + */ | |
96 | + @Override | |
97 | + public Control cloneForSpatial(Spatial spatial) { | |
98 | + try { | |
99 | + AbstractControl c = (AbstractControl)clone(); | |
100 | + c.spatial = null; // to keep setSpatial() from throwing an exception | |
101 | + c.setSpatial(spatial); | |
102 | + return c; | |
103 | + } catch(CloneNotSupportedException e) { | |
104 | + throw new RuntimeException( "Can't clone control for spatial", e ); | |
105 | + } | |
106 | + } | |
107 | + | |
86 | 108 | public void update(float tpf) { |
87 | 109 | if (!enabled) |
88 | 110 | return; |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (c) 2009-2010 jMonkeyEngine | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -29,7 +29,6 @@ | ||
29 | 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | 31 | */ |
32 | - | |
33 | 32 | package com.jme3.scene.control; |
34 | 33 | |
35 | 34 | import com.jme3.bounding.BoundingBox; |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (c) 2009-2010 jMonkeyEngine | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -29,11 +29,8 @@ | ||
29 | 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | 31 | */ |
32 | - | |
33 | 32 | package com.jme3.scene.control; |
34 | 33 | |
35 | -import java.io.IOException; | |
36 | - | |
37 | 34 | import com.jme3.export.InputCapsule; |
38 | 35 | import com.jme3.export.JmeExporter; |
39 | 36 | import com.jme3.export.JmeImporter; |
@@ -47,6 +44,7 @@ import com.jme3.renderer.RenderManager; | ||
47 | 44 | import com.jme3.renderer.ViewPort; |
48 | 45 | import com.jme3.scene.Node; |
49 | 46 | import com.jme3.scene.Spatial; |
47 | +import java.io.IOException; | |
50 | 48 | |
51 | 49 | public class BillboardControl extends AbstractControl { |
52 | 50 |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (c) 2009-2010 jMonkeyEngine | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -31,8 +31,10 @@ | ||
31 | 31 | */ |
32 | 32 | package com.jme3.scene.control; |
33 | 33 | |
34 | +import com.jme3.export.InputCapsule; | |
34 | 35 | import com.jme3.export.JmeExporter; |
35 | 36 | import com.jme3.export.JmeImporter; |
37 | +import com.jme3.export.OutputCapsule; | |
36 | 38 | import com.jme3.math.Quaternion; |
37 | 39 | import com.jme3.math.Vector3f; |
38 | 40 | import com.jme3.renderer.Camera; |
@@ -64,7 +66,7 @@ public class CameraControl extends AbstractControl { | ||
64 | 66 | SpatialToCamera; |
65 | 67 | } |
66 | 68 | private Camera camera; |
67 | - private ControlDirection controlDir = ControlDirection.CameraToSpatial; | |
69 | + private ControlDirection controlDir = ControlDirection.SpatialToCamera; | |
68 | 70 | |
69 | 71 | /** |
70 | 72 | * Constructor used for Serialization. |
@@ -142,18 +144,21 @@ public class CameraControl extends AbstractControl { | ||
142 | 144 | return control; |
143 | 145 | } |
144 | 146 | private static final String CONTROL_DIR_NAME = "controlDir"; |
145 | - | |
147 | + private static final String CAMERA_NAME = "camera"; | |
148 | + | |
146 | 149 | @Override |
147 | 150 | public void read(JmeImporter im) throws IOException { |
148 | 151 | super.read(im); |
149 | - im.getCapsule(this).readEnum(CONTROL_DIR_NAME, | |
150 | - ControlDirection.class, ControlDirection.SpatialToCamera); | |
152 | + InputCapsule ic = im.getCapsule(this); | |
153 | + controlDir = ic.readEnum(CONTROL_DIR_NAME, ControlDirection.class, ControlDirection.SpatialToCamera); | |
154 | + camera = (Camera)ic.readSavable(CAMERA_NAME, null); | |
151 | 155 | } |
152 | 156 | |
153 | 157 | @Override |
154 | 158 | public void write(JmeExporter ex) throws IOException { |
155 | 159 | super.write(ex); |
156 | - ex.getCapsule(this).write(controlDir, CONTROL_DIR_NAME, | |
157 | - ControlDirection.SpatialToCamera); | |
160 | + OutputCapsule oc = ex.getCapsule(this); | |
161 | + oc.write(controlDir, CONTROL_DIR_NAME, ControlDirection.SpatialToCamera); | |
162 | + oc.write(camera, CAMERA_NAME, null); | |
158 | 163 | } |
159 | 164 | } |
\ No newline at end of file |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (c) 2009-2010 jMonkeyEngine | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -29,7 +29,6 @@ | ||
29 | 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | 31 | */ |
32 | - | |
33 | 32 | package com.jme3.scene.control; |
34 | 33 | |
35 | 34 | import com.jme3.export.Savable; |
@@ -62,18 +61,6 @@ public interface Control extends Savable { | ||
62 | 61 | public void setSpatial(Spatial spatial); |
63 | 62 | |
64 | 63 | /** |
65 | - * @param enabled Enable or disable the control. If disabled, update() | |
66 | - * should do nothing. | |
67 | - */ | |
68 | - public void setEnabled(boolean enabled); | |
69 | - | |
70 | - /** | |
71 | - * @return True if enabled, false otherwise. | |
72 | - * @see Control#setEnabled(boolean) | |
73 | - */ | |
74 | - public boolean isEnabled(); | |
75 | - | |
76 | - /** | |
77 | 64 | * Updates the control. This should not be called from user code. |
78 | 65 | * @param tpf Time per frame. |
79 | 66 | */ |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (c) 2009-2010 jMonkeyEngine | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -31,14 +31,15 @@ | ||
31 | 31 | */ |
32 | 32 | package com.jme3.scene.control; |
33 | 33 | |
34 | +import com.jme3.export.InputCapsule; | |
34 | 35 | import com.jme3.export.JmeExporter; |
35 | 36 | import com.jme3.export.JmeImporter; |
37 | +import com.jme3.export.OutputCapsule; | |
36 | 38 | import com.jme3.light.DirectionalLight; |
37 | 39 | import com.jme3.light.Light; |
38 | 40 | import com.jme3.light.PointLight; |
39 | -import com.jme3.math.Quaternion; | |
41 | +import com.jme3.light.SpotLight; | |
40 | 42 | import com.jme3.math.Vector3f; |
41 | -import com.jme3.renderer.Camera; | |
42 | 43 | import com.jme3.renderer.RenderManager; |
43 | 44 | import com.jme3.renderer.ViewPort; |
44 | 45 | import com.jme3.scene.Spatial; |
@@ -130,12 +131,12 @@ public class LightControl extends AbstractControl { | ||
130 | 131 | if (light instanceof DirectionalLight) { |
131 | 132 | ((DirectionalLight) light).setDirection(vars.vect1.set(spatial.getWorldTranslation()).multLocal(-1.0f)); |
132 | 133 | } |
134 | + | |
135 | + if (light instanceof SpotLight) { | |
136 | + ((SpotLight) light).setPosition(spatial.getWorldTranslation()); | |
137 | + ((SpotLight) light).setDirection(spatial.getWorldRotation().multLocal(vars.vect1.set(Vector3f.UNIT_Y).multLocal(-1))); | |
138 | + } | |
133 | 139 | vars.release(); |
134 | - //TODO add code for Spot light here when it's done | |
135 | -// if( light instanceof SpotLight){ | |
136 | -// ((SpotLight)light).setPosition(spatial.getWorldTranslation()); | |
137 | -// ((SpotLight)light).setRotation(spatial.getWorldRotation()); | |
138 | -// } | |
139 | 140 | |
140 | 141 | } |
141 | 142 |
@@ -174,18 +175,21 @@ public class LightControl extends AbstractControl { | ||
174 | 175 | return control; |
175 | 176 | } |
176 | 177 | private static final String CONTROL_DIR_NAME = "controlDir"; |
177 | - | |
178 | + private static final String LIGHT_NAME = "light"; | |
179 | + | |
178 | 180 | @Override |
179 | 181 | public void read(JmeImporter im) throws IOException { |
180 | 182 | super.read(im); |
181 | - im.getCapsule(this).readEnum(CONTROL_DIR_NAME, | |
182 | - ControlDirection.class, ControlDirection.SpatialToLight); | |
183 | + InputCapsule ic = im.getCapsule(this); | |
184 | + controlDir = ic.readEnum(CONTROL_DIR_NAME, ControlDirection.class, ControlDirection.SpatialToLight); | |
185 | + light = (Light)ic.readSavable(LIGHT_NAME, null); | |
183 | 186 | } |
184 | 187 | |
185 | 188 | @Override |
186 | 189 | public void write(JmeExporter ex) throws IOException { |
187 | 190 | super.write(ex); |
188 | - ex.getCapsule(this).write(controlDir, CONTROL_DIR_NAME, | |
189 | - ControlDirection.SpatialToLight); | |
191 | + OutputCapsule oc = ex.getCapsule(this); | |
192 | + oc.write(controlDir, CONTROL_DIR_NAME, ControlDirection.SpatialToLight); | |
193 | + oc.write(light, LIGHT_NAME, null); | |
190 | 194 | } |
191 | 195 | } |
\ No newline at end of file |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (c) 2009-2010 jMonkeyEngine | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -29,13 +29,12 @@ | ||
29 | 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
30 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | 31 | */ |
32 | - | |
33 | 32 | package com.jme3.scene.control; |
34 | 33 | |
35 | 34 | import com.jme3.bounding.BoundingVolume; |
35 | +import com.jme3.export.InputCapsule; | |
36 | 36 | import com.jme3.export.JmeExporter; |
37 | 37 | import com.jme3.export.JmeImporter; |
38 | -import com.jme3.export.InputCapsule; | |
39 | 38 | import com.jme3.export.OutputCapsule; |
40 | 39 | import com.jme3.math.FastMath; |
41 | 40 | import com.jme3.renderer.Camera; |
@@ -1,5 +1,5 @@ | ||
1 | 1 | /* |
2 | - * Copyright (c) 2009-2010 jMonkeyEngine | |
2 | + * Copyright (c) 2009-2012 jMonkeyEngine | |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -49,6 +49,7 @@ import com.jme3.math.Vector3f; | ||
49 | 49 | import com.jme3.scene.CameraNode; |
50 | 50 | import com.jme3.scene.Geometry; |
51 | 51 | import com.jme3.scene.Spatial; |
52 | +import com.jme3.scene.control.CameraControl; | |
52 | 53 | import com.jme3.scene.control.CameraControl.ControlDirection; |
53 | 54 | import com.jme3.scene.shape.Box; |
54 | 55 |
@@ -73,7 +74,7 @@ public class TestCameraMotionPath extends SimpleApplication { | ||
73 | 74 | cam.setLocation(new Vector3f(8.4399185f, 11.189463f, 14.267577f)); |
74 | 75 | camNode = new CameraNode("Motion cam", cam); |
75 | 76 | camNode.setControlDir(ControlDirection.SpatialToCamera); |
76 | - camNode.getControl(0).setEnabled(false); | |
77 | + camNode.getControl(CameraControl.class).setEnabled(false); | |
77 | 78 | path = new MotionPath(); |
78 | 79 | path.setCycle(true); |
79 | 80 | path.addWayPoint(new Vector3f(20, 3, 0)); |
@@ -170,11 +171,11 @@ public class TestCameraMotionPath extends SimpleApplication { | ||
170 | 171 | playing = false; |
171 | 172 | cameraMotionControl.stop(); |
172 | 173 | chaser.setEnabled(true); |
173 | - camNode.getControl(0).setEnabled(false); | |
174 | + camNode.getControl(CameraControl.class).setEnabled(false); | |
174 | 175 | } else { |
175 | 176 | playing = true; |
176 | 177 | chaser.setEnabled(false); |
177 | - camNode.getControl(0).setEnabled(true); | |
178 | + camNode.getControl(CameraControl.class).setEnabled(true); | |
178 | 179 | cameraMotionControl.play(); |
179 | 180 | } |
180 | 181 | } |