]> gerrit.simantics Code Review - simantics/3d.git/blob
e581a1be19e47764e0645c7a248a848f2c798b1e
[simantics/3d.git] /
1 package org.simantics.processeditor.scenegraph;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.Collection;\r
5 import java.util.List;\r
6 \r
7 import javax.vecmath.AxisAngle4d;\r
8 import javax.vecmath.Quat4d;\r
9 \r
10 import org.simantics.db.Graph;\r
11 import org.simantics.db.Resource;\r
12 import org.simantics.layer0.utils.EntityFactory;\r
13 import org.simantics.layer0.utils.IEntity;\r
14 import org.simantics.processeditor.ProcessResource;\r
15 import org.simantics.processeditor.common.ControlPointTools;\r
16 import org.simantics.processeditor.common.PipingTools;\r
17 import org.simantics.processeditor.stubs.CodedComponent;\r
18 import org.simantics.processeditor.stubs.PipeControlPoint;\r
19 import org.simantics.processeditor.stubs.Plant3DResource;\r
20 import org.simantics.processeditor.stubs.SizeChangeControlPoint;\r
21 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
22 import org.simantics.proconf.g3d.scenegraph.IGraphicsNode;\r
23 import org.simantics.proconf.g3d.scenegraph.ShapeNode;\r
24 \r
25 import com.jme.math.Quaternion;\r
26 import com.jme.renderer.ColorRGBA;\r
27 import com.jme.scene.Geometry;\r
28 import com.jme.scene.state.MaterialState;\r
29 import com.jme.scene.state.RenderState;\r
30 \r
31 \r
32 \r
33 /**\r
34  * This is for hard-coded geometries\r
35  * TODO : we need an extension point for geometries,\r
36  *        so that other code-based geometries can be supported\r
37  * \r
38  * \r
39  * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>\r
40  *\r
41  */\r
42 public class PipeComponentNode extends ShapeNode {\r
43         \r
44         enum Type{ELBOW,STRAIGHT,REDUCER};\r
45         \r
46         Type type;\r
47         Resource controlPoint;\r
48 \r
49         \r
50         public PipeComponentNode(ThreeDimensionalEditorBase editor, IGraphicsNode parent, Graph graph, Resource resource) {\r
51                 super(editor, parent, graph, resource);\r
52                 CodedComponent component = new CodedComponent(graph,resource);\r
53                 PipeControlPoint cp = component.getControlPoint();\r
54                 Plant3DResource p3r = ProcessResource.plant3Dresource;\r
55                 controlPoint = cp.getResource();\r
56                 \r
57                 if (component.isInstanceOf(p3r.Elbow)) {\r
58                         type = Type.ELBOW;      \r
59                 } else if (component.isInstanceOf(p3r.Straight)) {\r
60                         type = Type.STRAIGHT;\r
61                 } else if (component.isInstanceOf(p3r.Elbow)) {\r
62                         type = Type.REDUCER;\r
63                 }\r
64         \r
65         \r
66         }\r
67         \r
68         @Override\r
69         public Collection<RenderState> getMaterial() {\r
70                 MaterialState ms = null;\r
71                 ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();\r
72                 ms.setEmissive(new ColorRGBA(0.f,0.f,0.f,0.f));\r
73         ms.setSpecular(new ColorRGBA(1.f,1.f,1.f,1.f));\r
74         ms.setEnabled(true);\r
75         ms.setShininess(128.f);\r
76         if (type == Type.ELBOW) {\r
77                 ms.setDiffuse(new ColorRGBA(0.5f,0.5f,0.5f,0.f));\r
78                 ms.setAmbient(new ColorRGBA(0.5f,0.5f,0.5f,0.f));\r
79         } else if (type == Type.STRAIGHT) {\r
80                 ms.setDiffuse(new ColorRGBA(0.75f,0.75f,0.75f,0.f));\r
81                 ms.setAmbient(new ColorRGBA(0.75f,0.75f,0.75f,0.f));\r
82         } else {\r
83                 ms.setDiffuse(new ColorRGBA(0.6f,0.6f,0.6f,0.f));\r
84                 ms.setAmbient(new ColorRGBA(0.6f,0.6f,0.6f,0.f));\r
85         } \r
86                 List<RenderState> states = new ArrayList<RenderState>();\r
87                 states.add(ms);\r
88                 return states;\r
89         }\r
90         \r
91         \r
92         @Override\r
93         public void updateTransform(Graph graph) {\r
94                 if (type == Type.REDUCER) {\r
95                         SizeChangeControlPoint sccp = new SizeChangeControlPoint(graph, controlPoint);\r
96                         Quat4d q = ControlPointTools.getControlPointLocalOrientationQuat(sccp, sccp.getRotationAngle()[0], true);\r
97                         update(q);\r
98                 } \r
99                 if (type != Type.STRAIGHT) {\r
100                         super.updateTransform(graph);\r
101                 } else {\r
102                         transform.setLocalTranslation(0.f,0.f,0.f);\r
103                         transform.setLocalRotation(new Quaternion());\r
104                 }\r
105         }\r
106 \r
107 }\r