diff --git a/src/views/home.vue b/src/views/home.vue index 02c0ec7..3af210c 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -3,15 +3,15 @@ const demos = [ { name: '加载GLB模型', path: '/three/1' }, { name: '添加灯光', path: '/three/2' }, { name: '添加控制器、AxesHelper', path: '/three/3' }, - { name: '设置地面', path: '/three/3' }, - { name: '地面上设置光效', path: '/three/4' }, - { name: '模型漫游(巡检业务)', path: '/three/5' }, + { name: '设置地面', path: '/three/4' }, + { name: '地面上设置光效', path: '/three/5' }, { name: '模型动画(模型本身存在动画)', path: '/three/6' }, - { name: '漫游 修改材质(设备告警业务)', path: '/three/7' }, - { name: '粒子效果(蒸汽)', path: '/three/8' }, - { name: '模型与Web的交互', path: '/three/9' }, - { name: '后期处理效果', path: '/three/10' }, - { name: '公共函数抽象', path: '/three/11' }, + { name: '模型漫游(巡检业务)', path: '/three/7' }, + { name: '漫游 修改材质(设备告警业务)', path: '/three/8' }, + { name: '粒子效果(蒸汽)', path: '/three/9' }, + { name: '模型与Web的交互', path: '/three/10' }, + { name: '后期处理效果', path: '/three/11' }, + { name: '公共函数抽象', path: '/three/12' }, ] diff --git a/src/views/three/10/index.vue b/src/views/three/10/index.vue index fe03d57..da80ffe 100644 --- a/src/views/three/10/index.vue +++ b/src/views/three/10/index.vue @@ -2,5 +2,5 @@ - 1 + 10 diff --git a/src/views/three/11/index.vue b/src/views/three/11/index.vue index fe03d57..f3fb7c1 100644 --- a/src/views/three/11/index.vue +++ b/src/views/three/11/index.vue @@ -2,5 +2,5 @@ - 1 + 11 diff --git a/src/views/three/12/index.vue b/src/views/three/12/index.vue new file mode 100644 index 0000000..3fefbf4 --- /dev/null +++ b/src/views/three/12/index.vue @@ -0,0 +1,6 @@ + + + + 12 + diff --git a/src/views/three/5/index.vue b/src/views/three/5/index.vue index bdef10f..7974008 100644 --- a/src/views/three/5/index.vue +++ b/src/views/three/5/index.vue @@ -246,8 +246,8 @@ onBeforeUnmount(cleanup) - - 地面上设置光效 + + 模型漫游(巡检业务) diff --git a/src/views/three/6/index.vue b/src/views/three/6/index.vue index 4abe627..15bb5fd 100644 --- a/src/views/three/6/index.vue +++ b/src/views/three/6/index.vue @@ -6,11 +6,15 @@ import { onMounted, shallowRef } from 'vue' const threeRef = shallowRef() +const animations = shallowRef([]) +const model = shallowRef() + +let scene: THREE.Scene | undefined function initModel() { const width = threeRef.value!.clientWidth const height = threeRef.value!.clientHeight - const scene = new THREE.Scene() + scene = new THREE.Scene() scene.background = new THREE.Color(0x000000) const camera = new THREE.PerspectiveCamera( @@ -58,28 +62,14 @@ function initModel() { const loader = new GLTFLoader() loader.load('/lxb_grp.glb', (gltf) => { - scene.add(gltf.scene) - - const { animations = [] } = gltf - animations.forEach((clip) => { - const mixer = new THREE.AnimationMixer(gltf.scene) - const action = mixer.clipAction(clip) - action.play() - - const clock = new THREE.Clock() - // 在动画循环中更新混合器 - function updateMixer() { - requestAnimationFrame(updateMixer) - const delta = clock.getDelta() - mixer.update(delta) - } - updateMixer() - }) + scene!.add(gltf.scene) + model.value = gltf.scene + animations.value = gltf.animations ?? [] }) function animate() { requestAnimationFrame(animate) - renderer.render(scene, camera) + renderer.render(scene!, camera) renderer.setSize(width, height) camera.aspect = width / height camera.updateProjectionMatrix() @@ -88,11 +78,41 @@ function initModel() { animate() } +function handlePlay(index: number) { + const clip = animations.value[index] + if (!clip) + return + + const mixer = new THREE.AnimationMixer(model.value!) + const action = mixer.clipAction(clip) + action.play() + // setTimeout(() => { + // action.stop() + // }, 3000) + + const clock = new THREE.Clock() + // 在动画循环中更新混合器 + function updateMixer() { + requestAnimationFrame(updateMixer) + const delta = clock.getDelta() + mixer.update(delta) + } + updateMixer() +} + onMounted(initModel) + + 模型漫游(巡检业务) + + + + 播放动画{{ index + 1 }} - {{ ani.name }} + +