1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00
This commit is contained in:
Kevin Levron 2020-10-03 22:57:33 +02:00
parent d52616f4b0
commit 9fc7ef75b7
2 changed files with 15 additions and 0 deletions

View File

@ -8,6 +8,9 @@
<InstancedMesh ref="imesh" material-id="material" :count="NUM_INSTANCES"> <InstancedMesh ref="imesh" material-id="material" :count="NUM_INSTANCES">
<BoxGeometry :width="2" :height="2" :depth="10" /> <BoxGeometry :width="2" :height="2" :depth="10" />
<!-- <CylinderGeometry :radius-top="2" :radius-bottom="2" :height="10" :rotate-x="Math.PI / 2" /> -->
<!-- <ConeGeometry :radius="2" :height="10" :rotate-x="Math.PI / 2" /> -->
<!-- <OctahedronGeometry :radius="3" /> -->
<StandardMaterial :transparent="true" :opacity="0.9" :metalness="0.8" :roughness="0.5" /> <StandardMaterial :transparent="true" :opacity="0.9" :metalness="0.8" :roughness="0.5" />
</InstancedMesh> </InstancedMesh>

View File

@ -3,6 +3,11 @@ import { watch } from 'vue';
export default { export default {
emits: ['ready'], emits: ['ready'],
inject: ['mesh'], inject: ['mesh'],
props: {
rotateX: Number,
rotateY: Number,
rotateZ: Number,
},
created() { created() {
if (!this.mesh) { if (!this.mesh) {
console.error('Missing parent Mesh'); console.error('Missing parent Mesh');
@ -12,6 +17,7 @@ export default {
}, },
beforeMount() { beforeMount() {
this.createGeometry(); this.createGeometry();
this.rotateGeometry();
this.mesh.setGeometry(this.geometry); this.mesh.setGeometry(this.geometry);
}, },
mounted() { mounted() {
@ -21,6 +27,11 @@ export default {
this.geometry.dispose(); this.geometry.dispose();
}, },
methods: { methods: {
rotateGeometry() {
if (this.rotateX) this.geometry.rotateX(this.rotateX);
if (this.rotateY) this.geometry.rotateY(this.rotateY);
if (this.rotateZ) this.geometry.rotateZ(this.rotateZ);
},
addWatchers() { addWatchers() {
this.watchProps.forEach(prop => { this.watchProps.forEach(prop => {
watch(() => this[prop], () => { watch(() => this[prop], () => {
@ -31,6 +42,7 @@ export default {
refreshGeometry() { refreshGeometry() {
const oldGeo = this.geometry; const oldGeo = this.geometry;
this.createGeometry(); this.createGeometry();
this.rotateGeometry();
this.mesh.setGeometry(this.geometry); this.mesh.setGeometry(this.geometry);
oldGeo.dispose(); oldGeo.dispose();
}, },