diff --git a/src/components/physics/CannonWorld.js b/src/components/physics/CannonWorld.js index 3d38726..6148c26 100644 --- a/src/components/physics/CannonWorld.js +++ b/src/components/physics/CannonWorld.js @@ -3,7 +3,7 @@ import useCannon from './useCannon.js'; // import { bindProp } from '../../tools'; export default defineComponent({ - inject: ['three', 'scene', 'renderer'], + inject: ['renderer', 'scene'], props: { gravity: { type: Object, default: () => ({ x: 0, y: 0, z: -9.82 }) }, broadphase: { type: String }, diff --git a/src/core/Camera.ts b/src/core/Camera.ts index 8b188a0..164eccd 100644 --- a/src/core/Camera.ts +++ b/src/core/Camera.ts @@ -16,6 +16,7 @@ export default defineComponent({ const renderer = inject('renderer') as RendererInterface return { renderer } }, + render() { return this.$slots.default ? this.$slots.default() : [] }, diff --git a/src/core/Object3D.ts b/src/core/Object3D.ts index 89724c3..d2117e7 100644 --- a/src/core/Object3D.ts +++ b/src/core/Object3D.ts @@ -2,11 +2,9 @@ import { Object3D, Scene } from 'three' import { ComponentPublicInstance, defineComponent, inject, watch } from 'vue' import { bindProp } from '../tools' import { RendererInterface } from './Renderer' -import { ThreeInterface } from './useThree' export interface Object3DSetupInterface { renderer: RendererInterface - three: ThreeInterface scene: Scene o3d?: Object3D parent?: ComponentPublicInstance @@ -21,14 +19,13 @@ export interface Object3DInterface extends Object3DSetupInterface { 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 } + return { scene, renderer } } export default defineComponent({ name: 'Object3D', - inject: ['renderer', 'three', 'scene'], + inject: ['renderer', 'scene'], emits: ['created', 'ready'], props: { position: { type: Object, default: () => ({ x: 0, y: 0, z: 0 }) }, diff --git a/src/core/Renderer.ts b/src/core/Renderer.ts index 18ff93e..f812fb8 100644 --- a/src/core/Renderer.ts +++ b/src/core/Renderer.ts @@ -157,7 +157,6 @@ export default defineComponent({ provide() { return { renderer: this, - three: this.three, } }, mounted() { diff --git a/src/core/Scene.ts b/src/core/Scene.ts index 4a11178..4f2abd4 100644 --- a/src/core/Scene.ts +++ b/src/core/Scene.ts @@ -23,9 +23,7 @@ export default defineComponent({ } }, created() { - if (!this.renderer.scene) { - this.renderer.scene = this.scene - } + this.renderer.scene = this.scene }, methods: { add(o: Object3D) { this.scene.add(o) }, diff --git a/src/effects/EffectPass.ts b/src/effects/EffectPass.ts index 74dcede..5204cb6 100644 --- a/src/effects/EffectPass.ts +++ b/src/effects/EffectPass.ts @@ -1,24 +1,21 @@ import { Pass } from 'three/examples/jsm/postprocessing/Pass' import { defineComponent, inject } from 'vue' import { RendererInterface } from '../core/Renderer' -import { ThreeInterface } from '../core/useThree' import { EffectComposerInterface } from './EffectComposer' interface EffectSetupInterface { renderer: RendererInterface - three: ThreeInterface composer: EffectComposerInterface pass?: Pass } export default defineComponent({ - inject: ['renderer', 'three', 'composer'], + inject: ['renderer', 'composer'], emits: ['ready'], setup(): EffectSetupInterface { const renderer = inject('renderer') as RendererInterface - const three = inject('three') as ThreeInterface const composer = inject('composer') as EffectComposerInterface - return { renderer, three, composer } + return { renderer, composer } }, created() { if (!this.composer) { diff --git a/src/materials/Material.ts b/src/materials/Material.ts index 4201b20..76ae45f 100644 --- a/src/materials/Material.ts +++ b/src/materials/Material.ts @@ -14,7 +14,7 @@ export interface MaterialInterface extends MaterialSetupInterface { } export default defineComponent({ - inject: ['three', 'mesh'], + inject: ['mesh'], props: { color: { type: [String, Number], default: '#ffffff' }, depthTest: { type: Boolean, default: true }, diff --git a/src/meshes/InstancedMesh.ts b/src/meshes/InstancedMesh.ts index 2defaf0..f3e5fba 100644 --- a/src/meshes/InstancedMesh.ts +++ b/src/meshes/InstancedMesh.ts @@ -28,7 +28,7 @@ export default defineComponent({ this.onPointerDown || this.onPointerUp || this.onClick) { - this.three.addIntersectObject(this.mesh) + this.renderer.three.addIntersectObject(this.mesh) } this.initObject3D(this.mesh) diff --git a/src/meshes/Mesh.ts b/src/meshes/Mesh.ts index 1e8b1f7..67cc021 100644 --- a/src/meshes/Mesh.ts +++ b/src/meshes/Mesh.ts @@ -59,7 +59,7 @@ const Mesh = defineComponent({ this.onPointerDown || this.onPointerUp || this.onClick) { - this.three?.addIntersectObject(mesh) + this.renderer.three.addIntersectObject(mesh) } this.mesh = mesh