mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
wip
This commit is contained in:
parent
c8a3ed739d
commit
209939778c
@ -1,4 +1,3 @@
|
|||||||
import { watch } from 'vue';
|
|
||||||
import { bindProp } from '../tools.js';
|
import { bindProp } from '../tools.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -7,8 +6,6 @@ export default {
|
|||||||
position: Object,
|
position: Object,
|
||||||
rotation: Object,
|
rotation: Object,
|
||||||
scale: Object,
|
scale: Object,
|
||||||
castShadow: Boolean,
|
|
||||||
receiveShadow: Boolean,
|
|
||||||
loading: Boolean,
|
loading: Boolean,
|
||||||
},
|
},
|
||||||
// can't use setup because it will not be used in sub components
|
// can't use setup because it will not be used in sub components
|
||||||
@ -25,11 +22,6 @@ export default {
|
|||||||
bindProp(this, 'rotation', this.o3d.rotation);
|
bindProp(this, 'rotation', this.o3d.rotation);
|
||||||
bindProp(this, 'scale', this.o3d.scale);
|
bindProp(this, 'scale', this.o3d.scale);
|
||||||
|
|
||||||
['castShadow', 'receiveShadow'].forEach(p => {
|
|
||||||
this.o3d[p] = this[p];
|
|
||||||
watch(() => this[p], () => { this.o3d[p] = this[p]; });
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.$parent.add) this.$parent.add(this.o3d);
|
if (this.$parent.add) this.$parent.add(this.o3d);
|
||||||
},
|
},
|
||||||
add(o) { this.o3d.add(o); },
|
add(o) { this.o3d.add(o); },
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
import { Color } from 'three';
|
import { Color } from 'three';
|
||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
|
import Object3D from '../core/Object3D.js';
|
||||||
import { bindProp, setFromProp } from '../tools.js';
|
import { bindProp, setFromProp } from '../tools.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
extends: Object3D,
|
||||||
props: {
|
props: {
|
||||||
color: { type: String, default: '#ffffff' },
|
color: { type: String, default: '#ffffff' },
|
||||||
intensity: { type: Number, default: 1 },
|
intensity: { type: Number, default: 1 },
|
||||||
castShadow: { type: Boolean, default: false },
|
castShadow: { type: Boolean, default: false },
|
||||||
shadowMapSize: { type: Object, default: { x: 512, y: 512 } },
|
shadowMapSize: { type: Object, default: { x: 512, y: 512 } },
|
||||||
position: Object,
|
|
||||||
},
|
},
|
||||||
// can't use setup because it will not be used in sub components
|
// can't use setup because it will not be used in sub components
|
||||||
// setup() {},
|
// setup() {},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
this.$parent.remove(this.light);
|
|
||||||
if (this.light.target) this.$parent.remove(this.light.target);
|
if (this.light.target) this.$parent.remove(this.light.target);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initLight() {
|
initLight() {
|
||||||
bindProp(this, 'position', this.light.position);
|
|
||||||
|
|
||||||
if (this.light.target) {
|
if (this.light.target) {
|
||||||
bindProp(this, 'target', this.light.target.position);
|
bindProp(this, 'target', this.light.target.position);
|
||||||
}
|
}
|
||||||
@ -39,7 +37,7 @@ export default {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$parent.add(this.light);
|
this.initObject3D(this.light);
|
||||||
if (this.light.target) this.$parent.add(this.light.target);
|
if (this.light.target) this.$parent.add(this.light.target);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
|
import { watch } from 'vue';
|
||||||
import { InstancedMesh } from 'three';
|
import { InstancedMesh } from 'three';
|
||||||
import Object3D from '../core/Object3D.js';
|
import Object3D from '../core/Object3D.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
extends: Object3D,
|
extends: Object3D,
|
||||||
props: {
|
props: {
|
||||||
|
castShadow: Boolean,
|
||||||
|
receiveShadow: Boolean,
|
||||||
count: Number,
|
count: Number,
|
||||||
},
|
},
|
||||||
provide() {
|
provide() {
|
||||||
@ -22,6 +25,12 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
initMesh() {
|
initMesh() {
|
||||||
this.mesh = new InstancedMesh(this.geometry, this.material, this.count);
|
this.mesh = new InstancedMesh(this.geometry, this.material, this.count);
|
||||||
|
|
||||||
|
['castShadow', 'receiveShadow'].forEach(p => {
|
||||||
|
this.mesh[p] = this[p];
|
||||||
|
watch(() => this[p], () => { this.mesh[p] = this[p]; });
|
||||||
|
});
|
||||||
|
|
||||||
this.initObject3D(this.mesh);
|
this.initObject3D(this.mesh);
|
||||||
},
|
},
|
||||||
setGeometry(geometry) {
|
setGeometry(geometry) {
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
|
import { watch } from 'vue';
|
||||||
import { Mesh } from 'three';
|
import { Mesh } from 'three';
|
||||||
import Object3D from '../core/Object3D.js';
|
import Object3D from '../core/Object3D.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
extends: Object3D,
|
extends: Object3D,
|
||||||
props: {
|
props: {
|
||||||
|
castShadow: Boolean,
|
||||||
|
receiveShadow: Boolean,
|
||||||
onHover: Function,
|
onHover: Function,
|
||||||
onClick: Function,
|
onClick: Function,
|
||||||
},
|
},
|
||||||
@ -21,6 +24,11 @@ export default {
|
|||||||
initMesh() {
|
initMesh() {
|
||||||
this.mesh = new Mesh(this.geometry, this.material);
|
this.mesh = new Mesh(this.geometry, this.material);
|
||||||
|
|
||||||
|
['castShadow', 'receiveShadow'].forEach(p => {
|
||||||
|
this.mesh[p] = this[p];
|
||||||
|
watch(() => this[p], () => { this.mesh[p] = this[p]; });
|
||||||
|
});
|
||||||
|
|
||||||
if (this.onHover) {
|
if (this.onHover) {
|
||||||
this.mesh.onHover = (over) => { this.onHover({ component: this, over }); };
|
this.mesh.onHover = (over) => { this.onHover({ component: this, over }); };
|
||||||
this.three.addIntersectObject(this.mesh);
|
this.three.addIntersectObject(this.mesh);
|
||||||
|
Loading…
Reference in New Issue
Block a user