]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Let root node determine up direction for rotation angle calculations 91/3891/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Thu, 20 Feb 2020 14:28:50 +0000 (16:28 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Thu, 20 Feb 2020 14:31:06 +0000 (16:31 +0200)
gitlab #85

Change-Id: I549af4f0b93cbf3867e334165db8c2dacee12968

org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/P3DRootNode.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java

index 27b1d471bf97733e9fe46bbadc79a85b5898470f..7a5ce551a7c317c16df776455125398213378934 100644 (file)
@@ -27,7 +27,9 @@ import vtk.vtkProp;
 @GraphType(Plant3D.URIs.Plant)
 public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapProvider<Resource, vtkProp, INode> {
        
-       
+       // Vertical direction that determines the interpretation of rotation angle origin
+       protected Vector3d upVector = new Vector3d(0.0, 1.0, 0.0);
+
        @RelatedElementsAdd(Plant3D.URIs.children)
        public void addChild(INode node) {
        //public void addChild(IP3DVisualNode node) {
@@ -183,4 +185,8 @@ public class P3DRootNode extends ParentNode<INode> implements IG3DNode, NodeMapP
        public TurnComponent createTurn() {
                return new TurnComponent();
        }
+
+       public Vector3d getUpVector() {
+               return upVector;
+       }
 }
index 2905d26c4493058b1483705c8a2df8e68a9ba209..72ef4e687a0f378d24400f94ff79405585c61179 100644 (file)
@@ -15,6 +15,7 @@ import javax.vecmath.Vector3d;
 import org.simantics.g3d.math.MathTools;
 import org.simantics.g3d.property.annotations.GetPropertyValue;
 import org.simantics.g3d.scenegraph.G3DNode;
+import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.plant3d.scenegraph.IP3DNode;
 import org.simantics.plant3d.scenegraph.Nozzle;
 import org.simantics.plant3d.scenegraph.P3DRootNode;
@@ -581,15 +582,24 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
                if (dir == null || dir.lengthSquared() < MathTools.NEAR_ZERO)
                        return MathTools.getIdentityQuat();
 
-               Vector3d up = new Vector3d(0.0, 1.0, 0.0);
+               final P3DRootNode root = getRoot();
+               Vector3d up = root != null ? new Vector3d(root.getUpVector()) : new Vector3d(0.0, 1.0, 0.0);
                double a = up.angle(getPathLegEndpointVector());
                if (a < 0.1 || (Math.PI - a) < 0.1) {
-                       up.set(1.0, 0.0, 0.0);
+                       // Rotate components
+                       up.set(up.getY(), up.getZ(), up.getX());
                }
 
                return getControlPointOrientationQuat(dir, up, angle);
        }
 
+       public P3DRootNode getRoot() {
+               INode n = getParent();
+               while (n != null && !(n instanceof P3DRootNode))
+                       n = n.getParent();
+               return (P3DRootNode) n;
+       }
+
        public static Quat4d getControlPointOrientationQuat(Vector3d dir, Vector3d up,  double angle) {
                if (dir == null || dir.lengthSquared() < MathTools.NEAR_ZERO)
                        return MathTools.getIdentityQuat();
@@ -600,7 +610,8 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
 
 
                Vector3d right = new Vector3d();
-
+               
+               up = new Vector3d(up);
                right.cross(dir, up);
                up.cross(right, dir);
                right.normalize();