19
19
import java .util .ArrayList ;
20
20
21
21
import eu .mihosoft .vrl .v3d .Vector3d ;
22
+ import eu .mihosoft .vrl .v3d .Vertex ;
22
23
23
24
;
24
25
@@ -60,10 +61,10 @@ public STLLoader() {
60
61
61
62
/** The vertices. */
62
63
// attributes of the currently read mesh
63
- private ArrayList <Vector3d > vertices = new ArrayList <>();
64
+ private ArrayList <Vertex > vertices = new ArrayList <>();
64
65
65
66
/** The normal. */
66
- private Vector3d normal = new Vector3d (0.0f , 0.0f , 0.0f ); // to be used for file checking
67
+ // private Vector3d normal = new Vector3d(0.0f, 0.0f, 0.0f); // to be used for file checking
67
68
68
69
/** The fis. */
69
70
private FileInputStream fis ;
@@ -79,7 +80,7 @@ public STLLoader() {
79
80
* @return the array list
80
81
* @throws IOException Signals that an I/O exception has occurred.
81
82
*/
82
- public ArrayList <Vector3d > parse (File f ) throws IOException {
83
+ public ArrayList <Vertex > parse (File f ) throws IOException {
83
84
vertices .clear ();
84
85
85
86
// determine if this is a binary or ASCII STL
@@ -132,14 +133,15 @@ private void parseAscii(File f) {
132
133
}
133
134
vertices = new ArrayList <>();
134
135
try {
136
+ Vector3d normal = new Vector3d (0 , 0 ,0 );
135
137
while ((line = in .readLine ()) != null ) {
136
138
String [] numbers = line .trim ().split ("\\ s+" );
137
139
if (numbers [0 ].equals ("vertex" )) {
138
140
double x = parseDouble (numbers [1 ]);
139
141
double y = parseDouble (numbers [2 ]);
140
142
double z = parseDouble (numbers [3 ]);
141
143
Vector3d vertex = new Vector3d (x , y , z );
142
- vertices .add (vertex );
144
+ vertices .add (new Vertex ( vertex , normal ) );
143
145
} else if (numbers [0 ].equals ("facet" ) && numbers [1 ].equals ("normal" )) {
144
146
normal .x = parseDouble (numbers [2 ]);
145
147
normal .y = parseDouble (numbers [3 ]);
@@ -160,7 +162,7 @@ private void parseAscii(File f) {
160
162
* @param f the f
161
163
*/
162
164
private void parseBinary (File f ) {
163
- vertices = new ArrayList <Vector3d >();
165
+ vertices = new ArrayList <Vertex >();
164
166
try {
165
167
fis = new FileInputStream (f );
166
168
for (int h = 0 ; h < 84 ; h ++) {
@@ -171,6 +173,7 @@ private void parseBinary(File f) {
171
173
for (int tb = 0 ; tb < 50 ; tb ++) {
172
174
tri [tb ] = (byte ) fis .read ();
173
175
}
176
+ Vector3d normal = new Vector3d (0 , 0 ,0 );
174
177
normal .x = leBytesToFloat (tri [0 ], tri [1 ], tri [2 ], tri [3 ]);
175
178
normal .y = leBytesToFloat (tri [4 ], tri [5 ], tri [6 ], tri [7 ]);
176
179
normal .z = leBytesToFloat (tri [8 ], tri [9 ], tri [10 ], tri [11 ]);
@@ -180,7 +183,7 @@ private void parseBinary(File f) {
180
183
double py = leBytesToFloat (tri [j + 4 ], tri [j + 5 ], tri [j + 6 ], tri [j + 7 ]);
181
184
double pz = leBytesToFloat (tri [j + 8 ], tri [j + 9 ], tri [j + 10 ], tri [j + 11 ]);
182
185
Vector3d p = new Vector3d (px , py , pz );
183
- vertices .add (p );
186
+ vertices .add (new Vertex ( p , normal ) );
184
187
}
185
188
}
186
189
fis .close ();
0 commit comments