three-cad-viewer 1.6.3 → 1.6.4

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.
@@ -53986,9 +53986,10 @@ const _hbox = new BoundingBox();
53986
53986
  const _sphere = new Sphere();
53987
53987
 
53988
53988
  class ObjectGroup extends Group {
53989
- constructor(opacity, edge_color, renderback) {
53989
+ constructor(opacity, alpha, edge_color, renderback) {
53990
53990
  super();
53991
53991
  this.opacity = opacity;
53992
+ this.alpha = (alpha == null) ? 1.0 : alpha;
53992
53993
  this.edge_color = edge_color;
53993
53994
  this.renderback = renderback;
53994
53995
  this.types = { front: null, back: null, edges: null, vertrices: null };
@@ -54001,12 +54002,14 @@ class ObjectGroup extends Group {
54001
54002
 
54002
54003
  setTransparent(flag) {
54003
54004
  if (this.types.back) {
54004
- this.types.back.material.opacity = flag ? this.opacity : 1.0;
54005
- this.types.front.material.opacity = flag ? this.opacity : 1.0;
54005
+ this.types.back.material.opacity = flag ? this.opacity * this.alpha : this.alpha;
54006
+ this.types.front.material.opacity = flag ? this.opacity * this.alpha : this.alpha;
54006
54007
  }
54007
54008
  for (var child of this.children) {
54008
- child.material.depthWrite = !flag;
54009
- child.material.depthTest = !flag;
54009
+ // turn depth write off for transparent objects
54010
+ child.material.depthWrite = (this.alpha < 1.0) ? false : !flag;
54011
+ // but keep depth test
54012
+ child.material.depthTest = true;
54010
54013
  child.material.needsUpdate = true;
54011
54014
  }
54012
54015
  }
@@ -54189,6 +54192,7 @@ class NestedGroup {
54189
54192
  renderEdges(edgeList, lineWidth, color, name, state) {
54190
54193
  var group = new ObjectGroup(
54191
54194
  this.defaultOpacity,
54195
+ 1.0,
54192
54196
  color == null ? this.edgeColor : color,
54193
54197
  );
54194
54198
 
@@ -54204,6 +54208,7 @@ class NestedGroup {
54204
54208
  renderVertices(vertexList, size, color, name, state) {
54205
54209
  var group = new ObjectGroup(
54206
54210
  this.defaultOpacity,
54211
+ 1.0,
54207
54212
  color == null ? this.edgeColor : color,
54208
54213
  );
54209
54214
 
@@ -54238,7 +54243,7 @@ class NestedGroup {
54238
54243
  return group;
54239
54244
  }
54240
54245
 
54241
- renderShape(shape, color, renderback, name, states) {
54246
+ renderShape(shape, color, alpha, renderback, name, states) {
54242
54247
  const positions =
54243
54248
  shape.vertices instanceof Float32Array
54244
54249
  ? shape.vertices
@@ -54254,10 +54259,16 @@ class NestedGroup {
54254
54259
 
54255
54260
  var group = new ObjectGroup(
54256
54261
  this.defaultOpacity,
54262
+ alpha,
54257
54263
  this.edgeColor,
54258
54264
  renderback,
54259
54265
  );
54260
-
54266
+
54267
+ if (alpha == null) {
54268
+ alpha = 1.0;
54269
+ } else if (alpha < 1.0) {
54270
+ this.transparent = true;
54271
+ }
54261
54272
  var shapeGeometry = new BufferGeometry();
54262
54273
  shapeGeometry.setAttribute(
54263
54274
  "position",
@@ -54266,20 +54277,26 @@ class NestedGroup {
54266
54277
  shapeGeometry.setAttribute("normal", new BufferAttribute(normals, 3));
54267
54278
  shapeGeometry.setIndex(new BufferAttribute(triangles, 1));
54268
54279
 
54280
+ // see https://stackoverflow.com/a/37651610
54281
+ // "A common draw configuration you see is to draw all the opaque object with depth testing on,
54282
+ // turn depth write off, then draw the transparent objects in a back to front order."
54283
+
54269
54284
  const frontMaterial = new MeshStandardMaterial({
54270
54285
  color: color,
54271
54286
  polygonOffset: true,
54272
54287
  polygonOffsetFactor: 1.0,
54273
54288
  polygonOffsetUnits: 1.0,
54274
54289
  transparent: true,
54275
- opacity: this.transparent ? this.defaultOpacity : 1.0,
54290
+ opacity: this.transparent ? this.defaultOpacity * alpha : alpha,
54291
+ // turn depth write off for transparent objects
54276
54292
  depthWrite: !this.transparent,
54277
- depthTest: !this.transparent,
54293
+ // but keep depth test
54294
+ depthTest: true,
54278
54295
  clipIntersection: false,
54279
54296
  side: FrontSide,
54280
54297
  visible: states[0] == 1,
54281
54298
  });
54282
-
54299
+
54283
54300
  const backMaterial = new MeshBasicMaterial({
54284
54301
  color: new Color(this.edgeColor),
54285
54302
  side: BackSide,
@@ -54287,9 +54304,11 @@ class NestedGroup {
54287
54304
  polygonOffsetFactor: 1.0,
54288
54305
  polygonOffsetUnits: 1.0,
54289
54306
  transparent: true,
54290
- opacity: this.transparent ? this.defaultOpacity : 1.0,
54307
+ opacity: this.transparent ? this.defaultOpacity * alpha : alpha,
54308
+ // turn depth write off for transparent objects
54291
54309
  depthWrite: !this.transparent,
54292
- depthTest: !this.transparent,
54310
+ // but keep depth test
54311
+ depthTest: true,
54293
54312
  clipIntersection: false,
54294
54313
  visible: states[0] == 1 && (renderback || this.backVisible),
54295
54314
  });
@@ -54299,6 +54318,12 @@ class NestedGroup {
54299
54318
 
54300
54319
  const back = new Mesh(shapeGeometry, backMaterial);
54301
54320
  back.name = name;
54321
+
54322
+ // ensure, transparent objects will be rendered at the end
54323
+ if (alpha < 1.0) {
54324
+ back.renderOrder = 999;
54325
+ front.renderOrder = 999;
54326
+ }
54302
54327
 
54303
54328
  group.addType(back, "back");
54304
54329
  group.addType(front, "front");
@@ -54350,6 +54375,7 @@ class NestedGroup {
54350
54375
  mesh = this.renderShape(
54351
54376
  shape.shape,
54352
54377
  shape.color,
54378
+ shape.alpha,
54353
54379
  shape.renderback == null ? false : shape.renderback,
54354
54380
  shape.name,
54355
54381
  states[shape.id],
@@ -57643,7 +57669,7 @@ class Camera {
57643
57669
  }
57644
57670
  }
57645
57671
 
57646
- const version="1.6.3";
57672
+ const version="1.6.4";
57647
57673
 
57648
57674
  class Viewer {
57649
57675
  /**
@@ -57809,6 +57835,7 @@ class Viewer {
57809
57835
  this.clipSlider1 = -1;
57810
57836
  this.clipSlider2 = -1;
57811
57837
  this.control = "orbit";
57838
+ this.up = "Z";
57812
57839
  this.ticks = 10;
57813
57840
 
57814
57841
  this.position = null;