1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package fi.vtt.simantics.processeditor.animations;
\r
13 import java.util.List;
\r
15 import javax.vecmath.Point3d;
\r
16 import javax.vecmath.Vector3d;
\r
18 import org.simantics.db.Graph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.proconf.g3d.animation.Animatable;
\r
21 import org.simantics.proconf.g3d.base.G3DTools;
\r
22 import org.simantics.proconf.g3d.base.VecmathJmeTools;
\r
24 import com.jme.renderer.ColorRGBA;
\r
25 import com.jme.scene.Node;
\r
26 import com.jmex.effects.particles.ParticleFactory;
\r
27 import com.jmex.effects.particles.ParticleGeometry;
\r
30 import fi.vtt.simantics.processeditor.common.ControlPointTools;
\r
31 import fi.vtt.simantics.processeditor.common.PipingTools2;
\r
32 import fi.vtt.simantics.processeditor.stubs.PipeControlPoint;
\r
33 import fi.vtt.simantics.processeditor.stubs.VariableLengthInlineComponent;
\r
36 public class PipeFlowAnimation implements Animatable{
\r
38 ParticleGeometry particle;
\r
42 public PipeFlowAnimation(List<ParticleGeometry> pipeAnimations, Node particleNode, VariableLengthInlineComponent s, boolean reversed) {
\r
43 PipeControlPoint pcp = s.getControlPoint();
\r
45 Point3d p1 = new Point3d();
\r
46 Point3d p2 = new Point3d();
\r
48 ControlPointTools.getInlineControlPointEnds(pcp, p2, p1);
\r
57 Vector3d dir = new Vector3d(p2);
\r
59 length = (float)dir.length();
\r
60 //if (length < 0.1f)
\r
63 // with longer pipes particles will travel too far so the length of the pipe must be scaled
\r
66 //float size = (float)s.getPipeRadiusValue() + 0.1f;
\r
68 float size = (float)s.getPipeDiameter()[0];
\r
70 float life = length/vel;
\r
72 //int releaseRate = 40;
\r
73 //int numParticles = (int)(releaseRate * life / 100.f);//(int)(releaseRate * life / 500.f);
\r
75 numParticles = (int)(length * 2.0);
\r
76 int releaseRate = (int)((numParticles * 500.0) / life);
\r
78 if (numParticles < 2)
\r
81 particle = ParticleFactory.buildParticles("Animation of " + s.getResource().getResourceId(),numParticles, ParticleGeometry.PT_QUAD);//new ParticleMesh("Animation of " + r.getId(),40);
\r
82 particle.setEmissionDirection(VecmathJmeTools.get(dir).normalize());
\r
83 particle.setLocalTranslation(VecmathJmeTools.get(p1));
\r
84 particle.setEmitType(ParticleGeometry.ET_POINT);
\r
85 particle.setInitialVelocity(vel);
\r
86 particle.setMinimumAngle(0.f);
\r
87 particle.setMaximumAngle(0.f);
\r
88 particle.setReleaseRate(releaseRate);
\r
89 particle.getParticleController().setReleaseVariance(0.f);
\r
90 particle.getParticleController().setControlFlow(true);
\r
91 particle.setStartColor(new ColorRGBA(1.f,1.f,0.f,1.f));
\r
92 particle.setEndColor(new ColorRGBA(1.f,1.f,0.f,1.f));
\r
93 particle.setStartSize(size);
\r
94 particle.setEndSize(size);
\r
96 particle.getParticleController().setSpeed(vel);
\r
97 particle.warmUp(60);
\r
98 pipeAnimations.add(particle);
\r
99 particleNode.attachChild(particle);
\r
102 ParticleGeometry getParticleGeometry() {
\r
106 private void setFlow(float vel) {
\r
112 particle.setInitialVelocity(vel);
\r
113 particle.setMaximumLifeTime(life);
\r
114 particle.setMinimumLifeTime(life);
\r
115 particle.getParticleController().setSpeed(vel);
\r
119 private void setReleaserate(float vel) {
\r
125 particle.setInitialVelocity(vel);
\r
126 particle.setMaximumLifeTime(life);
\r
127 particle.setMinimumLifeTime(life);
\r
128 particle.setReleaseRate((int)((numParticles * 500.0) / life));
\r
131 public void animate(double delta,double frameRate) {
\r
132 //setFlow(0.1f*(float)delta);
\r
133 setReleaserate(0.05f*(float)delta);
\r
136 public boolean setAnimation(Graph graph, Resource animation) {
\r
140 public boolean setRandomAnimation(Graph graph) {
\r