From 7cdda981efc733d5c519331804e8c863218ea6c9 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Wed, 21 Apr 2021 16:04:20 +0200 Subject: [PATCH] object3d --- src/core/Object3D.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core/Object3D.ts b/src/core/Object3D.ts index 87d309c..89724c3 100644 --- a/src/core/Object3D.ts +++ b/src/core/Object3D.ts @@ -4,10 +4,10 @@ import { bindProp } from '../tools' import { RendererInterface } from './Renderer' import { ThreeInterface } from './useThree' -interface Object3DSetupInterface { +export interface Object3DSetupInterface { + renderer: RendererInterface three: ThreeInterface scene: Scene - renderer: RendererInterface o3d?: Object3D parent?: ComponentPublicInstance } @@ -19,9 +19,16 @@ export interface Object3DInterface extends Object3DSetupInterface { remove(o: Object3D): void } +export function object3DSetup(): Object3DSetupInterface { + const renderer = inject('renderer') as RendererInterface + const three = inject('three') as ThreeInterface + const scene = inject('scene') as Scene + return { three, scene, renderer } +} + export default defineComponent({ name: 'Object3D', - inject: ['three', 'scene', 'renderer'], + inject: ['renderer', 'three', 'scene'], emits: ['created', 'ready'], props: { position: { type: Object, default: () => ({ x: 0, y: 0, z: 0 }) }, @@ -31,11 +38,8 @@ export default defineComponent({ autoRemove: { type: Boolean, default: true }, userData: { type: Object, default: () => ({}) }, }, - setup(): Object3DSetupInterface { - const three = inject('three') as ThreeInterface - const scene = inject('scene') as Scene - const renderer = inject('renderer') as RendererInterface - return { three, scene, renderer } + setup() { + return object3DSetup() }, unmounted() { if (this.autoRemove) this.removeFromParent()