three-cad-viewer 2.2.4 → 2.3.0
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/dist/three-cad-viewer.esm.js +75 -59
- package/dist/three-cad-viewer.esm.min.js +1 -1
- package/dist/three-cad-viewer.js +75 -59
- package/dist/three-cad-viewer.min.js +1 -1
- package/package.json +1 -1
- package/src/_version.js +1 -1
- package/src/bbox.js +0 -3
- package/src/nestedgroup.js +9 -8
- package/src/timer.js +4 -4
- package/src/utils.js +4 -1
- package/src/viewer.js +52 -36
|
@@ -18209,7 +18209,7 @@ const mat2array = new Float32Array( 4 );
|
|
|
18209
18209
|
|
|
18210
18210
|
// Flattening for arrays of vectors and matrices
|
|
18211
18211
|
|
|
18212
|
-
function flatten( array, nBlocks, blockSize ) {
|
|
18212
|
+
function flatten$1( array, nBlocks, blockSize ) {
|
|
18213
18213
|
|
|
18214
18214
|
const firstElem = array[ 0 ];
|
|
18215
18215
|
|
|
@@ -18826,7 +18826,7 @@ function setValueV1fArray( gl, v ) {
|
|
|
18826
18826
|
|
|
18827
18827
|
function setValueV2fArray( gl, v ) {
|
|
18828
18828
|
|
|
18829
|
-
const data = flatten( v, this.size, 2 );
|
|
18829
|
+
const data = flatten$1( v, this.size, 2 );
|
|
18830
18830
|
|
|
18831
18831
|
gl.uniform2fv( this.addr, data );
|
|
18832
18832
|
|
|
@@ -18834,7 +18834,7 @@ function setValueV2fArray( gl, v ) {
|
|
|
18834
18834
|
|
|
18835
18835
|
function setValueV3fArray( gl, v ) {
|
|
18836
18836
|
|
|
18837
|
-
const data = flatten( v, this.size, 3 );
|
|
18837
|
+
const data = flatten$1( v, this.size, 3 );
|
|
18838
18838
|
|
|
18839
18839
|
gl.uniform3fv( this.addr, data );
|
|
18840
18840
|
|
|
@@ -18842,7 +18842,7 @@ function setValueV3fArray( gl, v ) {
|
|
|
18842
18842
|
|
|
18843
18843
|
function setValueV4fArray( gl, v ) {
|
|
18844
18844
|
|
|
18845
|
-
const data = flatten( v, this.size, 4 );
|
|
18845
|
+
const data = flatten$1( v, this.size, 4 );
|
|
18846
18846
|
|
|
18847
18847
|
gl.uniform4fv( this.addr, data );
|
|
18848
18848
|
|
|
@@ -18852,7 +18852,7 @@ function setValueV4fArray( gl, v ) {
|
|
|
18852
18852
|
|
|
18853
18853
|
function setValueM2Array( gl, v ) {
|
|
18854
18854
|
|
|
18855
|
-
const data = flatten( v, this.size, 4 );
|
|
18855
|
+
const data = flatten$1( v, this.size, 4 );
|
|
18856
18856
|
|
|
18857
18857
|
gl.uniformMatrix2fv( this.addr, false, data );
|
|
18858
18858
|
|
|
@@ -18860,7 +18860,7 @@ function setValueM2Array( gl, v ) {
|
|
|
18860
18860
|
|
|
18861
18861
|
function setValueM3Array( gl, v ) {
|
|
18862
18862
|
|
|
18863
|
-
const data = flatten( v, this.size, 9 );
|
|
18863
|
+
const data = flatten$1( v, this.size, 9 );
|
|
18864
18864
|
|
|
18865
18865
|
gl.uniformMatrix3fv( this.addr, false, data );
|
|
18866
18866
|
|
|
@@ -18868,7 +18868,7 @@ function setValueM3Array( gl, v ) {
|
|
|
18868
18868
|
|
|
18869
18869
|
function setValueM4Array( gl, v ) {
|
|
18870
18870
|
|
|
18871
|
-
const data = flatten( v, this.size, 16 );
|
|
18871
|
+
const data = flatten$1( v, this.size, 16 );
|
|
18872
18872
|
|
|
18873
18873
|
gl.uniformMatrix4fv( this.addr, false, data );
|
|
18874
18874
|
|
|
@@ -54010,6 +54010,9 @@ function clone(obj) {
|
|
|
54010
54010
|
return obj;
|
|
54011
54011
|
}
|
|
54012
54012
|
}
|
|
54013
|
+
function flatten(arr, depth = 1) {
|
|
54014
|
+
return (Array.isArray(arr)) ? arr.flat(depth) : arr;
|
|
54015
|
+
}
|
|
54013
54016
|
|
|
54014
54017
|
function isEqual(obj1, obj2, tol = 1e-9) {
|
|
54015
54018
|
if (Array.isArray(obj1) && Array.isArray(obj2)) {
|
|
@@ -58230,9 +58233,6 @@ class VertexNormalsHelper extends LineSegments {
|
|
|
58230
58233
|
}
|
|
58231
58234
|
|
|
58232
58235
|
class BoundingBox extends Box3 {
|
|
58233
|
-
constructor() {
|
|
58234
|
-
super();
|
|
58235
|
-
}
|
|
58236
58236
|
|
|
58237
58237
|
expandByObject(object, precise = false) {
|
|
58238
58238
|
object.updateWorldMatrix(false, false);
|
|
@@ -58687,7 +58687,7 @@ class NestedGroup {
|
|
|
58687
58687
|
var positions =
|
|
58688
58688
|
edgeList instanceof Float32Array
|
|
58689
58689
|
? edgeList
|
|
58690
|
-
: new Float32Array(edgeList
|
|
58690
|
+
: new Float32Array(flatten(edgeList, 2));
|
|
58691
58691
|
|
|
58692
58692
|
const lineGeometry = new LineSegmentsGeometry();
|
|
58693
58693
|
lineGeometry.setPositions(positions);
|
|
@@ -58735,7 +58735,7 @@ class NestedGroup {
|
|
|
58735
58735
|
var edges = this._renderEdges(
|
|
58736
58736
|
edgeList.edges
|
|
58737
58737
|
? edgeList.edges // protocol version 2
|
|
58738
|
-
: edgeList, // protocol version 1
|
|
58738
|
+
: flatten(edgeList), // protocol version 1
|
|
58739
58739
|
lineWidth,
|
|
58740
58740
|
color,
|
|
58741
58741
|
state,
|
|
@@ -58774,8 +58774,8 @@ class NestedGroup {
|
|
|
58774
58774
|
// protocol version 1
|
|
58775
58775
|
positions =
|
|
58776
58776
|
vertexList instanceof Float32Array
|
|
58777
|
-
? vertexList
|
|
58778
|
-
: new Float32Array(vertexList
|
|
58777
|
+
? vertexList
|
|
58778
|
+
: new Float32Array(flatten(vertexList));
|
|
58779
58779
|
}
|
|
58780
58780
|
const geometry = new BufferGeometry();
|
|
58781
58781
|
geometry.setAttribute(
|
|
@@ -58822,15 +58822,15 @@ class NestedGroup {
|
|
|
58822
58822
|
const positions =
|
|
58823
58823
|
shape.vertices instanceof Float32Array
|
|
58824
58824
|
? shape.vertices
|
|
58825
|
-
: new Float32Array(shape.vertices
|
|
58825
|
+
: new Float32Array(flatten(shape.vertices));
|
|
58826
58826
|
const normals =
|
|
58827
58827
|
shape.normals instanceof Float32Array
|
|
58828
58828
|
? shape.normals
|
|
58829
|
-
: new Float32Array(shape.normals
|
|
58829
|
+
: new Float32Array(flatten(shape.normals));
|
|
58830
58830
|
const triangles =
|
|
58831
58831
|
shape.triangles instanceof Uint32Array
|
|
58832
58832
|
? shape.triangles
|
|
58833
|
-
: new Uint32Array(shape.triangles
|
|
58833
|
+
: new Uint32Array(flatten(shape.triangles));
|
|
58834
58834
|
|
|
58835
58835
|
var group = new ObjectGroup(
|
|
58836
58836
|
this.defaultOpacity,
|
|
@@ -58905,7 +58905,7 @@ class NestedGroup {
|
|
|
58905
58905
|
side: FrontSide,
|
|
58906
58906
|
visible: states[0] == 1,
|
|
58907
58907
|
map: texture,
|
|
58908
|
-
name:"frontMaterial"
|
|
58908
|
+
name: "frontMaterial"
|
|
58909
58909
|
});
|
|
58910
58910
|
}
|
|
58911
58911
|
|
|
@@ -60244,7 +60244,7 @@ class Timer {
|
|
|
60244
60244
|
this.timeit = timeit;
|
|
60245
60245
|
this.start = performance.now();
|
|
60246
60246
|
if (timeit) {
|
|
60247
|
-
console.info(`three-cad-viewer:
|
|
60247
|
+
console.info(`three-cad-viewer: ${prefix}:timer start`);
|
|
60248
60248
|
}
|
|
60249
60249
|
}
|
|
60250
60250
|
|
|
@@ -60252,7 +60252,7 @@ class Timer {
|
|
|
60252
60252
|
if (this.timeit) {
|
|
60253
60253
|
const t = performance.now();
|
|
60254
60254
|
console.info(
|
|
60255
|
-
`three-cad-viewer:
|
|
60255
|
+
`three-cad-viewer: ${this.prefix}:${msg}:timer split ${(
|
|
60256
60256
|
t - this.start
|
|
60257
60257
|
).toFixed(1)} ms`,
|
|
60258
60258
|
);
|
|
@@ -60263,9 +60263,9 @@ class Timer {
|
|
|
60263
60263
|
if (this.timeit) {
|
|
60264
60264
|
const t = performance.now();
|
|
60265
60265
|
console.info(
|
|
60266
|
-
`three-cad-viewer:
|
|
60266
|
+
`three-cad-viewer: ${this.prefix}:timer stop ${(t - this.start).toFixed(
|
|
60267
60267
|
1,
|
|
60268
|
-
)} ms
|
|
60268
|
+
)} ms:`,
|
|
60269
60269
|
);
|
|
60270
60270
|
}
|
|
60271
60271
|
}
|
|
@@ -62864,7 +62864,7 @@ class Camera {
|
|
|
62864
62864
|
}
|
|
62865
62865
|
}
|
|
62866
62866
|
|
|
62867
|
-
const version = "2.
|
|
62867
|
+
const version = "2.3.0";
|
|
62868
62868
|
|
|
62869
62869
|
class Viewer {
|
|
62870
62870
|
/**
|
|
@@ -63158,6 +63158,12 @@ class Viewer {
|
|
|
63158
63158
|
this.roughness,
|
|
63159
63159
|
this.normalLen,
|
|
63160
63160
|
);
|
|
63161
|
+
if (shapes.bb) {
|
|
63162
|
+
this.bbox = new BoundingBox(
|
|
63163
|
+
new Vector3(shapes.bb.xmin, shapes.bb.ymin, shapes.bb.zmin),
|
|
63164
|
+
new Vector3(shapes.bb.xmax, shapes.bb.ymax, shapes.bb.zmax)
|
|
63165
|
+
);
|
|
63166
|
+
}
|
|
63161
63167
|
nestedGroup.render(states);
|
|
63162
63168
|
return nestedGroup;
|
|
63163
63169
|
}
|
|
@@ -63216,10 +63222,30 @@ class Viewer {
|
|
|
63216
63222
|
name: "faces",
|
|
63217
63223
|
id: `${part.id}/faces`,
|
|
63218
63224
|
};
|
|
63225
|
+
var triangles;
|
|
63219
63226
|
const vertices = shape.vertices;
|
|
63220
63227
|
const normals = shape.normals;
|
|
63221
|
-
|
|
63222
|
-
|
|
63228
|
+
const num = (shape.triangles_per_face) ? shape.triangles_per_face.length : shape.triangles.length;
|
|
63229
|
+
var current = 0;
|
|
63230
|
+
for (j = 0; j < num; j++) {
|
|
63231
|
+
if (shape.triangles_per_face) {
|
|
63232
|
+
triangles = shape.triangles.subarray(current, current + 3 * shape.triangles_per_face[j]);
|
|
63233
|
+
current += 3 * shape.triangles_per_face[j];
|
|
63234
|
+
} else {
|
|
63235
|
+
triangles = shape.triangles[j];
|
|
63236
|
+
}
|
|
63237
|
+
|
|
63238
|
+
var vecs = new Float32Array(triangles.length * 3);
|
|
63239
|
+
var norms = new Float32Array(triangles.length * 3);
|
|
63240
|
+
for (var i = 0; i < triangles.length; i++) {
|
|
63241
|
+
var s = triangles[i];
|
|
63242
|
+
vecs[3 * i] = vertices[3 * s];
|
|
63243
|
+
vecs[3 * i + 1] = vertices[3 * s + 1];
|
|
63244
|
+
vecs[3 * i + 2] = vertices[3 * s + 2];
|
|
63245
|
+
norms[3 * i] = normals[3 * s];
|
|
63246
|
+
norms[3 * i + 1] = normals[3 * s + 1];
|
|
63247
|
+
norms[3 * i + 2] = normals[3 * s + 2];
|
|
63248
|
+
}
|
|
63223
63249
|
var new_shape = {
|
|
63224
63250
|
loc: [
|
|
63225
63251
|
[0, 0, 0],
|
|
@@ -63237,20 +63263,8 @@ class Viewer {
|
|
|
63237
63263
|
subtype: part.subtype,
|
|
63238
63264
|
shape: {
|
|
63239
63265
|
triangles: [...Array(triangles.length).keys()],
|
|
63240
|
-
vertices:
|
|
63241
|
-
|
|
63242
|
-
vertices[3 * s],
|
|
63243
|
-
vertices[3 * s + 1],
|
|
63244
|
-
vertices[3 * s + 2],
|
|
63245
|
-
])
|
|
63246
|
-
.flat(),
|
|
63247
|
-
normals: triangles
|
|
63248
|
-
.map((s) => [
|
|
63249
|
-
normals[3 * s],
|
|
63250
|
-
normals[3 * s + 1],
|
|
63251
|
-
normals[3 * s + 2],
|
|
63252
|
-
])
|
|
63253
|
-
.flat(),
|
|
63266
|
+
vertices: vecs,
|
|
63267
|
+
normals: norms,
|
|
63254
63268
|
edges: [],
|
|
63255
63269
|
},
|
|
63256
63270
|
};
|
|
@@ -63275,8 +63289,17 @@ class Viewer {
|
|
|
63275
63289
|
const multiColor =
|
|
63276
63290
|
Array.isArray(part.color) && part.color.length == shape.edges.length;
|
|
63277
63291
|
var color;
|
|
63278
|
-
|
|
63279
|
-
|
|
63292
|
+
|
|
63293
|
+
const num = (shape.segments_per_edge) ? shape.segments_per_edge.length : shape.triangles.length;
|
|
63294
|
+
current = 0;
|
|
63295
|
+
var edge;
|
|
63296
|
+
for (j = 0; j < num; j++) {
|
|
63297
|
+
if (shape.segments_per_edge) {
|
|
63298
|
+
edge = shape.edges.subarray(current, current + 6 * shape.segments_per_edge[j]);
|
|
63299
|
+
current += 6 * shape.segments_per_edge[j];
|
|
63300
|
+
} else {
|
|
63301
|
+
edge = shape.edges[j];
|
|
63302
|
+
}
|
|
63280
63303
|
color = multiColor ? part.color[j] : part.color;
|
|
63281
63304
|
new_shape = {
|
|
63282
63305
|
loc: [
|
|
@@ -63359,8 +63382,8 @@ class Viewer {
|
|
|
63359
63382
|
renderTessellatedShapes(shapes, states, options) {
|
|
63360
63383
|
this.setRenderDefaults(options);
|
|
63361
63384
|
const _render = (shapes, states, measureTools) => {
|
|
63362
|
-
var part
|
|
63363
|
-
if (shapes.version == 2) {
|
|
63385
|
+
var part;
|
|
63386
|
+
if (shapes.version == 2 || shapes.version == 3) {
|
|
63364
63387
|
if (measureTools) {
|
|
63365
63388
|
var i, tmp;
|
|
63366
63389
|
let parts = [];
|
|
@@ -63374,17 +63397,6 @@ class Viewer {
|
|
|
63374
63397
|
}
|
|
63375
63398
|
}
|
|
63376
63399
|
shapes.parts = parts;
|
|
63377
|
-
} else {
|
|
63378
|
-
for (i = 0; i < shapes.parts.length; i++) {
|
|
63379
|
-
part = shapes.parts[i];
|
|
63380
|
-
shape = part.shape;
|
|
63381
|
-
if (part.type == "shapes") {
|
|
63382
|
-
shape.triangles = shape.triangles.flat();
|
|
63383
|
-
shape.edges = shape.edges.flat();
|
|
63384
|
-
} else if (part.type == "edges" || part.type == "shapes") {
|
|
63385
|
-
shape.edges = shape.edges.flat();
|
|
63386
|
-
}
|
|
63387
|
-
}
|
|
63388
63400
|
}
|
|
63389
63401
|
}
|
|
63390
63402
|
return shapes;
|
|
@@ -63713,7 +63725,9 @@ class Viewer {
|
|
|
63713
63725
|
|
|
63714
63726
|
timer.split("rendered nested group");
|
|
63715
63727
|
|
|
63716
|
-
this.bbox
|
|
63728
|
+
if (!this.bbox) {
|
|
63729
|
+
this.bbox = this.nestedGroup.boundingBox();
|
|
63730
|
+
}
|
|
63717
63731
|
const center = new Vector3();
|
|
63718
63732
|
this.bbox.getCenter(center);
|
|
63719
63733
|
this.bb_max = this.bbox.max_dist_from_center();
|
|
@@ -63966,12 +63980,12 @@ class Viewer {
|
|
|
63966
63980
|
this.tools,
|
|
63967
63981
|
this.glass,
|
|
63968
63982
|
);
|
|
63969
|
-
|
|
63983
|
+
timer.split("ui updated");
|
|
63970
63984
|
this.display.autoCollapse();
|
|
63971
63985
|
|
|
63972
63986
|
// ensure all for all deselected objects the stencil planes are invisible
|
|
63973
63987
|
this.setObjects(this.states, true, true);
|
|
63974
|
-
|
|
63988
|
+
timer.split("stencil done");
|
|
63975
63989
|
//
|
|
63976
63990
|
// show the rendering
|
|
63977
63991
|
//
|
|
@@ -63986,7 +64000,7 @@ class Viewer {
|
|
|
63986
64000
|
//
|
|
63987
64001
|
// notify calculated results
|
|
63988
64002
|
//
|
|
63989
|
-
|
|
64003
|
+
timer.split("show done");
|
|
63990
64004
|
if (this.notifyCallback) {
|
|
63991
64005
|
this.notifyCallback({
|
|
63992
64006
|
tab: { old: null, new: this.display.activeTab },
|
|
@@ -63997,8 +64011,10 @@ class Viewer {
|
|
|
63997
64011
|
clip_normal_2: { old: null, new: this.clipNormal2 },
|
|
63998
64012
|
});
|
|
63999
64013
|
}
|
|
64000
|
-
|
|
64014
|
+
timer.split("notification done");
|
|
64001
64015
|
|
|
64016
|
+
this.update(true, false);
|
|
64017
|
+
timer.split("update done");
|
|
64002
64018
|
timer.stop();
|
|
64003
64019
|
}
|
|
64004
64020
|
|