1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.geometry.io.euclidean.threed.obj;
18
19 import java.io.Reader;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.apache.commons.geometry.euclidean.threed.Vector3D;
24 import org.apache.commons.geometry.io.euclidean.threed.FacetDefinition;
25 import org.apache.commons.geometry.io.euclidean.threed.FacetDefinitionReader;
26 import org.apache.commons.geometry.io.euclidean.threed.SimpleFacetDefinition;
27
28
29
30 public class ObjFacetDefinitionReader extends AbstractObjPolygonReader
31 implements FacetDefinitionReader {
32
33
34 private final List<Vector3D> vertices = new ArrayList<>();
35
36
37 private final List<Vector3D> normals = new ArrayList<>();
38
39
40
41
42 public ObjFacetDefinitionReader(final Reader reader) {
43 super(reader);
44 }
45
46
47 @Override
48 public FacetDefinition readFacet() {
49 final PolygonObjParser.Face face = readFace();
50 if (face != null) {
51 final List<Vector3D> faceVertices = face.getVertices(vertices::get);
52 final Vector3D definedNormal = face.getDefinedCompositeNormal(normals::get);
53
54 return new SimpleFacetDefinition(faceVertices, definedNormal);
55 }
56
57 return null;
58 }
59
60
61 @Override
62 protected void handleVertex(final Vector3D vertex) {
63 vertices.add(vertex);
64 }
65
66
67 @Override
68 protected void handleNormal(final Vector3D normal) {
69 normals.add(normal);
70 }
71 }