]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/shape/Box.java
Mesh API to use Tuple3d instead of Vector3d
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / shape / Box.java
1 package org.simantics.g3d.shape;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.vecmath.Vector3d;
7
8 public class Box {
9         
10         Vector3d min;
11         Vector3d max;
12         
13         public Vector3d getMin() {
14                 return min;
15         }
16         public Vector3d getMax() {
17                 return max;
18         }
19         
20         public Box(Vector3d min, Vector3d max) {
21                 this.max = max;
22                 this.min = min;
23         }
24         
25         public Box(double minx, double miny, double minz, double maxx, double maxy, double maxz) {
26                 min = new Vector3d(minx, miny, minz);
27                 max = new Vector3d(maxx, maxy, maxz);
28         }
29         
30         public Box(double min[], double max[]) {
31                 this.min = new Vector3d(min);
32                 this.max = new Vector3d(max);
33         }
34         
35         public Mesh createMesh() {
36                 List<Vector3d> vertices = new ArrayList<Vector3d>();
37                 vertices.add(new Vector3d(min.x, min.y, min.z));
38                 vertices.add(new Vector3d(min.x, min.y, max.z));
39                 vertices.add(new Vector3d(min.x, max.y, min.z));
40                 vertices.add(new Vector3d(min.x, max.y, max.z));
41                 vertices.add(new Vector3d(max.x, min.y, min.z));
42                 vertices.add(new Vector3d(max.x, min.y, max.z));
43                 vertices.add(new Vector3d(max.x, max.y, min.z));
44                 vertices.add(new Vector3d(max.x, max.y, max.z));
45                 List<Integer> indices = new ArrayList<Integer>();
46                 indices.add(0);
47                 indices.add(2);
48                 indices.add(1);
49                 
50                 indices.add(1);
51                 indices.add(2);
52                 indices.add(3);
53                 
54                 indices.add(2);
55                 indices.add(6);
56                 indices.add(3);
57                 
58                 indices.add(3);
59                 indices.add(6);
60                 indices.add(7);
61                 
62                 indices.add(5);
63                 indices.add(1);
64                 indices.add(7);
65                 
66                 indices.add(1);
67                 indices.add(3);
68                 indices.add(7);
69                 
70                 indices.add(4);
71                 indices.add(5);
72                 indices.add(6);
73                 
74                 indices.add(5);
75                 indices.add(7);
76                 indices.add(6);
77                 
78                 indices.add(0);
79                 indices.add(4);
80                 indices.add(2);
81                 
82                 indices.add(2);
83                 indices.add(4);
84                 indices.add(6);
85                 
86                 indices.add(0);
87                 indices.add(1);
88                 indices.add(4);
89                 
90                 indices.add(5);
91                 indices.add(4);
92                 indices.add(1);
93                 return Mesh.create(vertices, indices);
94         }
95
96 }