@tresjs/core 4.0.0-next.0 → 4.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/index.d.ts +3 -17
  2. package/dist/{components → src/components}/TresCanvas.vue.d.ts +10 -2
  3. package/dist/{composables → src/composables}/useCamera/index.d.ts +366 -399
  4. package/dist/src/composables/usePointerEventHandler/index.d.ts +17 -0
  5. package/dist/{composables → src/composables}/useRenderer/const.d.ts +4 -0
  6. package/dist/{composables → src/composables}/useRenderer/index.d.ts +8 -3
  7. package/dist/src/composables/useSizes/index.d.ts +11 -0
  8. package/dist/src/composables/useTresContextProvider/index.d.ts +75 -0
  9. package/dist/src/core/nodeOps.d.ts +4 -0
  10. package/dist/src/directives/index.d.ts +5 -0
  11. package/dist/src/directives/vAlwaysLookAt.d.ts +6 -0
  12. package/dist/src/directives/vDistanceTo.d.ts +6 -0
  13. package/dist/src/directives/vLightHelper.d.ts +6 -0
  14. package/dist/src/directives/vLog.d.ts +6 -0
  15. package/dist/src/index.d.ts +18 -0
  16. package/dist/{types → src/types}/index.d.ts +20 -16
  17. package/dist/{utils → src/utils}/index.d.ts +3 -2
  18. package/dist/tres.js +866 -587
  19. package/dist/tres.umd.cjs +3 -3
  20. package/package.json +30 -29
  21. package/dist/composables/useLoader/index.d.ts +0 -44
  22. package/dist/composables/usePointerEventHandler/index.d.ts +0 -19
  23. package/dist/composables/useRaycaster/index.d.ts +0 -18
  24. package/dist/composables/useSeek/index.d.ts +0 -19
  25. package/dist/composables/useTresContextProvider/index.d.ts +0 -44
  26. package/dist/core/nodeOps.d.ts +0 -3
  27. package/dist/core/renderer.d.ts +0 -5
  28. /package/dist/{components → src/components}/index.d.ts +0 -0
  29. /package/dist/{composables → src/composables}/index.d.ts +0 -0
  30. /package/dist/{composables → src/composables}/useLogger.d.ts +0 -0
  31. /package/dist/{composables → src/composables}/useRenderLoop/index.d.ts +0 -0
  32. /package/dist/{composables → src/composables}/useTexture/index.d.ts +0 -0
  33. /package/dist/{core → src/core}/catalogue.d.ts +0 -0
  34. /package/dist/{core → src/core}/revision.d.ts +0 -0
  35. /package/dist/{devtools → src/devtools}/highlight.d.ts +0 -0
  36. /package/dist/{devtools → src/devtools}/index.d.ts +0 -0
  37. /package/dist/{devtools → src/devtools}/plugin.d.ts +0 -0
  38. /package/dist/{devtools → src/devtools}/utils.d.ts +0 -0
  39. /package/dist/{utils → src/utils}/normalize.d.ts +0 -0
  40. /package/dist/{utils → src/utils}/perf.d.ts +0 -0
  41. /package/dist/{utils → src/utils}/template-compiler-options.d.ts +0 -0
  42. /package/dist/{utils → src/utils}/test-utils.d.ts +0 -0
@@ -0,0 +1,17 @@
1
+ import type { Intersection, Object3D, Object3DEventMap } from 'three';
2
+ import type { TresContext } from '../useTresContextProvider';
3
+ type CallbackFn = (intersection: Intersection<Object3D<Object3DEventMap>>, event: PointerEvent) => void;
4
+ type CallbackFnPointerLeave = (object: Object3D, event: PointerEvent) => void;
5
+ export interface EventProps {
6
+ onClick?: CallbackFn;
7
+ onPointerEnter?: CallbackFn;
8
+ onPointerMove?: CallbackFn;
9
+ onPointerLeave?: CallbackFnPointerLeave;
10
+ }
11
+ export declare const usePointerEventHandler: (ctx: TresContext) => {
12
+ registerObject: (object: Object3D & EventProps) => void;
13
+ deregisterObject: (object: Object3D) => void;
14
+ registerBlockingObject: (object: Object3D) => void;
15
+ deregisterBlockingObject: (object: Object3D) => void;
16
+ };
17
+ export {};
@@ -10,5 +10,9 @@ export declare const rendererPresets: {
10
10
  type: 2;
11
11
  };
12
12
  };
13
+ flat: {
14
+ toneMapping: 0;
15
+ toneMappingExposure: number;
16
+ };
13
17
  };
14
18
  export type RendererPresetsType = keyof typeof rendererPresets;
@@ -52,7 +52,7 @@ export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRen
52
52
  * CineonToneMapping, ACESFilmicToneMapping,
53
53
  * CustomToneMapping
54
54
  *
55
- * @default NoToneMapping
55
+ * @default ACESFilmicToneMapping
56
56
  */
57
57
  toneMapping?: MaybeRefOrGetter<ToneMapping>;
58
58
  /**
@@ -69,6 +69,7 @@ export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRen
69
69
  clearColor?: MaybeRefOrGetter<TresColor>;
70
70
  windowSize?: MaybeRefOrGetter<boolean | string>;
71
71
  preset?: MaybeRefOrGetter<RendererPresetsType>;
72
+ renderMode?: MaybeRefOrGetter<'always' | 'on-demand' | 'manual'>;
72
73
  }
73
74
  /**
74
75
  * Reactive three.js WebGLRenderer instance
@@ -76,11 +77,15 @@ export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRen
76
77
  * @param canvas
77
78
  * @param {UseRendererOptions} [options]
78
79
  */
79
- export declare function useRenderer({ scene, canvas, options, disableRender, contextParts: { sizes, camera }, }: {
80
+ export declare function useRenderer({ scene, canvas, options, disableRender, emit, contextParts: { sizes, camera, render, invalidate, advance }, }: {
80
81
  canvas: MaybeRef<HTMLCanvasElement>;
81
82
  scene: Scene;
82
83
  options: UseRendererOptions;
83
- contextParts: Pick<TresContext, 'sizes' | 'camera'>;
84
+ emit: (event: string, ...args: any[]) => void;
85
+ contextParts: Pick<TresContext, 'sizes' | 'camera' | 'render'> & {
86
+ invalidate: () => void;
87
+ advance: () => void;
88
+ };
84
89
  disableRender: MaybeRefOrGetter<boolean>;
85
90
  }): {
86
91
  renderer: import("vue").ShallowRef<WebGLRenderer>;
@@ -0,0 +1,11 @@
1
+ import type { MaybeRefOrGetter, MaybeRef, ComputedRef, Ref } from 'vue';
2
+ export interface SizesType {
3
+ height: Readonly<Ref<number>>;
4
+ width: Readonly<Ref<number>>;
5
+ aspectRatio: ComputedRef<number>;
6
+ }
7
+ export default function useSizes(windowSize: MaybeRefOrGetter<boolean>, canvas: MaybeRef<HTMLCanvasElement>, debounceMs?: number): {
8
+ height: Readonly<Ref<number>>;
9
+ width: Readonly<Ref<number>>;
10
+ aspectRatio: ComputedRef<number>;
11
+ };
@@ -0,0 +1,75 @@
1
+ import type { Camera, EventDispatcher, Object3D, WebGLRenderer } from 'three';
2
+ import { Raycaster } from 'three';
3
+ import type { ComputedRef, DeepReadonly, MaybeRef, MaybeRefOrGetter, Ref, ShallowRef } from 'vue';
4
+ import type { UseRendererOptions } from '../useRenderer';
5
+ import type { TresScene } from '../../types';
6
+ import type { EventProps } from '../usePointerEventHandler';
7
+ import { type SizesType } from '../useSizes';
8
+ export interface InternalState {
9
+ priority: Ref<number>;
10
+ frames: Ref<number>;
11
+ maxFrames: number;
12
+ }
13
+ export interface RenderState {
14
+ /**
15
+ * If set to 'on-demand', the scene will only be rendered when the current frame is invalidated
16
+ * If set to 'manual', the scene will only be rendered when advance() is called
17
+ * If set to 'always', the scene will be rendered every frame
18
+ */
19
+ mode: Ref<'always' | 'on-demand' | 'manual'>;
20
+ priority: Ref<number>;
21
+ frames: Ref<number>;
22
+ maxFrames: number;
23
+ canBeInvalidated: ComputedRef<boolean>;
24
+ }
25
+ export interface PerformanceState {
26
+ maxFrames: number;
27
+ fps: {
28
+ value: number;
29
+ accumulator: number[];
30
+ };
31
+ memory: {
32
+ currentMem: number;
33
+ allocatedMem: number;
34
+ accumulator: number[];
35
+ };
36
+ }
37
+ export interface TresContext {
38
+ scene: ShallowRef<TresScene>;
39
+ sizes: SizesType;
40
+ extend: (objects: any) => void;
41
+ camera: ComputedRef<Camera | undefined>;
42
+ cameras: DeepReadonly<Ref<Camera[]>>;
43
+ controls: Ref<(EventDispatcher & {
44
+ enabled: boolean;
45
+ }) | null>;
46
+ renderer: ShallowRef<WebGLRenderer>;
47
+ raycaster: ShallowRef<Raycaster>;
48
+ perf: PerformanceState;
49
+ render: RenderState;
50
+ /**
51
+ * Invalidates the current frame when renderMode === 'on-demand'
52
+ */
53
+ invalidate: () => void;
54
+ /**
55
+ * Advance one frame when renderMode === 'manual'
56
+ */
57
+ advance: () => void;
58
+ registerCamera: (camera: Camera) => void;
59
+ setCameraActive: (cameraOrUuid: Camera | string) => void;
60
+ deregisterCamera: (camera: Camera) => void;
61
+ registerObjectAtPointerEventHandler: (object: Object3D & EventProps) => void;
62
+ deregisterObjectAtPointerEventHandler: (object: Object3D) => void;
63
+ registerBlockingObjectAtPointerEventHandler: (object: Object3D) => void;
64
+ deregisterBlockingObjectAtPointerEventHandler: (object: Object3D) => void;
65
+ }
66
+ export declare function useTresContextProvider({ scene, canvas, windowSize, disableRender, rendererOptions, emit, }: {
67
+ scene: TresScene;
68
+ canvas: MaybeRef<HTMLCanvasElement>;
69
+ windowSize: MaybeRefOrGetter<boolean>;
70
+ disableRender: MaybeRefOrGetter<boolean>;
71
+ rendererOptions: UseRendererOptions;
72
+ emit: (event: string, ...args: any[]) => void;
73
+ }): TresContext;
74
+ export declare function useTresContext(): TresContext;
75
+ export declare const useTres: typeof useTresContext;
@@ -0,0 +1,4 @@
1
+ import { type RendererOptions } from 'vue';
2
+ import type { TresObject } from '../types';
3
+ export declare function invalidateInstance(instance: TresObject): void;
4
+ export declare const nodeOps: () => RendererOptions<TresObject, TresObject | null>;
@@ -0,0 +1,5 @@
1
+ import { vLog } from './vLog';
2
+ import { vLightHelper } from './vLightHelper';
3
+ import { vAlwaysLookAt } from './vAlwaysLookAt';
4
+ import { vDistanceTo } from './vDistanceTo';
5
+ export { vLog, vLightHelper, vAlwaysLookAt, vDistanceTo };
@@ -0,0 +1,6 @@
1
+ import type { Object3D } from 'three';
2
+ import type { Ref } from 'vue';
3
+ import type { TresVector3 } from '../types';
4
+ export declare const vAlwaysLookAt: {
5
+ updated: (el: Object3D, binding: Ref<TresVector3>) => void;
6
+ };
@@ -0,0 +1,6 @@
1
+ import type { Ref } from 'vue';
2
+ import type { TresObject } from '../types';
3
+ export declare const vDistanceTo: {
4
+ updated: (el: TresObject, binding: Ref<TresObject>) => void;
5
+ unmounted: (el: TresObject) => void;
6
+ };
@@ -0,0 +1,6 @@
1
+ import type { TresObject } from '../types';
2
+ export declare const vLightHelper: {
3
+ mounted: (el: TresObject) => void;
4
+ updated: (el: TresObject) => void;
5
+ unmounted: (el: TresObject) => void;
6
+ };
@@ -0,0 +1,6 @@
1
+ import type { TresObject } from '../types';
2
+ export declare const vLog: {
3
+ mounted: (el: TresObject, binding: {
4
+ arg: string;
5
+ }) => void;
6
+ };
@@ -0,0 +1,18 @@
1
+ import type { App } from 'vue';
2
+ import { normalizeColor, normalizeVectorFlexibleParam } from './utils/normalize';
3
+ import templateCompilerOptions from './utils/template-compiler-options';
4
+ export * from './composables';
5
+ export * from './core/catalogue';
6
+ export * from './components';
7
+ export * from './types';
8
+ export * from './directives';
9
+ export interface TresOptions {
10
+ extends?: Record<string, unknown>;
11
+ }
12
+ export interface TresPlugin {
13
+ [key: string]: any;
14
+ install: (app: App, options?: TresOptions) => void;
15
+ }
16
+ declare const plugin: TresPlugin;
17
+ export default plugin;
18
+ export { normalizeColor, normalizeVectorFlexibleParam, templateCompilerOptions, };
@@ -1,6 +1,6 @@
1
1
  import type { DefineComponent, VNode, VNodeRef } from 'vue';
2
2
  import type * as THREE from 'three';
3
- import type { EventProps as PointerEventHandlerEventProps } from '../composables/usePointerEventHandler';
3
+ import type { TresContext } from '../composables/useTresContextProvider';
4
4
  export type AttachFnType<O = any> = (parent: any, self: O) => () => void;
5
5
  export type AttachType<O = any> = string | AttachFnType<O>;
6
6
  export type ConstructorRepresentation = new (...args: any[]) => any;
@@ -30,25 +30,29 @@ interface TresBaseObject {
30
30
  dispose?: () => void;
31
31
  [prop: string]: any;
32
32
  }
33
- export interface TresObject3D extends THREE.Object3D {
34
- geometry?: THREE.BufferGeometry & TresBaseObject;
35
- material?: THREE.Material & TresBaseObject;
36
- userData: {
37
- tres__materialViaProp: boolean;
38
- tres__geometryViaProp: boolean;
33
+ export interface LocalState {
34
+ type: string;
35
+ objects: TresObject3D[];
36
+ parent: TresObject3D | null;
37
+ primitive?: boolean;
38
+ eventCount: number;
39
+ handlers: Partial<EventHandlers>;
40
+ memoizedProps: {
39
41
  [key: string]: any;
40
42
  };
43
+ disposable: boolean;
44
+ root: TresContext;
41
45
  }
42
- export type TresObject = TresBaseObject & (TresObject3D | THREE.BufferGeometry | THREE.Material | THREE.Fog);
46
+ export interface TresObject3D extends THREE.Object3D<THREE.Object3DEventMap> {
47
+ geometry?: THREE.BufferGeometry & TresBaseObject;
48
+ material?: THREE.Material & TresBaseObject;
49
+ }
50
+ export type TresObject = TresBaseObject & (TresObject3D | THREE.BufferGeometry | THREE.Material | THREE.Fog) & {
51
+ __tres: LocalState;
52
+ };
43
53
  export interface TresScene extends THREE.Scene {
44
- userData: {
45
- tres__registerCamera?: (newCamera: THREE.Camera, active?: boolean) => void;
46
- tres__deregisterCamera?: (camera: THREE.Camera) => void;
47
- tres__registerAtPointerEventHandler?: (object: THREE.Object3D & PointerEventHandlerEventProps) => void;
48
- tres__deregisterAtPointerEventHandler?: (object: THREE.Object3D) => void;
49
- tres__registerBlockingObjectAtPointerEventHandler?: (object: THREE.Object3D) => void;
50
- tres__deregisterBlockingObjectAtPointerEventHandler?: (object: THREE.Object3D) => void;
51
- [key: string]: any;
54
+ __tres: {
55
+ root: TresContext;
52
56
  };
53
57
  }
54
58
  export interface Intersection extends THREE.Intersection {
@@ -1,5 +1,5 @@
1
- import { MeshBasicMaterial } from 'three';
2
- import type { Mesh, type Scene, type Object3D } from 'three';
1
+ import { MeshBasicMaterial, Vector3 } from 'three';
2
+ import type { Mesh, Scene, Object3D } from 'three';
3
3
  export declare function toSetMethodName(key: string): string;
4
4
  export declare const merge: (target: any, source: any) => any;
5
5
  export declare const isHTMLTag: (key: string) => boolean;
@@ -20,3 +20,4 @@ export declare function createHighlightMaterial(): MeshBasicMaterial;
20
20
  export declare function animateHighlight(highlightMesh: Mesh, startTime: number): void;
21
21
  export declare function stopHighlightAnimation(): void;
22
22
  export declare function createHighlightMesh(object: Object3D): Mesh;
23
+ export declare function extractBindingPosition(binding: any): Vector3;