/******************************************************************************* * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.processeditor.animations; import java.util.List; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import org.simantics.db.Graph; import org.simantics.db.Resource; import org.simantics.processeditor.common.ControlPointTools; import org.simantics.processeditor.stubs.PipeControlPoint; import org.simantics.processeditor.stubs.VariableLengthInlineComponent; import org.simantics.proconf.g3d.animation.Animatable; import org.simantics.proconf.g3d.base.VecmathJmeTools; import com.jme.renderer.ColorRGBA; import com.jme.scene.Node; import com.jmex.effects.particles.ParticleFactory; import com.jmex.effects.particles.ParticleGeometry; public class PipeFlowAnimation implements Animatable{ ParticleGeometry particle; float length; int numParticles; public PipeFlowAnimation(List pipeAnimations, Node particleNode, VariableLengthInlineComponent s, boolean reversed) { PipeControlPoint pcp = s.getControlPoint(); Point3d p1 = new Point3d(); Point3d p2 = new Point3d(); ControlPointTools.getInlineControlPointEnds(pcp, p2, p1); if (reversed) { Point3d t = p1; p1 = p2; p2 = t; } Vector3d dir = new Vector3d(p2); dir.sub(p1); length = (float)dir.length(); //if (length < 0.1f) // return; //continue; // with longer pipes particles will travel too far so the length of the pipe must be scaled length *= 0.83f; float vel = 0.1f; //float size = (float)s.getPipeRadiusValue() + 0.1f; //size *= 2.f; float size = (float)s.getPipeDiameter()[0]; //size *= 1.2f; float life = length/vel; //int releaseRate = 40; //int numParticles = (int)(releaseRate * life / 100.f);//(int)(releaseRate * life / 500.f); numParticles = (int)(length * 2.0); int releaseRate = (int)((numParticles * 500.0) / life); if (numParticles < 2) numParticles = 2; particle = ParticleFactory.buildParticles("Animation of " + s.getResource().getResourceId(),numParticles, ParticleGeometry.PT_QUAD);//new ParticleMesh("Animation of " + r.getId(),40); particle.setEmissionDirection(VecmathJmeTools.get(dir).normalize()); particle.setLocalTranslation(VecmathJmeTools.get(p1)); particle.setEmitType(ParticleGeometry.ET_POINT); particle.setInitialVelocity(vel); particle.setMinimumAngle(0.f); particle.setMaximumAngle(0.f); particle.setReleaseRate(releaseRate); particle.getParticleController().setReleaseVariance(0.f); particle.getParticleController().setControlFlow(true); particle.setStartColor(new ColorRGBA(1.f,1.f,0.f,1.f)); particle.setEndColor(new ColorRGBA(1.f,1.f,0.f,1.f)); particle.setStartSize(size); particle.setEndSize(size); setFlow(vel); particle.getParticleController().setSpeed(vel); particle.warmUp(60); pipeAnimations.add(particle); particleNode.attachChild(particle); } ParticleGeometry getParticleGeometry() { return particle; } private void setFlow(float vel) { float life; if (vel > 0.f) life = length/vel; else life = 0.f; particle.setInitialVelocity(vel); particle.setMaximumLifeTime(life); particle.setMinimumLifeTime(life); particle.getParticleController().setSpeed(vel); } private void setReleaserate(float vel) { float life; if (vel > 0.f) life = length/vel; else life = 0.f; particle.setInitialVelocity(vel); particle.setMaximumLifeTime(life); particle.setMinimumLifeTime(life); particle.setReleaseRate((int)((numParticles * 500.0) / life)); } public void animate(double delta,double frameRate) { //setFlow(0.1f*(float)delta); setReleaserate(0.05f*(float)delta); } public boolean setAnimation(Graph graph, Resource animation) { return false; } public boolean setRandomAnimation(Graph graph) { return false; } }