1 package org.simantics.plant3d.geometry;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
9 import javax.vecmath.Point3d;
10 import javax.vecmath.Tuple3d;
11 import javax.vecmath.Vector3d;
13 import org.jcae.opencascade.jni.TopoDS_Shape;
14 import org.simantics.db.Resource;
15 import org.simantics.g3d.math.MathTools;
16 import org.simantics.g3d.shape.Mesh;
17 import org.simantics.g3d.shape.Tube;
18 import org.simantics.opencascade.OccTriangulator;
20 //public class ReducerGeometryProvider extends BuiltinGeometryProvider {
21 public class ReducerGeometryProvider extends BuiltinMeshProvider {
23 public ReducerGeometryProvider(Resource resource) {
27 private double radius = 0.01;
28 private double radius2 = 0.02;
29 private double offset = 0.0;
32 public Collection<TopoDS_Shape> getModel() throws Exception {
33 if (radius < MathTools.NEAR_ZERO || radius2 < MathTools.NEAR_ZERO)
34 return Collections.emptyList();
35 double length = Math.max(0.1, Math.abs(radius-radius2)*4.0);
37 if (Math.abs(radius-radius2) < MathTools.NEAR_ZERO) {
38 shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
40 shape = OccTriangulator.makeCone(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius,radius2, length);
42 return Collections.singletonList(shape);
46 public Mesh getMesh() {
47 double length = Math.max(0.1, Math.abs(radius-radius2)*4.0);
48 if (length < .0001 || radius < MathTools.NEAR_ZERO || radius2 < MathTools.NEAR_ZERO)
50 Tube tube = new Tube();
51 tube.setResolution(16);
52 List<Tuple3d> vertices = new ArrayList<Tuple3d>();
53 List<Double> radius = new ArrayList<Double>();
54 List<Vector3d> tangents = new ArrayList<Vector3d>();
55 vertices.add(new Point3d(-length*0.5, 0.0, 0.0));
56 vertices.add(new Point3d( length*0.5, offset, 0.0));
57 radius.add(this.radius);
58 radius.add(this.radius2);
59 tangents.add(new Vector3d(1.0,0.0,0.0));
60 tangents.add(new Vector3d(1.0,0.0,0.0));
61 tube.setVertices(vertices);
62 tube.setRadiis(radius);
63 tube.setTangents(tangents);
69 public void setProperties(Map<String, Object> props) {
72 if (props.containsKey("radius")) {
73 radius = (Double)props.get("radius");
75 if (props.containsKey("radius2")) {
76 radius2 = (Double)props.get("radius2");
79 if (props.containsKey("offset")) {
80 offset = (Double)props.get("offset");
88 public void updateCalculatedProperties(Map<String, Object> returnProps) {
89 returnProps.put("length", Math.max(0.1, Math.abs(radius-radius2)*4.0));