JavaCAD
SubdivisionMesh.java
Go to the documentation of this file.
1 
2 /*
3  * Copyright (c) 2010, 2014, Oracle and/or its affiliates.
4  * All rights reserved. Use is subject to license terms.
5  *
6  * This file is available and licensed under the following license:
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * - Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * - Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the distribution.
17  * - Neither the name of Oracle Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */package eu.mihosoft.vrl.v3d.ext.openjfx.shape3d;
33 
34 
35 
36 import eu.mihosoft.vrl.v3d.ext.openjfx.shape3d.symbolic.SymbolicPolygonMesh;
37 import eu.mihosoft.vrl.v3d.ext.openjfx.shape3d.symbolic.SymbolicSubdivisionBuilder;
38 import java.util.ArrayList;
39 import java.util.List;
40 
41 // TODO: Auto-generated Javadoc
45 public class SubdivisionMesh extends PolygonMesh {
46 
48  private final PolygonMesh originalMesh;
49 
51  private int subdivisionLevel;
52 
55 
58 
60  private final List<SymbolicPolygonMesh> symbolicMeshes;
61 
63  private boolean pointValuesDirty;
64 
66  private boolean meshDirty;
67 
69  private boolean subdivisionLevelDirty;
70 
75  public enum BoundaryMode {
76 
79 
81  CREASE_ALL
82  }
83 
87  public enum MapBorderMode {
88 
91 
94 
96  SMOOTH_ALL
97  }
98 
108  this.originalMesh = originalMesh;
112 
113  symbolicMeshes = new ArrayList<>(4); // the polymesh is usually subdivided up to 3 times
114 
115  originalMesh.getPoints().addListener((observableArray, sizeChanged, from, to) -> {
116  if (sizeChanged) {
117  meshDirty = true;
118  } else {
119  pointValuesDirty = true;
120  }
121  });
122  originalMesh.getTexCoords().addListener((observableArray, sizeChanged, from, to) -> meshDirty = true);
123  }
124 
129  public void update() {
130  if (meshDirty) {
131  symbolicMeshes.clear();
133  pointValuesDirty = true;
134  subdivisionLevelDirty = true;
135  }
136 
137  while (subdivisionLevel >= symbolicMeshes.size()) {
139  pointValuesDirty = true;
140  subdivisionLevelDirty = true;
141  }
142 
143  if (pointValuesDirty) {
144  for (int i = 0; i <= subdivisionLevel; i++) {
145  SymbolicPolygonMesh symbolicMesh = symbolicMeshes.get(i);
146  symbolicMesh.points.update();
147  }
148  }
149 
151  getPoints().setAll(symbolicMeshes.get(subdivisionLevel).points.data);
152  }
153 
154  if (subdivisionLevelDirty) {
156  numEdgesInFaces = -1;
157  getFaceSmoothingGroups().setAll(symbolicMeshes.get(subdivisionLevel).faceSmoothingGroups);
158  getTexCoords().setAll(symbolicMeshes.get(subdivisionLevel).texCoords);
159  }
160 
161  meshDirty = false;
162  pointValuesDirty = false;
163  subdivisionLevelDirty = false;
164  }
165 
172  this.subdivisionLevel = subdivisionLevel;
173  subdivisionLevelDirty = true;
174  }
175 
182  this.boundaryMode = boundaryMode;
183  meshDirty = true;
184  }
185 
192  this.mapBorderMode = mapBorderMode;
193  meshDirty = true;
194  }
195 
202  return originalMesh;
203  }
204 
210  public int getSubdivisionLevel() {
211  return subdivisionLevel;
212  }
213 
220  if (subdivisionLevel != this.subdivisionLevel) {
222  }
223  }
224 
231  return boundaryMode;
232  }
233 
240  if (boundaryMode != this.boundaryMode) {
242  }
243  }
244 
251  return mapBorderMode;
252  }
253 
260  if (mapBorderMode != this.mapBorderMode) {
262  }
263  }
264 }
void setBoundaryModeForced(SubdivisionMesh.BoundaryMode boundaryMode)
SubdivisionMesh(PolygonMesh originalMesh, int subdivisionLevel, BoundaryMode boundaryMode, MapBorderMode mapBorderMode)
void setMapBorderModeForced(SubdivisionMesh.MapBorderMode mapBorderMode)
void setMapBorderMode(SubdivisionMesh.MapBorderMode mapBorderMode)
void setBoundaryMode(SubdivisionMesh.BoundaryMode boundaryMode)