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.
@@ -18215,7 +18215,7 @@
18215
18215
 
18216
18216
  // Flattening for arrays of vectors and matrices
18217
18217
 
18218
- function flatten( array, nBlocks, blockSize ) {
18218
+ function flatten$1( array, nBlocks, blockSize ) {
18219
18219
 
18220
18220
  const firstElem = array[ 0 ];
18221
18221
 
@@ -18832,7 +18832,7 @@
18832
18832
 
18833
18833
  function setValueV2fArray( gl, v ) {
18834
18834
 
18835
- const data = flatten( v, this.size, 2 );
18835
+ const data = flatten$1( v, this.size, 2 );
18836
18836
 
18837
18837
  gl.uniform2fv( this.addr, data );
18838
18838
 
@@ -18840,7 +18840,7 @@
18840
18840
 
18841
18841
  function setValueV3fArray( gl, v ) {
18842
18842
 
18843
- const data = flatten( v, this.size, 3 );
18843
+ const data = flatten$1( v, this.size, 3 );
18844
18844
 
18845
18845
  gl.uniform3fv( this.addr, data );
18846
18846
 
@@ -18848,7 +18848,7 @@
18848
18848
 
18849
18849
  function setValueV4fArray( gl, v ) {
18850
18850
 
18851
- const data = flatten( v, this.size, 4 );
18851
+ const data = flatten$1( v, this.size, 4 );
18852
18852
 
18853
18853
  gl.uniform4fv( this.addr, data );
18854
18854
 
@@ -18858,7 +18858,7 @@
18858
18858
 
18859
18859
  function setValueM2Array( gl, v ) {
18860
18860
 
18861
- const data = flatten( v, this.size, 4 );
18861
+ const data = flatten$1( v, this.size, 4 );
18862
18862
 
18863
18863
  gl.uniformMatrix2fv( this.addr, false, data );
18864
18864
 
@@ -18866,7 +18866,7 @@
18866
18866
 
18867
18867
  function setValueM3Array( gl, v ) {
18868
18868
 
18869
- const data = flatten( v, this.size, 9 );
18869
+ const data = flatten$1( v, this.size, 9 );
18870
18870
 
18871
18871
  gl.uniformMatrix3fv( this.addr, false, data );
18872
18872
 
@@ -18874,7 +18874,7 @@
18874
18874
 
18875
18875
  function setValueM4Array( gl, v ) {
18876
18876
 
18877
- const data = flatten( v, this.size, 16 );
18877
+ const data = flatten$1( v, this.size, 16 );
18878
18878
 
18879
18879
  gl.uniformMatrix4fv( this.addr, false, data );
18880
18880
 
@@ -54016,6 +54016,9 @@ void main() {
54016
54016
  return obj;
54017
54017
  }
54018
54018
  }
54019
+ function flatten(arr, depth = 1) {
54020
+ return (Array.isArray(arr)) ? arr.flat(depth) : arr;
54021
+ }
54019
54022
 
54020
54023
  function isEqual(obj1, obj2, tol = 1e-9) {
54021
54024
  if (Array.isArray(obj1) && Array.isArray(obj2)) {
@@ -58236,9 +58239,6 @@ void main() {
58236
58239
  }
58237
58240
 
58238
58241
  class BoundingBox extends Box3 {
58239
- constructor() {
58240
- super();
58241
- }
58242
58242
 
58243
58243
  expandByObject(object, precise = false) {
58244
58244
  object.updateWorldMatrix(false, false);
@@ -58693,7 +58693,7 @@ void main() {
58693
58693
  var positions =
58694
58694
  edgeList instanceof Float32Array
58695
58695
  ? edgeList
58696
- : new Float32Array(edgeList.flat(2));
58696
+ : new Float32Array(flatten(edgeList, 2));
58697
58697
 
58698
58698
  const lineGeometry = new LineSegmentsGeometry();
58699
58699
  lineGeometry.setPositions(positions);
@@ -58741,7 +58741,7 @@ void main() {
58741
58741
  var edges = this._renderEdges(
58742
58742
  edgeList.edges
58743
58743
  ? edgeList.edges // protocol version 2
58744
- : edgeList, // protocol version 1
58744
+ : flatten(edgeList), // protocol version 1
58745
58745
  lineWidth,
58746
58746
  color,
58747
58747
  state,
@@ -58780,8 +58780,8 @@ void main() {
58780
58780
  // protocol version 1
58781
58781
  positions =
58782
58782
  vertexList instanceof Float32Array
58783
- ? vertexList.flat()
58784
- : new Float32Array(vertexList.flat());
58783
+ ? vertexList
58784
+ : new Float32Array(flatten(vertexList));
58785
58785
  }
58786
58786
  const geometry = new BufferGeometry();
58787
58787
  geometry.setAttribute(
@@ -58828,15 +58828,15 @@ void main() {
58828
58828
  const positions =
58829
58829
  shape.vertices instanceof Float32Array
58830
58830
  ? shape.vertices
58831
- : new Float32Array(shape.vertices.flat());
58831
+ : new Float32Array(flatten(shape.vertices));
58832
58832
  const normals =
58833
58833
  shape.normals instanceof Float32Array
58834
58834
  ? shape.normals
58835
- : new Float32Array(shape.normals.flat());
58835
+ : new Float32Array(flatten(shape.normals));
58836
58836
  const triangles =
58837
58837
  shape.triangles instanceof Uint32Array
58838
58838
  ? shape.triangles
58839
- : new Uint32Array(shape.triangles.flat());
58839
+ : new Uint32Array(flatten(shape.triangles));
58840
58840
 
58841
58841
  var group = new ObjectGroup(
58842
58842
  this.defaultOpacity,
@@ -58911,7 +58911,7 @@ void main() {
58911
58911
  side: FrontSide,
58912
58912
  visible: states[0] == 1,
58913
58913
  map: texture,
58914
- name:"frontMaterial"
58914
+ name: "frontMaterial"
58915
58915
  });
58916
58916
  }
58917
58917
 
@@ -60250,7 +60250,7 @@ void main() {
60250
60250
  this.timeit = timeit;
60251
60251
  this.start = performance.now();
60252
60252
  if (timeit) {
60253
- console.info(`three-cad-viewer: Timer ${prefix}:start`);
60253
+ console.info(`three-cad-viewer: ${prefix}:timer start`);
60254
60254
  }
60255
60255
  }
60256
60256
 
@@ -60258,7 +60258,7 @@ void main() {
60258
60258
  if (this.timeit) {
60259
60259
  const t = performance.now();
60260
60260
  console.info(
60261
- `three-cad-viewer: Timer ${this.prefix}:${msg} ${(
60261
+ `three-cad-viewer: ${this.prefix}:${msg}:timer split ${(
60262
60262
  t - this.start
60263
60263
  ).toFixed(1)} ms`,
60264
60264
  );
@@ -60269,9 +60269,9 @@ void main() {
60269
60269
  if (this.timeit) {
60270
60270
  const t = performance.now();
60271
60271
  console.info(
60272
- `three-cad-viewer: Timer ${this.prefix}:stop ${(t - this.start).toFixed(
60272
+ `three-cad-viewer: ${this.prefix}:timer stop ${(t - this.start).toFixed(
60273
60273
  1,
60274
- )} ms`,
60274
+ )} ms:`,
60275
60275
  );
60276
60276
  }
60277
60277
  }
@@ -62870,7 +62870,7 @@ void main() {
62870
62870
  }
62871
62871
  }
62872
62872
 
62873
- const version = "2.2.4";
62873
+ const version = "2.3.0";
62874
62874
 
62875
62875
  class Viewer {
62876
62876
  /**
@@ -63164,6 +63164,12 @@ void main() {
63164
63164
  this.roughness,
63165
63165
  this.normalLen,
63166
63166
  );
63167
+ if (shapes.bb) {
63168
+ this.bbox = new BoundingBox(
63169
+ new Vector3(shapes.bb.xmin, shapes.bb.ymin, shapes.bb.zmin),
63170
+ new Vector3(shapes.bb.xmax, shapes.bb.ymax, shapes.bb.zmax)
63171
+ );
63172
+ }
63167
63173
  nestedGroup.render(states);
63168
63174
  return nestedGroup;
63169
63175
  }
@@ -63222,10 +63228,30 @@ void main() {
63222
63228
  name: "faces",
63223
63229
  id: `${part.id}/faces`,
63224
63230
  };
63231
+ var triangles;
63225
63232
  const vertices = shape.vertices;
63226
63233
  const normals = shape.normals;
63227
- for (j = 0; j < shape.triangles.length; j++) {
63228
- var triangles = shape.triangles[j];
63234
+ const num = (shape.triangles_per_face) ? shape.triangles_per_face.length : shape.triangles.length;
63235
+ var current = 0;
63236
+ for (j = 0; j < num; j++) {
63237
+ if (shape.triangles_per_face) {
63238
+ triangles = shape.triangles.subarray(current, current + 3 * shape.triangles_per_face[j]);
63239
+ current += 3 * shape.triangles_per_face[j];
63240
+ } else {
63241
+ triangles = shape.triangles[j];
63242
+ }
63243
+
63244
+ var vecs = new Float32Array(triangles.length * 3);
63245
+ var norms = new Float32Array(triangles.length * 3);
63246
+ for (var i = 0; i < triangles.length; i++) {
63247
+ var s = triangles[i];
63248
+ vecs[3 * i] = vertices[3 * s];
63249
+ vecs[3 * i + 1] = vertices[3 * s + 1];
63250
+ vecs[3 * i + 2] = vertices[3 * s + 2];
63251
+ norms[3 * i] = normals[3 * s];
63252
+ norms[3 * i + 1] = normals[3 * s + 1];
63253
+ norms[3 * i + 2] = normals[3 * s + 2];
63254
+ }
63229
63255
  var new_shape = {
63230
63256
  loc: [
63231
63257
  [0, 0, 0],
@@ -63243,20 +63269,8 @@ void main() {
63243
63269
  subtype: part.subtype,
63244
63270
  shape: {
63245
63271
  triangles: [...Array(triangles.length).keys()],
63246
- vertices: triangles
63247
- .map((s) => [
63248
- vertices[3 * s],
63249
- vertices[3 * s + 1],
63250
- vertices[3 * s + 2],
63251
- ])
63252
- .flat(),
63253
- normals: triangles
63254
- .map((s) => [
63255
- normals[3 * s],
63256
- normals[3 * s + 1],
63257
- normals[3 * s + 2],
63258
- ])
63259
- .flat(),
63272
+ vertices: vecs,
63273
+ normals: norms,
63260
63274
  edges: [],
63261
63275
  },
63262
63276
  };
@@ -63281,8 +63295,17 @@ void main() {
63281
63295
  const multiColor =
63282
63296
  Array.isArray(part.color) && part.color.length == shape.edges.length;
63283
63297
  var color;
63284
- for (j = 0; j < shape.edges.length; j++) {
63285
- const edge = shape.edges[j];
63298
+
63299
+ const num = (shape.segments_per_edge) ? shape.segments_per_edge.length : shape.triangles.length;
63300
+ current = 0;
63301
+ var edge;
63302
+ for (j = 0; j < num; j++) {
63303
+ if (shape.segments_per_edge) {
63304
+ edge = shape.edges.subarray(current, current + 6 * shape.segments_per_edge[j]);
63305
+ current += 6 * shape.segments_per_edge[j];
63306
+ } else {
63307
+ edge = shape.edges[j];
63308
+ }
63286
63309
  color = multiColor ? part.color[j] : part.color;
63287
63310
  new_shape = {
63288
63311
  loc: [
@@ -63365,8 +63388,8 @@ void main() {
63365
63388
  renderTessellatedShapes(shapes, states, options) {
63366
63389
  this.setRenderDefaults(options);
63367
63390
  const _render = (shapes, states, measureTools) => {
63368
- var part, shape;
63369
- if (shapes.version == 2) {
63391
+ var part;
63392
+ if (shapes.version == 2 || shapes.version == 3) {
63370
63393
  if (measureTools) {
63371
63394
  var i, tmp;
63372
63395
  let parts = [];
@@ -63380,17 +63403,6 @@ void main() {
63380
63403
  }
63381
63404
  }
63382
63405
  shapes.parts = parts;
63383
- } else {
63384
- for (i = 0; i < shapes.parts.length; i++) {
63385
- part = shapes.parts[i];
63386
- shape = part.shape;
63387
- if (part.type == "shapes") {
63388
- shape.triangles = shape.triangles.flat();
63389
- shape.edges = shape.edges.flat();
63390
- } else if (part.type == "edges" || part.type == "shapes") {
63391
- shape.edges = shape.edges.flat();
63392
- }
63393
- }
63394
63406
  }
63395
63407
  }
63396
63408
  return shapes;
@@ -63719,7 +63731,9 @@ void main() {
63719
63731
 
63720
63732
  timer.split("rendered nested group");
63721
63733
 
63722
- this.bbox = this.nestedGroup.boundingBox();
63734
+ if (!this.bbox) {
63735
+ this.bbox = this.nestedGroup.boundingBox();
63736
+ }
63723
63737
  const center = new Vector3();
63724
63738
  this.bbox.getCenter(center);
63725
63739
  this.bb_max = this.bbox.max_dist_from_center();
@@ -63972,12 +63986,12 @@ void main() {
63972
63986
  this.tools,
63973
63987
  this.glass,
63974
63988
  );
63975
-
63989
+ timer.split("ui updated");
63976
63990
  this.display.autoCollapse();
63977
63991
 
63978
63992
  // ensure all for all deselected objects the stencil planes are invisible
63979
63993
  this.setObjects(this.states, true, true);
63980
-
63994
+ timer.split("stencil done");
63981
63995
  //
63982
63996
  // show the rendering
63983
63997
  //
@@ -63992,7 +64006,7 @@ void main() {
63992
64006
  //
63993
64007
  // notify calculated results
63994
64008
  //
63995
-
64009
+ timer.split("show done");
63996
64010
  if (this.notifyCallback) {
63997
64011
  this.notifyCallback({
63998
64012
  tab: { old: null, new: this.display.activeTab },
@@ -64003,8 +64017,10 @@ void main() {
64003
64017
  clip_normal_2: { old: null, new: this.clipNormal2 },
64004
64018
  });
64005
64019
  }
64006
- this.update(true, false);
64020
+ timer.split("notification done");
64007
64021
 
64022
+ this.update(true, false);
64023
+ timer.split("update done");
64008
64024
  timer.stop();
64009
64025
  }
64010
64026