X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fgeometry%2FReducerGeometryProvider.java;h=c82eab565bbafda5835a1cb69b55efbf962c8008;hb=a7945695983a62d0e1d25a4a1400458f16bcfd70;hp=d3387f799181226eda8fe0ae373ec674d8a5bb4d;hpb=22bb24d2a7e26c70b0dd4c57080f2c25ac3d40a8;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java index d3387f79..c82eab56 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/geometry/ReducerGeometryProvider.java @@ -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,12 +26,12 @@ public class ReducerGeometryProvider extends BuiltinGeometryProvider { private double radius = 0.01; private double radius2 = 0.02; + private double offset = 0.0; - @Override +// @Override public Collection 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); -// System.out.println("Reducer " + length + " " + radius + " " + radius2); + if (radius < MathTools.NEAR_ZERO || radius2 < MathTools.NEAR_ZERO) + return Collections.emptyList(); double length = Math.max(0.1, Math.abs(radius-radius2)*4.0); TopoDS_Shape shape; if (Math.abs(radius-radius2) < MathTools.NEAR_ZERO) { @@ -33,6 +42,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 || radius < MathTools.NEAR_ZERO || radius2 < MathTools.NEAR_ZERO) + return null; + Tube tube = new Tube(); + tube.setResolution(16); + List vertices = new ArrayList(); + List radius = new ArrayList(); + List tangents = new ArrayList(); + 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 props) { @@ -44,6 +76,12 @@ public class ReducerGeometryProvider extends BuiltinGeometryProvider { radius2 = (Double)props.get("radius2"); } + if (props.containsKey("offset")) { + offset = (Double)props.get("offset"); + } else { + offset = 0.0; + } + }