From dde4c566ae5da14b4cd5d743ffde21bd02b4571c Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sun, 2 May 2021 20:44:13 +0200 Subject: [PATCH 1/3] improve renderer interface --- src/core/Renderer.ts | 6 ++++-- src/core/index.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/Renderer.ts b/src/core/Renderer.ts index b67007b..452be16 100644 --- a/src/core/Renderer.ts +++ b/src/core/Renderer.ts @@ -1,7 +1,7 @@ /* eslint-disable no-use-before-define */ import { Camera, NoToneMapping, PCFShadowMap, Scene, WebGLRenderer } from 'three' import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer' -import { defineComponent, InjectionKey, PropType } from 'vue' +import { ComponentPublicInstance, defineComponent, InjectionKey, PropType } from 'vue' import { bindProp } from '../tools' import { PointerPublicConfigInterface } from './usePointer' import useThree, { SizeInterface, ThreeConfigInterface, ThreeInterface } from './useThree' @@ -93,7 +93,9 @@ export interface RendererInterface extends RendererSetupInterface { removeListener(t: T, cb: EventCallbackMap[T]): void } -export const RendererInjectionKey: InjectionKey = Symbol('Renderer') +export interface RendererPublicInterface extends ComponentPublicInstance, RendererInterface {} + +export const RendererInjectionKey: InjectionKey = Symbol('Renderer') export default defineComponent({ name: 'Renderer', diff --git a/src/core/index.ts b/src/core/index.ts index 7c49cc4..26fef3c 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -9,5 +9,5 @@ export { default as Raycaster } from './Raycaster' export { default as CubeCamera } from './CubeCamera' -export type { RendererInterface } from './Renderer' +export type { RendererPublicInterface } from './Renderer' export type { Object3DInterface } from './Object3D' From 3705f97c61c943bad4a17b7a7b1491811b0eec4a Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sun, 2 May 2021 20:51:19 +0200 Subject: [PATCH 2/3] improve interfaces --- src/core/Object3D.ts | 2 ++ src/core/index.ts | 2 +- src/materials/Material.ts | 6 ++++-- src/materials/index.ts | 2 +- src/meshes/Mesh.ts | 6 ++++-- src/meshes/index.ts | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/Object3D.ts b/src/core/Object3D.ts index 1d274e0..b046b42 100644 --- a/src/core/Object3D.ts +++ b/src/core/Object3D.ts @@ -18,6 +18,8 @@ export interface Object3DInterface extends Object3DSetupInterface { remove(o: Object3D): void } +export interface Object3DPublicInterface extends ComponentPublicInstance, Object3DInterface {} + // export function object3DSetup(): Object3DSetupInterface { // const renderer = inject(RendererInjectionKey) // const scene = inject(SceneInjectionKey) diff --git a/src/core/index.ts b/src/core/index.ts index 26fef3c..43300c0 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -10,4 +10,4 @@ export { default as Raycaster } from './Raycaster' export { default as CubeCamera } from './CubeCamera' export type { RendererPublicInterface } from './Renderer' -export type { Object3DInterface } from './Object3D' +export type { Object3DPublicInterface } from './Object3D' diff --git a/src/materials/Material.ts b/src/materials/Material.ts index 3cf8a56..ecbe438 100644 --- a/src/materials/Material.ts +++ b/src/materials/Material.ts @@ -1,4 +1,4 @@ -import { defineComponent, InjectionKey, PropType, watch } from 'vue' +import { ComponentPublicInstance, defineComponent, InjectionKey, PropType, watch } from 'vue' import { FrontSide, Material, NormalBlending, Texture } from 'three' import { MeshInjectionKey, MeshInterface } from '../meshes/Mesh' @@ -13,7 +13,9 @@ export interface MaterialInterface extends MaterialSetupInterface { setTexture(texture: Texture | null, key: string): void } -export const MaterialInjectionKey: InjectionKey = Symbol('Material') +export interface MaterialPublicInterface extends ComponentPublicInstance, MaterialInterface {} + +export const MaterialInjectionKey: InjectionKey = Symbol('Material') export default defineComponent({ // inject for sub components diff --git a/src/materials/index.ts b/src/materials/index.ts index c1b1a5c..dca9f74 100644 --- a/src/materials/index.ts +++ b/src/materials/index.ts @@ -14,4 +14,4 @@ export { default as CubeTexture } from './CubeTexture' export { default as PointsMaterial } from './PointsMaterial' -export type { MaterialInterface } from './Material' +export type { MaterialPublicInterface } from './Material' diff --git a/src/meshes/Mesh.ts b/src/meshes/Mesh.ts index 9d2f84c..426cd69 100644 --- a/src/meshes/Mesh.ts +++ b/src/meshes/Mesh.ts @@ -1,4 +1,4 @@ -import { ComponentPropsOptions, defineComponent, InjectionKey, watch } from 'vue' +import { ComponentPropsOptions, ComponentPublicInstance, defineComponent, InjectionKey, watch } from 'vue' import { BufferGeometry, Material, Mesh as TMesh } from 'three' import Object3D, { Object3DSetupInterface } from '../core/Object3D' import { bindProp } from '../tools' @@ -25,7 +25,9 @@ export interface MeshInterface extends MeshSetupInterface { setMaterial(m: Material): void } -export const MeshInjectionKey: InjectionKey = Symbol('Mesh') +export interface MeshPublicInterface extends ComponentPublicInstance, MeshInterface {} + +export const MeshInjectionKey: InjectionKey = Symbol('Mesh') const Mesh = defineComponent({ name: 'Mesh', diff --git a/src/meshes/index.ts b/src/meshes/index.ts index 6c20836..a6211b5 100644 --- a/src/meshes/index.ts +++ b/src/meshes/index.ts @@ -24,4 +24,4 @@ export { default as Sprite } from './Sprite' export { default as Points } from './Points' -export type { MeshInterface } from './Mesh' +export type { MeshPublicInterface } from './Mesh' From 785e09d447e2f8f24fc2c39ae736d43e49a6f1a5 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sun, 2 May 2021 20:56:34 +0200 Subject: [PATCH 3/3] update example app --- src/App.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/App.vue b/src/App.vue index 98778c3..29d533b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -12,13 +12,13 @@