Skip to content

Commit

Permalink
fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
klevron committed Feb 26, 2021
1 parent a620b7c commit a6c77ce
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/lights/Light.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { setFromProp } from '../tools.js';
import useBindProp from '../use/useBindProp.js';

export default {
inject: ['scene'],
inject: {
scene: 'scene',
parent: {
from: 'group',
default: () => inject('scene'),
},
},
props: {
color: {
type: String,
Expand All @@ -23,9 +29,6 @@ export default {
},
// can't use setup because it will not be used in sub components
// setup() {},
created() {
this.parent = inject('group', this.scene);
},
mounted() {
useBindProp(this, 'position', this.light.position);

Expand Down
5 changes: 3 additions & 2 deletions src/meshes/InstancedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export default {
castShadow: Boolean,
receiveShadow: Boolean,
},
created() {
this.parent = inject('group', this.scene);
setup() {
const parent = inject('group', inject('scene'));
return { parent };
},
provide() {
return {
Expand Down
15 changes: 11 additions & 4 deletions src/meshes/Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import { inject, watch } from 'vue';
import useBindProp from '../use/useBindProp.js';

export default {
inject: ['three', 'scene', 'rendererComponent'],
inject: {
three: 'three',
scene: 'scene',
rendererComponent: 'rendererComponent',
parent: {
from: 'group',
default: () => inject('scene'),
},
},
emits: ['ready'],
props: {
materialId: String,
Expand All @@ -17,9 +25,6 @@ export default {
},
// can't use setup because it will not be used in sub components
// setup() {},
created() {
this.parent = inject('group', this.scene);
},
provide() {
return {
mesh: this,
Expand Down Expand Up @@ -55,6 +60,8 @@ export default {
this.three.addIntersectObject(this.mesh);
}

console.log(this.parent);

this.bindProps();
this.parent.add(this.mesh);
this.$emit('ready');
Expand Down
5 changes: 3 additions & 2 deletions src/meshes/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export default {
position: Object,
scale: Object,
},
created() {
this.parent = inject('group', this.scene);
setup() {
const parent = inject('group', inject('scene'));
return { parent };
},
mounted() {
this.texture = new TextureLoader().load(this.src, this.onLoaded);
Expand Down

0 comments on commit a6c77ce

Please sign in to comment.