0👍
Thanks to fritx for this answer pasted
here from: https://github.com/fritx/vue-threejs/issues/2
Thanks for using the library!
For now, an component supposes that the mesh exists when it is created, like <object3d :obj="mesh"></object3d>
.
If you’re using async loaders, your code might look like this:
<template>
<object3d v-if="mesh" :obj="mesh"></object3d>
</template>
<script>
export default {
data () {
return {
mesh: null // <----
}
},
methods: {
createBox () {
objLoader.load(xxx, geometry => {
let mesh = new THREE.Mesh(geometry, material)
this.mesh = mesh // <----
})
}
}
}
</script>
More snippets by key word user:fritx "Loader.load(":
(including code in both vue-threejs and react-threejs)
https://github.com/search?q=user%3Afritx+%22Loader%28%29.load%28%22&ref=opensearch&type=Code
In “ExSpaceFighter.js”, I also had a snippet with MTLLoader and OBJLoader:
Hope that helps.
var mtlLoader = new MTLLoader();
mtlLoader.setBaseUrl( 'SpaceFighter03/' )
mtlLoader.setPath( 'SpaceFighter03/' )
mtlLoader.load( 'SpaceFighter03.mtl', ( materials ) => {
materials.preload();
var objLoader = new OBJLoader();
objLoader.setMaterials( materials );
objLoader.setPath( 'SpaceFighter03/' )
objLoader.load( 'SpaceFighter03.obj', ( group ) => {
const body = group.children[0]
body.material.color.set(0xffffff)
this.setState({ body })
})
})
If I’m wrong, please let me know 😉
Source:stackexchange.com