Skip to content

Commit

Permalink
new version demo playground
Browse files Browse the repository at this point in the history
  • Loading branch information
damienmontastier committed Feb 8, 2025
1 parent 7bb1142 commit b131cef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
43 changes: 33 additions & 10 deletions playground/vue/src/pages/abstractions/WiggleDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<TresObject | null>(null)
const modelRefBis = ref<TresObject | null>(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,
Expand All @@ -49,7 +47,7 @@ const { velocity, stiffness, damping } = useControls({
},
damping: {
label: 'Damping',
value: 30,
value: 25,
min: 1,
max: 50,
step: 1,
Expand All @@ -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)
})
</script>

Expand Down Expand Up @@ -106,9 +123,15 @@ onLoop(({ elapsed }) => {
</Wiggle>
</Suspense>

<Suspense>
<Wiggle ref="testRefOpposite" :position-z="-areaLimit" :position-x="-areaLimit" :scale="15" :debug="true" :basic="{ velocity: velocity.value }">
<primitive ref="modelRef" :object="model1" />
</Wiggle>
</Suspense>

<Suspense>
<Wiggle ref="testRefBis" :scale="15" :debug="false" :spring="{ stiffness: stiffness.value, damping: damping.value }">
<primitive ref="modelRefBis" :object="modelFlower.scene" />
<primitive ref="modelRefBis" :object="model2" />
</Wiggle>
</Suspense>

Expand Down
2 changes: 2 additions & 0 deletions src/core/abstractions/Wiggle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function useWiggle(model: Object3D, { debug = false, basic = true, spring
return
}

console.log(model)

Check failure on line 33 in src/core/abstractions/Wiggle/index.ts

View workflow job for this annotation

GitHub Actions / Lint (20)

Unexpected console statement

const { scene } = useTresContext()
const { onLoop } = useRenderLoop()

Expand Down

0 comments on commit b131cef

Please sign in to comment.