Przeglądaj źródła

feat: mighty sexy runtime types

alvarosabu 2 lat temu
rodzic
commit
97a5b64f39

+ 0 - 110
plugins/vite-tres-types-plugin.ts

@@ -1,110 +0,0 @@
-import { createUnplugin } from 'unplugin'
-import * as THREE from 'three'
-
-import fs from 'fs'
-import { join } from 'pathe'
-
-export const unplugin = createUnplugin(() => {
-  return {
-    name: 'unplugin-tres',
-    apply: 'build',
-    configResolved(config) {
-      // Check if the output directory exists, if not create it
-      const outputDir = join(config.root, 'src/types')
-      if (!fs.existsSync(outputDir)) {
-        fs.mkdirSync(outputDir)
-      }
-
-      const typeDefs = `
-      import type { DefineComponent } from 'vue'
-      import type { Vector2, Vector3, Color } from 'three'
-      export type TresVectorProp = Vector2 | Vector3 | number[] | number
-      export type TresColor = string | number | Color | number[]
-      import type {
-        Mesh,
-        ${Object.keys(THREE)
-          .filter(
-            key =>
-              key.endsWith('Geometry') ||
-              key.endsWith('Material') ||
-              key.endsWith('Helper') ||
-              key.endsWith('Light') ||
-              key.endsWith('Camera') ||
-              key.endsWith('Fog'),
-          )
-          .join(',\n')}
-      } from 'three';
-
-      type OverwrittenProps = 'position' | 'rotation' | 'scale' | 'color'
-
-      type TresModifiedObject = {
-        /**
-         * A Vector3 | Array | scalar representing the object's local position. Default is (0, 0, 0).
-         *
-         * @type {TresVectorProp}
-         */
-        position: TresVectorProp
-        /**
-         * A Vector3 | Array | scalar representing the object's local rotation. Default is (0, 0, 0).
-         *
-         * @type {TresVectorProp}
-         */
-        rotation: TresVectorProp
-        /**
-         * A Vector3 | Array | scalar representing the object's local scale. Default is (0, 0, 0).
-         *
-         * @type {TresVectorProp}
-         */
-        scale: TresVectorProp
-        /**
-         * Color of the material, by default set to white (0xffffff).
-         *
-         * @type {TresColor}
-         */
-        color: TresColor,
-        /**
-         * Arguments of the THREE instance, by default set to empty array.
-         *
-         * @type {any[]}
-         * 
-         * @example
-         * 
-         * \`\`\`html
-         * <TresBoxGeometry args="[1, 3, 4]" /> // BoxGeometry(1, 3, 4)
-         * \`\`\`
-         */
-        args?: any[],
-      }
-      
-      declare module 'vue' {
-        export interface GlobalComponents {
-          TresMesh: DefineComponent<Partial<Omit<Mesh, OverwrittenProps> & TresModifiedObject>>
-      ${Object.keys(THREE)
-        .filter(key => key.endsWith('Geometry'))
-        .map(
-          key =>
-            `Tres${key}: DefineComponent<Partial<Omit<${key}['parameters'], OverwrittenProps> & TresModifiedObject>>`,
-        )
-        .join('\n')}
-        ${Object.keys(THREE)
-          .filter(
-            key =>
-              key.endsWith('Geometry') ||
-              key.endsWith('Material') ||
-              key.endsWith('Helper') ||
-              key.endsWith('Light') ||
-              key.endsWith('Camera') ||
-              key.endsWith('Fog'),
-          )
-          .map(key => `Tres${key}: DefineComponent<Partial<Omit<${key}, OverwrittenProps > & TresModifiedObject>>`)
-          .join('\n')}
-        }
-      }
-      `
-
-      fs.writeFileSync(join(outputDir, 'tres-components.d.ts'), typeDefs)
-    },
-  }
-})
-
-export const ViteTresPlugin = unplugin.vite

+ 7 - 8
src/components/TresScene.ts

@@ -1,6 +1,8 @@
-import { App, defineComponent, h, onMounted, onUnmounted, ref, watch, watchEffect } from 'vue'
+import { App, defineComponent, h, onMounted, onUnmounted, ref, watch, watchEffect, VNode } from 'vue'
 import * as THREE from 'three'
 import { ColorSpace, ShadowMapType, ToneMapping } from 'three'
+import { useEventListener } from '@vueuse/core'
+import { isString } from '@alvarosabu/utils'
 import { createTres } from '../core/renderer'
 import {
   CameraType,
@@ -14,10 +16,6 @@ import {
 } from '../composables'
 import { extend } from '../core/catalogue'
 import { type RendererPresetsType } from '../composables/useRenderer/const'
-import { TresEvent, TresObject } from '../types'
-import { useEventListener } from '@vueuse/core'
-import { isString } from '@alvarosabu/utils'
-import { VNode } from 'vue'
 
 export interface TresSceneProps {
   shadows?: boolean
@@ -108,8 +106,9 @@ export const TresScene = defineComponent<TresSceneProps>({
 
       const { raycaster, pointer } = useRaycaster()
 
-      let prevInstance: TresEvent | null = null
-      let currentInstance: TresEvent | null = null
+      // TODO: Type raycasting events correctly
+      let prevInstance: any = null
+      let currentInstance: any = null
 
       watchEffect(() => {
         if (activeCamera.value) raycaster.value.setFromCamera(pointer.value, activeCamera.value)
@@ -150,7 +149,7 @@ export const TresScene = defineComponent<TresSceneProps>({
       app.provide('useTres', useTres())
       app.provide(TRES_CONTEXT_KEY, useTres())
       app.provide('extend', extend)
-      app.mount(scene as unknown as TresObject)
+      app.mount(scene as unknown)
     }
     mountApp()
 

+ 1 - 2
src/core/catalogue.ts

@@ -1,8 +1,7 @@
-import { MathUtils } from 'three'
 import { Ref, ref } from 'vue'
 import { TresCatalogue } from '../types'
 
-export const catalogue: Ref<TresCatalogue> = ref({ uuid: MathUtils.generateUUID() })
+export const catalogue: Ref<TresCatalogue> = ref({})
 
 export const extend = (objects: any) => void Object.assign(catalogue.value, objects)
 

+ 13 - 12
src/core/nodeOps.ts

@@ -1,9 +1,9 @@
 import { RendererOptions } from 'vue'
-import { BufferAttribute, BufferGeometry, Material, Object3D } from 'three'
+import { BufferAttribute, BufferGeometry, Material } from 'three'
 import { useCamera, useLogger } from '../composables'
 import { isFunction } from '@alvarosabu/utils'
 import { catalogue } from './catalogue'
-import { TresInstance, TresObject } from '../types'
+import { EventHandlers, TresObject } from '../types'
 import { isHTMLTag, kebabToCamel } from '../utils'
 
 const onRE = /^on[^a-z]/
@@ -37,7 +37,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
 
     if (tag === 'primitive') {
       if (props?.object === undefined) logError(`Tres primitives need a prop 'object'`)
-      const object = props.object as TresInstance
+      const object = props.object as TresObject
       name = object.type
       instance = Object.assign(object, { type: name, attach: props.attach, primitive: true })
     } else {
@@ -70,8 +70,8 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
     const { GEOMETRY_VIA_PROP, MATERIAL_VIA_PROP } = OBJECT_3D_USER_DATA_KEYS
 
     if (instance.isObject3D) {
-      if (props?.material?.isMaterial) (instance as Object3D).userData[MATERIAL_VIA_PROP] = true
-      if (props?.geometry?.isBufferGeometry) (instance as Object3D).userData[GEOMETRY_VIA_PROP] = true
+      if (props?.material?.isMaterial) (instance as TresObject).userData[MATERIAL_VIA_PROP] = true
+      if (props?.geometry?.isBufferGeometry) (instance as TresObject).userData[GEOMETRY_VIA_PROP] = true
     }
 
     instance.events = {}
@@ -98,7 +98,7 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
     } else if (child?.isFog) {
       parent.fog = child
     } else if (typeof child?.attach === 'string') {
-      child.__previousAttach = child[parent?.attach]
+      child.__previousAttach = child[parent?.attach as string]
       if (parent) {
         parent[child.attach] = child
       }
@@ -109,17 +109,17 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
     // remove is only called on the node being removed and not on child nodes.
 
     if (node.isObject3D) {
-      const object3D = node as unknown as Object3D
+      const object3D = node as unknown as TresObject
 
-      const disposeMaterialsAndGeometries = (object3D: Object3D) => {
+      const disposeMaterialsAndGeometries = (object3D: TresObject) => {
         const { GEOMETRY_VIA_PROP, MATERIAL_VIA_PROP } = OBJECT_3D_USER_DATA_KEYS
 
-        if (!object3D.userData[MATERIAL_VIA_PROP]) (object3D as Object3D & { material: Material }).material?.dispose()
+        if (!object3D.userData[MATERIAL_VIA_PROP]) (object3D as TresObject & { material: Material }).material?.dispose()
         if (!object3D.userData[GEOMETRY_VIA_PROP])
-          (object3D as Object3D & { geometry: BufferGeometry }).geometry?.dispose()
+          (object3D as TresObject & { geometry: BufferGeometry }).geometry?.dispose()
       }
 
-      object3D.traverse(child => disposeMaterialsAndGeometries(child))
+      object3D.traverse((child: TresObject) => disposeMaterialsAndGeometries(child))
 
       disposeMaterialsAndGeometries(object3D)
     }
@@ -153,7 +153,8 @@ export const nodeOps: RendererOptions<TresObject, TresObject> = {
         if (!target?.set) root = chain.reduce((acc, key) => acc[kebabToCamel(key)], root)
       }
       if (isOn(key)) {
-        node.events[key] = nextValue
+        const eventHandlerKey: keyof EventHandlers = key as keyof EventHandlers // This is fine
+        node.events[eventHandlerKey] = nextValue
       }
       let value = nextValue
       if (value === '') value = true

+ 169 - 51
src/types/index.ts

@@ -1,59 +1,177 @@
-import { Color, Intersection, Object3D, Vector2, Vector3, Event } from 'three'
-import { VNode, VNodeTypes } from 'vue'
-
-export type TresInstance = Object3D<Event> & { [key: string]: any }
-
-export type TresObject = {
-  /**
-   * A Vector3 | Array | scalar representing the object's local position. Default is (0, 0, 0).
-   *
-   * @type {TresVectorProp}
-   */
-  position?: TresVectorProp
-  /**
-   * A Vector3 | Array | scalar representing the object's local rotation. Default is (0, 0, 0).
-   *
-   * @type {TresVectorProp}
-   */
-  rotation?: TresVectorProp
-  /**
-   * A Vector3 | Array | scalar representing the object's local scale. Default is (0, 0, 0).
-   *
-   * @type {TresVectorProp}
-   */
-  scale?: TresVectorProp
-  /**
-   * Color of the material, by default set to white (0xffffff).
-   *
-   * @type {TresColor}
-   */
-  color?: TresColor
-  opacity?: number
+/* eslint-disable @typescript-eslint/ban-types */
+import type * as THREE from 'three'
+import { DefineComponent, Ref, VNode } from 'vue'
+
+// Based on React Three Fiber types by Pmndrs
+// https://github.com/pmndrs/react-three-fiber/blob/v9/packages/fiber/src/three-types.ts
+
+export type AttachFnType<O = any> = (parent: any, self: O) => () => void
+export type AttachType<O = any> = string | AttachFnType<O>
+
+export type ConstructorRepresentation = new (...args: any[]) => any
+export type NonFunctionKeys<P> = { [K in keyof P]-?: P[K] extends Function ? never : K }[keyof P]
+export type Overwrite<P, O> = Omit<P, NonFunctionKeys<O>> & O
+export type Properties<T> = Pick<T, NonFunctionKeys<T>>
+export type Mutable<P> = { [K in keyof P]: P[K] | Readonly<P[K]> }
+export type Args<T> = T extends ConstructorRepresentation ? ConstructorParameters<T> : any[]
+
+export interface TresCatalogue {
+  [name: string]: ConstructorRepresentation
+}
+export type TresCamera = THREE.OrthographicCamera | THREE.PerspectiveCamera
+
+export interface InstanceProps<T = any, P = any> {
+  args?: Args<P>
+  object?: T
   visible?: boolean
-  attach: string
-  parent: TresObject | null
+  dispose?: null
+  attach?: AttachType<T>
+}
+
+interface TresBaseObject {
+  attach?: string
+  events: EventHandlers
+  removeFromParent?: () => void
   dispose?: () => void
-  __previousAttach?: string
-  [key: string]: any
+  [prop: string]: any // for arbitrary properties
 }
 
-export type TresCatalogue = Record<string, any>
-export type TresVNodeType = VNodeTypes & {
-  name?: string | Array<string>
-  __name?: string
-  setup?: (props: Readonly<any>) => void
+// Custom type for geometry and material properties in Object3D
+export interface TresObject3D extends THREE.Object3D {
+  geometry?: THREE.BufferGeometry & TresBaseObject
+  material?: THREE.Material & TresBaseObject
+  userData: {
+    MATERIAL_VIA_PROP: boolean
+    GEOMETRY_VIA_PROP: boolean
+  } & { [key: string]: any }
 }
-export type TresVNode = VNode & { children?: Array<VNode | { default: any }>; type: TresVNodeType }
-export type TresAttributes = Record<string, any> & { args?: number[] }
 
-export type TresVectorProp = Vector2 | Vector3 | number[] | number
-export type TresColor = string | number | Color | number[]
+export type TresObject = TresBaseObject & (TresObject3D | THREE.BufferGeometry | THREE.Material | THREE.Fog)
+
+// Events
+export interface Intersection extends THREE.Intersection {
+  /** The event source (the object which registered the handler) */
+  eventObject: TresObject
+}
+
+export interface IntersectionEvent<TSourceEvent> extends Intersection {
+  /** The event source (the object which registered the handler) */
+  eventObject: TresObject
+  /** An array of intersections */
+  intersections: Intersection[]
+  /** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
+  unprojectedPoint: THREE.Vector3
+  /** Normalized event coordinates */
+  pointer: THREE.Vector2
+  /** Delta between first click and this event */
+  delta: number
+  /** The ray that pierced it */
+  ray: THREE.Ray
+  /** The camera that was used by the raycaster */
+  camera: TresCamera
+  /** stopPropagation will stop underlying handlers from firing */
+  stopPropagation: () => void
+  /** The original host event */
+  nativeEvent: TSourceEvent
+  /** If the event was stopped by calling stopPropagation */
+  stopped: boolean
+}
+
+export type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
+export type DomEvent = PointerEvent | MouseEvent | WheelEvent
+
+export interface Events {
+  onClick: EventListener
+  onContextMenu: EventListener
+  onDoubleClick: EventListener
+  onWheel: EventListener
+  onPointerDown: EventListener
+  onPointerUp: EventListener
+  onPointerLeave: EventListener
+  onPointerMove: EventListener
+  onPointerCancel: EventListener
+  onLostPointerCapture: EventListener
+}
+
+export interface EventHandlers {
+  onClick?: (event: ThreeEvent<MouseEvent>) => void
+  onContextMenu?: (event: ThreeEvent<MouseEvent>) => void
+  onDoubleClick?: (event: ThreeEvent<MouseEvent>) => void
+  onPointerUp?: (event: ThreeEvent<PointerEvent>) => void
+  onPointerDown?: (event: ThreeEvent<PointerEvent>) => void
+  onPointerOver?: (event: ThreeEvent<PointerEvent>) => void
+  onPointerOut?: (event: ThreeEvent<PointerEvent>) => void
+  onPointerEnter?: (event: ThreeEvent<PointerEvent>) => void
+  onPointerLeave?: (event: ThreeEvent<PointerEvent>) => void
+  onPointerMove?: (event: ThreeEvent<PointerEvent>) => void
+  onPointerMissed?: (event: MouseEvent) => void
+  onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void
+  onWheel?: (event: ThreeEvent<WheelEvent>) => void
+}
+
+interface MathRepresentation {
+  set(...args: number[]): any
+}
+interface VectorRepresentation extends MathRepresentation {
+  setScalar(s: number): any
+}
+
+export interface VectorCoordinates {
+  x: number
+  y: number
+  z: number
+}
+
+export type MathType<T extends MathRepresentation | THREE.Euler> = T extends THREE.Color
+  ? ConstructorParameters<typeof THREE.Color> | THREE.ColorRepresentation
+  : T extends VectorRepresentation | THREE.Layers | THREE.Euler
+  ? T | Parameters<T['set']> | number | VectorCoordinates
+  : T | Parameters<T['set']>
+
+export type TresVector2 = MathType<THREE.Vector2>
+export type TresVector3 = MathType<THREE.Vector3>
+export type TresVector4 = MathType<THREE.Vector4>
+export type TresColor = MathType<THREE.Color>
+export type TresLayers = MathType<THREE.Layers>
+export type TresQuaternion = MathType<THREE.Quaternion>
+export type TresEuler = MathType<THREE.Euler>
+
+type WithMathProps<P> = { [K in keyof P]: P[K] extends MathRepresentation | THREE.Euler ? MathType<P[K]> : P[K] }
+
+interface RaycastableRepresentation {
+  raycast(raycaster: THREE.Raycaster, intersects: THREE.Intersection[]): void
+}
+type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : unknown
+
+export interface VueProps<P> {
+  children?: VNode[]
+  ref?: Ref<P>
+  key?: string
+}
+
+type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
+  Overwrite<WithMathProps<P>, VueProps<P> & EventProps<P>>
+>
+
+export type ThreeElement<T extends ConstructorRepresentation> = Mutable<
+  Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
+>
+
+type ThreeExports = typeof THREE
+type ThreeInstancesImpl = {
+  [K in keyof ThreeExports as Uncapitalize<K>]: ThreeExports[K] extends ConstructorRepresentation
+    ? ThreeElement<ThreeExports[K]>
+    : never
+}
+
+export interface ThreeInstances extends ThreeInstancesImpl {
+  primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
+}
+
+type TresComponents = {
+  [K in keyof ThreeInstances as `Tres${Capitalize<string & K>}`]: DefineComponent<ThreeInstances[K]>
+}
 
-export interface TresEvent extends Intersection<Object3D<Event>> {
-  object: Object3D & { events?: Record<string, any>}
-  distance: number
-  faceIndex?: number | undefined
-  point: Vector3
-  uv?: Vector2
-  events?: Record<string, any>
+declare module 'vue' {
+  export type GlobalComponents = TresComponents
 }

+ 0 - 272
src/types/tres-components.d.ts

@@ -1,272 +0,0 @@
-
-      import type { DefineComponent } from 'vue'
-      import type { Vector2, Vector3, Color } from 'three'
-      export type TresVectorProp = Vector2 | Vector3 | number[] | number
-      export type TresColor = string | number | Color | number[]
-      import type {
-        Mesh,
-        AmbientLight,
-ArrayCamera,
-ArrowHelper,
-AxesHelper,
-Box3Helper,
-BoxBufferGeometry,
-BoxGeometry,
-BoxHelper,
-BufferGeometry,
-Camera,
-CameraHelper,
-CapsuleBufferGeometry,
-CapsuleGeometry,
-CircleBufferGeometry,
-CircleGeometry,
-ConeBufferGeometry,
-ConeGeometry,
-CubeCamera,
-CylinderBufferGeometry,
-CylinderGeometry,
-DirectionalLight,
-DirectionalLightHelper,
-DodecahedronBufferGeometry,
-DodecahedronGeometry,
-EdgesGeometry,
-ExtrudeBufferGeometry,
-ExtrudeGeometry,
-Fog,
-GridHelper,
-HemisphereLight,
-HemisphereLightHelper,
-IcosahedronBufferGeometry,
-IcosahedronGeometry,
-InstancedBufferGeometry,
-LatheBufferGeometry,
-LatheGeometry,
-Light,
-LineBasicMaterial,
-LineDashedMaterial,
-Material,
-MeshBasicMaterial,
-MeshDepthMaterial,
-MeshDistanceMaterial,
-MeshLambertMaterial,
-MeshMatcapMaterial,
-MeshNormalMaterial,
-MeshPhongMaterial,
-MeshPhysicalMaterial,
-MeshStandardMaterial,
-MeshToonMaterial,
-OctahedronBufferGeometry,
-OctahedronGeometry,
-OrthographicCamera,
-PerspectiveCamera,
-PlaneBufferGeometry,
-PlaneGeometry,
-PlaneHelper,
-PointLight,
-PointLightHelper,
-PointsMaterial,
-PolarGridHelper,
-PolyhedronBufferGeometry,
-PolyhedronGeometry,
-RawShaderMaterial,
-RectAreaLight,
-RingBufferGeometry,
-RingGeometry,
-ShaderMaterial,
-ShadowMaterial,
-ShapeBufferGeometry,
-ShapeGeometry,
-SkeletonHelper,
-SphereBufferGeometry,
-SphereGeometry,
-SpotLight,
-SpotLightHelper,
-SpriteMaterial,
-StereoCamera,
-TetrahedronBufferGeometry,
-TetrahedronGeometry,
-TorusBufferGeometry,
-TorusGeometry,
-TorusKnotBufferGeometry,
-TorusKnotGeometry,
-TubeBufferGeometry,
-TubeGeometry,
-WireframeGeometry
-      } from 'three';
-
-      type OverwrittenProps = 'position' | 'rotation' | 'scale' | 'color'
-
-      type TresModifiedObject = {
-        /**
-         * A Vector3 | Array | scalar representing the object's local position. Default is (0, 0, 0).
-         *
-         * @type {TresVectorProp}
-         */
-        position: TresVectorProp
-        /**
-         * A Vector3 | Array | scalar representing the object's local rotation. Default is (0, 0, 0).
-         *
-         * @type {TresVectorProp}
-         */
-        rotation: TresVectorProp
-        /**
-         * A Vector3 | Array | scalar representing the object's local scale. Default is (0, 0, 0).
-         *
-         * @type {TresVectorProp}
-         */
-        scale: TresVectorProp
-        /**
-         * Color of the material, by default set to white (0xffffff).
-         *
-         * @type {TresColor}
-         */
-        color: TresColor,
-        /**
-         * Arguments of the THREE instance, by default set to empty array.
-         *
-         * @type {any[]}
-         * 
-         * @example
-         * 
-         * ```html
-         * <TresBoxGeometry args="[1, 3, 4]" /> // BoxGeometry(1, 3, 4)
-         * ```
-         */
-        args?: any[],
-      }
-      
-      declare module 'vue' {
-        export interface GlobalComponents {
-          TresMesh: DefineComponent<Partial<Omit<Mesh, OverwrittenProps> & TresModifiedObject>>
-      TresBoxBufferGeometry: DefineComponent<Partial<Omit<BoxBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresBoxGeometry: DefineComponent<Partial<Omit<BoxGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresBufferGeometry: DefineComponent<Partial<Omit<BufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresCapsuleBufferGeometry: DefineComponent<Partial<Omit<CapsuleBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresCapsuleGeometry: DefineComponent<Partial<Omit<CapsuleGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresCircleBufferGeometry: DefineComponent<Partial<Omit<CircleBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresCircleGeometry: DefineComponent<Partial<Omit<CircleGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresConeBufferGeometry: DefineComponent<Partial<Omit<ConeBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresConeGeometry: DefineComponent<Partial<Omit<ConeGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresCylinderBufferGeometry: DefineComponent<Partial<Omit<CylinderBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresCylinderGeometry: DefineComponent<Partial<Omit<CylinderGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresDodecahedronBufferGeometry: DefineComponent<Partial<Omit<DodecahedronBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresDodecahedronGeometry: DefineComponent<Partial<Omit<DodecahedronGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresEdgesGeometry: DefineComponent<Partial<Omit<EdgesGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresExtrudeBufferGeometry: DefineComponent<Partial<Omit<ExtrudeBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresExtrudeGeometry: DefineComponent<Partial<Omit<ExtrudeGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresIcosahedronBufferGeometry: DefineComponent<Partial<Omit<IcosahedronBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresIcosahedronGeometry: DefineComponent<Partial<Omit<IcosahedronGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresInstancedBufferGeometry: DefineComponent<Partial<Omit<InstancedBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresLatheBufferGeometry: DefineComponent<Partial<Omit<LatheBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresLatheGeometry: DefineComponent<Partial<Omit<LatheGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresOctahedronBufferGeometry: DefineComponent<Partial<Omit<OctahedronBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresOctahedronGeometry: DefineComponent<Partial<Omit<OctahedronGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresPlaneBufferGeometry: DefineComponent<Partial<Omit<PlaneBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresPlaneGeometry: DefineComponent<Partial<Omit<PlaneGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresPolyhedronBufferGeometry: DefineComponent<Partial<Omit<PolyhedronBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresPolyhedronGeometry: DefineComponent<Partial<Omit<PolyhedronGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresRingBufferGeometry: DefineComponent<Partial<Omit<RingBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresRingGeometry: DefineComponent<Partial<Omit<RingGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresShapeBufferGeometry: DefineComponent<Partial<Omit<ShapeBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresShapeGeometry: DefineComponent<Partial<Omit<ShapeGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresSphereBufferGeometry: DefineComponent<Partial<Omit<SphereBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresSphereGeometry: DefineComponent<Partial<Omit<SphereGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresTetrahedronBufferGeometry: DefineComponent<Partial<Omit<TetrahedronBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresTetrahedronGeometry: DefineComponent<Partial<Omit<TetrahedronGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresTorusBufferGeometry: DefineComponent<Partial<Omit<TorusBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresTorusGeometry: DefineComponent<Partial<Omit<TorusGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresTorusKnotBufferGeometry: DefineComponent<Partial<Omit<TorusKnotBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresTorusKnotGeometry: DefineComponent<Partial<Omit<TorusKnotGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresTubeBufferGeometry: DefineComponent<Partial<Omit<TubeBufferGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresTubeGeometry: DefineComponent<Partial<Omit<TubeGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-TresWireframeGeometry: DefineComponent<Partial<Omit<WireframeGeometry['parameters'], OverwrittenProps> & TresModifiedObject>>
-        TresAmbientLight: DefineComponent<Partial<Omit<AmbientLight, OverwrittenProps > & TresModifiedObject>>
-TresArrayCamera: DefineComponent<Partial<Omit<ArrayCamera, OverwrittenProps > & TresModifiedObject>>
-TresArrowHelper: DefineComponent<Partial<Omit<ArrowHelper, OverwrittenProps > & TresModifiedObject>>
-TresAxesHelper: DefineComponent<Partial<Omit<AxesHelper, OverwrittenProps > & TresModifiedObject>>
-TresBox3Helper: DefineComponent<Partial<Omit<Box3Helper, OverwrittenProps > & TresModifiedObject>>
-TresBoxBufferGeometry: DefineComponent<Partial<Omit<BoxBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresBoxGeometry: DefineComponent<Partial<Omit<BoxGeometry, OverwrittenProps > & TresModifiedObject>>
-TresBoxHelper: DefineComponent<Partial<Omit<BoxHelper, OverwrittenProps > & TresModifiedObject>>
-TresBufferGeometry: DefineComponent<Partial<Omit<BufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresCamera: DefineComponent<Partial<Omit<Camera, OverwrittenProps > & TresModifiedObject>>
-TresCameraHelper: DefineComponent<Partial<Omit<CameraHelper, OverwrittenProps > & TresModifiedObject>>
-TresCapsuleBufferGeometry: DefineComponent<Partial<Omit<CapsuleBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresCapsuleGeometry: DefineComponent<Partial<Omit<CapsuleGeometry, OverwrittenProps > & TresModifiedObject>>
-TresCircleBufferGeometry: DefineComponent<Partial<Omit<CircleBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresCircleGeometry: DefineComponent<Partial<Omit<CircleGeometry, OverwrittenProps > & TresModifiedObject>>
-TresConeBufferGeometry: DefineComponent<Partial<Omit<ConeBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresConeGeometry: DefineComponent<Partial<Omit<ConeGeometry, OverwrittenProps > & TresModifiedObject>>
-TresCubeCamera: DefineComponent<Partial<Omit<CubeCamera, OverwrittenProps > & TresModifiedObject>>
-TresCylinderBufferGeometry: DefineComponent<Partial<Omit<CylinderBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresCylinderGeometry: DefineComponent<Partial<Omit<CylinderGeometry, OverwrittenProps > & TresModifiedObject>>
-TresDirectionalLight: DefineComponent<Partial<Omit<DirectionalLight, OverwrittenProps > & TresModifiedObject>>
-TresDirectionalLightHelper: DefineComponent<Partial<Omit<DirectionalLightHelper, OverwrittenProps > & TresModifiedObject>>
-TresDodecahedronBufferGeometry: DefineComponent<Partial<Omit<DodecahedronBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresDodecahedronGeometry: DefineComponent<Partial<Omit<DodecahedronGeometry, OverwrittenProps > & TresModifiedObject>>
-TresEdgesGeometry: DefineComponent<Partial<Omit<EdgesGeometry, OverwrittenProps > & TresModifiedObject>>
-TresExtrudeBufferGeometry: DefineComponent<Partial<Omit<ExtrudeBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresExtrudeGeometry: DefineComponent<Partial<Omit<ExtrudeGeometry, OverwrittenProps > & TresModifiedObject>>
-TresFog: DefineComponent<Partial<Omit<Fog, OverwrittenProps > & TresModifiedObject>>
-TresGridHelper: DefineComponent<Partial<Omit<GridHelper, OverwrittenProps > & TresModifiedObject>>
-TresHemisphereLight: DefineComponent<Partial<Omit<HemisphereLight, OverwrittenProps > & TresModifiedObject>>
-TresHemisphereLightHelper: DefineComponent<Partial<Omit<HemisphereLightHelper, OverwrittenProps > & TresModifiedObject>>
-TresIcosahedronBufferGeometry: DefineComponent<Partial<Omit<IcosahedronBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresIcosahedronGeometry: DefineComponent<Partial<Omit<IcosahedronGeometry, OverwrittenProps > & TresModifiedObject>>
-TresInstancedBufferGeometry: DefineComponent<Partial<Omit<InstancedBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresLatheBufferGeometry: DefineComponent<Partial<Omit<LatheBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresLatheGeometry: DefineComponent<Partial<Omit<LatheGeometry, OverwrittenProps > & TresModifiedObject>>
-TresLight: DefineComponent<Partial<Omit<Light, OverwrittenProps > & TresModifiedObject>>
-TresLineBasicMaterial: DefineComponent<Partial<Omit<LineBasicMaterial, OverwrittenProps > & TresModifiedObject>>
-TresLineDashedMaterial: DefineComponent<Partial<Omit<LineDashedMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMaterial: DefineComponent<Partial<Omit<Material, OverwrittenProps > & TresModifiedObject>>
-TresMeshBasicMaterial: DefineComponent<Partial<Omit<MeshBasicMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshDepthMaterial: DefineComponent<Partial<Omit<MeshDepthMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshDistanceMaterial: DefineComponent<Partial<Omit<MeshDistanceMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshLambertMaterial: DefineComponent<Partial<Omit<MeshLambertMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshMatcapMaterial: DefineComponent<Partial<Omit<MeshMatcapMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshNormalMaterial: DefineComponent<Partial<Omit<MeshNormalMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshPhongMaterial: DefineComponent<Partial<Omit<MeshPhongMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshPhysicalMaterial: DefineComponent<Partial<Omit<MeshPhysicalMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshStandardMaterial: DefineComponent<Partial<Omit<MeshStandardMaterial, OverwrittenProps > & TresModifiedObject>>
-TresMeshToonMaterial: DefineComponent<Partial<Omit<MeshToonMaterial, OverwrittenProps > & TresModifiedObject>>
-TresOctahedronBufferGeometry: DefineComponent<Partial<Omit<OctahedronBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresOctahedronGeometry: DefineComponent<Partial<Omit<OctahedronGeometry, OverwrittenProps > & TresModifiedObject>>
-TresOrthographicCamera: DefineComponent<Partial<Omit<OrthographicCamera, OverwrittenProps > & TresModifiedObject>>
-TresPerspectiveCamera: DefineComponent<Partial<Omit<PerspectiveCamera, OverwrittenProps > & TresModifiedObject>>
-TresPlaneBufferGeometry: DefineComponent<Partial<Omit<PlaneBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresPlaneGeometry: DefineComponent<Partial<Omit<PlaneGeometry, OverwrittenProps > & TresModifiedObject>>
-TresPlaneHelper: DefineComponent<Partial<Omit<PlaneHelper, OverwrittenProps > & TresModifiedObject>>
-TresPointLight: DefineComponent<Partial<Omit<PointLight, OverwrittenProps > & TresModifiedObject>>
-TresPointLightHelper: DefineComponent<Partial<Omit<PointLightHelper, OverwrittenProps > & TresModifiedObject>>
-TresPointsMaterial: DefineComponent<Partial<Omit<PointsMaterial, OverwrittenProps > & TresModifiedObject>>
-TresPolarGridHelper: DefineComponent<Partial<Omit<PolarGridHelper, OverwrittenProps > & TresModifiedObject>>
-TresPolyhedronBufferGeometry: DefineComponent<Partial<Omit<PolyhedronBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresPolyhedronGeometry: DefineComponent<Partial<Omit<PolyhedronGeometry, OverwrittenProps > & TresModifiedObject>>
-TresRawShaderMaterial: DefineComponent<Partial<Omit<RawShaderMaterial, OverwrittenProps > & TresModifiedObject>>
-TresRectAreaLight: DefineComponent<Partial<Omit<RectAreaLight, OverwrittenProps > & TresModifiedObject>>
-TresRingBufferGeometry: DefineComponent<Partial<Omit<RingBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresRingGeometry: DefineComponent<Partial<Omit<RingGeometry, OverwrittenProps > & TresModifiedObject>>
-TresShaderMaterial: DefineComponent<Partial<Omit<ShaderMaterial, OverwrittenProps > & TresModifiedObject>>
-TresShadowMaterial: DefineComponent<Partial<Omit<ShadowMaterial, OverwrittenProps > & TresModifiedObject>>
-TresShapeBufferGeometry: DefineComponent<Partial<Omit<ShapeBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresShapeGeometry: DefineComponent<Partial<Omit<ShapeGeometry, OverwrittenProps > & TresModifiedObject>>
-TresSkeletonHelper: DefineComponent<Partial<Omit<SkeletonHelper, OverwrittenProps > & TresModifiedObject>>
-TresSphereBufferGeometry: DefineComponent<Partial<Omit<SphereBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresSphereGeometry: DefineComponent<Partial<Omit<SphereGeometry, OverwrittenProps > & TresModifiedObject>>
-TresSpotLight: DefineComponent<Partial<Omit<SpotLight, OverwrittenProps > & TresModifiedObject>>
-TresSpotLightHelper: DefineComponent<Partial<Omit<SpotLightHelper, OverwrittenProps > & TresModifiedObject>>
-TresSpriteMaterial: DefineComponent<Partial<Omit<SpriteMaterial, OverwrittenProps > & TresModifiedObject>>
-TresStereoCamera: DefineComponent<Partial<Omit<StereoCamera, OverwrittenProps > & TresModifiedObject>>
-TresTetrahedronBufferGeometry: DefineComponent<Partial<Omit<TetrahedronBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresTetrahedronGeometry: DefineComponent<Partial<Omit<TetrahedronGeometry, OverwrittenProps > & TresModifiedObject>>
-TresTorusBufferGeometry: DefineComponent<Partial<Omit<TorusBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresTorusGeometry: DefineComponent<Partial<Omit<TorusGeometry, OverwrittenProps > & TresModifiedObject>>
-TresTorusKnotBufferGeometry: DefineComponent<Partial<Omit<TorusKnotBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresTorusKnotGeometry: DefineComponent<Partial<Omit<TorusKnotGeometry, OverwrittenProps > & TresModifiedObject>>
-TresTubeBufferGeometry: DefineComponent<Partial<Omit<TubeBufferGeometry, OverwrittenProps > & TresModifiedObject>>
-TresTubeGeometry: DefineComponent<Partial<Omit<TubeGeometry, OverwrittenProps > & TresModifiedObject>>
-TresWireframeGeometry: DefineComponent<Partial<Omit<WireframeGeometry, OverwrittenProps > & TresModifiedObject>>
-        }
-      }
-      

+ 3 - 14
vite.config.ts

@@ -1,5 +1,4 @@
 /// <reference types="vitest" />
-import fs from 'fs'
 
 import { defineConfig } from 'vite'
 
@@ -12,11 +11,11 @@ import copy from 'rollup-plugin-copy'
 
 /* import analyze from 'rollup-plugin-analyzer'
  */ /* import { visualizer } from 'rollup-plugin-visualizer' */
-import { resolve, join } from 'pathe'
+import { resolve } from 'pathe'
 
 import { lightGreen, yellow, gray, bold } from 'kolorist'
-import { ViteTresPlugin } from './plugins/vite-tres-types-plugin'
-
+/* import { ViteTresPlugin } from './plugins/vite-tres-types-plugin'
+ */
 import pkg from './package.json'
 
 // eslint-disable-next-line no-console
@@ -40,17 +39,7 @@ export default defineConfig({
     }),
     dts({
       insertTypesEntry: true,
-      afterBuild() {
-        console.log('🪄 ✨ Magically generating types for TresJS')
-        const outputDir = join(__dirname, 'dist/types')
-        const outputFile = join(outputDir, 'index.d.ts')
-        if (fs.existsSync(outputFile)) {
-          const index = fs.readFileSync(outputFile, 'utf-8')
-          fs.writeFileSync(outputFile, `import './tres-components';\n${index}`)
-        }
-      },
     }),
-    ViteTresPlugin(),
     banner({
       content: `/**\n * name: ${pkg.name}\n * version: v${
         pkg.version