+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.processeditor.animations;\r
-\r
-import java.net.URL;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.FileLocator;\r
-import org.eclipse.core.runtime.Path;\r
-import org.simantics.db.Graph;\r
-import org.simantics.layer0.utils.IEntity;\r
-import org.simantics.processeditor.Activator;\r
-import org.simantics.processeditor.ProcessResource;\r
-import org.simantics.processeditor.stubs.PipeRun;\r
-import org.simantics.processeditor.stubs.VariableLengthInlineComponent;\r
-import org.simantics.proconf.g3d.animation.Animatable;\r
-import org.simantics.proconf.g3d.animation.AnimationController;\r
-import org.simantics.proconf.g3d.base.JmeRenderingComponent;\r
-\r
-import com.jme.bounding.BoundingBox;\r
-import com.jme.image.Texture;\r
-import com.jme.intersection.PickResults;\r
-import com.jme.math.Ray;\r
-import com.jme.renderer.Renderer;\r
-import com.jme.scene.Node;\r
-import com.jme.scene.state.AlphaState;\r
-import com.jme.scene.state.TextureState;\r
-import com.jme.scene.state.ZBufferState;\r
-import com.jme.util.TextureManager;\r
-import com.jmex.effects.particles.ParticleGeometry;\r
-\r
-\r
-\r
-public class PipeAnimationController implements AnimationController {\r
- private List<ParticleGeometry> pipeAnimations = new ArrayList<ParticleGeometry>();\r
- \r
- List<PipeFlowAnimation> animatables = new ArrayList<PipeFlowAnimation>();\r
- \r
- private double d = Math.random();\r
- private double delta = 0.01;\r
- \r
- AlphaState as1;\r
- TextureState ts;\r
- Node particleNode = new Node() {\r
- private static final long serialVersionUID = 7477121374264124684L;\r
-\r
- // Without this picking code tries to pick particles which doesn't work (Causes class cast exception)\r
- public void findPick(Ray toTest, PickResults results) {\r
- return;\r
- }\r
- };\r
- \r
- public PipeAnimationController(JmeRenderingComponent component, PipeRun pipeline) {\r
- as1 = component.getDisplaySystem().getRenderer().createAlphaState();\r
- as1.setBlendEnabled(true);\r
- as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);\r
- as1.setDstFunction(AlphaState.DB_ONE);\r
- //as1.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);\r
- as1.setTestEnabled(true);\r
- as1.setTestFunction(AlphaState.TF_GREATER);\r
- as1.setEnabled(true);\r
-\r
- TextureState ts = component.getDisplaySystem().getRenderer().createTextureState();\r
- //URL url = FileLocator.find(com.jme.eclipse.Activator.getDefault().getBundle(),new Path("data/textures/flaresmall.jpg"),null);\r
- URL url = FileLocator.find(Activator.getDefault().getBundle(),new Path("icons/bubble.png"),null);\r
- \r
- ts.setTexture(\r
- TextureManager.loadTexture(url,\r
- Texture.MM_LINEAR_LINEAR,\r
- Texture.FM_LINEAR));\r
- ts.setEnabled(true);\r
- \r
- ZBufferState zs = component.getDisplaySystem().getRenderer().createZBufferState();\r
- zs.setFunction(ZBufferState.CF_LEQUAL);\r
- zs.setWritable(false);\r
- //zs.setFunction(ZBufferState.CF_ALWAYS);\r
- particleNode.setRenderState(as1);\r
- particleNode.setRenderState(ts);\r
- particleNode.setRenderState(zs);\r
- particleNode.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);\r
- component.getShadowRoot().attachChild(particleNode);\r
- createAnimations(pipeline);\r
- }\r
- \r
- public void addAnimatable(Animatable animatable) {\r
- animatables.add((PipeFlowAnimation)animatable);\r
- \r
- }\r
- \r
- public void setAnimatable(Animatable animatable) {\r
- animatables.clear();\r
- animatables.add((PipeFlowAnimation)animatable);\r
- \r
- }\r
- \r
- \r
- public void updateAnimation(Graph g, double frameTime) {\r
- d += delta;\r
- if (d > 1.0) {\r
- d = 1.0;\r
- delta = -delta;\r
- } else if (d < 0.0) {\r
- delta = -delta;\r
- d = 0.0;\r
- }\r
- for (Animatable a : animatables)\r
- a.animate(d,frameTime); \r
- }\r
- \r
- public void dispose() {\r
- for (ParticleGeometry p : pipeAnimations)\r
- p.removeFromParent();\r
- pipeAnimations.clear();\r
- \r
- }\r
- \r
- private void createAnimations(PipeRun pipeline) {\r
- List<IEntity> straights = new ArrayList<IEntity>();\r
- for (IEntity t : pipeline.getChild()) {\r
- if (t.isInstanceOf(ProcessResource.plant3Dresource.VariableLengthInlineComponent))\r
- straights.add(t);\r
- }\r
- \r
- for (IEntity r : straights) {\r
- animatables.add(new PipeFlowAnimation(pipeAnimations, particleNode, new VariableLengthInlineComponent(r),false));\r
- }\r
- particleNode.setModelBound(new BoundingBox());\r
- particleNode.updateModelBound();\r
- particleNode.updateRenderState();\r
- }\r
-\r
-}\r