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 2021-03-03 23:21:53 +01:00
parent 8c95b5344c
commit 4bd0927b2f
4 changed files with 29 additions and 22 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "troisjs", "name": "troisjs",
"version": "0.1.7", "version": "0.1.8",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",

View File

@ -1,28 +1,30 @@
import { Group } from 'three'; import { Group } from 'three';
import { inject } from 'vue';
import useBindProp from '../use/useBindProp.js'; import useBindProp from '../use/useBindProp.js';
export default { export default {
inject: ['three', 'scene'], inject: {
three: 'three',
scene: 'scene',
group: { default: null },
},
props: { props: {
position: Object, position: Object,
rotation: Object, rotation: Object,
scale: Object, scale: Object,
}, },
setup(props) {
const parent = inject('group', inject('scene'));
const group = new Group();
useBindProp(props, 'position', group.position);
useBindProp(props, 'rotation', group.rotation);
useBindProp(props, 'scale', group.scale);
return { parent, group };
},
provide() { provide() {
return { return {
group: this.group, group: this.group,
}; };
}, },
created() { created() {
this.parent = this.group ? this.group : this.scene;
this.group = new Group();
useBindProp(this, 'position', this.group.position);
useBindProp(this, 'rotation', this.group.rotation);
useBindProp(this, 'scale', this.group.scale);
this.parent.add(this.group); this.parent.add(this.group);
}, },
unmounted() { unmounted() {

View File

@ -1,9 +1,13 @@
import { InstancedMesh } from 'three'; import { InstancedMesh } from 'three';
import { inject, watch } from 'vue'; import { watch } from 'vue';
import useBindProp from '../use/useBindProp.js'; import useBindProp from '../use/useBindProp.js';
export default { export default {
inject: ['three', 'scene'], inject: {
three: 'three',
scene: 'scene',
group: { default: null },
},
props: { props: {
materialId: String, materialId: String,
count: Number, count: Number,
@ -11,15 +15,14 @@ export default {
castShadow: Boolean, castShadow: Boolean,
receiveShadow: Boolean, receiveShadow: Boolean,
}, },
setup() {
const parent = inject('group', inject('scene'));
return { parent };
},
provide() { provide() {
return { return {
mesh: this, mesh: this,
}; };
}, },
created() {
this.parent = this.group ? this.group : this.scene;
},
beforeMount() { beforeMount() {
if (!this.$slots.default) { if (!this.$slots.default) {
console.error('Missing Geometry'); console.error('Missing Geometry');

View File

@ -1,18 +1,20 @@
import { Sprite, SpriteMaterial, TextureLoader } from 'three'; import { Sprite, SpriteMaterial, TextureLoader } from 'three';
import { inject } from 'vue';
import useBindProp from '../use/useBindProp.js'; import useBindProp from '../use/useBindProp.js';
export default { export default {
emits: ['ready', 'loaded'], emits: ['ready', 'loaded'],
inject: ['three', 'scene'], inject: {
three: 'three',
scene: 'scene',
group: { default: null },
},
props: { props: {
src: String, src: String,
position: Object, position: Object,
scale: Object, scale: Object,
}, },
setup() { created() {
const parent = inject('group', inject('scene')); this.parent = this.group ? this.group : this.scene;
return { parent };
}, },
mounted() { mounted() {
this.texture = new TextureLoader().load(this.src, this.onLoaded); this.texture = new TextureLoader().load(this.src, this.onLoaded);