|
2 | 2 | Copyright (c) 2021-2025 Armin Reichert (MIT License)
|
3 | 3 | See file LICENSE in repository root directory for details.
|
4 | 4 | */
|
5 |
| - |
6 | 5 | /*
|
7 | 6 | * Copyright (c) 2010, 2014, Oracle and/or its affiliates.
|
8 | 7 | * All rights reserved. Use is subject to license terms.
|
|
48 | 47 | import java.io.InputStreamReader;
|
49 | 48 | import java.net.URL;
|
50 | 49 | import java.nio.charset.Charset;
|
51 |
| -import java.time.Duration; |
52 |
| -import java.time.Instant; |
53 | 50 | import java.util.ArrayList;
|
54 | 51 | import java.util.HashMap;
|
55 | 52 | import java.util.List;
|
|
58 | 55 | import static java.util.Objects.requireNonNull;
|
59 | 56 |
|
60 | 57 | /**
|
61 |
| - * Derived from Oracle's OBJ importer from the 3DViewer sample project. |
| 58 | + * Code is based on Oracle's OBJ importer from the 3DViewer sample project. |
62 | 59 | *
|
63 | 60 | * @see <a href=
|
64 | 61 | * "https://github.com/teamfx/openjfx-10-dev-rt/tree/master/apps/samples/3DViewer/src/main/java/com/javafx/experiments/importers">3DViewer
|
@@ -117,14 +114,8 @@ public static ObjFileData importObjFile(URL url, Charset charset) {
|
117 | 114 | requireNonNull(charset);
|
118 | 115 | ObjFileImporter importer = new ObjFileImporter(url);
|
119 | 116 | try (InputStream is = url.openStream()) {
|
120 |
| - Instant start = Instant.now(); |
121 | 117 | var reader = new BufferedReader(new InputStreamReader(is, charset));
|
122 | 118 | importer.parse(reader);
|
123 |
| - for (TriangleMesh mesh : importer.data.triangleMeshMap.values()) { |
124 |
| - validateTriangleMesh(mesh); |
125 |
| - } |
126 |
| - Duration duration = Duration.between(start, Instant.now()); |
127 |
| - Logger.info("OBJ file parsed in {} milliseconds; '{}'", duration.toMillis(), url); |
128 | 119 | }
|
129 | 120 | catch (IOException x) {
|
130 | 121 | Logger.error(x);
|
@@ -400,25 +391,25 @@ private void commitCurrentMesh() {
|
400 | 391 | mesh.getPoints().setAll(verticesArray);
|
401 | 392 | mesh.getTexCoords().setAll(texCoordsArray);
|
402 | 393 |
|
403 |
| - int[] faces = toIntArray(restOf(data.facesList, facesStart)); |
| 394 | + final int[] faces = toIntArray(restOf(data.facesList, facesStart)); |
404 | 395 | mesh.getFaces().setAll(faces);
|
405 | 396 |
|
406 |
| - int[] smoothingGroups = useNormals |
| 397 | + final int[] smoothingGroups = useNormals |
407 | 398 | ? computeSmoothingGroups(mesh, faces, toIntArray(restOf(data.faceNormalsList, facesNormalStart)), toFloatArray(normalsArray))
|
408 | 399 | : toIntArray(restOf(data.smoothingGroupList, smoothingGroupsStart));
|
409 | 400 | mesh.getFaceSmoothingGroups().setAll(smoothingGroups);
|
410 | 401 |
|
411 | 402 | // try specified name, if already used, make unique name using serial number e.g. "my_mesh (3)"
|
412 | 403 | int serialNumber = 2;
|
413 |
| - String nextMeshName = meshName; |
414 |
| - while (data.triangleMeshMap.containsKey(nextMeshName)) { |
415 |
| - Logger.info("Mesh name '{}' already exists", nextMeshName); |
416 |
| - nextMeshName = "%s (%d)".formatted(meshName, serialNumber); |
| 404 | + String unusedMeshName = meshName; |
| 405 | + while (data.triangleMeshMap.containsKey(unusedMeshName)) { |
| 406 | + Logger.info("Mesh name '{}' already exists", unusedMeshName); |
| 407 | + unusedMeshName = "%s (%d)".formatted(meshName, serialNumber); |
417 | 408 | ++serialNumber;
|
418 | 409 | }
|
419 |
| - data.triangleMeshMap.put(nextMeshName, mesh); |
| 410 | + data.triangleMeshMap.put(unusedMeshName, mesh); |
420 | 411 |
|
421 |
| - Logger.trace("Mesh '{}' added, vertices: {}, uvs: {}, faces: {}, smoothing groups: {}", |
| 412 | + Logger.trace("Added mesh '{}', vertices: {}, texture coordinates: {}, faces: {}, smoothing groups: {}", |
422 | 413 | meshName,
|
423 | 414 | mesh.getPoints().size() / mesh.getPointElementSize(),
|
424 | 415 | mesh.getTexCoords().size() / mesh.getTexCoordElementSize(),
|
|
0 commit comments