@itwin/core-geometry 4.5.0-dev.3 → 4.5.0-dev.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -1
- package/LICENSE.md +1 -1
- package/lib/cjs/Geometry.d.ts +15 -0
- package/lib/cjs/Geometry.d.ts.map +1 -1
- package/lib/cjs/Geometry.js +27 -0
- package/lib/cjs/Geometry.js.map +1 -1
- package/lib/cjs/curve/CoordinateXYZ.d.ts +10 -13
- package/lib/cjs/curve/CoordinateXYZ.d.ts.map +1 -1
- package/lib/cjs/curve/CoordinateXYZ.js +16 -15
- package/lib/cjs/curve/CoordinateXYZ.js.map +1 -1
- package/lib/cjs/curve/GeometryQuery.d.ts +17 -17
- package/lib/cjs/curve/GeometryQuery.d.ts.map +1 -1
- package/lib/cjs/curve/GeometryQuery.js +16 -15
- package/lib/cjs/curve/GeometryQuery.js.map +1 -1
- package/lib/cjs/curve/PointString3d.d.ts +17 -13
- package/lib/cjs/curve/PointString3d.d.ts.map +1 -1
- package/lib/cjs/curve/PointString3d.js +35 -20
- package/lib/cjs/curve/PointString3d.js.map +1 -1
- package/lib/cjs/curve/spiral/MXCubicAlongArcSpiralEvaluator.js +1 -1
- package/lib/cjs/curve/spiral/MXCubicAlongArcSpiralEvaluator.js.map +1 -1
- package/lib/cjs/curve/spiral/PolishCubicSpiralEvaluator.js +1 -1
- package/lib/cjs/curve/spiral/PolishCubicSpiralEvaluator.js.map +1 -1
- package/lib/cjs/geometry3d/FrameBuilder.d.ts.map +1 -1
- package/lib/cjs/geometry3d/FrameBuilder.js +3 -0
- package/lib/cjs/geometry3d/FrameBuilder.js.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYZArray.d.ts +8 -2
- package/lib/cjs/geometry3d/GrowableXYZArray.d.ts.map +1 -1
- package/lib/cjs/geometry3d/GrowableXYZArray.js +11 -2
- package/lib/cjs/geometry3d/GrowableXYZArray.js.map +1 -1
- package/lib/cjs/polyface/IndexedPolyfaceVisitor.d.ts +42 -50
- package/lib/cjs/polyface/IndexedPolyfaceVisitor.d.ts.map +1 -1
- package/lib/cjs/polyface/IndexedPolyfaceVisitor.js +81 -105
- package/lib/cjs/polyface/IndexedPolyfaceVisitor.js.map +1 -1
- package/lib/cjs/polyface/Polyface.d.ts +166 -120
- package/lib/cjs/polyface/Polyface.d.ts.map +1 -1
- package/lib/cjs/polyface/Polyface.js +251 -162
- package/lib/cjs/polyface/Polyface.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceBuilder.d.ts +18 -10
- package/lib/cjs/polyface/PolyfaceBuilder.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceBuilder.js +27 -21
- package/lib/cjs/polyface/PolyfaceBuilder.js.map +1 -1
- package/lib/cjs/polyface/PolyfaceData.d.ts +142 -86
- package/lib/cjs/polyface/PolyfaceData.d.ts.map +1 -1
- package/lib/cjs/polyface/PolyfaceData.js +305 -164
- package/lib/cjs/polyface/PolyfaceData.js.map +1 -1
- package/lib/cjs/serialization/GeometrySamples.js.map +1 -1
- package/lib/cjs/topology/Graph.d.ts +2 -8
- package/lib/cjs/topology/Graph.d.ts.map +1 -1
- package/lib/cjs/topology/Graph.js +0 -3
- package/lib/cjs/topology/Graph.js.map +1 -1
- package/lib/cjs/topology/Triangulation.d.ts +18 -7
- package/lib/cjs/topology/Triangulation.d.ts.map +1 -1
- package/lib/cjs/topology/Triangulation.js +50 -9
- package/lib/cjs/topology/Triangulation.js.map +1 -1
- package/lib/esm/Geometry.d.ts +15 -0
- package/lib/esm/Geometry.d.ts.map +1 -1
- package/lib/esm/Geometry.js +27 -0
- package/lib/esm/Geometry.js.map +1 -1
- package/lib/esm/curve/CoordinateXYZ.d.ts +10 -13
- package/lib/esm/curve/CoordinateXYZ.d.ts.map +1 -1
- package/lib/esm/curve/CoordinateXYZ.js +16 -15
- package/lib/esm/curve/CoordinateXYZ.js.map +1 -1
- package/lib/esm/curve/GeometryQuery.d.ts +17 -17
- package/lib/esm/curve/GeometryQuery.d.ts.map +1 -1
- package/lib/esm/curve/GeometryQuery.js +16 -15
- package/lib/esm/curve/GeometryQuery.js.map +1 -1
- package/lib/esm/curve/PointString3d.d.ts +17 -13
- package/lib/esm/curve/PointString3d.d.ts.map +1 -1
- package/lib/esm/curve/PointString3d.js +35 -20
- package/lib/esm/curve/PointString3d.js.map +1 -1
- package/lib/esm/curve/spiral/MXCubicAlongArcSpiralEvaluator.js +1 -1
- package/lib/esm/curve/spiral/MXCubicAlongArcSpiralEvaluator.js.map +1 -1
- package/lib/esm/curve/spiral/PolishCubicSpiralEvaluator.js +1 -1
- package/lib/esm/curve/spiral/PolishCubicSpiralEvaluator.js.map +1 -1
- package/lib/esm/geometry3d/FrameBuilder.d.ts.map +1 -1
- package/lib/esm/geometry3d/FrameBuilder.js +3 -0
- package/lib/esm/geometry3d/FrameBuilder.js.map +1 -1
- package/lib/esm/geometry3d/GrowableXYZArray.d.ts +8 -2
- package/lib/esm/geometry3d/GrowableXYZArray.d.ts.map +1 -1
- package/lib/esm/geometry3d/GrowableXYZArray.js +11 -2
- package/lib/esm/geometry3d/GrowableXYZArray.js.map +1 -1
- package/lib/esm/polyface/IndexedPolyfaceVisitor.d.ts +42 -50
- package/lib/esm/polyface/IndexedPolyfaceVisitor.d.ts.map +1 -1
- package/lib/esm/polyface/IndexedPolyfaceVisitor.js +80 -103
- package/lib/esm/polyface/IndexedPolyfaceVisitor.js.map +1 -1
- package/lib/esm/polyface/Polyface.d.ts +166 -120
- package/lib/esm/polyface/Polyface.d.ts.map +1 -1
- package/lib/esm/polyface/Polyface.js +251 -162
- package/lib/esm/polyface/Polyface.js.map +1 -1
- package/lib/esm/polyface/PolyfaceBuilder.d.ts +18 -10
- package/lib/esm/polyface/PolyfaceBuilder.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceBuilder.js +27 -21
- package/lib/esm/polyface/PolyfaceBuilder.js.map +1 -1
- package/lib/esm/polyface/PolyfaceData.d.ts +142 -86
- package/lib/esm/polyface/PolyfaceData.d.ts.map +1 -1
- package/lib/esm/polyface/PolyfaceData.js +305 -164
- package/lib/esm/polyface/PolyfaceData.js.map +1 -1
- package/lib/esm/serialization/GeometrySamples.js.map +1 -1
- package/lib/esm/topology/Graph.d.ts +2 -8
- package/lib/esm/topology/Graph.d.ts.map +1 -1
- package/lib/esm/topology/Graph.js +0 -3
- package/lib/esm/topology/Graph.js.map +1 -1
- package/lib/esm/topology/Triangulation.d.ts +18 -7
- package/lib/esm/topology/Triangulation.d.ts.map +1 -1
- package/lib/esm/topology/Triangulation.js +50 -9
- package/lib/esm/topology/Triangulation.js.map +1 -1
- package/package.json +4 -3
|
@@ -9,6 +9,7 @@ exports.IndexedPolyface = exports.Polyface = void 0;
|
|
|
9
9
|
* @module Polyface
|
|
10
10
|
*/
|
|
11
11
|
/* eslint-disable @typescript-eslint/naming-convention, no-empty */
|
|
12
|
+
// cspell:word internaldocs
|
|
12
13
|
const GeometryQuery_1 = require("../curve/GeometryQuery");
|
|
13
14
|
const Geometry_1 = require("../Geometry");
|
|
14
15
|
const GrowableXYArray_1 = require("../geometry3d/GrowableXYArray");
|
|
@@ -24,6 +25,7 @@ const PolyfaceData_1 = require("./PolyfaceData");
|
|
|
24
25
|
* @public
|
|
25
26
|
*/
|
|
26
27
|
class Polyface extends GeometryQuery_1.GeometryQuery {
|
|
28
|
+
/** Constructor */
|
|
27
29
|
constructor(data) {
|
|
28
30
|
super();
|
|
29
31
|
/** String name for schema properties */
|
|
@@ -31,70 +33,103 @@ class Polyface extends GeometryQuery_1.GeometryQuery {
|
|
|
31
33
|
this.data = data;
|
|
32
34
|
}
|
|
33
35
|
/** Flag indicating if the mesh display must assume both sides are visible. */
|
|
34
|
-
get twoSided() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
get twoSided() {
|
|
37
|
+
return this.data.twoSided;
|
|
38
|
+
}
|
|
39
|
+
set twoSided(value) {
|
|
40
|
+
this.data.twoSided = value;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Flag indicating if the mesh closure is unknown (0), open sheet (1), closed solid (2).
|
|
44
|
+
* * A boundary edge of a mesh is defined as an edge with only one connected facet.
|
|
45
|
+
* * Closed solid is a mesh with no boundary edge. Open sheet is a mesh that has boundary edge(s).
|
|
46
|
+
*/
|
|
47
|
+
get expectedClosure() {
|
|
48
|
+
return this.data.expectedClosure;
|
|
49
|
+
}
|
|
50
|
+
set expectedClosure(value) {
|
|
51
|
+
this.data.expectedClosure = value;
|
|
52
|
+
}
|
|
39
53
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
* Check validity of indices into a data array.
|
|
55
|
+
* * It is valid to have both indices and data undefined.
|
|
56
|
+
* * It is NOT valid for just one to be defined.
|
|
57
|
+
* * Index values at indices[indexPositionA <= i < indexPositionB] must be valid indices to the data array.
|
|
58
|
+
* @param indices array of indices.
|
|
59
|
+
* @param indexPositionA first index to test.
|
|
60
|
+
* @param indexPositionB one past final index to test.
|
|
61
|
+
* @param data data array.
|
|
62
|
+
* @param dataLength length of data array.
|
|
63
|
+
*/
|
|
50
64
|
static areIndicesValid(indices, indexPositionA, indexPositionB, data, dataLength) {
|
|
51
65
|
if (indices === undefined && data === undefined)
|
|
52
66
|
return true;
|
|
53
|
-
if (
|
|
67
|
+
if (indices === undefined || data === undefined)
|
|
54
68
|
return false;
|
|
55
69
|
if (indexPositionA < 0 || indexPositionA >= indices.length)
|
|
56
70
|
return false;
|
|
57
|
-
if (indexPositionB
|
|
71
|
+
if (indexPositionB <= indexPositionA || indexPositionB > indices.length)
|
|
58
72
|
return false;
|
|
59
73
|
for (let i = indexPositionA; i < indexPositionB; i++)
|
|
60
74
|
if (indices[i] < 0 || indices[i] >= dataLength)
|
|
61
75
|
return false;
|
|
62
76
|
return true;
|
|
63
77
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns the number of facets of this polyface. Subclasses should override.
|
|
66
|
-
*/
|
|
78
|
+
/** Returns the number of facets of this polyface. Subclasses should override. */
|
|
67
79
|
get facetCount() {
|
|
68
80
|
return undefined;
|
|
69
81
|
}
|
|
70
82
|
}
|
|
71
83
|
exports.Polyface = Polyface;
|
|
72
84
|
/**
|
|
73
|
-
* An `IndexedPolyface` is a set of facets which can have normal, param, and color arrays with independent point,
|
|
85
|
+
* An `IndexedPolyface` is a set of facets which can have normal, param, and color arrays with independent point,
|
|
86
|
+
* normal, param, and color indices.
|
|
74
87
|
* @public
|
|
75
88
|
*/
|
|
76
89
|
class IndexedPolyface extends Polyface {
|
|
90
|
+
/**
|
|
91
|
+
* Constructor for a new polyface.
|
|
92
|
+
* @param data PolyfaceData arrays to capture.
|
|
93
|
+
* @param facetStart optional array of facet start indices (e.g. known during clone)
|
|
94
|
+
* @param facetToFacetData optional array of face identifiers (e.g. known during clone)
|
|
95
|
+
*/
|
|
96
|
+
constructor(data, facetStart, facetToFaceData) {
|
|
97
|
+
super(data);
|
|
98
|
+
if (facetStart)
|
|
99
|
+
this._facetStart = facetStart.slice(); // deep copy
|
|
100
|
+
else {
|
|
101
|
+
this._facetStart = [];
|
|
102
|
+
this._facetStart.push(0);
|
|
103
|
+
}
|
|
104
|
+
if (facetToFaceData)
|
|
105
|
+
this._facetToFaceData = facetToFaceData.slice(); // deep copy
|
|
106
|
+
else
|
|
107
|
+
this._facetToFaceData = [];
|
|
108
|
+
}
|
|
77
109
|
/** Test if other is an instance of `IndexedPolyface` */
|
|
78
|
-
isSameGeometryClass(other) {
|
|
110
|
+
isSameGeometryClass(other) {
|
|
111
|
+
return other instanceof IndexedPolyface;
|
|
112
|
+
}
|
|
79
113
|
/** Tests for equivalence between two IndexedPolyfaces. */
|
|
80
114
|
isAlmostEqual(other) {
|
|
81
115
|
if (other instanceof IndexedPolyface) {
|
|
82
|
-
return this.data.isAlmostEqual(other.data) &&
|
|
116
|
+
return this.data.isAlmostEqual(other.data) &&
|
|
117
|
+
PointHelpers_1.NumberArray.isExactEqual(this._facetStart, other._facetStart) &&
|
|
83
118
|
PointHelpers_1.NumberArray.isExactEqual(this._facetToFaceData, other._facetToFaceData);
|
|
84
119
|
}
|
|
85
120
|
return false;
|
|
86
121
|
}
|
|
122
|
+
/** Returns true if either the point array or the point index array is empty. */
|
|
123
|
+
get isEmpty() {
|
|
124
|
+
return this.data.pointCount === 0 || this.data.pointIndex.length === 0;
|
|
125
|
+
}
|
|
87
126
|
/**
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
* * apply the transform to points
|
|
93
|
-
* * apply the (inverse transpose of) the matrix part to normals
|
|
94
|
-
* * If determinant is negative, also
|
|
127
|
+
* Transform the mesh.
|
|
128
|
+
* * Apply the transform to points.
|
|
129
|
+
* * Apply the (inverse transpose of the) matrix part to normals.
|
|
130
|
+
* * If determinant of the transform matrix is negative, also
|
|
95
131
|
* * negate normals
|
|
96
132
|
* * reverse index order around each facet.
|
|
97
|
-
* @param transform
|
|
98
133
|
*/
|
|
99
134
|
tryTransformInPlace(transform) {
|
|
100
135
|
if (!this.data.tryTransformInPlace(transform))
|
|
@@ -115,52 +150,47 @@ class IndexedPolyface extends Polyface {
|
|
|
115
150
|
const result = new IndexedPolyface(this.data.clone(), this._facetStart.slice(), this._facetToFaceData.slice());
|
|
116
151
|
return result;
|
|
117
152
|
}
|
|
118
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Return a deep clone with transformed points and normals.
|
|
155
|
+
* @see [[IndexedPolyface.tryTransformInPlace]] for details of how transform is done.
|
|
156
|
+
*/
|
|
119
157
|
cloneTransformed(transform) {
|
|
120
158
|
const result = this.clone();
|
|
121
159
|
result.tryTransformInPlace(transform);
|
|
122
160
|
return result;
|
|
123
161
|
}
|
|
124
162
|
/** Reverse the order of indices around all facets. */
|
|
125
|
-
reverseIndices() {
|
|
163
|
+
reverseIndices() {
|
|
164
|
+
this.data.reverseIndices(this._facetStart);
|
|
165
|
+
}
|
|
126
166
|
/** Reverse the direction of all normal vectors. */
|
|
127
|
-
reverseNormals() {
|
|
128
|
-
|
|
167
|
+
reverseNormals() {
|
|
168
|
+
this.data.reverseNormals();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Return face data using a facet index.
|
|
172
|
+
* * Returns `undefined` if none found.
|
|
173
|
+
* * This is the REFERENCE to the FacetFaceData not a copy.
|
|
174
|
+
*/
|
|
129
175
|
tryGetFaceData(i) {
|
|
176
|
+
if (i < 0 || i >= this._facetToFaceData.length)
|
|
177
|
+
return undefined;
|
|
130
178
|
const faceIndex = this._facetToFaceData[i];
|
|
131
|
-
if (faceIndex >= this.data.face.length)
|
|
179
|
+
if (faceIndex < 0 || faceIndex >= this.data.face.length)
|
|
132
180
|
return undefined;
|
|
133
181
|
return this.data.face[faceIndex];
|
|
134
182
|
}
|
|
135
183
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*/
|
|
141
|
-
constructor(data, facetStart, facetToFaceData) {
|
|
142
|
-
super(data);
|
|
143
|
-
if (facetStart)
|
|
144
|
-
this._facetStart = facetStart.slice();
|
|
145
|
-
else {
|
|
146
|
-
this._facetStart = [];
|
|
147
|
-
this._facetStart.push(0);
|
|
148
|
-
}
|
|
149
|
-
if (facetToFaceData)
|
|
150
|
-
this._facetToFaceData = facetToFaceData.slice();
|
|
151
|
-
else
|
|
152
|
-
this._facetToFaceData = [];
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* * Add facets from source to this polyface.
|
|
156
|
-
* * Optionally reverse facet indices as per PolyfaceData.reverseIndicesSingleFacet() with preserveStart = false, and invert source normals.
|
|
157
|
-
* * Optionally apply a transform to points and normals.
|
|
184
|
+
* Add facets from `source` to `this` polyface.
|
|
185
|
+
* * Optionally reverse facet indices as per `PolyfaceData.reverseIndicesSingleFacet()` with `preserveStart = false` and
|
|
186
|
+
* invert source normals.
|
|
187
|
+
* * Optionally apply a `transform` to points and normals.
|
|
158
188
|
* * Will only copy param, normal, color, and face data if we are already tracking them AND/OR the source contains them.
|
|
159
189
|
*/
|
|
160
190
|
addIndexedPolyface(source, reversed, transform) {
|
|
161
191
|
const numSourceFacets = source.facetCount;
|
|
162
|
-
//
|
|
163
|
-
//
|
|
192
|
+
// add point, point index, and edge visibility data
|
|
193
|
+
// note that there is no need to build an intermediate index map since all points are added
|
|
164
194
|
const startOfNewPoints = this.data.point.length;
|
|
165
195
|
const xyz = Point3dVector3d_1.Point3d.create();
|
|
166
196
|
for (let i = 0; i < source.data.point.length; i++) {
|
|
@@ -187,11 +217,11 @@ class IndexedPolyface extends Polyface {
|
|
|
187
217
|
}
|
|
188
218
|
this.terminateFacet(false);
|
|
189
219
|
}
|
|
190
|
-
//
|
|
220
|
+
// add param and param index data
|
|
191
221
|
if (undefined !== this.data.param && undefined !== source.data.param && undefined !== source.data.paramIndex) {
|
|
192
222
|
const startOfNewParams = this.data.param.length;
|
|
193
223
|
this.data.param.pushFromGrowableXYArray(source.data.param);
|
|
194
|
-
for (let i = 0; i < numSourceFacets; i++) { //
|
|
224
|
+
for (let i = 0; i < numSourceFacets; i++) { // expect facet start and ends for points to match normals
|
|
195
225
|
const i0 = source._facetStart[i];
|
|
196
226
|
const i1 = source._facetStart[i + 1];
|
|
197
227
|
if (reversed) {
|
|
@@ -204,7 +234,7 @@ class IndexedPolyface extends Polyface {
|
|
|
204
234
|
}
|
|
205
235
|
}
|
|
206
236
|
}
|
|
207
|
-
//
|
|
237
|
+
// add normal and normal index data
|
|
208
238
|
if (undefined !== this.data.normal && undefined !== source.data.normal && undefined !== source.data.normalIndex) {
|
|
209
239
|
const startOfNewNormals = this.data.normal.length;
|
|
210
240
|
for (let i = 0; i < source.data.normal.length; i++) {
|
|
@@ -215,7 +245,7 @@ class IndexedPolyface extends Polyface {
|
|
|
215
245
|
sourceNormal.scaleInPlace(-1.0);
|
|
216
246
|
this.addNormal(sourceNormal);
|
|
217
247
|
}
|
|
218
|
-
for (let i = 0; i < numSourceFacets; i++) { //
|
|
248
|
+
for (let i = 0; i < numSourceFacets; i++) { // expect facet start and ends for points to match normals
|
|
219
249
|
const i0 = source._facetStart[i];
|
|
220
250
|
const i1 = source._facetStart[i + 1];
|
|
221
251
|
if (reversed) {
|
|
@@ -228,12 +258,12 @@ class IndexedPolyface extends Polyface {
|
|
|
228
258
|
}
|
|
229
259
|
}
|
|
230
260
|
}
|
|
231
|
-
//
|
|
261
|
+
// add color and color index data
|
|
232
262
|
if (undefined !== this.data.color && undefined !== source.data.color && undefined !== source.data.colorIndex) {
|
|
233
263
|
const startOfNewColors = this.data.color.length;
|
|
234
264
|
for (const sourceColor of source.data.color)
|
|
235
265
|
this.addColor(sourceColor);
|
|
236
|
-
for (let i = 0; i < numSourceFacets; i++) { //
|
|
266
|
+
for (let i = 0; i < numSourceFacets; i++) { // expect facet start and ends for points to match colors
|
|
237
267
|
const i0 = source._facetStart[i];
|
|
238
268
|
const i1 = source._facetStart[i + 1];
|
|
239
269
|
if (reversed) {
|
|
@@ -246,7 +276,7 @@ class IndexedPolyface extends Polyface {
|
|
|
246
276
|
}
|
|
247
277
|
}
|
|
248
278
|
}
|
|
249
|
-
//
|
|
279
|
+
// add face and facetToFace index data
|
|
250
280
|
if (source.data.face.length !== 0) {
|
|
251
281
|
const startOfNewFaceData = this.data.face.length;
|
|
252
282
|
for (const face of source.data.face) {
|
|
@@ -258,25 +288,31 @@ class IndexedPolyface extends Polyface {
|
|
|
258
288
|
}
|
|
259
289
|
}
|
|
260
290
|
}
|
|
261
|
-
/**
|
|
262
|
-
*
|
|
291
|
+
/**
|
|
292
|
+
* Return the total number of indices in zero-terminated style, which includes
|
|
293
|
+
* * all the indices in the packed zero-based table.
|
|
263
294
|
* * one additional index for the zero-terminator of each facet.
|
|
264
|
-
* @note Note that all index arrays (
|
|
295
|
+
* @note Note that all index arrays (pointIndex, normalIndex, paramIndex, colorIndex) have the same counts, so there
|
|
265
296
|
* is not a separate query for each of them.
|
|
266
297
|
*/
|
|
267
|
-
get zeroTerminatedIndexCount() {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
*
|
|
298
|
+
get zeroTerminatedIndexCount() {
|
|
299
|
+
return this.data.pointIndex.length + this._facetStart.length - 1;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Create an empty facet set with coordinate and index data to be supplied later.
|
|
303
|
+
* @param needNormals `true` to allocate empty normal data and index arrays; `false` (default) to leave undefined.
|
|
304
|
+
* @param needParams `true` to allocate empty uv parameter data and index arrays; `false` (default) to leave undefined.
|
|
305
|
+
* @param needColors `true` to allocate empty color data and index arrays; `false` (default) to leave undefined.
|
|
306
|
+
* @param twoSided `true` if the facets are to be considered viewable from the back; `false` (default) if not.
|
|
272
307
|
*/
|
|
273
308
|
static create(needNormals = false, needParams = false, needColors = false, twoSided = false) {
|
|
274
309
|
return new IndexedPolyface(new PolyfaceData_1.PolyfaceData(needNormals, needParams, needColors, twoSided));
|
|
275
310
|
}
|
|
276
|
-
/**
|
|
277
|
-
*
|
|
278
|
-
* @param
|
|
279
|
-
* @
|
|
311
|
+
/**
|
|
312
|
+
* Add (a clone of) a point to point array.
|
|
313
|
+
* @param point the point.
|
|
314
|
+
* @param priorIndex (optional) index of prior point to check for possible duplicate value.
|
|
315
|
+
* @returns the zero-based index of the added or duplicate point.
|
|
280
316
|
*/
|
|
281
317
|
addPoint(point, priorIndex) {
|
|
282
318
|
if (priorIndex !== undefined) {
|
|
@@ -287,12 +323,21 @@ class IndexedPolyface extends Polyface {
|
|
|
287
323
|
this.data.point.pushXYZ(point.x, point.y, point.z);
|
|
288
324
|
return this.data.point.length - 1;
|
|
289
325
|
}
|
|
290
|
-
/**
|
|
291
|
-
*
|
|
326
|
+
/**
|
|
327
|
+
* Add a point to point array.
|
|
328
|
+
* @param x the x coordinate of point.
|
|
329
|
+
* @param y the y coordinate of point.
|
|
330
|
+
* @param z the z coordinate of point.
|
|
331
|
+
* @returns the zero-based index of the added point.
|
|
292
332
|
*/
|
|
293
|
-
addPointXYZ(x, y, z) {
|
|
294
|
-
|
|
295
|
-
|
|
333
|
+
addPointXYZ(x, y, z) {
|
|
334
|
+
this.data.point.pushXYZ(x, y, z);
|
|
335
|
+
return this.data.point.length - 1;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Add (a clone of) a uv parameter to the parameter array.
|
|
339
|
+
* @param param the parameter.
|
|
340
|
+
* @returns zero-based index of the added param.
|
|
296
341
|
*/
|
|
297
342
|
addParam(param) {
|
|
298
343
|
if (!this.data.param)
|
|
@@ -300,10 +345,13 @@ class IndexedPolyface extends Polyface {
|
|
|
300
345
|
this.data.param.push(param);
|
|
301
346
|
return this.data.param.length - 1;
|
|
302
347
|
}
|
|
303
|
-
/**
|
|
348
|
+
/**
|
|
349
|
+
* Add a uv parameter to the parameter array.
|
|
350
|
+
* @param u the u part of parameter.
|
|
351
|
+
* @param v the v part of parameter.
|
|
304
352
|
* @param priorIndexA first index to check for possible duplicate value.
|
|
305
353
|
* @param priorIndexB second index to check for possible duplicate value.
|
|
306
|
-
* @returns
|
|
354
|
+
* @returns zero-based index of the added or duplicate parameter.
|
|
307
355
|
*/
|
|
308
356
|
addParamUV(u, v, priorIndexA, priorIndexB) {
|
|
309
357
|
if (!this.data.param)
|
|
@@ -315,37 +363,39 @@ class IndexedPolyface extends Polyface {
|
|
|
315
363
|
this.data.param.pushXY(u, v);
|
|
316
364
|
return this.data.param.length - 1;
|
|
317
365
|
}
|
|
318
|
-
/**
|
|
366
|
+
/**
|
|
367
|
+
* Add (a clone of) a normal vector to the normal array.
|
|
368
|
+
* @param normal the normal vector.
|
|
319
369
|
* @param priorIndexA first index to check for possible duplicate value.
|
|
320
370
|
* @param priorIndexB second index to check for possible duplicate value.
|
|
321
|
-
* @returns
|
|
371
|
+
* @returns zero-based index of the added or duplicate normal.
|
|
322
372
|
*/
|
|
323
373
|
addNormal(normal, priorIndexA, priorIndexB) {
|
|
374
|
+
// check if `normal` is duplicate of `dataNormal` at index `i`
|
|
375
|
+
const normalIsDuplicate = (i) => {
|
|
376
|
+
const distance = this.data.normal.distanceIndexToPoint(i, normal);
|
|
377
|
+
return distance !== undefined && Geometry_1.Geometry.isSmallMetricDistance(distance);
|
|
378
|
+
};
|
|
324
379
|
if (this.data.normal !== undefined) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
if (priorIndexB !== undefined) {
|
|
332
|
-
distance = this.data.normal.distanceIndexToPoint(priorIndexB, normal);
|
|
333
|
-
if (distance !== undefined && Geometry_1.Geometry.isSmallMetricDistance(distance))
|
|
334
|
-
return priorIndexB;
|
|
335
|
-
}
|
|
336
|
-
// Note: Do NOT attempt to chain to tail if no prior indices given.
|
|
337
|
-
// But if they are, look also to the tail.
|
|
380
|
+
if (priorIndexA !== undefined && normalIsDuplicate(priorIndexA))
|
|
381
|
+
return priorIndexA;
|
|
382
|
+
if (priorIndexB !== undefined && normalIsDuplicate(priorIndexB))
|
|
383
|
+
return priorIndexB;
|
|
384
|
+
// check the tail index for possible duplicate
|
|
338
385
|
if (priorIndexA !== undefined || priorIndexB !== undefined) {
|
|
339
386
|
const tailIndex = this.data.normal.length - 1;
|
|
340
|
-
|
|
341
|
-
if (distance !== undefined && Geometry_1.Geometry.isSmallMetricDistance(distance))
|
|
387
|
+
if (normalIsDuplicate(tailIndex))
|
|
342
388
|
return tailIndex;
|
|
343
389
|
}
|
|
344
390
|
}
|
|
345
391
|
return this.addNormalXYZ(normal.x, normal.y, normal.z);
|
|
346
392
|
}
|
|
347
|
-
/**
|
|
348
|
-
*
|
|
393
|
+
/**
|
|
394
|
+
* Add a normal vector to the normal array.
|
|
395
|
+
* @param x the x coordinate of normal.
|
|
396
|
+
* @param y the y coordinate of normal.
|
|
397
|
+
* @param z the z coordinate of normal.
|
|
398
|
+
* @returns zero-based index of the added normal vector.
|
|
349
399
|
*/
|
|
350
400
|
addNormalXYZ(x, y, z) {
|
|
351
401
|
if (!this.data.normal)
|
|
@@ -353,8 +403,10 @@ class IndexedPolyface extends Polyface {
|
|
|
353
403
|
this.data.normal.pushXYZ(x, y, z);
|
|
354
404
|
return this.data.normal.length - 1;
|
|
355
405
|
}
|
|
356
|
-
/**
|
|
357
|
-
*
|
|
406
|
+
/**
|
|
407
|
+
* Add a color to the color array
|
|
408
|
+
* @param color the color.
|
|
409
|
+
* @returns zero-based index of the added color.
|
|
358
410
|
*/
|
|
359
411
|
addColor(color) {
|
|
360
412
|
if (!this.data.color)
|
|
@@ -363,46 +415,54 @@ class IndexedPolyface extends Polyface {
|
|
|
363
415
|
return this.data.color.length - 1;
|
|
364
416
|
}
|
|
365
417
|
/** Add a point index with edge visibility flag. */
|
|
366
|
-
addPointIndex(index, visible = true) {
|
|
367
|
-
|
|
418
|
+
addPointIndex(index, visible = true) {
|
|
419
|
+
this.data.pointIndex.push(index);
|
|
420
|
+
this.data.edgeVisible.push(visible);
|
|
421
|
+
}
|
|
422
|
+
/** Add a normal index. */
|
|
368
423
|
addNormalIndex(index) {
|
|
369
424
|
if (!this.data.normalIndex)
|
|
370
425
|
this.data.normalIndex = [];
|
|
371
426
|
this.data.normalIndex.push(index);
|
|
372
427
|
}
|
|
373
|
-
/** Add a param index */
|
|
428
|
+
/** Add a param index. */
|
|
374
429
|
addParamIndex(index) {
|
|
375
430
|
if (!this.data.paramIndex)
|
|
376
431
|
this.data.paramIndex = [];
|
|
377
432
|
this.data.paramIndex.push(index);
|
|
378
433
|
}
|
|
379
|
-
/** Add a color index */
|
|
434
|
+
/** Add a color index. */
|
|
380
435
|
addColorIndex(index) {
|
|
381
436
|
if (!this.data.colorIndex)
|
|
382
437
|
this.data.colorIndex = [];
|
|
383
438
|
this.data.colorIndex.push(index);
|
|
384
439
|
}
|
|
385
|
-
/**
|
|
440
|
+
/**
|
|
441
|
+
* Clean up the open facet.
|
|
442
|
+
* @deprecated in 4.x to remove nebulous "open facet" concept from the API. Call [[PolyfaceData.trimAllIndexArrays]]
|
|
443
|
+
* instead.
|
|
444
|
+
*/
|
|
386
445
|
cleanupOpenFacet() {
|
|
387
446
|
this.data.trimAllIndexArrays(this.data.pointIndex.length);
|
|
388
447
|
}
|
|
389
|
-
/**
|
|
390
|
-
*
|
|
391
|
-
* *
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
* *
|
|
396
|
-
* * "undefined" return is normal. Any other return is a description of an error.
|
|
448
|
+
/**
|
|
449
|
+
* Announce the end of construction of a facet.
|
|
450
|
+
* * Optionally check for:
|
|
451
|
+
* * Same number of indices among all active index arrays -- point, normal, param, color
|
|
452
|
+
* * All indices are within bounds of the respective data arrays.
|
|
453
|
+
* * In error cases, all index arrays are trimmed back to the size when previous facet was terminated.
|
|
454
|
+
* * A return value of `undefined` is normal. Otherwise, a string array of error messages is returned.
|
|
397
455
|
*/
|
|
398
456
|
terminateFacet(validateAllIndices = true) {
|
|
399
457
|
const numFacets = this._facetStart.length - 1;
|
|
400
|
-
|
|
401
|
-
const
|
|
458
|
+
// number of indices in accepted facets
|
|
459
|
+
const lengthA = this._facetStart[numFacets];
|
|
460
|
+
// number of indices in all facets (accepted facet plus the last facet to be accepted)
|
|
461
|
+
const lengthB = this.data.pointIndex.length;
|
|
402
462
|
if (validateAllIndices) {
|
|
403
463
|
const messages = [];
|
|
404
464
|
if (lengthB < lengthA + 2)
|
|
405
|
-
messages.push("Less than 3 indices in
|
|
465
|
+
messages.push("Less than 3 indices in the last facet");
|
|
406
466
|
if (this.data.normalIndex && this.data.normalIndex.length !== lengthB)
|
|
407
467
|
messages.push("normalIndex count must match pointIndex count");
|
|
408
468
|
if (this.data.paramIndex && this.data.paramIndex.length !== lengthB)
|
|
@@ -411,71 +471,100 @@ class IndexedPolyface extends Polyface {
|
|
|
411
471
|
messages.push("colorIndex count must equal pointIndex count");
|
|
412
472
|
if (this.data.edgeVisible.length !== lengthB)
|
|
413
473
|
messages.push("visibleIndex count must equal pointIndex count");
|
|
474
|
+
if (!Polyface.areIndicesValid(this.data.pointIndex, lengthA, lengthB, this.data.point, this.data.point ? this.data.point.length : 0))
|
|
475
|
+
messages.push("invalid point indices in the last facet");
|
|
414
476
|
if (!Polyface.areIndicesValid(this.data.normalIndex, lengthA, lengthB, this.data.normal, this.data.normal ? this.data.normal.length : 0))
|
|
415
|
-
messages.push("invalid normal indices in
|
|
477
|
+
messages.push("invalid normal indices in the last facet");
|
|
478
|
+
if (!Polyface.areIndicesValid(this.data.paramIndex, lengthA, lengthB, this.data.param, this.data.param ? this.data.param.length : 0))
|
|
479
|
+
messages.push("invalid param indices in the last facet");
|
|
480
|
+
if (!Polyface.areIndicesValid(this.data.colorIndex, lengthA, lengthB, this.data.color, this.data.color ? this.data.color.length : 0))
|
|
481
|
+
messages.push("invalid color indices in the last facet");
|
|
416
482
|
if (messages.length > 0) {
|
|
417
|
-
this.
|
|
483
|
+
this.data.trimAllIndexArrays(lengthA);
|
|
418
484
|
return messages;
|
|
419
485
|
}
|
|
420
486
|
}
|
|
421
|
-
//
|
|
422
|
-
this._facetStart.push(lengthB);
|
|
487
|
+
this._facetStart.push(lengthB); // append start index of the future facet
|
|
423
488
|
return undefined;
|
|
424
489
|
}
|
|
425
|
-
/**
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
/** (read-only property)
|
|
430
|
-
get
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
/** (read-only property)
|
|
434
|
-
get pointCount() {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
/** (read-only property)
|
|
438
|
-
get
|
|
439
|
-
|
|
440
|
-
|
|
490
|
+
/** Number of facets (read-only property). */
|
|
491
|
+
get facetCount() {
|
|
492
|
+
return this._facetStart.length - 1;
|
|
493
|
+
}
|
|
494
|
+
/** Number of faces (read-only property). */
|
|
495
|
+
get faceCount() {
|
|
496
|
+
return this.data.faceCount;
|
|
497
|
+
}
|
|
498
|
+
/** Number of points (read-only property). */
|
|
499
|
+
get pointCount() {
|
|
500
|
+
return this.data.pointCount;
|
|
501
|
+
}
|
|
502
|
+
/** Number of colors (read-only property). */
|
|
503
|
+
get colorCount() {
|
|
504
|
+
return this.data.colorCount;
|
|
505
|
+
}
|
|
506
|
+
/** Number of parameters (read-only property). */
|
|
507
|
+
get paramCount() {
|
|
508
|
+
return this.data.paramCount;
|
|
509
|
+
}
|
|
510
|
+
/** Number of normals (read-only property). */
|
|
511
|
+
get normalCount() {
|
|
512
|
+
return this.data.normalCount;
|
|
513
|
+
}
|
|
514
|
+
/** Test if `index` is a valid facet index. */
|
|
515
|
+
isValidFacetIndex(index) {
|
|
516
|
+
return index >= 0 && index < this.facetCount;
|
|
517
|
+
}
|
|
441
518
|
/** Return the number of edges in a particular facet. */
|
|
442
519
|
numEdgeInFacet(facetIndex) {
|
|
443
520
|
if (this.isValidFacetIndex(facetIndex))
|
|
444
521
|
return this._facetStart[facetIndex + 1] - this._facetStart[facetIndex];
|
|
445
522
|
return 0;
|
|
446
523
|
}
|
|
447
|
-
/**
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
/** ASSUME valid facet index
|
|
452
|
-
facetIndex1(index) {
|
|
453
|
-
|
|
454
|
-
|
|
524
|
+
/** ASSUME valid facet index. Return start index of facet in pointIndex arrays. */
|
|
525
|
+
facetIndex0(index) {
|
|
526
|
+
return this._facetStart[index];
|
|
527
|
+
}
|
|
528
|
+
/** ASSUME valid facet index. Return one past end index of facet in pointIndex arrays. */
|
|
529
|
+
facetIndex1(index) {
|
|
530
|
+
return this._facetStart[index + 1];
|
|
531
|
+
}
|
|
532
|
+
/** Create a visitor for this polyface */
|
|
533
|
+
createVisitor(numWrap = 0) {
|
|
534
|
+
return IndexedPolyfaceVisitor_1.IndexedPolyfaceVisitor.create(this, numWrap);
|
|
535
|
+
}
|
|
455
536
|
/** Return the range of (optionally transformed) points in this mesh. */
|
|
456
|
-
range(transform, result) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
/**
|
|
537
|
+
range(transform, result) {
|
|
538
|
+
return this.data.range(result, transform);
|
|
539
|
+
}
|
|
540
|
+
/** Extend `range` with coordinates from this mesh. */
|
|
541
|
+
extendRange(range, transform) {
|
|
542
|
+
this.data.range(range, transform);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Given the index of a facet, return the data pertaining to the face it is a part of.
|
|
546
|
+
* @deprecated in 4.x. Use [[IndexedPolyface.tryGetFaceData]], which verifies the index is in range.
|
|
547
|
+
*/
|
|
460
548
|
getFaceDataByFacetIndex(facetIndex) {
|
|
461
549
|
return this.data.face[this._facetToFaceData[facetIndex]];
|
|
462
550
|
}
|
|
463
551
|
/**
|
|
464
|
-
*
|
|
465
|
-
*
|
|
552
|
+
* Set new FacetFaceData.
|
|
553
|
+
* * All terminated facets since the last face declaration will be mapped to a single new FacetFaceData object using
|
|
554
|
+
* facetToFaceData[]. FacetFaceData holds the 2D range of the face. Returns `true` if successful, `false` otherwise.
|
|
466
555
|
*/
|
|
467
556
|
setNewFaceData(endFacetIndex = 0) {
|
|
468
557
|
const facetStart = this._facetToFaceData.length;
|
|
469
558
|
if (facetStart >= this._facetStart.length)
|
|
470
559
|
return false;
|
|
471
|
-
if (0 === endFacetIndex) //
|
|
472
|
-
endFacetIndex = this._facetStart.length; //
|
|
560
|
+
if (0 === endFacetIndex) // the default for endFacetIndex is really the last facet
|
|
561
|
+
endFacetIndex = this._facetStart.length; // last facet index corresponds to the future facet
|
|
473
562
|
const faceData = FacetFaceData_1.FacetFaceData.createNull();
|
|
474
563
|
const visitor = IndexedPolyfaceVisitor_1.IndexedPolyfaceVisitor.create(this, 0);
|
|
475
|
-
if (!visitor.moveToReadIndex(facetStart)) { //
|
|
564
|
+
if (!visitor.moveToReadIndex(facetStart)) { // move visitor to first facet of new face
|
|
476
565
|
return false;
|
|
477
566
|
}
|
|
478
|
-
//
|
|
567
|
+
// if parameter range is provided (by the polyface planeSet clipper) then use it
|
|
479
568
|
const paramDefined = this.data.param !== undefined;
|
|
480
569
|
const setParamRange = faceData.paramRange.isNull && paramDefined;
|
|
481
570
|
do {
|
|
@@ -490,7 +579,7 @@ class IndexedPolyface extends Polyface {
|
|
|
490
579
|
this._facetToFaceData.push(0 === this._facetStart[i] ? 0 : faceDataIndex);
|
|
491
580
|
return true;
|
|
492
581
|
}
|
|
493
|
-
/** Second step of double dispatch:
|
|
582
|
+
/** Second step of double dispatch: call `handler.handleIndexedPolyface(this)`. */
|
|
494
583
|
dispatchToGeometryHandler(handler) {
|
|
495
584
|
return handler.handleIndexedPolyface(this);
|
|
496
585
|
}
|