@tresjs/core 4.3.6 → 5.0.0-alpha.0
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.
- package/dist/src/components/TresCanvas.vue.d.ts +70 -64
- package/dist/src/composables/index.d.ts +6 -12
- package/dist/src/composables/useCamera/index.d.ts +42 -8555
- package/dist/src/composables/useCreateRafLoop/index.d.ts +14 -0
- package/dist/src/composables/useEventManager/index.d.ts +10 -0
- package/dist/src/composables/useGraph/index.d.ts +3 -0
- package/dist/src/composables/useLoader/component.vue.d.ts +31 -17
- package/dist/src/composables/useLoader/index.d.ts +44 -37
- package/dist/src/composables/useLoop/index.d.ts +13 -16
- package/dist/src/composables/useRenderer/pixelRatio.d.ts +4 -0
- package/dist/src/composables/useRenderer/useRendererManager.d.ts +194 -0
- package/dist/src/composables/useTres/index.d.ts +37 -0
- package/dist/src/composables/useTresContextProvider/index.d.ts +14 -64
- package/dist/src/devtools/inspectorHandlers.d.ts +60 -0
- package/dist/src/devtools/plugin.d.ts +3 -8
- package/dist/src/devtools/setupDevtools.d.ts +14 -0
- package/dist/src/devtools/types.d.ts +90 -0
- package/dist/src/index.d.ts +4 -1
- package/dist/src/types/index.d.ts +13 -69
- package/dist/src/utils/array.d.ts +6 -0
- package/dist/src/utils/createPriorityEventHook.d.ts +4 -6
- package/dist/src/utils/graph.d.ts +15 -0
- package/dist/src/utils/index.d.ts +2 -34
- package/dist/src/utils/is/dom.d.ts +1 -0
- package/dist/src/utils/is/index.d.ts +4 -0
- package/dist/src/utils/is/three.d.ts +162 -0
- package/dist/src/utils/is/tres.d.ts +70 -0
- package/dist/src/utils/is/typed.d.ts +1 -0
- package/dist/src/utils/is/util.d.ts +1 -0
- package/dist/src/utils/logger.d.ts +25 -0
- package/dist/src/utils/makeMap.d.ts +9 -0
- package/dist/src/utils/perf.d.ts +1 -0
- package/dist/src/utils/pointerEvents.d.ts +10 -0
- package/dist/src/utils/string.d.ts +1 -0
- package/dist/src/utils/three.d.ts +9 -0
- package/dist/tres.js +5320 -1482
- package/package.json +42 -16
- package/dist/src/composables/useLogger.d.ts +0 -11
- package/dist/src/composables/useRaycaster/index.d.ts +0 -16
- package/dist/src/composables/useRenderLoop/index.d.ts +0 -17
- package/dist/src/composables/useRenderer/const.d.ts +0 -18
- package/dist/src/composables/useRenderer/index.d.ts +0 -91
- package/dist/src/composables/useSeek/index.d.ts +0 -20
- package/dist/src/composables/useTexture/component.vue.d.ts +0 -29
- package/dist/src/composables/useTexture/index.d.ts +0 -103
- package/dist/src/composables/useTresEventManager/index.d.ts +0 -25
- package/dist/src/composables/useTresReady/createReadyEventHook/index.d.ts +0 -4
- package/dist/src/composables/useTresReady/index.d.ts +0 -7
- package/dist/src/core/loop.d.ts +0 -38
- package/dist/src/utils/is.d.ts +0 -36
- package/dist/tres.umd.cjs +0 -8
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface RafLoopContext {
|
|
2
|
+
delta: number;
|
|
3
|
+
elapsed: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @param cycleFn the function that is called before the after event hook is triggered and after the before event hook is triggered.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useCreateRafLoop: (cycleFn: () => void) => {
|
|
9
|
+
start: () => void;
|
|
10
|
+
stop: () => void;
|
|
11
|
+
isActive: Readonly<import('vue').ShallowRef<boolean>>;
|
|
12
|
+
onBeforeLoop: import('@vueuse/core').EventHookOn<RafLoopContext>;
|
|
13
|
+
onLoop: import('@vueuse/core').EventHookOn<RafLoopContext>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PointerEvent, PointerEventsMap } from '@pmndrs/pointer-events';
|
|
2
|
+
import { Event, Object3D, Object3DEventMap } from 'three';
|
|
3
|
+
import { MaybeRef } from 'vue';
|
|
4
|
+
import { TresContext } from '../useTresContextProvider';
|
|
5
|
+
export declare function useEventManager({ canvas, contextParts: { scene, camera, renderer }, }: {
|
|
6
|
+
canvas: MaybeRef<HTMLCanvasElement>;
|
|
7
|
+
contextParts: Pick<TresContext, 'scene' | 'camera' | 'renderer'>;
|
|
8
|
+
}): {
|
|
9
|
+
onPointerMissed: import('@vueuse/core').EventHookOn<PointerEvent<MouseEvent> & Event<"click", Object3D<Object3DEventMap & PointerEventsMap>>>;
|
|
10
|
+
};
|
|
@@ -1,24 +1,38 @@
|
|
|
1
|
+
import { LoadingManager } from 'three';
|
|
1
2
|
import { LoaderProto } from './index';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { TresObjectMap } from '../../utils/graph';
|
|
4
|
+
declare const _default: <T extends TresObjectMap>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
5
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
|
|
6
|
+
readonly onLoaded?: ((result: T) => any) | undefined;
|
|
7
|
+
readonly onError?: ((error: unknown) => any) | undefined;
|
|
8
|
+
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, "onError" | "onLoaded"> & {
|
|
9
|
+
/**
|
|
10
|
+
* The THREE.js loader to use
|
|
11
|
+
*/
|
|
12
|
+
loader: LoaderProto<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Path to resource
|
|
15
|
+
*/
|
|
16
|
+
path: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional THREE.js LoadingManager
|
|
19
|
+
*/
|
|
20
|
+
manager?: LoadingManager;
|
|
21
|
+
} & Partial<{}>> & import('vue').PublicProps;
|
|
22
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
|
23
|
+
attrs: any;
|
|
8
24
|
slots: {
|
|
9
25
|
default?(_: {
|
|
10
|
-
|
|
26
|
+
state: import('vue').UnwrapRef<T>;
|
|
27
|
+
isLoading: boolean;
|
|
28
|
+
error: unknown;
|
|
11
29
|
}): any;
|
|
12
30
|
};
|
|
13
|
-
|
|
14
|
-
|
|
31
|
+
emit: ((evt: "loaded", result: T) => void) & ((evt: "error", error: unknown) => void);
|
|
32
|
+
}>) => import('vue').VNode & {
|
|
33
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
15
34
|
};
|
|
16
|
-
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
17
|
-
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
18
|
-
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
19
35
|
export default _default;
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
};
|
|
36
|
+
type __VLS_PrettifyLocal<T> = {
|
|
37
|
+
[K in keyof T]: T[K];
|
|
38
|
+
} & {};
|
|
@@ -1,44 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { UseAsyncStateOptions, UseAsyncStateReturn } from '@vueuse/core';
|
|
2
|
+
import { Loader, LoadingManager } from 'three';
|
|
3
|
+
import { MaybeRef } from 'vue';
|
|
4
|
+
export interface LoaderMethods {
|
|
5
|
+
setDRACOLoader: (dracoLoader: any) => void;
|
|
6
|
+
setMeshoptDecoder: (meshoptDecoder: any) => void;
|
|
7
|
+
setKTX2Loader: (ktx2Loader: any) => void;
|
|
5
8
|
}
|
|
9
|
+
export type TresLoader<T> = Loader & Partial<LoaderMethods> & {
|
|
10
|
+
load: (url: string, onLoad: (result: T) => void, onProgress?: (event: ProgressEvent<EventTarget>) => void, onError?: (err: unknown) => void) => void;
|
|
11
|
+
loadAsync: (url: string, onProgress?: (event: ProgressEvent) => void) => Promise<T>;
|
|
12
|
+
};
|
|
6
13
|
export type LoaderProto<T> = new (manager?: LoadingManager) => TresLoader<T>;
|
|
7
|
-
export
|
|
14
|
+
export interface TresLoaderOptions<T, Shallow extends boolean> {
|
|
15
|
+
manager?: LoadingManager;
|
|
16
|
+
extensions?: (loader: TresLoader<T>) => void;
|
|
17
|
+
initialValue?: T;
|
|
18
|
+
asyncOptions?: UseAsyncStateOptions<Shallow, any | null>;
|
|
19
|
+
}
|
|
8
20
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
13
|
-
* @return { [key: string]: any }
|
|
21
|
+
* Return type for the useLoader composable
|
|
22
|
+
* @template T - The type of the loaded asset (e.g., GLTF, Texture, etc.)
|
|
23
|
+
* @template Shallow - Whether to use shallow reactivity for better performance
|
|
24
|
+
* @extends {UseAsyncStateReturn<T, [string], Shallow>} - Extends VueUse's useAsyncState return type
|
|
14
25
|
*/
|
|
15
|
-
export
|
|
16
|
-
|
|
26
|
+
export type UseLoaderReturn<T, Shallow extends boolean> = UseAsyncStateReturn<T, [string], Shallow> & {
|
|
27
|
+
/**
|
|
28
|
+
* Loads a new asset from the given path
|
|
29
|
+
* @param path - The URL or path to the asset to load
|
|
30
|
+
*/
|
|
31
|
+
load: (path: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Progress of the loading process
|
|
34
|
+
* @property loaded - The number of bytes loaded
|
|
35
|
+
* @property total - The total number of bytes to load
|
|
36
|
+
* @property percentage - The percentage of the loading process
|
|
37
|
+
*/
|
|
38
|
+
progress: {
|
|
39
|
+
loaded: number;
|
|
40
|
+
total: number;
|
|
41
|
+
percentage: number;
|
|
42
|
+
};
|
|
17
43
|
};
|
|
18
|
-
export type Extensions<T extends {
|
|
19
|
-
prototype: LoaderProto<any>;
|
|
20
|
-
}> = (loader: T['prototype']) => void;
|
|
21
44
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
25
|
-
* @
|
|
26
|
-
*
|
|
27
|
-
* ```ts
|
|
28
|
-
* import { useLoader } from '@tresjs/core'
|
|
29
|
-
* import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
|
|
30
|
-
*
|
|
31
|
-
* const { scene } = await useLoader(THREE.GLTFLoader, 'path/to/asset.gltf')
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @export
|
|
35
|
-
* @template LoaderProto<T>
|
|
36
|
-
* @template string | string[],
|
|
37
|
-
* @param {LoaderProto<T>} Loader
|
|
38
|
-
* @param {string | string[],} url
|
|
39
|
-
* @param {Extensions<TresLoader<T>>} [extensions]
|
|
40
|
-
* @param {(event: ProgressEvent<EventTarget>) => void} [onProgress]
|
|
41
|
-
* @param {(proto: TresLoader<T>) => void} [cb]
|
|
42
|
-
* @return {*}
|
|
45
|
+
* Vue composable for loading 3D models using Three.js loaders
|
|
46
|
+
* @param Loader - The Three.js loader constructor
|
|
47
|
+
* @param path - The path to the model file
|
|
48
|
+
* @param options - Optional configuration for the loader
|
|
49
|
+
* @returns UseAsyncState composable with the loaded model
|
|
43
50
|
*/
|
|
44
|
-
export declare function useLoader<T>(Loader: LoaderProto<T>,
|
|
51
|
+
export declare function useLoader<T, Shallow extends boolean = false>(Loader: LoaderProto<T>, path: MaybeRef<string>, options?: TresLoaderOptions<T, Shallow>): UseLoaderReturn<T, Shallow>;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
onAfterRender: (cb: LoopCallbackFn, index?: number) => {
|
|
15
|
-
off: import('@vueuse/core').Fn;
|
|
16
|
-
};
|
|
1
|
+
import { RafLoopContext } from '../useCreateRafLoop';
|
|
2
|
+
import { TresPartialContext } from '../useTres';
|
|
3
|
+
export type LoopContext = RafLoopContext & TresPartialContext;
|
|
4
|
+
/**
|
|
5
|
+
* Composable that provides control over the render loop and animation lifecycle.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useLoop: () => {
|
|
8
|
+
stop: () => void;
|
|
9
|
+
start: () => void;
|
|
10
|
+
isActive: Readonly<import('vue').ShallowRef<boolean>>;
|
|
11
|
+
onBeforeRender: import('../../utils/createPriorityEventHook').PriorityEventHookOn<LoopContext>;
|
|
12
|
+
onRender: import('../../utils/createPriorityEventHook').PriorityEventHookOn<LoopContext>;
|
|
13
|
+
render: (fn: import('..').RenderFunction) => void;
|
|
17
14
|
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { ColorRepresentation, ColorSpace, ShadowMapType, ToneMapping, WebGLRenderer } from 'three';
|
|
2
|
+
import { TresContext } from '../useTresContextProvider';
|
|
3
|
+
import { MaybeRef, Reactive, ShallowRef } from 'vue';
|
|
4
|
+
import { Renderer } from 'three/webgpu';
|
|
5
|
+
import { SizesType } from '../useSizes';
|
|
6
|
+
import { UseCameraReturn } from '../useCamera';
|
|
7
|
+
import { TresScene } from '../../types';
|
|
8
|
+
/**
|
|
9
|
+
* If set to 'on-demand', the scene will only be rendered when the current frame is invalidated
|
|
10
|
+
* If set to 'manual', the scene will only be rendered when advance() is called
|
|
11
|
+
* If set to 'always', the scene will be rendered every frame
|
|
12
|
+
*/
|
|
13
|
+
export type RenderMode = 'always' | 'on-demand' | 'manual';
|
|
14
|
+
export type RenderFunction = (notifySuccess: () => void) => void;
|
|
15
|
+
export type TresRenderer = WebGLRenderer | Renderer;
|
|
16
|
+
export interface RendererOptions {
|
|
17
|
+
/**
|
|
18
|
+
* WebGL Context options (Readonly because they are passed to the renderer constructor)
|
|
19
|
+
* They can't be changed after the renderer is created because they are passed to the canvas context
|
|
20
|
+
*/
|
|
21
|
+
antialias?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Enables stencil buffer with 8 bits.
|
|
24
|
+
* Required for stencil-based operations like shadow volumes or post-processing effects.
|
|
25
|
+
* @readonly
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
stencil?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Enables depth buffer with at least 16 bits.
|
|
31
|
+
* Required for proper 3D rendering and depth testing.
|
|
32
|
+
* @readonly
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
depth?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Sets the shader precision of the renderer.
|
|
38
|
+
* @see {@link https://threejs.org/docs/#api/en/renderers/WebGLRenderer}
|
|
39
|
+
* @default 'highp'
|
|
40
|
+
*/
|
|
41
|
+
precision?: 'highp' | 'mediump' | 'lowp';
|
|
42
|
+
/**
|
|
43
|
+
* Enables logarithmic depth buffer. Useful for scenes with large differences in scale.
|
|
44
|
+
* Helps prevent z-fighting in scenes with objects very close and very far from the camera.
|
|
45
|
+
* @readonly
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
logarithmicDepthBuffer?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Preserves the buffers until manually cleared or overwritten.
|
|
51
|
+
* Needed for screenshots or when reading pixels from the canvas.
|
|
52
|
+
* Warning: This may impact performance.
|
|
53
|
+
* @readonly
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
preserveDrawingBuffer?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Power preference for the renderer.
|
|
59
|
+
* Power preference for the renderer.
|
|
60
|
+
* - `default`: Automatically chooses the most suitable power setting.
|
|
61
|
+
* - `high-performance`: Prioritizes rendering performance.
|
|
62
|
+
* - `low-power`: Tries to reduce power usage.
|
|
63
|
+
* @see {@link https://threejs.org/docs/#api/en/renderers/WebGLRenderer}
|
|
64
|
+
* @default 'default'
|
|
65
|
+
* @readonly
|
|
66
|
+
*/
|
|
67
|
+
powerPreference?: WebGLPowerPreference;
|
|
68
|
+
/**
|
|
69
|
+
* Whether to create the WebGL context with an alpha buffer.
|
|
70
|
+
* This is a WebGL context option that must be set during context creation and cannot be changed later.
|
|
71
|
+
* When true, the canvas can be transparent, showing content behind it.
|
|
72
|
+
* @readonly
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
alpha?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to premultiply the alpha of the canvas.
|
|
78
|
+
* @see {@link https://threejs.org/docs/#api/en/renderers/WebGLRenderer}
|
|
79
|
+
* @default true
|
|
80
|
+
*/
|
|
81
|
+
premultipliedAlpha?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Whether to fail if the major performance caveat is detected.
|
|
84
|
+
* @see {@link https://threejs.org/docs/#api/en/renderers/WebGLRenderer}
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
failIfMajorPerformanceCaveat?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* WebGL options with set methods
|
|
90
|
+
* @see {@link https://threejs.org/docs/#api/en/renderers/WebGLRenderer}
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* Clear color for the canvas
|
|
94
|
+
* Can include alpha value (e.g. '#00808000' for fully transparent teal)
|
|
95
|
+
*/
|
|
96
|
+
clearColor?: ColorRepresentation;
|
|
97
|
+
/**
|
|
98
|
+
* The opacity of the clear color (0-1)
|
|
99
|
+
* Controls the transparency of the clear color
|
|
100
|
+
* @default 1
|
|
101
|
+
*/
|
|
102
|
+
clearAlpha?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Enable shadow rendering in the scene
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
shadows?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Tone mapping technique to use for the scene
|
|
110
|
+
* - `NoToneMapping`: No tone mapping is applied.
|
|
111
|
+
* - `LinearToneMapping`: Linear tone mapping.
|
|
112
|
+
* - `ReinhardToneMapping`: Reinhard tone mapping.
|
|
113
|
+
* - `CineonToneMapping`: Cineon tone mapping.
|
|
114
|
+
* - `ACESFilmicToneMapping`: ACES Filmic tone mapping.
|
|
115
|
+
* - `AgXToneMapping`: AgX tone mapping.
|
|
116
|
+
* - `NeutralToneMapping`: Neutral tone mapping.
|
|
117
|
+
* @see {@link https://threejs.org/docs/#api/en/constants/Renderer}
|
|
118
|
+
* @default ACESFilmicToneMapping (Opinionated default by TresJS)
|
|
119
|
+
*/
|
|
120
|
+
toneMapping?: ToneMapping;
|
|
121
|
+
/**
|
|
122
|
+
* Type of shadow map to use for shadow calculations
|
|
123
|
+
* - `BasicShadowMap`: Basic shadow map.
|
|
124
|
+
* - `PCFShadowMap`: Percentage-Closer Filtering shadow map.
|
|
125
|
+
* - `PCFSoftShadowMap`: Percentage-Closer Filtering soft shadow map.
|
|
126
|
+
* - `VSMShadowMap`: Variance shadow map.
|
|
127
|
+
* @see {@link https://threejs.org/docs/#api/en/constants/Renderer}
|
|
128
|
+
* @default PCFSoftShadowMap (Opinionated default by TresJS)
|
|
129
|
+
*/
|
|
130
|
+
shadowMapType?: ShadowMapType;
|
|
131
|
+
/**
|
|
132
|
+
* Whether to use legacy lights system instead of the new one
|
|
133
|
+
* @deprecated Use `useLegacyLights: false` for the new lighting system
|
|
134
|
+
*/
|
|
135
|
+
useLegacyLights?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Color space for the output render
|
|
138
|
+
* @see {@link https://threejs.org/docs/#api/en/constants/Renderer}
|
|
139
|
+
*/
|
|
140
|
+
outputColorSpace?: ColorSpace;
|
|
141
|
+
/**
|
|
142
|
+
* Exposure level of tone mapping
|
|
143
|
+
* @default 1
|
|
144
|
+
*/
|
|
145
|
+
toneMappingExposure?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Rendering mode for the canvas
|
|
148
|
+
* - 'always': Renders every frame
|
|
149
|
+
* - 'on-demand': Renders only when changes are detected
|
|
150
|
+
* - 'manual': Renders only when explicitly called
|
|
151
|
+
* @default 'always'
|
|
152
|
+
*/
|
|
153
|
+
renderMode?: 'always' | 'on-demand' | 'manual';
|
|
154
|
+
/**
|
|
155
|
+
* Device Pixel Ratio for the renderer
|
|
156
|
+
* Can be a single number or a tuple defining a range [min, max]
|
|
157
|
+
*/
|
|
158
|
+
dpr?: number | [number, number];
|
|
159
|
+
/**
|
|
160
|
+
* Custom WebGL renderer instance
|
|
161
|
+
* Allows using a pre-configured renderer instead of creating a new one
|
|
162
|
+
*/
|
|
163
|
+
renderer?: (ctx: TresRendererSetupContext) => TresRenderer;
|
|
164
|
+
}
|
|
165
|
+
export interface TresRendererSetupContext {
|
|
166
|
+
sizes: SizesType;
|
|
167
|
+
scene: ShallowRef<TresScene>;
|
|
168
|
+
camera: UseCameraReturn;
|
|
169
|
+
canvas: MaybeRef<HTMLCanvasElement>;
|
|
170
|
+
}
|
|
171
|
+
export interface UseRendererOptions {
|
|
172
|
+
scene: ShallowRef<TresScene>;
|
|
173
|
+
canvas: MaybeRef<HTMLCanvasElement>;
|
|
174
|
+
options: Reactive<RendererOptions>;
|
|
175
|
+
contextParts: Pick<TresContext, 'sizes' | 'camera'>;
|
|
176
|
+
}
|
|
177
|
+
export declare function useRendererManager({ scene, canvas, options, contextParts: { sizes, camera }, }: UseRendererOptions): {
|
|
178
|
+
loop: {
|
|
179
|
+
start: () => void;
|
|
180
|
+
stop: () => void;
|
|
181
|
+
isActive: Readonly<ShallowRef<boolean>>;
|
|
182
|
+
onBeforeLoop: import('@vueuse/core').EventHookOn<import('../useCreateRafLoop').RafLoopContext>;
|
|
183
|
+
onLoop: import('@vueuse/core').EventHookOn<import('../useCreateRafLoop').RafLoopContext>;
|
|
184
|
+
};
|
|
185
|
+
instance: TresRenderer;
|
|
186
|
+
advance: () => void;
|
|
187
|
+
onReady: import('@vueuse/core').EventHookOn<TresRenderer>;
|
|
188
|
+
onRender: import('@vueuse/core').EventHookOn<TresRenderer>;
|
|
189
|
+
invalidate: (amountOfFramesToInvalidate?: number) => void;
|
|
190
|
+
canBeInvalidated: import('vue').ComputedRef<boolean>;
|
|
191
|
+
mode: "always" | "on-demand" | "manual" | undefined;
|
|
192
|
+
replaceRenderFunction: (fn: RenderFunction) => void;
|
|
193
|
+
};
|
|
194
|
+
export type UseRendererManagerReturn = ReturnType<typeof useRendererManager>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { TresContext } from '../useTresContextProvider';
|
|
3
|
+
import { Camera } from 'three';
|
|
4
|
+
import { TresRenderer } from '..';
|
|
5
|
+
export interface TresPartialContext extends Omit<TresContext, 'renderer' | 'camera'> {
|
|
6
|
+
/**
|
|
7
|
+
* The renderer instance
|
|
8
|
+
*
|
|
9
|
+
* @type {TresRenderer}
|
|
10
|
+
* @memberof TresPartialContext
|
|
11
|
+
*/
|
|
12
|
+
renderer: TresRenderer;
|
|
13
|
+
/**
|
|
14
|
+
* The current active camera
|
|
15
|
+
*
|
|
16
|
+
* @type {ComputedRef<Camera | undefined>}
|
|
17
|
+
* @memberof TresPartialContext
|
|
18
|
+
*/
|
|
19
|
+
camera: ComputedRef<Camera | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Marks the scene as needing an update in the next frame.
|
|
22
|
+
* This is used in on-demand rendering mode to schedule a render.
|
|
23
|
+
*
|
|
24
|
+
* @type {() => void}
|
|
25
|
+
* @memberof TresPartialContext
|
|
26
|
+
*/
|
|
27
|
+
invalidate: () => void;
|
|
28
|
+
/**
|
|
29
|
+
* Manually advances the render loop by one frame.
|
|
30
|
+
* This is particularly useful in manual rendering mode where you want explicit control over when frames are rendered.
|
|
31
|
+
*
|
|
32
|
+
* @type {() => void}
|
|
33
|
+
* @memberof TresPartialContext
|
|
34
|
+
*/
|
|
35
|
+
advance: () => void;
|
|
36
|
+
}
|
|
37
|
+
export declare function useTres(): TresPartialContext;
|
|
@@ -1,74 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { UseRendererOptions } from '../useRenderer';
|
|
1
|
+
import { MaybeRef, MaybeRefOrGetter, Ref, ShallowRef } from 'vue';
|
|
2
|
+
import { TresControl, TresScene } from '../../types';
|
|
3
|
+
import { RendererOptions, UseRendererManagerReturn } from '../useRenderer/useRendererManager';
|
|
4
|
+
import { UseCameraReturn } from '../useCamera/';
|
|
6
5
|
import { SizesType } from '../useSizes';
|
|
7
|
-
import {
|
|
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
|
-
}
|
|
6
|
+
import { useEventManager } from '../useEventManager';
|
|
37
7
|
export interface TresContext {
|
|
38
8
|
scene: ShallowRef<TresScene>;
|
|
39
9
|
sizes: SizesType;
|
|
40
10
|
extend: (objects: any) => void;
|
|
41
|
-
camera:
|
|
42
|
-
cameras: DeepReadonly<Ref<Camera[]>>;
|
|
11
|
+
camera: UseCameraReturn;
|
|
43
12
|
controls: Ref<TresControl | null>;
|
|
44
|
-
renderer:
|
|
45
|
-
|
|
46
|
-
perf: PerformanceState;
|
|
47
|
-
render: RenderState;
|
|
48
|
-
loop: RendererLoop;
|
|
49
|
-
/**
|
|
50
|
-
* Invalidates the current frame when renderMode === 'on-demand'
|
|
51
|
-
*/
|
|
52
|
-
invalidate: () => void;
|
|
53
|
-
/**
|
|
54
|
-
* Advance one frame when renderMode === 'manual'
|
|
55
|
-
*/
|
|
56
|
-
advance: () => void;
|
|
57
|
-
registerCamera: (maybeCamera: unknown) => void;
|
|
58
|
-
setCameraActive: (cameraOrUuid: Camera | string) => void;
|
|
59
|
-
deregisterCamera: (maybeCamera: unknown) => void;
|
|
60
|
-
eventManager?: TresEventManager;
|
|
61
|
-
registerObjectAtPointerEventHandler?: (object: TresObject) => void;
|
|
62
|
-
deregisterObjectAtPointerEventHandler?: (object: TresObject) => void;
|
|
63
|
-
registerBlockingObjectAtPointerEventHandler?: (object: TresObject) => void;
|
|
64
|
-
deregisterBlockingObjectAtPointerEventHandler?: (object: TresObject) => void;
|
|
13
|
+
renderer: UseRendererManagerReturn;
|
|
14
|
+
events: ReturnType<typeof useEventManager>;
|
|
65
15
|
}
|
|
66
|
-
export declare
|
|
16
|
+
export declare const INJECTION_KEY = "useTres";
|
|
17
|
+
declare const useTresContextProvider: (args_0: {
|
|
67
18
|
scene: TresScene;
|
|
68
19
|
canvas: MaybeRef<HTMLCanvasElement>;
|
|
69
20
|
windowSize: MaybeRefOrGetter<boolean>;
|
|
70
|
-
rendererOptions:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export
|
|
74
|
-
export declare const useTres: typeof useTresContext;
|
|
21
|
+
rendererOptions: RendererOptions;
|
|
22
|
+
}) => TresContext;
|
|
23
|
+
declare const useTresContext: () => TresContext;
|
|
24
|
+
export { useTresContext, useTresContextProvider };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Mesh } from 'three';
|
|
2
|
+
import { TresObject } from '../types';
|
|
3
|
+
import { SceneGraphObject } from './types';
|
|
4
|
+
import { TresContext } from '../composables/useTresContextProvider';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a node representation of a Three.js object for the inspector tree
|
|
7
|
+
* @param object - The Three.js object to create a node for
|
|
8
|
+
* @returns A SceneGraphObject representing the Three.js object with relevant metadata
|
|
9
|
+
*/
|
|
10
|
+
export declare const createNode: (object: TresObject) => SceneGraphObject;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a context node for the inspector tree
|
|
13
|
+
* @param key - The key identifier for the context node
|
|
14
|
+
* @param uuid - The unique identifier for the context
|
|
15
|
+
* @param parentKey - Optional parent key for nested context nodes
|
|
16
|
+
* @returns A SceneGraphObject representing the context node
|
|
17
|
+
*/
|
|
18
|
+
export declare function createContextNode(key: string, uuid: string, parentKey?: string): SceneGraphObject;
|
|
19
|
+
/**
|
|
20
|
+
* Recursively builds a graph representation of Three.js objects for the inspector
|
|
21
|
+
* @param object - The root Three.js object to build the graph from
|
|
22
|
+
* @param node - The current node in the graph being built
|
|
23
|
+
* @param filter - Optional filter string to filter objects by type or name
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildGraph(object: TresObject, node: SceneGraphObject, filter?: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Recursively builds a graph representation of context objects for the inspector
|
|
28
|
+
* @param object - The root object to build the context graph from
|
|
29
|
+
* @param node - The current node in the graph being built
|
|
30
|
+
* @param visited - WeakSet to track visited objects and prevent circular references
|
|
31
|
+
* @param depth - Current depth in the object tree
|
|
32
|
+
* @param maxDepth - Maximum depth to traverse
|
|
33
|
+
* @param contextUuid - Optional UUID for the context
|
|
34
|
+
* @param parentKey - Optional parent key for nested objects
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildContextGraph(object: any, node: SceneGraphObject, visited?: WeakSet<WeakKey>, depth?: number, maxDepth?: number, contextUuid?: string, parentKey?: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Handler for inspector tree updates
|
|
39
|
+
* @param tres - The TresContext instance
|
|
40
|
+
* @returns A function that handles inspector tree payload updates
|
|
41
|
+
*/
|
|
42
|
+
export declare const inspectorTreeHandler: (tres: TresContext) => (payload: any) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Handler for inspector state updates
|
|
45
|
+
* @param tres - The TresContext instance
|
|
46
|
+
* @param options - Options for the handler
|
|
47
|
+
* @param options.highlightMesh - The currently highlighted mesh
|
|
48
|
+
* @param options.prevInstance - The previously selected instance
|
|
49
|
+
* @returns A function that handles inspector state payload updates
|
|
50
|
+
*/
|
|
51
|
+
export declare const inspectorStateHandler: (tres: TresContext, { highlightMesh, prevInstance }: {
|
|
52
|
+
highlightMesh: Mesh | null;
|
|
53
|
+
prevInstance: TresObject | null;
|
|
54
|
+
}) => (payload: any) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Handler for inspector state edits
|
|
57
|
+
* @param tres - The TresContext instance
|
|
58
|
+
* @returns A function that handles inspector state edit payload updates
|
|
59
|
+
*/
|
|
60
|
+
export declare const inspectorEditStateHandler: (tres: TresContext) => (payload: any) => void;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { App as DevtoolsApp } from '@vue/devtools-api';
|
|
2
1
|
import { TresContext } from '../composables';
|
|
2
|
+
import { App } from 'vue';
|
|
3
3
|
export interface Tags {
|
|
4
4
|
label: string;
|
|
5
5
|
textColor: number;
|
|
6
6
|
backgroundColor: number;
|
|
7
7
|
tooltip?: string;
|
|
8
8
|
}
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
label: string;
|
|
12
|
-
children: SceneGraphObject[];
|
|
13
|
-
tags: Tags[];
|
|
14
|
-
}
|
|
15
|
-
export declare function registerTresDevtools(app: DevtoolsApp, tres: TresContext): void;
|
|
9
|
+
export declare const INSPECTOR_ID = "tres:inspector";
|
|
10
|
+
export declare function registerTresDevtools(app: App, tres: TresContext): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TresContext } from '../composables';
|
|
2
|
+
export interface PerformanceState {
|
|
3
|
+
maxFrames: number;
|
|
4
|
+
fps: {
|
|
5
|
+
value: number;
|
|
6
|
+
accumulator: number[];
|
|
7
|
+
};
|
|
8
|
+
memory: {
|
|
9
|
+
currentMem: number;
|
|
10
|
+
allocatedMem: number;
|
|
11
|
+
accumulator: number[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare function setupTresDevtools(ctx: TresContext): void;
|