@tresjs/core 2.4.0-next.4 → 2.4.1

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.
@@ -1,5 +1,4 @@
1
- import type { TresContext } from '../useTresContextProvider';
2
- import type { Intersection, Event, Object3D, Scene } from 'three';
1
+ import type { Intersection, Event, Object3D } from 'three';
3
2
  type CallbackFn = (intersection: Intersection<Object3D<Event>>, event: PointerEvent) => void;
4
3
  type CallbackFnPointerLeave = (object: Object3D<Event>, event: PointerEvent) => void;
5
4
  type EventProps = {
@@ -8,7 +7,7 @@ type EventProps = {
8
7
  onPointerMove?: CallbackFn;
9
8
  onPointerLeave?: CallbackFnPointerLeave;
10
9
  };
11
- export declare const usePointerEventHandler: (scene: Scene, contextParts: Pick<TresContext, 'renderer' | 'camera'>) => {
10
+ export declare const usePointerEventHandler: () => {
12
11
  registerObject: (object: Object3D & EventProps) => void;
13
12
  deregisterObject: (object: Object3D) => void;
14
13
  };
@@ -1,7 +1,6 @@
1
- import { type Intersection, Object3D } from 'three';
1
+ import { Object3D } from 'three';
2
2
  import { Ref } from 'vue';
3
- import type { TresContext } from '../useTresContextProvider';
4
- export type Intersects = Intersection<THREE.Object3D<THREE.Event>>[];
3
+ export type Intersects = THREE.Intersection<THREE.Object3D<THREE.Event>>[];
5
4
  interface PointerMoveEventPayload {
6
5
  intersects?: Intersects;
7
6
  event: PointerEvent;
@@ -10,7 +9,7 @@ interface PointerClickEventPayload {
10
9
  intersects: Intersects;
11
10
  event: PointerEvent;
12
11
  }
13
- export declare const useRaycaster: (objects: Ref<THREE.Object3D[]>, { renderer, camera }: Pick<TresContext, 'renderer' | 'camera'>) => {
12
+ export declare const useRaycaster: (objects: Ref<THREE.Object3D[]>) => {
14
13
  intersects: import("vue").ComputedRef<Intersects>;
15
14
  onClick: (fn: (value: PointerClickEventPayload) => void) => () => void;
16
15
  onPointerMove: (fn: (value: PointerMoveEventPayload) => void) => () => void;
@@ -14,4 +14,4 @@ export interface UseRenderLoopReturn {
14
14
  resume: Fn;
15
15
  isActive: Ref<boolean>;
16
16
  }
17
- export declare const useRenderLoop: () => UseRenderLoopReturn;
17
+ export declare function useRenderLoop(): UseRenderLoopReturn;
@@ -1,15 +1,9 @@
1
- import { WebGLRenderer } from 'three';
2
- import { RendererPresetsType } from './const';
3
- import { type MaybeRef } from 'vue';
4
- import { type MaybeRefOrGetter } from '@vueuse/core';
1
+ import { MaybeRefOrGetter } from '@vueuse/core';
2
+ import { WebGLRendererParameters, WebGLRenderer, ShadowMapType, ColorSpace } from 'three';
3
+ import type { ToneMapping } from 'three';
5
4
  import { TresColor } from '../../types';
6
- import type { Scene, ToneMapping } from 'three';
7
- import type { TresContext } from '../useTresContextProvider';
8
- import type { ColorSpace, ShadowMapType, WebGLRendererParameters } from 'three';
9
- type TransformToMaybeRefOrGetter<T> = {
10
- [K in keyof T]: MaybeRefOrGetter<T[K]> | MaybeRefOrGetter<T[K]>;
11
- };
12
- export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRendererParameters> {
5
+ import { RendererPresetsType } from './const';
6
+ export interface UseRendererOptions extends WebGLRendererParameters {
13
7
  /**
14
8
  * Enable shadows in the Renderer
15
9
  *
@@ -48,10 +42,7 @@ export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRen
48
42
  outputColorSpace?: MaybeRefOrGetter<ColorSpace>;
49
43
  /**
50
44
  * Defines the tone mapping used by the renderer.
51
- * Can be NoToneMapping, LinearToneMapping,
52
- * ReinhardToneMapping, Uncharted2ToneMapping,
53
- * CineonToneMapping, ACESFilmicToneMapping,
54
- * CustomToneMapping
45
+ * Can be NoToneMapping, LinearToneMapping, ReinhardToneMapping, Uncharted2ToneMapping, CineonToneMapping, ACESFilmicToneMapping, CustomToneMapping
55
46
  *
56
47
  * @default NoToneMapping
57
48
  */
@@ -62,6 +53,25 @@ export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRen
62
53
  * @default 1
63
54
  */
64
55
  toneMappingExposure?: MaybeRefOrGetter<number>;
56
+ /**
57
+ * The context used by the renderer.
58
+ *
59
+ * @default undefined
60
+ */
61
+ context?: WebGLRenderingContext | undefined;
62
+ /**
63
+ * Provides a hint to the user agent indicating what configuration of GPU is suitable for this WebGL context.
64
+ * Can be "high-performance", "low-power" or "default".
65
+ *
66
+ * @default "default"
67
+ */
68
+ powerPreference?: 'high-performance' | 'low-power' | 'default';
69
+ /**
70
+ * Whether to preserve the buffers until manually cleared or overwritten.
71
+ *
72
+ * @default false
73
+ */
74
+ preserveDrawingBuffer?: boolean;
65
75
  /**
66
76
  * The color value to use when clearing the canvas.
67
77
  *
@@ -69,7 +79,7 @@ export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRen
69
79
  */
70
80
  clearColor?: MaybeRefOrGetter<TresColor>;
71
81
  windowSize?: MaybeRefOrGetter<boolean | string>;
72
- preset?: MaybeRefOrGetter<RendererPresetsType>;
82
+ preset?: RendererPresetsType;
73
83
  }
74
84
  /**
75
85
  * Reactive Three.js WebGLRenderer instance
@@ -77,14 +87,10 @@ export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRen
77
87
  * @param canvas
78
88
  * @param {UseRendererOptions} [options]
79
89
  */
80
- export declare function useRenderer({ scene, canvas, options, disableRender, contextParts: { sizes, camera }, }: {
81
- canvas: MaybeRef<HTMLCanvasElement>;
82
- scene: Scene;
83
- options: UseRendererOptions;
84
- contextParts: Pick<TresContext, 'sizes' | 'camera'>;
85
- disableRender: MaybeRefOrGetter<boolean>;
86
- }): {
87
- renderer: import("vue").ShallowRef<WebGLRenderer>;
90
+ export declare function useRenderer(options: UseRendererOptions): {
91
+ renderer: import("vue").ShallowRef<WebGLRenderer | undefined>;
92
+ isReady: import("vue").Ref<boolean>;
93
+ dispose: () => void;
94
+ aspectRatio: import("vue").ComputedRef<number>;
88
95
  };
89
96
  export type UseRendererReturn = ReturnType<typeof useRenderer>;
90
- export {};
@@ -0,0 +1,142 @@
1
+ import { Clock, EventDispatcher, Raycaster, Scene, Vector2, WebGLRenderer } from 'three';
2
+ import { ComputedRef, Ref } from 'vue';
3
+ import { Camera } from '../useCamera';
4
+ import type { usePointerEventHandler } from '../usePointerEventHandler';
5
+ export interface TresState {
6
+ /**
7
+ * The active camera used for rendering the scene.
8
+ *
9
+ * @see https://threejs.org/docs/index.html?q=camera#api/en/cameras/Camera
10
+ *
11
+ * @type {Camera}
12
+ * @memberof TresState
13
+ */
14
+ camera?: Camera;
15
+ /**
16
+ * All cameras available in the scene.
17
+ *
18
+ * @see https://threejs.org/docs/index.html?q=camera#api/en/cameras/Camera
19
+ *
20
+ * @type {Camera[]}
21
+ * @memberof TresState
22
+ */
23
+ cameras?: Camera[];
24
+ /**
25
+ * The aspect ratio of the scene.
26
+ *
27
+ * @type {ComputedRef<number>}
28
+ * @memberof TresState
29
+ */
30
+ aspectRatio?: ComputedRef<number>;
31
+ /**
32
+ * The WebGLRenderer used to display the scene using WebGL.
33
+ *
34
+ * @see https://threejs.org/docs/index.html?q=webglren#api/en/renderers/WebGLRenderer
35
+ *
36
+ * @type {WebGLRenderer}
37
+ * @memberof TresState
38
+ */
39
+ renderer?: WebGLRenderer;
40
+ /**
41
+ * The scene. This is the place where you place objects, lights and cameras.
42
+ *
43
+ * @see https://threejs.org/docs/index.html?q=scene#api/en/scenes/Scene
44
+ *
45
+ * @type {Scene}
46
+ * @memberof TresState
47
+ */
48
+ scene?: Scene;
49
+ /**
50
+ * The raycaster.
51
+ *
52
+ * @see https://threejs.org/docs/index.html?q=raycas#api/en/core/Raycaster
53
+ *
54
+ * @type {Raycaster}
55
+ * @memberof TresState
56
+ */
57
+ raycaster?: Raycaster;
58
+ /**
59
+ * Object for keeping track of time. This uses `performance.now` if it is available,
60
+ * otherwise it reverts to the less accurate `Date.now`.
61
+ *
62
+ * @see https://threejs.org/docs/index.html?q=clock#api/en/core/Clock
63
+ *
64
+ * @type {Clock}
65
+ * @memberof TresState
66
+ */
67
+ clock?: Clock;
68
+ /**
69
+ * The current mouse position.
70
+ *
71
+ * @type {Vector2}
72
+ * @memberof TresState
73
+ */
74
+ pointer?: Vector2;
75
+ /**
76
+ * The current instance of the component.
77
+ *
78
+ * @type {*}
79
+ * @memberof TresState
80
+ */
81
+ currentInstance?: any;
82
+ /**
83
+ * The current active scene control
84
+ *
85
+ * @type {((EventDispatcher & { enabled: boolean }) | null)}
86
+ * @memberof TresState
87
+ */
88
+ controls?: (EventDispatcher & {
89
+ enabled: boolean;
90
+ }) | null;
91
+ canvas?: Ref<HTMLElement>;
92
+ /**
93
+ * The entity that handles pointer events
94
+ * @type {ReturnType<typeof usePointerEventHandler>}
95
+ * @memberof TresState
96
+ */
97
+ pointerEventHandler?: ReturnType<typeof usePointerEventHandler>;
98
+ [key: string]: any;
99
+ }
100
+ export type UseTresReturn = {
101
+ state: TresState;
102
+ getState: (key: string) => void;
103
+ setState: (key: string, value: any) => void;
104
+ aspectRatio: ComputedRef<number>;
105
+ };
106
+ export declare const TRES_CONTEXT_KEY: unique symbol;
107
+ /**
108
+ * The Tres state.
109
+ *
110
+ * @see https://threejs.org/docs/index.html?q=scene#api/en/scenes/Scene
111
+ *
112
+ * @export
113
+ * @return {*} {TresState, getState, setState}
114
+ */
115
+ export declare function useTresProvider(): {
116
+ getState: (key: string) => any;
117
+ setState: (key: string, value: any) => void;
118
+ camera?: Ref<Camera | undefined> | undefined;
119
+ cameras?: Ref<Camera[] | undefined> | undefined;
120
+ aspectRatio?: Ref<ComputedRef<number> | undefined> | undefined;
121
+ renderer?: Ref<WebGLRenderer | undefined> | undefined;
122
+ scene?: Ref<Scene | undefined> | undefined;
123
+ raycaster?: Ref<Raycaster | undefined> | undefined;
124
+ clock?: Ref<Clock | undefined> | undefined;
125
+ pointer?: Ref<Vector2 | undefined> | undefined;
126
+ currentInstance?: Ref<any> | undefined;
127
+ controls?: Ref<(EventDispatcher<import("three").Event> & {
128
+ enabled: boolean;
129
+ }) | null | undefined> | undefined;
130
+ canvas?: Ref<Ref<HTMLElement> | undefined> | undefined;
131
+ pointerEventHandler?: Ref<{
132
+ registerObject: (object: import("three").Object3D<import("three").Event> & {
133
+ onClick?: ((intersection: import("three").Intersection<import("three").Object3D<import("three").Event>>, event: PointerEvent) => void) | undefined;
134
+ onPointerEnter?: ((intersection: import("three").Intersection<import("three").Object3D<import("three").Event>>, event: PointerEvent) => void) | undefined;
135
+ onPointerMove?: ((intersection: import("three").Intersection<import("three").Object3D<import("three").Event>>, event: PointerEvent) => void) | undefined;
136
+ onPointerLeave?: ((object: import("three").Object3D<import("three").Event>, event: PointerEvent) => void) | undefined;
137
+ }) => void;
138
+ deregisterObject: (object: import("three").Object3D<import("three").Event>) => void;
139
+ } | undefined> | undefined;
140
+ state: TresState;
141
+ };
142
+ export declare const useTres: () => UseTresReturn;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,6 @@ export * from './composables';
3
3
  export * from './core/catalogue';
4
4
  export * from './components';
5
5
  export * from './types';
6
- import { useTresContext, type TresContext } from './composables';
7
6
  import { normalizeColor, normalizeVectorFlexibleParam } from './utils/normalize';
8
7
  import templateCompilerOptions from './utils/template-compiler-options';
9
8
  export interface TresOptions {
@@ -15,4 +14,4 @@ export interface TresPlugin {
15
14
  }
16
15
  declare const plugin: TresPlugin;
17
16
  export default plugin;
18
- export { TresContext, useTresContext, normalizeColor, normalizeVectorFlexibleParam, templateCompilerOptions };
17
+ export { normalizeColor, normalizeVectorFlexibleParam, templateCompilerOptions };
package/dist/keys.d.ts CHANGED
@@ -1,9 +1,6 @@
1
+ export declare const UseTresStateSymbol: unique symbol;
1
2
  export declare const OBJECT_3D_USER_DATA_KEYS: {
2
- REGISTER_CAMERA: string;
3
- IS_ACTIVE_CAMERA: string;
4
3
  GEOMETRY_VIA_PROP: string;
5
4
  MATERIAL_VIA_PROP: string;
6
- DEREGISTER_CAMERA: string;
7
5
  REGISTER_AT_POINTER_EVENT_HANDLER: string;
8
- DEREGISTER_AT_POINTER_EVENT_HANDLER: string;
9
6
  };