@archvisioninc/canvas 3.3.6 → 3.3.7

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.
@@ -596,6 +596,9 @@ export const updateMesh = inboundData => {
596
596
  globalTransform,
597
597
  variantName,
598
598
  resetVariant,
599
+ animationId,
600
+ resetAnimation,
601
+ loopAnimation = true,
599
602
  sourceUnit,
600
603
  displayUnit
601
604
  } = payload;
@@ -725,6 +728,30 @@ export const updateMesh = inboundData => {
725
728
  khrExtension.Reset(rootMesh);
726
729
  newMetaDataEntry('selectedMaterialVariant', null);
727
730
  }
731
+ const animationGroups = scene.animationGroups || [];
732
+ const hasAnimationId = animationId !== undefined && animationId !== null && `${animationId}` !== '';
733
+ const stopAllAnimationGroups = () => {
734
+ animationGroups.forEach(group => {
735
+ group.stop();
736
+ group.reset();
737
+ });
738
+ };
739
+
740
+ // Reset current animation
741
+ if (resetAnimation) {
742
+ stopAllAnimationGroups();
743
+ newMetaDataEntry('selectedAnimation', null);
744
+ }
745
+
746
+ // Change active animation
747
+ if (hasAnimationId) {
748
+ const animationGroup = animationGroups.find((group, index) => `${index}` === `${animationId}`);
749
+ stopAllAnimationGroups();
750
+ if (animationGroup) {
751
+ animationGroup.start(Boolean(loopAnimation));
752
+ newMetaDataEntry('selectedAnimation', `${animationId}`);
753
+ }
754
+ }
728
755
 
729
756
  // Bounding Box Toggle
730
757
  if (boundingBoxEnabled !== undefined) {
@@ -3,7 +3,7 @@ import * as MATERIALS from 'babylonjs-materials';
3
3
  import * as BABYLONGUI from 'babylonjs-gui';
4
4
  import { LISTENERS, LIGHTS, CAMERAS, VIEWPORT } from '../constants';
5
5
  import { shortcuts, ratios, downscaling, exclusionMeshes, exclusionMaterials } from '../enums';
6
- import { newScene, newEngine, newCamera, newLight, newVector, newHighlightManager, handleMouseListeners, handleShortcutListeners, prepareCamera, newGround, newGridMaterial, newColor, setDefaultGridProperties, prepareAxes, getBoundingDistance, newGizmoManager, getUserMeshes, getUserMaterials, newPBRMaterial, createSafeFrame, createDragSelectBox, addInitialGizmoBehaviors, loadFromBlob, loadFromGuidURL, prepareMaterialCamera, loadFromDragDrop, addHighlightExclusion, warningChecks, toRadians, toDegrees, getStatisticsMetadata, newMetaDataEntry, serializeScene, buildMeshPositionsArray, buildMaterialsArray, updatePublish, buildSelectedMaterialArray, buildMaterialVariantsArray, removeAutoRotation, getUserNodes, buildLightsArray } from '../helpers';
6
+ import { newScene, newEngine, newCamera, newLight, newVector, newHighlightManager, handleMouseListeners, handleShortcutListeners, prepareCamera, newGround, newGridMaterial, newColor, setDefaultGridProperties, prepareAxes, getBoundingDistance, newGizmoManager, getUserMeshes, getUserMaterials, newPBRMaterial, createSafeFrame, createDragSelectBox, addInitialGizmoBehaviors, loadFromBlob, loadFromGuidURL, prepareMaterialCamera, loadFromDragDrop, addHighlightExclusion, warningChecks, toRadians, toDegrees, getStatisticsMetadata, newMetaDataEntry, serializeScene, buildMeshPositionsArray, buildMaterialsArray, buildAnimationsArray, updatePublish, buildSelectedMaterialArray, buildMaterialVariantsArray, removeAutoRotation, getUserNodes, buildLightsArray } from '../helpers';
7
7
  import { modelToOrigin, focusCamera } from '../actions';
8
8
  import { reactProps as props } from '../Canvas';
9
9
  import _ from 'lodash';
@@ -344,6 +344,8 @@ const initMetadataKeyDefaults = () => {
344
344
  newMetaDataEntry('fileName', null);
345
345
  newMetaDataEntry('uvScaleLock', false);
346
346
  newMetaDataEntry('lights', []);
347
+ newMetaDataEntry('animations', []);
348
+ newMetaDataEntry('selectedAnimation', null);
347
349
  };
348
350
  const checkForRootNode = () => {
349
351
  let rootNode = scene.getNodeById('__root__');
@@ -464,6 +466,10 @@ export const initSceneFromFile = (sceneFromFile, fileName) => {
464
466
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
465
467
  newMetaDataEntry('fileName', fileName);
466
468
  newMetaDataEntry('materialVariants', buildMaterialVariantsArray());
469
+ const animations = buildAnimationsArray();
470
+ const activeAnimationIndex = scene.animationGroups?.findIndex(group => group.isPlaying) ?? -1;
471
+ newMetaDataEntry('animations', animations);
472
+ newMetaDataEntry('selectedAnimation', activeAnimationIndex >= 0 ? `${activeAnimationIndex}` : null);
467
473
  newMetaDataEntry('uvScaleLock', scene.metadata.uvScaleLock || false);
468
474
  newMetaDataEntry('lights', buildLightsArray());
469
475
  updatePublish(fileName ? {
@@ -271,6 +271,19 @@ export const buildMaterialVariantsArray = () => {
271
271
  const variants = khrExtension.GetAvailableVariants(rootMesh);
272
272
  return variants;
273
273
  };
274
+ export const buildAnimationsArray = () => {
275
+ const animationGroups = scene?.animationGroups || [];
276
+ return animationGroups.map((group, index) => {
277
+ const fallbackLabel = `Animation ${index + 1}`;
278
+ const label = group.name || group.id || fallbackLabel;
279
+ return {
280
+ id: `${index}`,
281
+ index,
282
+ label,
283
+ name: group.name || ''
284
+ };
285
+ });
286
+ };
274
287
  export const buildSelectedMaterialArray = () => {
275
288
  if (props.materialMode) {
276
289
  const mainMaterial = scene.metadata?.materials?.find?.(item => item.materialId === 'material');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archvisioninc/canvas",
3
- "version": "3.3.6",
3
+ "version": "3.3.7",
4
4
  "private": false,
5
5
  "main": "dist/Canvas.js",
6
6
  "module": "dist/Canvas.js",
@@ -666,6 +666,9 @@ export const updateMesh = inboundData => {
666
666
  globalTransform,
667
667
  variantName,
668
668
  resetVariant,
669
+ animationId,
670
+ resetAnimation,
671
+ loopAnimation = true,
669
672
  sourceUnit,
670
673
  displayUnit,
671
674
  } = payload;
@@ -773,6 +776,34 @@ export const updateMesh = inboundData => {
773
776
  newMetaDataEntry('selectedMaterialVariant', null);
774
777
  }
775
778
 
779
+ const animationGroups = scene.animationGroups || [];
780
+ const hasAnimationId = animationId !== undefined && animationId !== null && `${animationId}` !== '';
781
+
782
+ const stopAllAnimationGroups = () => {
783
+ animationGroups.forEach(group => {
784
+ group.stop();
785
+ group.reset();
786
+ });
787
+ };
788
+
789
+ // Reset current animation
790
+ if (resetAnimation) {
791
+ stopAllAnimationGroups();
792
+ newMetaDataEntry('selectedAnimation', null);
793
+ }
794
+
795
+ // Change active animation
796
+ if (hasAnimationId) {
797
+ const animationGroup = animationGroups.find((group, index) => `${index}` === `${animationId}`);
798
+
799
+ stopAllAnimationGroups();
800
+
801
+ if (animationGroup) {
802
+ animationGroup.start(Boolean(loopAnimation));
803
+ newMetaDataEntry('selectedAnimation', `${animationId}`);
804
+ }
805
+ }
806
+
776
807
  // Bounding Box Toggle
777
808
  if (boundingBoxEnabled !== undefined) {
778
809
  toggleBoundingBoxWidget();
@@ -39,6 +39,7 @@ import {
39
39
  serializeScene,
40
40
  buildMeshPositionsArray,
41
41
  buildMaterialsArray,
42
+ buildAnimationsArray,
42
43
  updatePublish,
43
44
  buildSelectedMaterialArray,
44
45
  buildMaterialVariantsArray,
@@ -388,6 +389,8 @@ const initMetadataKeyDefaults = () => {
388
389
  newMetaDataEntry('fileName', null);
389
390
  newMetaDataEntry('uvScaleLock', false);
390
391
  newMetaDataEntry('lights', []);
392
+ newMetaDataEntry('animations', []);
393
+ newMetaDataEntry('selectedAnimation', null);
391
394
  };
392
395
 
393
396
  const checkForRootNode = () => {
@@ -506,6 +509,13 @@ export const initSceneFromFile = (sceneFromFile, fileName) => {
506
509
  newMetaDataEntry('selectedMaterials', buildSelectedMaterialArray());
507
510
  newMetaDataEntry('fileName', fileName);
508
511
  newMetaDataEntry('materialVariants', buildMaterialVariantsArray());
512
+ const animations = buildAnimationsArray();
513
+ const activeAnimationIndex = scene.animationGroups?.findIndex(group => group.isPlaying) ?? -1;
514
+ newMetaDataEntry('animations', animations);
515
+ newMetaDataEntry(
516
+ 'selectedAnimation',
517
+ activeAnimationIndex >= 0 ? `${activeAnimationIndex}` : null,
518
+ );
509
519
  newMetaDataEntry('uvScaleLock', scene.metadata.uvScaleLock || false);
510
520
  newMetaDataEntry('lights', buildLightsArray());
511
521
 
@@ -336,6 +336,23 @@ export const buildMaterialVariantsArray = () => {
336
336
  return variants;
337
337
  };
338
338
 
339
+
340
+ export const buildAnimationsArray = () => {
341
+ const animationGroups = scene?.animationGroups || [];
342
+
343
+ return animationGroups.map((group, index) => {
344
+ const fallbackLabel = `Animation ${index + 1}`;
345
+ const label = group.name || group.id || fallbackLabel;
346
+
347
+ return {
348
+ id: `${index}`,
349
+ index,
350
+ label,
351
+ name: group.name || '',
352
+ };
353
+ });
354
+ };
355
+
339
356
  export const buildSelectedMaterialArray = () => {
340
357
  if (props.materialMode) {
341
358
  const mainMaterial = scene.metadata?.materials?.find?.(item => item.materialId === 'material');