]> gerrit.simantics Code Review - simantics/3d.git/blob
43505000e32172286ea8d01ee551daedc972abc2
[simantics/3d.git] /
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package fi.vtt.simantics.processeditor.animations;\r
12 \r
13 import org.simantics.db.Graph;\r
14 import org.simantics.db.Resource;\r
15 import org.simantics.proconf.g3d.base.JmeRenderingComponent;\r
16 \r
17 import com.jme.renderer.ColorRGBA;\r
18 \r
19 import fi.vtt.simantics.processeditor.stubs.PipeRun;\r
20 \r
21 // TODO : this class won't work with valueSets\r
22 public class ResourcePipeAnimationController extends PipeAnimationController {\r
23         Resource color;\r
24         Resource velocity;\r
25         \r
26         ColorRGBA minColor = new ColorRGBA(0.f,0.f,1.f,1.f);\r
27         ColorRGBA maxColor = new ColorRGBA(1.f,0.f,0.f,1.f);\r
28         ColorRGBA currentColor = new ColorRGBA(1.f,1.f,1.f,1.f);\r
29         \r
30         double colorMin;\r
31         double colorMax;\r
32         double iColorRange;\r
33         \r
34         double velMin;\r
35         double velMax;\r
36         double iVelRange;\r
37         public ResourcePipeAnimationController(JmeRenderingComponent component, PipeRun pipeline, Resource color,double colorMin, double colorMax, Resource velocity, double velMin, double velMax) {\r
38                 super(component, pipeline);\r
39                 this.color = color;\r
40                 this.velocity = velocity;\r
41                 \r
42                 this.colorMin = colorMin;\r
43                 this.colorMax = colorMax;\r
44                 this.iColorRange = 1.0/(colorMax-colorMin);\r
45                 this.velMin = velMin;\r
46                 this.velMax = velMax;\r
47                 this.iVelRange = 1.0/(velMax-velMin);\r
48         }\r
49         \r
50         private double getVelocity(Graph graph) {\r
51                 return graph.getScalarDouble(velocity);\r
52                 //velocity.getDoubleScalarValue();\r
53         }\r
54         \r
55         private double getColor(Graph graph) {\r
56                 return graph.getScalarDouble(color);\r
57         }\r
58         public void updateAnimation(Graph g,double frameTime) {\r
59                 double d = (getVelocity(g)-velMin)*iVelRange;\r
60                 float f = (float)((getColor(g)-colorMin)*iColorRange);\r
61         currentColor.interpolate(minColor, maxColor, f);\r
62                 for (PipeFlowAnimation a : animatables) {\r
63             a.animate(d,frameTime);     \r
64             //a.getParticleGeometry().setDefaultColor(currentColor);\r
65             a.getParticleGeometry().setStartColor(currentColor);\r
66             a.getParticleGeometry().setEndColor(currentColor);\r
67         }\r
68         }\r
69         \r
70         \r
71 \r
72 }\r