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-04-21 16:04:20 +02:00
parent 8a2d874290
commit 7cdda981ef

View File

@ -4,10 +4,10 @@ import { bindProp } from '../tools'
import { RendererInterface } from './Renderer' import { RendererInterface } from './Renderer'
import { ThreeInterface } from './useThree' import { ThreeInterface } from './useThree'
interface Object3DSetupInterface { export interface Object3DSetupInterface {
renderer: RendererInterface
three: ThreeInterface three: ThreeInterface
scene: Scene scene: Scene
renderer: RendererInterface
o3d?: Object3D o3d?: Object3D
parent?: ComponentPublicInstance parent?: ComponentPublicInstance
} }
@ -19,9 +19,16 @@ export interface Object3DInterface extends Object3DSetupInterface {
remove(o: Object3D): void 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({ export default defineComponent({
name: 'Object3D', name: 'Object3D',
inject: ['three', 'scene', 'renderer'], inject: ['renderer', 'three', 'scene'],
emits: ['created', 'ready'], emits: ['created', 'ready'],
props: { props: {
position: { type: Object, default: () => ({ x: 0, y: 0, z: 0 }) }, position: { type: Object, default: () => ({ x: 0, y: 0, z: 0 }) },
@ -31,11 +38,8 @@ export default defineComponent({
autoRemove: { type: Boolean, default: true }, autoRemove: { type: Boolean, default: true },
userData: { type: Object, default: () => ({}) }, userData: { type: Object, default: () => ({}) },
}, },
setup(): Object3DSetupInterface { setup() {
const three = inject('three') as ThreeInterface return object3DSetup()
const scene = inject('scene') as Scene
const renderer = inject('renderer') as RendererInterface
return { three, scene, renderer }
}, },
unmounted() { unmounted() {
if (this.autoRemove) this.removeFromParent() if (this.autoRemove) this.removeFromParent()