From b131cef582dec474e5af174f344b515f8db4926e Mon Sep 17 00:00:00 2001 From: Damien Montastier Date: Sat, 8 Feb 2025 03:24:19 +0100 Subject: [PATCH] new version demo playground --- .../vue/src/pages/abstractions/WiggleDemo.vue | 43 ++++++++++++++----- src/core/abstractions/Wiggle/index.ts | 2 + 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/playground/vue/src/pages/abstractions/WiggleDemo.vue b/playground/vue/src/pages/abstractions/WiggleDemo.vue index 50d25314..ae2b4eca 100644 --- a/playground/vue/src/pages/abstractions/WiggleDemo.vue +++ b/playground/vue/src/pages/abstractions/WiggleDemo.vue @@ -3,6 +3,7 @@ import { gsap } from 'gsap' import { TresCanvas, useRenderLoop } from '@tresjs/core' import { ContactShadows, Environment, OrbitControls, TransformControls, useGLTF, Wiggle } from '@tresjs/cientos' import { TresLeches, useControls } from '@tresjs/leches' +import { SkeletonUtils } from 'three-stdlib' import '@tresjs/leches/styles' import type { TresObject } from '@tresjs/core' @@ -17,25 +18,22 @@ const model = await useGLTF( { draco: true }, ) -const modelFlower = await useGLTF( - '/wiggle/banana.glb', - { draco: true }, -) - -// console.log('demo — useGLTF', model) +const model1 = SkeletonUtils.clone(model.scene) +const model2 = SkeletonUtils.clone(model.scene) const modelRef = ref(null) const modelRefBis = ref(null) const testRef = ref(null) const testRefBis = ref(null) +const testRefOpposite = ref(null) -const areaLimit = 2.5 +const areaLimit = 3.5 const { velocity, stiffness, damping } = useControls({ debug: { value: false, type: 'boolean', label: 'Debug' }, velocity: { label: 'Velocity', - value: 0.2, + value: 0.3, min: 0.01, max: 1, step: 0.01, @@ -49,7 +47,7 @@ const { velocity, stiffness, damping } = useControls({ }, damping: { label: 'Damping', - value: 30, + value: 25, min: 1, max: 50, step: 1, @@ -71,11 +69,30 @@ watch(testRef, () => { }) }) +watch(testRefOpposite, () => { + if (!testRefOpposite.value) { return } + + gsap.to(testRefOpposite.value.root.position, { + keyframes: { + x: [-areaLimit, areaLimit, areaLimit, -areaLimit, -areaLimit], + z: [-areaLimit, -areaLimit, areaLimit, areaLimit, -areaLimit], + easeEach: 'elastic.inOut(0.85,0.6)', + }, + ease: 'none', + repeat: -1, + duration: 6.5, + }) +}) + const { onLoop } = useRenderLoop() onLoop(({ elapsed }) => { + if (!testRef.value || !testRefBis.value) { return } + testRef.value.root.rotation.y = Math.PI / 2 * Math.sin(elapsed) testRef.value.root.rotation.x = Math.PI / 6 * Math.sin(elapsed) + + testRefBis.value.root.position.y = 0.15 * Math.sin(elapsed) }) @@ -106,9 +123,15 @@ onLoop(({ elapsed }) => { + + + + + + - + diff --git a/src/core/abstractions/Wiggle/index.ts b/src/core/abstractions/Wiggle/index.ts index c99ba766..491c1333 100644 --- a/src/core/abstractions/Wiggle/index.ts +++ b/src/core/abstractions/Wiggle/index.ts @@ -30,6 +30,8 @@ export function useWiggle(model: Object3D, { debug = false, basic = true, spring return } + console.log(model) + const { scene } = useTresContext() const { onLoop } = useRenderLoop()