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 // GP_Circ circ = new GP_Circ(new double[]{-length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius);
34 // GP_Circ circ2 = new GP_Circ(new double[]{length*0.5, 0.0, 0.0,1.0,0.0,0.0}, radius2);
35 // System.out.println("Reducer " + length + " " + radius + " " + radius2);
36 double length = Math.max(0.1, Math.abs(radius-radius2)*4.0);
38 if (Math.abs(radius-radius2) < MathTools.NEAR_ZERO) {
39 shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
41 shape = OccTriangulator.makeCone(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius,radius2, length);
43 return Collections.singletonList(shape);
47 public Mesh getMesh() {
48 double length = Math.max(0.1, Math.abs(radius-radius2)*4.0);
51 Tube tube = new Tube();
52 tube.setResolution(16);
53 List<Tuple3d> vertices = new ArrayList<Tuple3d>();
54 List<Double> radius = new ArrayList<Double>();
55 List<Vector3d> tangents = new ArrayList<Vector3d>();
56 vertices.add(new Point3d(-length*0.5, 0.0, 0.0));
57 vertices.add(new Point3d( length*0.5, offset, 0.0));
58 radius.add(this.radius);
59 radius.add(this.radius2);
60 tangents.add(new Vector3d(1.0,0.0,0.0));
61 tangents.add(new Vector3d(1.0,0.0,0.0));
62 tube.setVertices(vertices);
63 tube.setRadiis(radius);
64 tube.setTangents(tangents);
70 public void setProperties(Map<String, Object> props) {
73 if (props.containsKey("radius")) {
74 radius = (Double)props.get("radius");
76 if (props.containsKey("radius2")) {
77 radius2 = (Double)props.get("radius2");
80 if (props.containsKey("offset")) {
81 offset = (Double)props.get("offset");
89 public void updateCalculatedProperties(Map<String, Object> returnProps) {
90 returnProps.put("length", Math.max(0.1, Math.abs(radius-radius2)*4.0));