]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/geometry/StraightGeometryProvider.java
Remove dependencies on log4j
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / StraightGeometryProvider.java
1 package org.simantics.plant3d.geometry;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Map;
6
7 import javax.vecmath.Point3d;
8 import javax.vecmath.Tuple3d;
9 import javax.vecmath.Vector3d;
10
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;
15
16 //public class StraightGeometryProvider extends BuiltinGeometryProvider {
17 public class StraightGeometryProvider extends BuiltinMeshProvider {
18         
19         public StraightGeometryProvider(Resource resource) {
20                 super(resource);
21         }
22
23         private double length = 1.0;
24         private double radius = 0.01;
25         
26 //      @Override
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);
31 //      }
32         
33         @Override
34         public Mesh getMesh() {
35                 if (length < .0001 || radius < MathTools.NEAR_ZERO )
36                         return null;
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);
51                 tube.setCap(false);
52                 return tube.create();
53         }
54         
55         @Override
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");
61                 }
62                 if (length < 0.0)
63                         length = 0.0;
64                 if (radius < MathTools.NEAR_ZERO)
65                         radius = MathTools.NEAR_ZERO;
66                 
67         }
68         
69         
70
71 }