]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java
Added support for eccentric reducers
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / ReducerGeometryProvider.java
index d3387f799181226eda8fe0ae373ec674d8a5bb4d..5ca0330dd34d0c38e12c248af81e7902d4d1605b 100644 (file)
@@ -1,15 +1,24 @@
 package org.simantics.plant3d.geometry;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 
+import javax.vecmath.Point3d;
+import javax.vecmath.Tuple3d;
+import javax.vecmath.Vector3d;
+
 import org.jcae.opencascade.jni.TopoDS_Shape;
 import org.simantics.db.Resource;
 import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.shape.Mesh;
+import org.simantics.g3d.shape.Tube;
 import org.simantics.opencascade.OccTriangulator;
 
-public class ReducerGeometryProvider extends BuiltinGeometryProvider  {
+//public class ReducerGeometryProvider extends BuiltinGeometryProvider  {
+public class ReducerGeometryProvider extends BuiltinMeshProvider  {
        
        public ReducerGeometryProvider(Resource resource) {
                super(resource);
@@ -17,8 +26,9 @@ public class ReducerGeometryProvider extends BuiltinGeometryProvider  {
 
        private double radius = 0.01;
        private double radius2 = 0.02;
+       private double offset = 0.0;
        
-       @Override
+//     @Override
        public Collection<TopoDS_Shape> getModel() throws Exception {
 //             GP_Circ circ = new GP_Circ(new double[]{-length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius);
 //             GP_Circ circ2 = new GP_Circ(new double[]{length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius2);
@@ -33,6 +43,29 @@ public class ReducerGeometryProvider extends BuiltinGeometryProvider  {
                return Collections.singletonList(shape);
        }
        
+       @Override
+       public Mesh getMesh() {
+               double length = Math.max(0.1, Math.abs(radius-radius2)*4.0);
+               if (length < .0001)
+                       return null;
+               Tube tube = new Tube();
+               tube.setResolution(16);
+               List<Tuple3d> vertices = new ArrayList<Tuple3d>();
+               List<Double> radius = new ArrayList<Double>();
+               List<Vector3d> tangents = new ArrayList<Vector3d>();
+               vertices.add(new Point3d(-length*0.5, 0.0, 0.0));
+               vertices.add(new Point3d( length*0.5, offset, 0.0));
+               radius.add(this.radius);
+               radius.add(this.radius2);
+               tangents.add(new Vector3d(1.0,0.0,0.0));
+               tangents.add(new Vector3d(1.0,0.0,0.0));
+               tube.setVertices(vertices);
+               tube.setRadiis(radius);
+               tube.setTangents(tangents);
+               tube.setCap(false);
+               return tube.create();
+       }
+       
        @Override
        public void setProperties(Map<String, Object> props) {
 
@@ -44,6 +77,10 @@ public class ReducerGeometryProvider extends BuiltinGeometryProvider  {
                        radius2 = (Double)props.get("radius2");
                }
                
+               if (props.containsKey("offset")) {
+                       offset = (Double)props.get("offset");
+               }
+               
                
                
        }