• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package com.jme3.cinematic.events;
6 
7 import com.jme3.animation.LoopMode;
8 import com.jme3.app.Application;
9 import com.jme3.cinematic.Cinematic;
10 import com.jme3.export.InputCapsule;
11 import com.jme3.export.JmeExporter;
12 import com.jme3.export.JmeImporter;
13 import com.jme3.export.OutputCapsule;
14 import com.jme3.math.FastMath;
15 import com.jme3.math.Vector3f;
16 import com.jme3.scene.Spatial;
17 import java.io.IOException;
18 import java.util.logging.Level;
19 import java.util.logging.Logger;
20 
21 /**
22  *
23  * @author Nehon
24  * @deprecated use spatial animation instead.
25  */
26 @Deprecated
27 public class ScaleTrack extends AbstractCinematicEvent {
28 
29     private static final Logger log = Logger.getLogger(RotationTrack.class.getName());
30     private Vector3f startScale;
31     private Vector3f endScale;
32     private Spatial spatial;
33     private String spatialName = "";
34     private float value = 0;
35 
36     @Override
initEvent(Application app, Cinematic cinematic)37     public void initEvent(Application app, Cinematic cinematic) {
38         super.initEvent(app, cinematic);
39         if (spatial == null) {
40             spatial = cinematic.getScene().getChild(spatialName);
41             if (spatial == null) {
42             } else {
43                 log.log(Level.WARNING, "spatial {0} not found in the scene", spatialName);
44             }
45         }
46     }
47 
ScaleTrack()48     public ScaleTrack() {
49     }
50 
ScaleTrack(Spatial spatial, Vector3f endScale)51     public ScaleTrack(Spatial spatial, Vector3f endScale) {
52         this.endScale = endScale;
53         this.spatial = spatial;
54         spatialName = spatial.getName();
55     }
56 
ScaleTrack(Spatial spatial, Vector3f endScale, float initialDuration, LoopMode loopMode)57     public ScaleTrack(Spatial spatial, Vector3f endScale, float initialDuration, LoopMode loopMode) {
58         super(initialDuration, loopMode);
59         this.endScale = endScale;
60         this.spatial = spatial;
61         spatialName = spatial.getName();
62     }
63 
ScaleTrack(Spatial spatial, Vector3f endScale, LoopMode loopMode)64     public ScaleTrack(Spatial spatial, Vector3f endScale, LoopMode loopMode) {
65         super(loopMode);
66         this.endScale = endScale;
67         this.spatial = spatial;
68         spatialName = spatial.getName();
69     }
70 
ScaleTrack(Spatial spatial, Vector3f endScale, float initialDuration)71     public ScaleTrack(Spatial spatial, Vector3f endScale, float initialDuration) {
72         super(initialDuration);
73         this.endScale = endScale;
74         this.spatial = spatial;
75         spatialName = spatial.getName();
76     }
77 
78     @Override
onPlay()79     public void onPlay() {
80         if (playState != playState.Paused) {
81             startScale = spatial.getWorldScale().clone();
82         }
83         if (initialDuration == 0 && spatial != null) {
84             spatial.setLocalScale(endScale);
85             stop();
86         }
87     }
88 
89     @Override
onUpdate(float tpf)90     public void onUpdate(float tpf) {
91         if (spatial != null) {
92             value = Math.min(time / initialDuration, 1.0f);
93             spatial.setLocalScale(FastMath.interpolateLinear(value, startScale, endScale));
94         }
95     }
96 
97     @Override
onStop()98     public void onStop() {
99         value = 0;
100     }
101 
102     @Override
onPause()103     public void onPause() {
104     }
105 
106     @Override
write(JmeExporter ex)107     public void write(JmeExporter ex) throws IOException {
108         super.write(ex);
109         OutputCapsule oc = ex.getCapsule(this);
110         oc.write(spatialName, "spatialName", "");
111         oc.write(endScale, "endScale", null);
112     }
113 
114     @Override
read(JmeImporter im)115     public void read(JmeImporter im) throws IOException {
116         super.read(im);
117         InputCapsule ic = im.getCapsule(this);
118         spatialName = ic.readString("spatialName", "");
119         endScale = (Vector3f) ic.readSavable("endScale", null);
120     }
121 }
122