@archvisioninc/canvas 2.4.5 → 2.4.6

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.
@@ -332,11 +332,12 @@ const initMetadataKeyDefaults = () => {
332
332
  };
333
333
  const checkForRootNode = () => {
334
334
  let rootNode = scene.getNodeById('__root__');
335
- let node0 = scene.getNodeById(node0Name);
335
+ let node0 = rootNode?.getChildren()?.find?.((child, index) => child.name === node0Name && index === 0);
336
336
  const isTransformNode = item => item?.getClassName() === 'TransformNode';
337
337
  const userMeshes = getUserMeshes();
338
338
  const userNodes = getUserNodes();
339
339
  const topLevelUserNodes = userNodes.filter(node => node.parent === null);
340
+ const otherNode0Nodes = userNodes?.filter(node => node.name === node0Name && node.parent !== rootNode);
340
341
  if (!rootNode) {
341
342
  rootNode = new BABYLON.Mesh('__root__', scene);
342
343
  rootNode.isPickable = false;
@@ -345,7 +346,7 @@ const checkForRootNode = () => {
345
346
  rootNode.isPointerBlocker = true;
346
347
  rootNode.isHitTestVisible = false;
347
348
  }
348
- if (!isTransformNode(node0) || !node0) {
349
+ if (!node0 || !isTransformNode(node0)) {
349
350
  node0 = new BABYLON.TransformNode(node0Name, scene);
350
351
  node0.isPickable = false;
351
352
  node0.isVisible = false;
@@ -355,6 +356,11 @@ const checkForRootNode = () => {
355
356
  node0.parent = rootNode;
356
357
  }
357
358
 
359
+ // NOTE: This renames all other node0's to avoid conflict with the main node0 for transformations etc.
360
+ if (!_.isEmpty(otherNode0Nodes)) {
361
+ otherNode0Nodes?.forEach((node, index) => node.name = `node0_(${index})`);
362
+ }
363
+
358
364
  // NOTE: This handles correcting any third-party files that have __root__ and children
359
365
  // but not node0, and makes sure everything is a child of the newly created node0.
360
366
  rootNode.getChildren().forEach(child => {
@@ -362,16 +368,17 @@ const checkForRootNode = () => {
362
368
  const isNode0 = child.name === node0Name && transformNode;
363
369
  const parentedToNode0 = child.parent.name === node0Name && transformNode;
364
370
  const hasNode0AsChild = child.getChildren().find(node => node.name === node0Name);
365
- if (!isNode0 && !parentedToNode0 && !hasNode0AsChild) child.setParent(node0);
371
+ if (!isNode0 && !parentedToNode0 && !hasNode0AsChild) {
372
+ child.setParent(node0);
373
+ }
366
374
  });
367
375
 
368
376
  // NOTE: This handles correcting any parentless user meshes from a third-party file and makes
369
- // sure they are parented to node0.
377
+ // sure they are named with the prefix "mesh" and parented to node0.
370
378
  userMeshes.forEach(mesh => {
371
379
  if (mesh.name === node0Name && !isTransformNode(mesh)) mesh.name = 'mesh0';
372
380
  if (mesh.parent === null) mesh.setParent(node0);
373
381
  });
374
- if (node0.parent !== rootNode) node0.setParent(rootNode);
375
382
 
376
383
  // NOTE: This handles correcting any parentless user nodes from a third-party file and makes
377
384
  // sure they are parented to node0.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archvisioninc/canvas",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "private": false,
5
5
  "main": "dist/Canvas.js",
6
6
  "module": "dist/Canvas.js",
@@ -371,11 +371,12 @@ const initMetadataKeyDefaults = () => {
371
371
 
372
372
  const checkForRootNode = () => {
373
373
  let rootNode = scene.getNodeById('__root__');
374
- let node0 = scene.getNodeById(node0Name);
374
+ let node0 = rootNode?.getChildren()?.find?.((child, index) => child.name === node0Name && index === 0);
375
375
  const isTransformNode = item => item?.getClassName() === 'TransformNode';
376
376
  const userMeshes = getUserMeshes();
377
377
  const userNodes = getUserNodes();
378
378
  const topLevelUserNodes = userNodes.filter(node => node.parent === null);
379
+ const otherNode0Nodes = userNodes?.filter(node => node.name === node0Name && node.parent !== rootNode);
379
380
 
380
381
  if (!rootNode) {
381
382
  rootNode = new BABYLON.Mesh('__root__', scene);
@@ -386,7 +387,7 @@ const checkForRootNode = () => {
386
387
  rootNode.isHitTestVisible = false;
387
388
  }
388
389
 
389
- if (!isTransformNode(node0) || !node0) {
390
+ if (!node0 || !isTransformNode(node0)) {
390
391
  node0 = new BABYLON.TransformNode(node0Name, scene);
391
392
  node0.isPickable = false;
392
393
  node0.isVisible = false;
@@ -396,6 +397,11 @@ const checkForRootNode = () => {
396
397
  node0.parent = rootNode;
397
398
  }
398
399
 
400
+ // NOTE: This renames all other node0's to avoid conflict with the main node0 for transformations etc.
401
+ if (!_.isEmpty(otherNode0Nodes)) {
402
+ otherNode0Nodes?.forEach((node, index) => node.name = `node0_(${index})`);
403
+ }
404
+
399
405
  // NOTE: This handles correcting any third-party files that have __root__ and children
400
406
  // but not node0, and makes sure everything is a child of the newly created node0.
401
407
  rootNode.getChildren().forEach(child => {
@@ -404,18 +410,18 @@ const checkForRootNode = () => {
404
410
  const parentedToNode0 = child.parent.name === node0Name && transformNode;
405
411
  const hasNode0AsChild = child.getChildren().find(node => node.name === node0Name);
406
412
 
407
- if (!isNode0 && !parentedToNode0 && !hasNode0AsChild) child.setParent(node0);
413
+ if (!isNode0 && !parentedToNode0 && !hasNode0AsChild) {
414
+ child.setParent(node0);
415
+ }
408
416
  });
409
417
 
410
418
  // NOTE: This handles correcting any parentless user meshes from a third-party file and makes
411
- // sure they are parented to node0.
419
+ // sure they are named with the prefix "mesh" and parented to node0.
412
420
  userMeshes.forEach(mesh => {
413
421
  if (mesh.name === node0Name && !isTransformNode(mesh)) mesh.name = 'mesh0';
414
422
  if (mesh.parent === null) mesh.setParent(node0);
415
423
  });
416
424
 
417
- if (node0.parent !== rootNode) node0.setParent(rootNode);
418
-
419
425
  // NOTE: This handles correcting any parentless user nodes from a third-party file and makes
420
426
  // sure they are parented to node0.
421
427
  topLevelUserNodes?.forEach(node => node.setParent(node0));