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);
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);
-// 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) {
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<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) {
radius2 = (Double)props.get("radius2");
}
+ if (props.containsKey("offset")) {
+ offset = (Double)props.get("offset");
+ }
+
}