From 732f64356fe8dc4f4cee319d2f876b0fe51ccc1c Mon Sep 17 00:00:00 2001 From: Yuki Shimada Date: Mon, 5 Jun 2023 16:16:28 +0900 Subject: [PATCH 1/4] remove unuse srcRootEntityForRetarget argument --- src/foundation/importer/AnimationAssigner.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/foundation/importer/AnimationAssigner.ts b/src/foundation/importer/AnimationAssigner.ts index f0df78e52..d35b34fcc 100644 --- a/src/foundation/importer/AnimationAssigner.ts +++ b/src/foundation/importer/AnimationAssigner.ts @@ -20,13 +20,23 @@ type RetargetMode = 'none' | 'global' | 'global2' | 'absolute'; export class AnimationAssigner { private static __instance: AnimationAssigner; + /** + * Assign Animation Function + * + * @param rootEntity - The root entity of the model which you want to assign animation. + * @param gltfModel - The glTF model that has animation data. + * @param vrmModel - The corresponding VRM model to the glTF model. + * @param isSameSkeleton + * @param retargetMode - Retarget mode. 'none' | 'global' | 'global2' | 'absolute' + * @param srcRootEntityForRetarget + * @returns + */ assignAnimation( rootEntity: ISceneGraphEntity, gltfModel: RnM2, vrmModel: Vrm0x | Vrm1, isSameSkeleton: boolean, - retargetMode: RetargetMode = 'none', - srcRootEntityForRetarget?: ISceneGraphEntity + retargetMode: RetargetMode ) { this.__setupAnimationForSameSkeleton( rootEntity, @@ -34,7 +44,6 @@ export class AnimationAssigner { vrmModel, isSameSkeleton, retargetMode, - srcRootEntityForRetarget ); return rootEntity; @@ -165,7 +174,6 @@ export class AnimationAssigner { vrmModel: Vrm0x | Vrm1, isSameSkeleton: boolean, retargetMode: RetargetMode, - srcRootEntityForRetarget?: ISceneGraphEntity ) { if (gltfModel.animations) { for (const animation of gltfModel.animations) { @@ -233,7 +241,7 @@ export class AnimationAssigner { ); } - if (retargetMode !== 'none' && Is.exist(srcRootEntityForRetarget)) { + if (retargetMode !== 'none') { const gltfEntity = gltfModel.extras.rnEntities[channel.target!.node!]; let retarget: IAnimationRetarget | undefined; if (retargetMode === 'global') { From b03ac457f8fcf908678833cfaf517ceec6b984a0 Mon Sep 17 00:00:00 2001 From: Yuki Shimada Date: Mon, 5 Jun 2023 16:35:01 +0900 Subject: [PATCH 2/4] refactoring --- .../Animation/AnimationComponent.ts | 11 +++ src/foundation/importer/AnimationAssigner.ts | 67 ++++++++++--------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/foundation/components/Animation/AnimationComponent.ts b/src/foundation/components/Animation/AnimationComponent.ts index bd2151d25..ec22b879a 100644 --- a/src/foundation/components/Animation/AnimationComponent.ts +++ b/src/foundation/components/Animation/AnimationComponent.ts @@ -1005,5 +1005,16 @@ export class AnimationComponent extends Component { this.__isAnimating = component.__isAnimating; this._animationRetarget = component._animationRetarget; } + + setAnimationRetarget(retarget: IAnimationRetarget) { + this._animationRetarget = retarget; + + this.__transformComponent = EntityRepository.getComponentOfEntity( + this.__entityUid, + TransformComponent + ) as TransformComponent; + + this.__transformComponent?._backupTransformAsRest(); + } } ComponentRepository.registerComponentClass(AnimationComponent); diff --git a/src/foundation/importer/AnimationAssigner.ts b/src/foundation/importer/AnimationAssigner.ts index d35b34fcc..47991b18b 100644 --- a/src/foundation/importer/AnimationAssigner.ts +++ b/src/foundation/importer/AnimationAssigner.ts @@ -209,39 +209,40 @@ export class AnimationAssigner { const newRnEntity = EntityRepository.addComponentToEntity(AnimationComponent, rnEntity); const animationComponent = newRnEntity.getAnimation(); - // apply animation data to the target joint entity - let animationAttributeType = 'translate'; - if (channel.target!.path === 'translation') { - animationAttributeType = 'translate'; - } else if (channel.target!.path! === 'rotation') { - animationAttributeType = 'quaternion'; - } else { - animationAttributeType = channel.target!.path; - } - if (animationAttributeType === 'quaternion') { - animationComponent.setAnimation( - Is.exist(animation.name) ? animation.name! : 'Untitled', - animationAttributeType, - animInputArray!, - animOutputArray!, - 4, // Quaternion - AnimationInterpolation.fromString(interpolation) - ); - } else if ( - animationAttributeType === 'translate' && - this.__isHips(rootEntity, vrmModel, channel.target!.node!) - ) { - animationComponent.setAnimation( - Is.exist(animation.name) ? animation.name! : 'Untitled', - animationAttributeType, - animInputArray!, - animOutputArray!, - 3, // translate - AnimationInterpolation.fromString(interpolation) - ); - } - if (retargetMode !== 'none') { + if (retargetMode === 'none') { + // apply animation data to the target joint entity + let animationAttributeType = 'translate'; + if (channel.target!.path === 'translation') { + animationAttributeType = 'translate'; + } else if (channel.target!.path! === 'rotation') { + animationAttributeType = 'quaternion'; + } else { + animationAttributeType = channel.target!.path; + } + if (animationAttributeType === 'quaternion') { + animationComponent.setAnimation( + Is.exist(animation.name) ? animation.name! : 'Untitled', + animationAttributeType, + animInputArray!, + animOutputArray!, + 4, // Quaternion + AnimationInterpolation.fromString(interpolation) + ); + } else if ( + animationAttributeType === 'translate' && + this.__isHips(rootEntity, vrmModel, channel.target!.node!) + ) { + animationComponent.setAnimation( + Is.exist(animation.name) ? animation.name! : 'Untitled', + animationAttributeType, + animInputArray!, + animOutputArray!, + 3, // translate + AnimationInterpolation.fromString(interpolation) + ); + } + } else { const gltfEntity = gltfModel.extras.rnEntities[channel.target!.node!]; let retarget: IAnimationRetarget | undefined; if (retargetMode === 'global') { @@ -253,7 +254,7 @@ export class AnimationAssigner { } else { throw new Error('unknown retarget mode'); } - animationComponent._animationRetarget = retarget; + animationComponent.setAnimationRetarget(retarget); } } } From 1507b59e3e1d440a04cdeb750844e0c110268085 Mon Sep 17 00:00:00 2001 From: Yuki Shimada Date: Tue, 6 Jun 2023 19:01:54 +0900 Subject: [PATCH 3/4] fix: VRM extension detection --- src/foundation/importer/GltfImporter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/foundation/importer/GltfImporter.ts b/src/foundation/importer/GltfImporter.ts index 824beae36..021380d23 100644 --- a/src/foundation/importer/GltfImporter.ts +++ b/src/foundation/importer/GltfImporter.ts @@ -265,12 +265,12 @@ export class GltfImporter { if (result.isOk()) { const gltfModel = result.get(); - if (gltfModel.extensionsUsed.indexOf('VRMC_vrm') > 0) { + if (gltfModel.extensionsUsed.indexOf('VRMC_vrm') >= 0) { options.__isImportVRM0x = false; gltfModel.asset.extras!.rnLoaderOptions!.__isImportVRM0x = false; options.__importedType = 'vrm1'; await VrmImporter.__importVRM(gltfModel, renderPasses); - } else if (gltfModel.extensionsUsed.indexOf('VRM') > 0) { + } else if (gltfModel.extensionsUsed.indexOf('VRM') >= 0) { options.__importedType = 'vrm0x'; await Vrm0xImporter.__importVRM0x(gltfModel, renderPasses); } From be24ebc1101c1a9e0cd03f8b094141639d580d19 Mon Sep 17 00:00:00 2001 From: Yuki Shimada Date: Tue, 6 Jun 2023 19:57:48 +0900 Subject: [PATCH 4/4] fix: some samples --- samples/test_e2e/VRM1Animation/main.ts | 3 +-- samples/test_e2e/VRMAnimation/main.ts | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/test_e2e/VRM1Animation/main.ts b/samples/test_e2e/VRM1Animation/main.ts index 0f0cda75a..37b5d8c7f 100644 --- a/samples/test_e2e/VRM1Animation/main.ts +++ b/samples/test_e2e/VRM1Animation/main.ts @@ -72,8 +72,7 @@ declare const Stats: any; animGltf2Result.unwrapForce(), vrmModelResult.unwrapForce(), false, - 'global', - animGltfModel + 'global' ); // for (let i = 0; i < 1; i++) { diff --git a/samples/test_e2e/VRMAnimation/main.ts b/samples/test_e2e/VRMAnimation/main.ts index 79609a964..26e89959b 100644 --- a/samples/test_e2e/VRMAnimation/main.ts +++ b/samples/test_e2e/VRMAnimation/main.ts @@ -72,7 +72,8 @@ declare const Stats: any; vrmRootEntity, animGltf2Result.unwrapForce(), vrmModelResult.unwrapForce(), - false + false, + 'none' ); for (let i = 0; i < 1; i++) { @@ -91,7 +92,8 @@ declare const Stats: any; vrmRootEntity2nd, animGltf2Result.unwrapForce(), vrmModelResult.unwrapForce(), - false + false, + 'none' ); } }