Hi everyone
I recently try to learn how to implement threeJS with Vue3 but face to a problem when trying to add mesh to a scene by declaring the scene and the mesh as data.
Here is the code of my actual project :
data() {
return {
scene: null,
camera: null,
renderer: null,
plane: null,
aspect: {}
}
},
mounted() {
this.aspect = {
ref: this.$refs.aspect,
data: this.$refs.aspect.getBoundingClientRect()
}
this.init()
},
methods: {
init() {
this.scene = new THREE.Scene()
this.camera = new THREE.OrthographicCamera(
window.innerWidth / -2,
window.innerWidth / 2,
window.innerHeight / 2,
window.innerHeight / -2,
1,
1000
)
this.camera.position.z = 1
this.renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
canvas: this.$refs.canvas
})
this.renderer.setSize(window.innerWidth, window.innerHeight)
const geometry = new THREE.PlaneBufferGeometry(
this.aspect.data.width,
this.aspect.data.height,
5
)
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 })
this.plane = new THREE.Mesh(geometry, material)
this.scene.add(this.plane)
this.renderer.render(this.scene, this.camera)
}
}
By doing that I get the following error :
Uncaught (in promise) TypeError: 'get' on proxy: property 'modelViewMatrix' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '#<Matrix4>' but got '[object Object]')
But if I declare the mesh and the scene like that, it works :
......
const scene = new THREE.Scene()
......
const plane = new THREE.Mesh(geometry, material)
......
scene.add(plane)
For a cleaner explanation here is the reproduction link
https://codesandbox.io/s/thirsty-mirzakhani-p8tdj?file=/src/App.vue
If someone could help me on this problem, it would be very cool !
Thank you in advance !