• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2010 jMonkeyEngine
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17  *   may be used to endorse or promote products derived from this software
18  *   without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 package jme3test.effect;
34 
35 import com.jme3.app.SimpleApplication;
36 import com.jme3.effect.ParticleEmitter;
37 import com.jme3.effect.ParticleMesh.Type;
38 import com.jme3.effect.shapes.EmitterSphereShape;
39 import com.jme3.export.binary.BinaryExporter;
40 import com.jme3.export.binary.BinaryImporter;
41 import com.jme3.material.Material;
42 import com.jme3.math.Vector3f;
43 import java.io.ByteArrayOutputStream;
44 import java.io.IOException;
45 
46 public class TestParticleExportingCloning extends SimpleApplication {
47 
main(String[] args)48     public static void main(String[] args){
49         TestParticleExportingCloning app = new TestParticleExportingCloning();
50         app.start();
51     }
52 
53     @Override
simpleInitApp()54     public void simpleInitApp() {
55         ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Triangle, 200);
56         emit.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
57         emit.setGravity(0, 0, 0);
58         emit.setLowLife(5);
59         emit.setHighLife(10);
60         emit.setInitialVelocity(new Vector3f(0, 0, 0));
61         emit.setImagesX(15);
62         Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
63         mat.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
64         emit.setMaterial(mat);
65 
66         ParticleEmitter emit2 = emit.clone();
67         emit2.move(3, 0, 0);
68 
69         rootNode.attachChild(emit);
70         rootNode.attachChild(emit2);
71 
72         ByteArrayOutputStream out = new ByteArrayOutputStream();
73         try {
74             BinaryExporter.getInstance().save(emit, out);
75 
76             BinaryImporter imp = new BinaryImporter();
77             imp.setAssetManager(assetManager);
78             ParticleEmitter emit3 = (ParticleEmitter) imp.load(out.toByteArray());
79 
80             emit3.move(-3, 0, 0);
81             rootNode.attachChild(emit3);
82         } catch (IOException ex) {
83             ex.printStackTrace();
84         }
85 
86             //        Camera cam2 = cam.clone();
87     //        cam.setViewPortTop(0.5f);
88     //        cam2.setViewPortBottom(0.5f);
89     //        ViewPort vp = renderManager.createMainView("SecondView", cam2);
90     //        viewPort.setClearEnabled(false);
91     //        vp.attachScene(rootNode);
92     }
93 
94 }
95