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.nio.charset.Charset;
21 import java.nio.charset.StandardCharsets;
22
23 import org.apache.commons.geometry.euclidean.threed.mesh.TriangleMesh;
24 import org.apache.commons.geometry.io.core.GeometryFormat;
25 import org.apache.commons.geometry.io.core.input.GeometryInput;
26 import org.apache.commons.geometry.io.core.internal.GeometryIOUtils;
27 import org.apache.commons.geometry.io.euclidean.threed.AbstractBoundaryReadHandler3D;
28 import org.apache.commons.geometry.io.euclidean.threed.FacetDefinitionReader;
29 import org.apache.commons.geometry.io.euclidean.threed.GeometryFormat3D;
30 import org.apache.commons.numbers.core.Precision;
31
32
33
34
35 public class ObjBoundaryReadHandler3D extends AbstractBoundaryReadHandler3D {
36
37
38 private Charset defaultCharset = StandardCharsets.UTF_8;
39
40
41 @Override
42 public GeometryFormat getFormat() {
43 return GeometryFormat3D.OBJ;
44 }
45
46
47
48
49
50 public Charset getDefaultCharset() {
51 return defaultCharset;
52 }
53
54
55
56
57
58 public void setDefaultCharset(final Charset charset) {
59 this.defaultCharset = charset;
60 }
61
62
63 @Override
64 public FacetDefinitionReader facetDefinitionReader(final GeometryInput in) {
65 return new ObjFacetDefinitionReader(createReader(in));
66 }
67
68
69 @Override
70 public TriangleMesh readTriangleMesh(final GeometryInput in, final Precision.DoubleEquivalence precision) {
71 try (ObjTriangleMeshReader meshReader = new ObjTriangleMeshReader(createReader(in), precision)) {
72 return meshReader.readTriangleMesh();
73 }
74 }
75
76
77
78
79
80
81 private Reader createReader(final GeometryInput in) {
82 return GeometryIOUtils.createBufferedReader(in, defaultCharset);
83 }
84 }