[英]How to Loop GlftModel with troisjs in Vue
Hey I want to Loop a 3D Model that I created but if i try to run this code it don't loop it only runs it once and then it stops and it returns no error.嘿,我想循环我创建的 3D Model 但如果我尝试运行此代码它不会循环它只运行一次然后它停止并且它不返回任何错误。 I hope you can help me
我希望你能帮帮我
<template>
<Renderer ref="renderer" antialias orbit-ctrl resize="window">
<Camera ref="cam" :position="{ z: 40, x: 3 }"></Camera>
<Scene :background="'white'">
<AmbientLight color="#808080"></AmbientLight>
<PointLight color="#ffffff" :position="{ y: 50, z: 0 }"></PointLight>
<PointLight color="#ffffff" :position="{ y: -50, z: 0 }"></PointLight>
<PointLight color="#ffffff" :position="{ y: 0, z: 0 }"></PointLight>
<GltfModel ref="model" :rotation="{ y: 0.2, x: 0.1, z: 1}" src="http://192.168.178.23:8080/car.gltf"/>
</Scene>
</Renderer>
</template>
<script>
import { Camera, PointLight, Renderer, Scene, GltfModel, AmbientLight } from 'troisjs';
export default {
name: 'Car',
components: { Camera, PointLight, Renderer, Scene, GltfModel, AmbientLight },
mounted() {
const renderer = this.$refs.renderer
const box = this.$refs.model
renderer.onBeforeRender(() => {
box.rotation.x += 0.01;
});
},
};
</script>
You could use .traverse
or .traverseVisible
making sure that the object is a Mesh.您可以使用
.traverse
或.traverseVisible
确保 object 是一个网格。
renderer.onBeforeRender(() => {
box.traverse((obj3D) => {
if (obj3D instanceof Mesh) {
// Make sure this object is a mesh.
obj3D.rotation.x += 0.01;
}
})
});
Callback would be invoked in the current object ( box
in this case) and all its descendants.回调将在当前 object(在本例中为
box
)及其所有后代中调用。
https://threejs.org/docs/index.html?q=object#api/en/core/Object3D.traverse https://threejs.org/docs/index.html?q=object#api/en/core/Object3D.traverse
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.