5858
5959import com .simsilica .es .*;
6060import com .simsilica .lemur .*;
61+ import com .simsilica .lemur .anim .*;
6162import com .simsilica .lemur .style .ElementId ;
6263import com .simsilica .mathd .*;
6364import com .simsilica .state .*;
@@ -75,6 +76,7 @@ public class ModelViewState extends BaseAppState {
7576 static Logger log = LoggerFactory .getLogger (ModelViewState .class );
7677
7778 private EntityData ed ;
79+ private AssetManager assets ;
7880
7981 private Node modelRoot ;
8082
@@ -103,6 +105,7 @@ public Spatial getModel( EntityId id ) {
103105 @ Override
104106 protected void initialize ( Application app ) {
105107 modelRoot = new Node ();
108+ assets = app .getAssetManager ();
106109
107110 this .ed = getState (GameSystemsState .class ).get (EntityData .class );
108111 }
@@ -159,11 +162,9 @@ public void update( float tpf ) {
159162
160163 protected Spatial createShip ( Entity entity ) {
161164
162- AssetManager assetManager = getApplication ().getAssetManager ();
163-
164- Spatial ship = assetManager .loadModel ("Models/fighter.j3o" );
165+ Spatial ship = assets .loadModel ("Models/fighter.j3o" );
165166 ship .center ();
166- Texture texture = assetManager .loadTexture ("Textures/ship1.png" );
167+ Texture texture = assets .loadTexture ("Textures/ship1.png" );
167168 Material mat = GuiGlobals .getInstance ().createMaterial (texture , false ).getMaterial ();
168169 mat .setTexture ("ColorMap" , texture );
169170 ship .setMaterial (mat );
@@ -219,13 +220,11 @@ protected Spatial createPlanet( Entity entity ) {
219220
220221 protected Spatial createAsteroid ( Entity entity ) {
221222
222- AssetManager assetManager = getApplication ().getAssetManager ();
223-
224- Spatial rock = assetManager .loadModel ("Models/Rock1/Rock1.j3o" );
223+ Spatial rock = assets .loadModel ("Models/Rock1/Rock1.j3o" );
225224 rock .setName ("rock" );
226225 //rock.setLocalScale(50);
227226 rock .center ();
228- Texture texture = assetManager .loadTexture ("Models/Rock1/textures/Rock02LV3_1_1024.jpg" );
227+ Texture texture = assets .loadTexture ("Models/Rock1/textures/Rock02LV3_1_1024.jpg" );
229228 Material mat = GuiGlobals .getInstance ().createMaterial (texture , false ).getMaterial ();
230229 //mat.setTexture("ColorMap", texture);
231230 rock .setMaterial (mat );
@@ -254,6 +253,36 @@ protected Spatial createAsteroid( Entity entity ) {
254253
255254 return result ;
256255 }
256+
257+ protected Spatial createThrust ( Entity entity ) {
258+
259+ GuiGlobals globals = GuiGlobals .getInstance ();
260+
261+ Node result = new Node ("thrust" );
262+
263+ Quad quad = new Quad (2 , 2 );
264+ Geometry geom = new Geometry ("quad" , quad );
265+ Texture texture = globals .loadTexture ("Textures/neon-puff256.png" , false , false );
266+ //Material mat = globals.createMaterial(ColorRGBA.Blue, false).getMaterial();
267+ Material mat = globals .createMaterial (texture , false ).getMaterial ();
268+ mat .getAdditionalRenderState ().setBlendMode (BlendMode .AlphaAdditive );
269+ geom .setQueueBucket (Bucket .Transparent );
270+ geom .rotate (-FastMath .HALF_PI , 0 , 0 );
271+ geom .setMaterial (mat );
272+ geom .center ();
273+ geom .move (0 , -1 , 0 );
274+
275+ ColorRGBA color = new ColorRGBA (2 , 2 , 0 , 1 );
276+ mat .setColor ("Color" , color );
277+
278+ // Fade it out over five seconds. We could have created a system to do
279+ // this based on decay, blah blah... but this is really easy.
280+ getState (AnimationState .class ).add (new ColorTween (color , ColorRGBA .White , new ColorRGBA (1 , 1 , 1 , 0 ), 5 ));
281+
282+ result .attachChild (geom );
283+
284+ return result ;
285+ }
257286
258287 protected Spatial createModel ( Entity entity ) {
259288 // Check to see if one already exists
@@ -271,6 +300,8 @@ protected Spatial createModel( Entity entity ) {
271300 result = createPlanet (entity );
272301 } else if ( typeName .equals ("asteroid" ) ) {
273302 result = createAsteroid (entity );
303+ } else if ( typeName .equals ("thrust" ) ) {
304+ result = createThrust (entity );
274305 } else {
275306 throw new RuntimeException ("Unknown spatial type:" + typeName );
276307 }
@@ -336,7 +367,39 @@ protected void removeObject( Spatial object, Entity e ) {
336367 log .trace ("removeObject(" + e + ")" );
337368 }
338369 removeModel (object , e );
339- }
370+ }
371+ }
372+
373+ /**
374+ * Lemur does not yet provide one of these so we will do it ourselves.
375+ */
376+ private class ColorTween extends AbstractTween {
377+
378+ private final ColorRGBA target ;
379+ private final ColorRGBA from ;
380+ private final ColorRGBA to ;
381+ private final ColorRGBA value ;
382+
383+ public ColorTween ( ColorRGBA target , ColorRGBA from , ColorRGBA to , double length ) {
384+ super (length );
385+ this .target = target ;
386+ this .from = from .clone ();
387+ this .to = to .clone ();
388+ this .value = new ColorRGBA (from );
389+ }
390+
391+ @ Override
392+ protected void doInterpolate ( double t ) {
393+ // Interpolate
394+ value .interpolateLocal (from , to , (float )t );
395+ target .set (value );
396+ }
397+
398+ @ Override
399+ public String toString () {
400+ return getClass ().getSimpleName () + "[target=" + target + ", from=" + from + ", to=" + to + ", length=" + getLength () + "]" ;
401+ }
340402 }
403+
341404}
342405
0 commit comments