]> gerrit.simantics Code Review - simantics/3d.git/blob
7ff93957ab119b1d5e084a8b1d200077afb2b9b4
[simantics/3d.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\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 org.simantics.proconf.g3d.shapeeditor.scenegraph;\r
12 \r
13 \r
14 import org.simantics.db.Graph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.proconf.g3d.base.GeometryProviderRegistry;\r
17 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
18 import org.simantics.proconf.g3d.scenegraph.IGraphicsNode;\r
19 import org.simantics.proconf.g3d.scenegraph.ShapeNode;\r
20 \r
21 import com.jme.scene.Geometry;\r
22 import com.jme.scene.state.AlphaState;\r
23 import com.jme.scene.state.ZBufferState;\r
24 \r
25 \r
26 \r
27 public class CSGShapeNode extends ShapeNode{\r
28 \r
29         \r
30     //protected Geometry axesGeometry = null;\r
31     protected boolean axesVisible = false;\r
32 \r
33     public CSGShapeNode(ThreeDimensionalEditorBase editor,IGraphicsNode parent, Graph graph, Resource shapeResource) {\r
34         super(editor,parent, graph,shapeResource);\r
35         //axesGeometry = AxesShape.getShape(editor.getRenderingComponent().getDisplaySystem().getRenderer());\r
36         ZBufferState zs = editor.getRenderingComponent().getDisplaySystem().getRenderer().createZBufferState();\r
37         zs.setFunction(ZBufferState.CF_ALWAYS);\r
38         AlphaState as = editor.getRenderingComponent().getDisplaySystem().getRenderer().createAlphaState();\r
39         as.setBlendEnabled(true);\r
40         as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);\r
41         as.setSrcFunction(AlphaState.DB_SRC_ALPHA);\r
42 //        axesGeometry.setRenderState(zs);\r
43 //        axesGeometry.setRenderState(as);\r
44 //        axesGeometry.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);\r
45     }\r
46 \r
47     \r
48 \r
49    public Geometry[] getGeometry(Graph graph) {\r
50            \r
51        return GeometryProviderRegistry.getGeometry(getG3DNode(graph), false);\r
52    }\r
53    \r
54    public void updateAllGeometry() {\r
55            //System.out.println("CSGSHapeNode.updateAllGeometry " + shapeResource.getResourceId());\r
56            editor.getScenegraphAdapter().updateGeometry(shapeResource);\r
57        if (parent != null && parent instanceof CSGShapeNode) {\r
58            ((CSGShapeNode)parent).updateAllGeometry();\r
59        }\r
60        \r
61    }\r
62    \r
63    @Override\r
64         public void updateGeometry(Graph graph) {\r
65                 super.updateGeometry(graph);\r
66                 if (isAxesVisible()) {\r
67                         //getGroup().attachChild(axesGeometry);\r
68                 } else {\r
69                         //axesGeometry.removeFromParent();\r
70                 }\r
71         }\r
72 \r
73 \r
74    \r
75    public boolean isAxesVisible() {\r
76        return axesVisible;\r
77    }\r
78 \r
79    public void setAxesVisible(boolean axesVisible) {\r
80        \r
81        if (this.axesVisible == axesVisible)\r
82            return;\r
83        this.axesVisible = axesVisible;\r
84        if (isAxesVisible()) {\r
85         //getGroup().getParent().attachChild(axesGeometry);\r
86            //getGroup().attachChild(axesGeometry);\r
87        } else {\r
88         //axesGeometry.removeFromParent();\r
89        }\r
90    }\r
91    \r
92    public void setSelected(boolean selected) {\r
93        if (this.selected == selected)\r
94            return;\r
95        this.selected = selected;\r
96        if (selected) {\r
97 \r
98            setSelectedVisible(true);\r
99            setAxesVisible(true);\r
100            setTransparentVisible(true);\r
101        } else {\r
102            setSelectedVisible(false);\r
103            setAxesVisible(false);\r
104            setTransparentVisible(false);\r
105        }\r
106    }\r
107 \r
108 }\r