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 org.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.processeditor.common.ControlPointTools;
\r
21 import org.simantics.processeditor.stubs.PipeControlPoint;
\r
22 import org.simantics.processeditor.stubs.VariableLengthInlineComponent;
\r
23 import org.simantics.proconf.g3d.animation.Animatable;
\r
24 import org.simantics.proconf.g3d.base.VecmathJmeTools;
\r
26 import com.jme.renderer.ColorRGBA;
\r
27 import com.jme.scene.Node;
\r
28 import com.jmex.effects.particles.ParticleFactory;
\r
29 import com.jmex.effects.particles.ParticleGeometry;
\r
34 public class PipeFlowAnimation implements Animatable{
\r
36 ParticleGeometry particle;
\r
40 public PipeFlowAnimation(List<ParticleGeometry> pipeAnimations, Node particleNode, VariableLengthInlineComponent s, boolean reversed) {
\r
41 PipeControlPoint pcp = s.getControlPoint();
\r
43 Point3d p1 = new Point3d();
\r
44 Point3d p2 = new Point3d();
\r
46 ControlPointTools.getInlineControlPointEnds(pcp, p2, p1);
\r
55 Vector3d dir = new Vector3d(p2);
\r
57 length = (float)dir.length();
\r
58 //if (length < 0.1f)
\r
61 // with longer pipes particles will travel too far so the length of the pipe must be scaled
\r
64 //float size = (float)s.getPipeRadiusValue() + 0.1f;
\r
66 float size = (float)s.getPipeDiameter()[0];
\r
68 float life = length/vel;
\r
70 //int releaseRate = 40;
\r
71 //int numParticles = (int)(releaseRate * life / 100.f);//(int)(releaseRate * life / 500.f);
\r
73 numParticles = (int)(length * 2.0);
\r
74 int releaseRate = (int)((numParticles * 500.0) / life);
\r
76 if (numParticles < 2)
\r
79 particle = ParticleFactory.buildParticles("Animation of " + s.getResource().getResourceId(s.getGraph().getSession()),numParticles, ParticleGeometry.PT_QUAD);//new ParticleMesh("Animation of " + r.getId(),40);
\r
80 particle.setEmissionDirection(VecmathJmeTools.get(dir).normalize());
\r
81 particle.setLocalTranslation(VecmathJmeTools.get(p1));
\r
82 particle.setEmitType(ParticleGeometry.ET_POINT);
\r
83 particle.setInitialVelocity(vel);
\r
84 particle.setMinimumAngle(0.f);
\r
85 particle.setMaximumAngle(0.f);
\r
86 particle.setReleaseRate(releaseRate);
\r
87 particle.getParticleController().setReleaseVariance(0.f);
\r
88 particle.getParticleController().setControlFlow(true);
\r
89 particle.setStartColor(new ColorRGBA(1.f,1.f,0.f,1.f));
\r
90 particle.setEndColor(new ColorRGBA(1.f,1.f,0.f,1.f));
\r
91 particle.setStartSize(size);
\r
92 particle.setEndSize(size);
\r
94 particle.getParticleController().setSpeed(vel);
\r
95 particle.warmUp(60);
\r
96 pipeAnimations.add(particle);
\r
97 particleNode.attachChild(particle);
\r
100 ParticleGeometry getParticleGeometry() {
\r
104 private void setFlow(float vel) {
\r
110 particle.setInitialVelocity(vel);
\r
111 particle.setMaximumLifeTime(life);
\r
112 particle.setMinimumLifeTime(life);
\r
113 particle.getParticleController().setSpeed(vel);
\r
117 private void setReleaserate(float vel) {
\r
123 particle.setInitialVelocity(vel);
\r
124 particle.setMaximumLifeTime(life);
\r
125 particle.setMinimumLifeTime(life);
\r
126 particle.setReleaseRate((int)((numParticles * 500.0) / life));
\r
129 public void animate(double delta,double frameRate) {
\r
130 //setFlow(0.1f*(float)delta);
\r
131 setReleaserate(0.05f*(float)delta);
\r
134 public boolean setAnimation(Graph graph, Resource animation) {
\r
138 public boolean setRandomAnimation(Graph graph) {
\r