diff --git a/src/threejs-tools.js b/src/threejs-tools.js new file mode 100644 index 0000000000000000000000000000000000000000..7d30d969ee7f4798eaf565180e16d9730806cd3e --- /dev/null +++ b/src/threejs-tools.js @@ -0,0 +1,36 @@ +import { ref, onMounted } from 'vue' +import * as THREE from 'three' +import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; + +export class ThreejsDefault { + constructor(container) { + // init scene camera + this.scene = new THREE.Scene() + this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) + this.camera.position.z = 5 + + // init renderer + this.renderer = new THREE.WebGLRenderer() + this.renderer.setSize(window.innerWidth, window.innerHeight) + + // init controls + this.controls = new OrbitControls(this.camera, this.renderer.domElement); + + this.animateFuncs = [] + const animate = () => { + requestAnimationFrame(animate) + this.animateFuncs.forEach(animFunc => animFunc()) + this.renderer.render(this.scene, this.camera) + } + + onMounted(() => { + container.value.appendChild(this.renderer.domElement) + animate() + }) + } + + + onAnimate(animFunc) { + this.animateFuncs.push(animFunc) + } +} diff --git a/src/views/basic.vue b/src/views/basic.vue index 8a818a3f2054580192f925fe779d93790f995b0c..8139b7c533abfb3753d2e7ff382c464bc0db25aa 100644 --- a/src/views/basic.vue +++ b/src/views/basic.vue @@ -4,41 +4,35 @@