From f62295ebbe5a7725fe13c3db8b93e7585d62960a Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 22 Sep 2024 20:48:11 -0400 Subject: [PATCH] Examples: add webgpu_animation_retargeting (#1248) * Update SkeletonUtils * Update three.js * Add examples * Update patch and delete examples * Format --- examples-testing/changes.patch | 53 +++++++++++++++++++ three.js | 2 +- .../examples/jsm/utils/SkeletonUtils.d.ts | 23 ++++++-- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/examples-testing/changes.patch b/examples-testing/changes.patch index 7b162d2aa..9eb2f6724 100644 --- a/examples-testing/changes.patch +++ b/examples-testing/changes.patch @@ -13142,6 +13142,59 @@ index d0255e43..c924d666 100644 init(); +diff --git a/examples-testing/examples/webgpu_animation_retargeting.ts b/examples-testing/examples/webgpu_animation_retargeting.ts +index 1d9c5eab..5c4fc4c5 100644 +--- a/examples-testing/examples/webgpu_animation_retargeting.ts ++++ b/examples-testing/examples/webgpu_animation_retargeting.ts +@@ -1,20 +1,20 @@ +-import * as THREE from 'three'; ++import * as THREE from 'three/webgpu'; + import { color, viewportUV, reflector } from 'three/tsl'; + + import Stats from 'three/addons/libs/stats.module.js'; + + import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; +-import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; ++import { GLTFLoader, GLTF } from 'three/addons/loaders/GLTFLoader.js'; + import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; + + import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js'; + + const [sourceModel, targetModel] = await Promise.all([ +- new Promise((resolve, reject) => { ++ new Promise((resolve, reject) => { + new GLTFLoader().load('./models/gltf/Michelle.glb', resolve, undefined, reject); + }), + +- new Promise((resolve, reject) => { ++ new Promise((resolve, reject) => { + new GLTFLoader().load('./models/gltf/Soldier.glb', resolve, undefined, reject); + }), + ]); +@@ -94,7 +94,13 @@ gui.add(helpers, 'visible').name('helpers'); + + // + +-function getSource(sourceModel) { ++interface Source { ++ clip: THREE.AnimationClip; ++ skeleton: THREE.Skeleton; ++ mixer: THREE.AnimationMixer; ++} ++ ++function getSource(sourceModel: GLTF) { + const clip = sourceModel.animations[0]; + + const helper = new THREE.SkeletonHelper(sourceModel.scene); +@@ -108,7 +114,7 @@ function getSource(sourceModel) { + return { clip, skeleton, mixer }; + } + +-function retargetModel(sourceModel, targetModel) { ++function retargetModel(sourceModel: Source, targetModel: GLTF) { + const targetSkin = targetModel.scene.children[0].children[0]; + + const targetSkelHelper = new THREE.SkeletonHelper(targetModel.scene); diff --git a/examples-testing/examples/webgpu_backdrop_area.ts b/examples-testing/examples/webgpu_backdrop_area.ts index 97c224ce..579cb796 100644 --- a/examples-testing/examples/webgpu_backdrop_area.ts diff --git a/three.js b/three.js index b6cb1eb5a..1d126cf52 160000 --- a/three.js +++ b/three.js @@ -1 +1 @@ -Subproject commit b6cb1eb5a04a94097f0dc947c84cc0c8e241af4a +Subproject commit 1d126cf52281fd1266d240d86d7162b5e4236265 diff --git a/types/three/examples/jsm/utils/SkeletonUtils.d.ts b/types/three/examples/jsm/utils/SkeletonUtils.d.ts index 6fbafc6fe..8a20c2501 100644 --- a/types/three/examples/jsm/utils/SkeletonUtils.d.ts +++ b/types/three/examples/jsm/utils/SkeletonUtils.d.ts @@ -1,12 +1,29 @@ import { AnimationClip, Object3D, Skeleton } from "three"; -export function clone(source: Object3D): Object3D; +export interface RetargetOptions { + preserveBoneMatrix?: boolean | undefined; + preserveBonePositions?: boolean | undefined; + preserveHipPosition?: boolean | undefined; + useTargetMatrix?: boolean | undefined; + hip?: string | undefined; + scale?: number | undefined; + names?: { [boneName: string]: string } | undefined; +} -export function retarget(target: Object3D | Skeleton, source: Object3D | Skeleton, options: {}): void; +declare function retarget(target: Object3D | Skeleton, source: Object3D | Skeleton, options: {}): void; -export function retargetClip( +export interface RetargetClipOptions extends RetargetOptions { + useFirstFramePosition?: boolean | undefined; + fps?: number | undefined; +} + +declare function retargetClip( target: Skeleton | Object3D, source: Skeleton | Object3D, clip: AnimationClip, options: {}, ): AnimationClip; + +declare function clone(source: Object3D): Object3D; + +export { clone, retarget, retargetClip };