1 package org.simantics.plant3d.geometry;
3 import java.util.ArrayList;
7 import javax.vecmath.Point3d;
8 import javax.vecmath.Tuple3d;
9 import javax.vecmath.Vector3d;
11 import org.simantics.db.Resource;
12 import org.simantics.g3d.math.MathTools;
13 import org.simantics.g3d.shape.Mesh;
14 import org.simantics.g3d.shape.Tube;
16 //public class StraightGeometryProvider extends BuiltinGeometryProvider {
17 public class StraightGeometryProvider extends BuiltinMeshProvider {
19 public StraightGeometryProvider(Resource resource) {
23 private double length = 1.0;
24 private double radius = 0.01;
27 // public Collection<TopoDS_Shape> getModel() throws Exception {
28 // TopoDS_Shape shape = OccTriangulator.makeCylinder(new double[] {-length*0.5, 0.0, 0.0}, new double[] { 1.0, 0.0, 0.0 }, radius, length);
29 // System.out.println("Create straight l:" + length + " r:" + radius);
30 // return Collections.singletonList(shape);
34 public Mesh getMesh() {
35 if (length < .0001 || radius < MathTools.NEAR_ZERO )
37 Tube tube = new Tube();
38 tube.setResolution(16);
39 List<Tuple3d> vertices = new ArrayList<Tuple3d>();
40 List<Double> radius = new ArrayList<Double>();
41 List<Vector3d> tangents = new ArrayList<Vector3d>();
42 vertices.add(new Point3d(-length*0.5, 0.0, 0.0));
43 vertices.add(new Point3d( length*0.5, 0.0, 0.0));
44 radius.add(this.radius);
45 radius.add(this.radius);
46 tangents.add(new Vector3d(1.0,0.0,0.0));
47 tangents.add(new Vector3d(1.0,0.0,0.0));
48 tube.setVertices(vertices);
49 tube.setRadiis(radius);
50 tube.setTangents(tangents);
56 public void setProperties(Map<String, Object> props) {
57 if (props.containsKey("length"))
58 length = (Double)props.get("length");
59 if (props.containsKey("radius")) {
60 radius = (Double)props.get("radius");
64 if (radius < MathTools.NEAR_ZERO)
65 radius = MathTools.NEAR_ZERO;