@tresjs/core 0.1.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.
Files changed (33) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -0
  3. package/dist/components/TresCanvas.vue.d.ts +117 -0
  4. package/dist/composables/index.d.ts +1 -0
  5. package/dist/composables/useLogger.d.ts +8 -0
  6. package/dist/core/index.d.ts +8 -0
  7. package/dist/core/useCamera/useCamera.d.ts +31 -0
  8. package/dist/core/useCatalog/useCatalog.d.ts +6 -0
  9. package/dist/core/useInstanceCreator/useInstanceCreator.d.ts +3 -0
  10. package/dist/core/useLoader/useLoader.d.ts +18 -0
  11. package/dist/core/useLoop/useLoop.d.ts +4 -0
  12. package/dist/core/useRenderer/useRenderer.d.ts +18 -0
  13. package/dist/core/useScene/useScene.d.ts +6 -0
  14. package/dist/core/useTexture/useTexture.d.ts +11 -0
  15. package/dist/env.d.ts +8 -0
  16. package/dist/favicon-dark.svg +6 -0
  17. package/dist/favicon.svg +5 -0
  18. package/dist/index.d.ts +8 -0
  19. package/dist/logo.svg +5 -0
  20. package/dist/pwa-192x192.png +0 -0
  21. package/dist/pwa-512x512.png +0 -0
  22. package/dist/safari-pinned-tab.svg +5 -0
  23. package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_ambientOcclusion.jpg +0 -0
  24. package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_basecolor.jpg +0 -0
  25. package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_height.png +0 -0
  26. package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_normal.jpg +0 -0
  27. package/dist/textures/stylized-leaves-material/Stylized_Leaves_002_roughness.jpg +0 -0
  28. package/dist/tres.js +690 -0
  29. package/dist/tres.umd.cjs +8 -0
  30. package/dist/types/index.d.ts +14 -0
  31. package/dist/utils/normalize.d.ts +17 -0
  32. package/dist/vite.svg +1 -0
  33. package/package.json +73 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present, (alvarosabu) Alvaro Saburido and Tres contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @tresjs/core ▲ ■ ●
2
+
3
+ > Declarative ThreeJS using Vue Components
4
+
5
+ - 💡 Build 3D scene as they were Vue components
6
+ - ⚡️ Powered by Vite
7
+ - 🥰 It brings all the updated features of ThreeJS right awayregardless the version
8
+ - 🦾 Fully Typed
9
+
10
+ Tres (Spanish word for "three", pronounced `/tres/` ) is a way of creating ThreeJS scenes with Vue components in a declarative fashion. Think of it as a [React-three-fiber](https://docs.pmnd.rs/react-three-fiber) or [Lunchbox](https://github.com/breakfast-studio/lunchboxjs) but without the need of a [custom Vue3 Renderer](https://vuejs.org/api/custom-renderer.html).
11
+
12
+ ## Setup
13
+
14
+ ```
15
+ pnpm install --shamefully-hoist
16
+ ```
17
+
18
+ ## Dev
19
+
20
+ To run the small playground without Histoire use
21
+
22
+ ```
23
+ pnpm run dev
24
+ ```
25
+
26
+ ## Histoire
27
+
28
+ All local demos will be inside [Histoire](https://histoire.dev/) stories.
29
+
30
+ ```
31
+ pnpm run story:dev
32
+ ```
33
+
34
+ ## Build lib
35
+
36
+ To build the core as library mode just use
37
+
38
+ ```
39
+ pnpm run build
40
+ ```
@@ -0,0 +1,117 @@
1
+ import { TextureEncoding, WebGLRenderer } from 'three';
2
+ import { CameraType, PerspectiveCameraOptions, Camera } from '../core/useCamera/useCamera';
3
+ import { VectorFlexibleParams } from '../utils/normalize';
4
+ export interface CanvasCameraOptions extends PerspectiveCameraOptions {
5
+ position: VectorFlexibleParams;
6
+ }
7
+ declare const _sfc_main: import("vue").DefineComponent<{
8
+ camera: {
9
+ type: ObjectConstructor;
10
+ required: false;
11
+ };
12
+ ortographic: {
13
+ type: BooleanConstructor;
14
+ required: false;
15
+ };
16
+ gl: {
17
+ type: null;
18
+ required: false;
19
+ };
20
+ shadows: {
21
+ type: BooleanConstructor;
22
+ required: false;
23
+ default: boolean;
24
+ };
25
+ physicallyCorrectLights: {
26
+ type: BooleanConstructor;
27
+ required: false;
28
+ default: boolean;
29
+ };
30
+ outputEncoding: {
31
+ type: null;
32
+ required: false;
33
+ default: TextureEncoding;
34
+ };
35
+ alpha: {
36
+ type: BooleanConstructor;
37
+ required: false;
38
+ default: boolean;
39
+ };
40
+ background: {
41
+ type: StringConstructor;
42
+ required: false;
43
+ };
44
+ async: {
45
+ type: BooleanConstructor;
46
+ required: false;
47
+ default: boolean;
48
+ };
49
+ }, {
50
+ props: any;
51
+ renderer: WebGLRenderer | null;
52
+ disposeRenderer: () => void;
53
+ canvasRef: import("vue").Ref<any>;
54
+ renderComponent: import("vue").Ref<boolean>;
55
+ scene: import("three").Scene | null;
56
+ clearScene: () => void;
57
+ slots: Readonly<{
58
+ [name: string]: import("vue").Slot | undefined;
59
+ }>;
60
+ attrs: {
61
+ [x: string]: unknown;
62
+ };
63
+ createCamera: (cameraType?: CameraType | undefined, options?: PerspectiveCameraOptions | import('../core/useCamera/useCamera').OrthographicCameraOptions | undefined) => Camera;
64
+ camera: Camera;
65
+ thereIsCameraAlready: boolean;
66
+ setupRenderer: () => void;
67
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
68
+ camera: {
69
+ type: ObjectConstructor;
70
+ required: false;
71
+ };
72
+ ortographic: {
73
+ type: BooleanConstructor;
74
+ required: false;
75
+ };
76
+ gl: {
77
+ type: null;
78
+ required: false;
79
+ };
80
+ shadows: {
81
+ type: BooleanConstructor;
82
+ required: false;
83
+ default: boolean;
84
+ };
85
+ physicallyCorrectLights: {
86
+ type: BooleanConstructor;
87
+ required: false;
88
+ default: boolean;
89
+ };
90
+ outputEncoding: {
91
+ type: null;
92
+ required: false;
93
+ default: TextureEncoding;
94
+ };
95
+ alpha: {
96
+ type: BooleanConstructor;
97
+ required: false;
98
+ default: boolean;
99
+ };
100
+ background: {
101
+ type: StringConstructor;
102
+ required: false;
103
+ };
104
+ async: {
105
+ type: BooleanConstructor;
106
+ required: false;
107
+ default: boolean;
108
+ };
109
+ }>>, {
110
+ ortographic: boolean;
111
+ shadows: boolean;
112
+ physicallyCorrectLights: boolean;
113
+ outputEncoding: any;
114
+ alpha: boolean;
115
+ async: boolean;
116
+ }>;
117
+ export default _sfc_main;
@@ -0,0 +1 @@
1
+ export * from './useLogger';
@@ -0,0 +1,8 @@
1
+ export declare const isProd: boolean;
2
+ interface LoggerComposition {
3
+ logError: (message: string, error: Error) => void;
4
+ logWarning: (message: string) => void;
5
+ logMessage: (name: string, value: any) => void;
6
+ }
7
+ export declare function useLogger(): LoggerComposition;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from './useCamera/useCamera';
2
+ export * from './useCatalog/useCatalog';
3
+ export * from './useInstanceCreator/useInstanceCreator';
4
+ export * from './useLoop/useLoop';
5
+ export * from './useRenderer/useRenderer';
6
+ export * from './useScene/useScene';
7
+ export * from './useLoader/useLoader';
8
+ export * from './useTexture/useTexture';
@@ -0,0 +1,31 @@
1
+ import { PerspectiveCamera, OrthographicCamera } from 'three';
2
+ import { ComputedRef } from 'vue';
3
+ export declare enum CameraType {
4
+ Perspective = "Perspective",
5
+ Orthographic = "Orthographic"
6
+ }
7
+ export declare type Camera = PerspectiveCamera | OrthographicCamera;
8
+ export declare type CameraState = {
9
+ cameras: Array<Camera>;
10
+ };
11
+ export interface PerspectiveCameraOptions {
12
+ fov?: number;
13
+ near?: number;
14
+ far?: number;
15
+ }
16
+ export interface OrthographicCameraOptions {
17
+ left?: number;
18
+ right?: number;
19
+ top?: number;
20
+ bottom?: number;
21
+ near?: number;
22
+ far?: number;
23
+ }
24
+ interface UseCameraReturn {
25
+ activeCamera: ComputedRef<Camera>;
26
+ createCamera: (cameraType?: CameraType, options?: PerspectiveCameraOptions | OrthographicCameraOptions) => Camera;
27
+ updateCamera: () => void;
28
+ pushCamera: (camera: Camera) => void;
29
+ }
30
+ export declare function useCamera(): UseCameraReturn;
31
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare function useCatalog(): {
2
+ extend: (objects: any) => void;
3
+ catalogue: {
4
+ [key: string]: any;
5
+ };
6
+ };
@@ -0,0 +1,3 @@
1
+ export declare function useInstanceCreator(): {
2
+ createComponentInstances: () => (string | import("vue").DefineComponent<{}, () => void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>)[][];
3
+ };
@@ -0,0 +1,18 @@
1
+ import { LoadingManager } from 'three';
2
+ export declare function useLoadingManager(): {
3
+ loadingManager: LoadingManager;
4
+ loadingManagerRef: import("vue").Ref<{
5
+ onStart?: ((url: string, loaded: number, total: number) => void) | undefined;
6
+ onLoad: () => void;
7
+ onProgress: (url: string, loaded: number, total: number) => void;
8
+ onError: (url: string) => void;
9
+ setURLModifier: (callback?: ((url: string) => string) | undefined) => LoadingManager;
10
+ resolveURL: (url: string) => string;
11
+ itemStart: (url: string) => void;
12
+ itemEnd: (url: string) => void;
13
+ itemError: (url: string) => void;
14
+ addHandler: (regex: RegExp, loader: import("three").Loader) => LoadingManager;
15
+ removeHandler: (regex: RegExp) => LoadingManager;
16
+ getHandler: (file: string) => import("three").Loader | null;
17
+ }>;
18
+ };
@@ -0,0 +1,4 @@
1
+ export declare type TresLoop = (delta: number, elapsedTime: number) => void;
2
+ export declare function useLoop(cb: TresLoop, beforeCb?: TresLoop, afterCb?: TresLoop): {
3
+ disposeLoop: () => void;
4
+ };
@@ -0,0 +1,18 @@
1
+ import { Ref } from 'vue';
2
+ import { TextureEncoding, ToneMapping, WebGLRenderer, WebGLRendererParameters, Color } from 'three';
3
+ export interface RendererOptions extends WebGLRendererParameters {
4
+ shadows?: boolean;
5
+ controls?: boolean;
6
+ physicallyCorrectLights?: boolean;
7
+ outputEncoding?: TextureEncoding;
8
+ toneMapping?: ToneMapping;
9
+ context?: WebGLRenderingContext | undefined;
10
+ powerPreference?: string;
11
+ preserveDrawingBuffer?: boolean;
12
+ }
13
+ export declare function useRenderer(canvas: Ref<HTMLCanvasElement>, options?: RendererOptions): {
14
+ renderer: WebGLRenderer | null;
15
+ setClearColor: (color: Color | string | number) => void;
16
+ updateRenderer: () => void;
17
+ disposeRenderer: () => void;
18
+ };
@@ -0,0 +1,6 @@
1
+ import { Scene } from 'three';
2
+ export declare function useScene(): {
3
+ isSceneReset: import("vue").Ref<boolean>;
4
+ clearScene: () => void;
5
+ scene: Scene | null;
6
+ };
@@ -0,0 +1,11 @@
1
+ import { Texture } from 'three';
2
+ export interface PBRMaterialOptions {
3
+ maps: string[];
4
+ ext: 'png' | 'jpg';
5
+ }
6
+ export interface PBRTextureMaps {
7
+ [key: string]: Texture | null;
8
+ }
9
+ export declare function useTexture(paths: Array<string> | {
10
+ [key: string]: string;
11
+ }): Promise<Texture | Array<Texture> | PBRTextureMaps>;
package/dist/env.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module '*.vue' {
4
+ import type { DefineComponent } from 'vue'
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
6
+ const component: DefineComponent<{}, {}, any>
7
+ export default component
8
+ }
@@ -0,0 +1,6 @@
1
+ <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="32" height="32" fill="white"/>
3
+ <path d="M11.6854 4.42916C12.0738 3.78182 13.012 3.78182 13.4004 4.42915L19.1771 14.0569C19.577 14.7235 19.0969 15.5714 18.3196 15.5714H6.76624C5.98894 15.5714 5.50883 14.7235 5.90875 14.0569L11.6854 4.42916Z" fill="#82DBC5"/>
4
+ <path d="M15.6857 11.5429C15.6857 10.9906 16.1334 10.5429 16.6857 10.5429H26C26.5522 10.5429 27 10.9906 27 11.5429V20.8572C27 21.4094 26.5522 21.8572 26 21.8572H16.6857C16.1334 21.8572 15.6857 21.4094 15.6857 20.8572V11.5429Z" fill="#4F4F4F"/>
5
+ <circle cx="16" cy="23" r="6" fill="#EFAC35"/>
6
+ </svg>
@@ -0,0 +1,5 @@
1
+ <svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M11.6854 3.42916C12.0738 2.78182 13.012 2.78182 13.4004 3.42915L19.1771 13.0569C19.577 13.7235 19.0969 14.5714 18.3196 14.5714H6.76624C5.98894 14.5714 5.50883 13.7235 5.90875 13.0569L11.6854 3.42916Z" fill="#82DBC5"/>
3
+ <path d="M15.6857 10.5429C15.6857 9.99059 16.1334 9.54288 16.6857 9.54288H26C26.5522 9.54288 27 9.99059 27 10.5429V19.8572C27 20.4094 26.5522 20.8572 26 20.8572H16.6857C16.1334 20.8572 15.6857 20.4094 15.6857 19.8572V10.5429Z" fill="#4F4F4F"/>
4
+ <circle cx="16" cy="22" r="6" fill="#EFAC35"/>
5
+ </svg>
@@ -0,0 +1,8 @@
1
+ import { App } from 'vue';
2
+ export * from './core';
3
+ export interface TresPlugin {
4
+ [key: string]: any;
5
+ install: (app: App, options?: any) => void;
6
+ }
7
+ declare const plugin: TresPlugin;
8
+ export default plugin;
package/dist/logo.svg ADDED
@@ -0,0 +1,5 @@
1
+ <svg width="44" height="10" viewBox="0 0 44 10" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M5.14255 1.42916C5.53095 0.781817 6.46913 0.781816 6.85753 1.42915L11.0913 8.4855C11.4913 9.15203 11.0111 10 10.2338 10H1.76623C0.988935 10 0.508822 9.15203 0.908736 8.4855L5.14255 1.42916Z" fill="#82DBC5"/>
3
+ <rect x="19" y="1" width="9" height="9" rx="1" fill="#4F4F4F"/>
4
+ <circle cx="39.5" cy="5.5" r="4.5" fill="#EFAC35"/>
5
+ </svg>
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ <svg width="934" height="934" viewBox="0 0 934 934" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M357.84 33.2164C358.228 32.5691 359.166 32.5691 359.555 33.2164L594.818 425.321C595.217 425.988 594.737 426.836 593.96 426.836H123.434C122.657 426.836 122.177 425.988 122.577 425.321L357.84 33.2164Z" fill="#82DBC5"/>
3
+ <path d="M457.456 269.817C457.456 269.265 457.904 268.817 458.456 268.817H812C812.552 268.817 813 269.265 813 269.817V623.361C813 623.913 812.552 624.361 812 624.361H458.456C457.904 624.361 457.456 623.913 457.456 623.361V269.817Z" fill="#4F4F4F"/>
4
+ <circle cx="467.334" cy="660.274" r="188.546" fill="#EFAC35"/>
5
+ </svg>
package/dist/tres.js ADDED
@@ -0,0 +1,690 @@
1
+ /**
2
+ * name: @tres/core
3
+ * version: v0.1.0
4
+ * (c) 2022
5
+ * description: Declarative ThreeJS using Vue Components
6
+ * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
+ */
8
+ import { computed as oe, watch as ae, ref as Z, defineComponent as Fe, useSlots as rt, useAttrs as it, onMounted as st, onBeforeUnmount as ct, openBlock as G, createElementBlock as Ae, normalizeStyle as Re, unref as xe, createElementVNode as lt, createBlock as ut, Suspense as pt, withCtx as ft, renderSlot as Se, createCommentVNode as De, Fragment as dt } from "vue";
9
+ import * as mt from "three";
10
+ import { PerspectiveCamera as $, OrthographicCamera as ht, EventDispatcher as gt, Vector3 as D, MOUSE as j, TOUCH as I, Quaternion as Ne, Spherical as ke, Vector2 as R, Color as Q, Scene as bt, Clock as yt, LoadingManager as Et, TextureLoader as wt, WebGLRenderer as Pt, PCFSoftShadowMap as Mt, sRGBEncoding as Tt } from "three";
11
+ import { useWindowSize as ve } from "@vueuse/core";
12
+ var F = /* @__PURE__ */ ((o) => (o.Perspective = "Perspective", o.Orthographic = "Orthographic", o))(F || {});
13
+ const Y = {
14
+ cameras: []
15
+ }, Ot = 45;
16
+ let _;
17
+ function re() {
18
+ const { width: o, height: a } = ve();
19
+ function b(i = "Perspective", c) {
20
+ if (i === "Perspective") {
21
+ const { near: h, far: E, fov: f } = c || {
22
+ near: 0.1,
23
+ far: 1e3,
24
+ fov: Ot
25
+ };
26
+ _ = new $(f, e.value, h, E), Y.cameras.push(_);
27
+ } else {
28
+ const { left: h, right: E, top: f, bottom: w, near: y, far: d } = c || {
29
+ left: -100,
30
+ right: 100,
31
+ top: 100,
32
+ bottom: -100,
33
+ near: 0.1,
34
+ far: 1e3
35
+ };
36
+ _ = new ht(h, E, f, w, y, d), Y.cameras.push(_);
37
+ }
38
+ return Y.cameras.push(_), _;
39
+ }
40
+ const e = oe(() => o.value / a.value), n = oe(() => Y.cameras[0]);
41
+ function r() {
42
+ n.value instanceof $ && (n.value.aspect = e.value), n.value.updateProjectionMatrix();
43
+ }
44
+ function p(i) {
45
+ Y.cameras.push(i), i instanceof $ && (i.aspect = e.value), i.updateProjectionMatrix();
46
+ }
47
+ return ae(e, r), {
48
+ activeCamera: n,
49
+ createCamera: b,
50
+ updateCamera: r,
51
+ pushCamera: p
52
+ };
53
+ }
54
+ const je = { type: "change" }, J = { type: "start" }, Ie = { type: "end" };
55
+ class Ct extends gt {
56
+ constructor(a, b) {
57
+ super(), this.object = a, this.domElement = b, this.domElement.style.touchAction = "none", this.enabled = !0, this.target = new D(), this.minDistance = 0, this.maxDistance = 1 / 0, this.minZoom = 0, this.maxZoom = 1 / 0, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.minAzimuthAngle = -1 / 0, this.maxAzimuthAngle = 1 / 0, this.enableDamping = !1, this.dampingFactor = 0.05, this.enableZoom = !0, this.zoomSpeed = 1, this.enableRotate = !0, this.rotateSpeed = 1, this.enablePan = !0, this.panSpeed = 1, this.screenSpacePanning = !0, this.keyPanSpeed = 7, this.autoRotate = !1, this.autoRotateSpeed = 2, this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }, this.mouseButtons = { LEFT: j.ROTATE, MIDDLE: j.DOLLY, RIGHT: j.PAN }, this.touches = { ONE: I.ROTATE, TWO: I.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this.getPolarAngle = function() {
58
+ return i.phi;
59
+ }, this.getAzimuthalAngle = function() {
60
+ return i.theta;
61
+ }, this.getDistance = function() {
62
+ return this.object.position.distanceTo(this.target);
63
+ }, this.listenToKeyEvents = function(t) {
64
+ t.addEventListener("keydown", Me), this._domElementKeyEvents = t;
65
+ }, this.saveState = function() {
66
+ e.target0.copy(e.target), e.position0.copy(e.object.position), e.zoom0 = e.object.zoom;
67
+ }, this.reset = function() {
68
+ e.target.copy(e.target0), e.object.position.copy(e.position0), e.object.zoom = e.zoom0, e.object.updateProjectionMatrix(), e.dispatchEvent(je), e.update(), r = n.NONE;
69
+ }, this.update = function() {
70
+ const t = new D(), s = new Ne().setFromUnitVectors(a.up, new D(0, 1, 0)), M = s.clone().invert(), O = new D(), A = new Ne(), k = 2 * Math.PI;
71
+ return function() {
72
+ const Le = e.object.position;
73
+ t.copy(Le).sub(e.target), t.applyQuaternion(s), i.setFromVector3(t), e.autoRotate && r === n.NONE && B(Ze()), e.enableDamping ? (i.theta += c.theta * e.dampingFactor, i.phi += c.phi * e.dampingFactor) : (i.theta += c.theta, i.phi += c.phi);
74
+ let x = e.minAzimuthAngle, S = e.maxAzimuthAngle;
75
+ return isFinite(x) && isFinite(S) && (x < -Math.PI ? x += k : x > Math.PI && (x -= k), S < -Math.PI ? S += k : S > Math.PI && (S -= k), x <= S ? i.theta = Math.max(x, Math.min(S, i.theta)) : i.theta = i.theta > (x + S) / 2 ? Math.max(x, i.theta) : Math.min(S, i.theta)), i.phi = Math.max(e.minPolarAngle, Math.min(e.maxPolarAngle, i.phi)), i.makeSafe(), i.radius *= h, i.radius = Math.max(e.minDistance, Math.min(e.maxDistance, i.radius)), e.enableDamping === !0 ? e.target.addScaledVector(E, e.dampingFactor) : e.target.add(E), t.setFromSpherical(i), t.applyQuaternion(M), Le.copy(e.target).add(t), e.object.lookAt(e.target), e.enableDamping === !0 ? (c.theta *= 1 - e.dampingFactor, c.phi *= 1 - e.dampingFactor, E.multiplyScalar(1 - e.dampingFactor)) : (c.set(0, 0, 0), E.set(0, 0, 0)), h = 1, f || O.distanceToSquared(e.object.position) > p || 8 * (1 - A.dot(e.object.quaternion)) > p ? (e.dispatchEvent(je), O.copy(e.object.position), A.copy(e.object.quaternion), f = !1, !0) : !1;
76
+ };
77
+ }(), this.dispose = function() {
78
+ e.domElement.removeEventListener("contextmenu", Te), e.domElement.removeEventListener("pointerdown", Ee), e.domElement.removeEventListener("pointercancel", we), e.domElement.removeEventListener("wheel", Pe), e.domElement.removeEventListener("pointermove", K), e.domElement.removeEventListener("pointerup", W), e._domElementKeyEvents !== null && e._domElementKeyEvents.removeEventListener("keydown", Me);
79
+ };
80
+ const e = this, n = {
81
+ NONE: -1,
82
+ ROTATE: 0,
83
+ DOLLY: 1,
84
+ PAN: 2,
85
+ TOUCH_ROTATE: 3,
86
+ TOUCH_PAN: 4,
87
+ TOUCH_DOLLY_PAN: 5,
88
+ TOUCH_DOLLY_ROTATE: 6
89
+ };
90
+ let r = n.NONE;
91
+ const p = 1e-6, i = new ke(), c = new ke();
92
+ let h = 1;
93
+ const E = new D();
94
+ let f = !1;
95
+ const w = new R(), y = new R(), d = new R(), C = new R(), P = new R(), u = new R(), T = new R(), g = new R(), L = new R(), l = [], v = {};
96
+ function Ze() {
97
+ return 2 * Math.PI / 60 / 60 * e.autoRotateSpeed;
98
+ }
99
+ function H() {
100
+ return Math.pow(0.95, e.zoomSpeed);
101
+ }
102
+ function B(t) {
103
+ c.theta -= t;
104
+ }
105
+ function se(t) {
106
+ c.phi -= t;
107
+ }
108
+ const ce = function() {
109
+ const t = new D();
110
+ return function(M, O) {
111
+ t.setFromMatrixColumn(O, 0), t.multiplyScalar(-M), E.add(t);
112
+ };
113
+ }(), le = function() {
114
+ const t = new D();
115
+ return function(M, O) {
116
+ e.screenSpacePanning === !0 ? t.setFromMatrixColumn(O, 1) : (t.setFromMatrixColumn(O, 0), t.crossVectors(e.object.up, t)), t.multiplyScalar(M), E.add(t);
117
+ };
118
+ }(), N = function() {
119
+ const t = new D();
120
+ return function(M, O) {
121
+ const A = e.domElement;
122
+ if (e.object.isPerspectiveCamera) {
123
+ const k = e.object.position;
124
+ t.copy(k).sub(e.target);
125
+ let U = t.length();
126
+ U *= Math.tan(e.object.fov / 2 * Math.PI / 180), ce(2 * M * U / A.clientHeight, e.object.matrix), le(2 * O * U / A.clientHeight, e.object.matrix);
127
+ } else
128
+ e.object.isOrthographicCamera ? (ce(M * (e.object.right - e.object.left) / e.object.zoom / A.clientWidth, e.object.matrix), le(O * (e.object.top - e.object.bottom) / e.object.zoom / A.clientHeight, e.object.matrix)) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), e.enablePan = !1);
129
+ };
130
+ }();
131
+ function V(t) {
132
+ e.object.isPerspectiveCamera ? h /= t : e.object.isOrthographicCamera ? (e.object.zoom = Math.max(e.minZoom, Math.min(e.maxZoom, e.object.zoom * t)), e.object.updateProjectionMatrix(), f = !0) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), e.enableZoom = !1);
133
+ }
134
+ function ue(t) {
135
+ e.object.isPerspectiveCamera ? h *= t : e.object.isOrthographicCamera ? (e.object.zoom = Math.max(e.minZoom, Math.min(e.maxZoom, e.object.zoom / t)), e.object.updateProjectionMatrix(), f = !0) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), e.enableZoom = !1);
136
+ }
137
+ function pe(t) {
138
+ w.set(t.clientX, t.clientY);
139
+ }
140
+ function Xe(t) {
141
+ T.set(t.clientX, t.clientY);
142
+ }
143
+ function fe(t) {
144
+ C.set(t.clientX, t.clientY);
145
+ }
146
+ function Be(t) {
147
+ y.set(t.clientX, t.clientY), d.subVectors(y, w).multiplyScalar(e.rotateSpeed);
148
+ const s = e.domElement;
149
+ B(2 * Math.PI * d.x / s.clientHeight), se(2 * Math.PI * d.y / s.clientHeight), w.copy(y), e.update();
150
+ }
151
+ function Ve(t) {
152
+ g.set(t.clientX, t.clientY), L.subVectors(g, T), L.y > 0 ? V(H()) : L.y < 0 && ue(H()), T.copy(g), e.update();
153
+ }
154
+ function Ke(t) {
155
+ P.set(t.clientX, t.clientY), u.subVectors(P, C).multiplyScalar(e.panSpeed), N(u.x, u.y), C.copy(P), e.update();
156
+ }
157
+ function We(t) {
158
+ t.deltaY < 0 ? ue(H()) : t.deltaY > 0 && V(H()), e.update();
159
+ }
160
+ function qe(t) {
161
+ let s = !1;
162
+ switch (t.code) {
163
+ case e.keys.UP:
164
+ N(0, e.keyPanSpeed), s = !0;
165
+ break;
166
+ case e.keys.BOTTOM:
167
+ N(0, -e.keyPanSpeed), s = !0;
168
+ break;
169
+ case e.keys.LEFT:
170
+ N(e.keyPanSpeed, 0), s = !0;
171
+ break;
172
+ case e.keys.RIGHT:
173
+ N(-e.keyPanSpeed, 0), s = !0;
174
+ break;
175
+ }
176
+ s && (t.preventDefault(), e.update());
177
+ }
178
+ function de() {
179
+ if (l.length === 1)
180
+ w.set(l[0].pageX, l[0].pageY);
181
+ else {
182
+ const t = 0.5 * (l[0].pageX + l[1].pageX), s = 0.5 * (l[0].pageY + l[1].pageY);
183
+ w.set(t, s);
184
+ }
185
+ }
186
+ function me() {
187
+ if (l.length === 1)
188
+ C.set(l[0].pageX, l[0].pageY);
189
+ else {
190
+ const t = 0.5 * (l[0].pageX + l[1].pageX), s = 0.5 * (l[0].pageY + l[1].pageY);
191
+ C.set(t, s);
192
+ }
193
+ }
194
+ function he() {
195
+ const t = l[0].pageX - l[1].pageX, s = l[0].pageY - l[1].pageY, M = Math.sqrt(t * t + s * s);
196
+ T.set(0, M);
197
+ }
198
+ function Ge() {
199
+ e.enableZoom && he(), e.enablePan && me();
200
+ }
201
+ function $e() {
202
+ e.enableZoom && he(), e.enableRotate && de();
203
+ }
204
+ function ge(t) {
205
+ if (l.length == 1)
206
+ y.set(t.pageX, t.pageY);
207
+ else {
208
+ const M = q(t), O = 0.5 * (t.pageX + M.x), A = 0.5 * (t.pageY + M.y);
209
+ y.set(O, A);
210
+ }
211
+ d.subVectors(y, w).multiplyScalar(e.rotateSpeed);
212
+ const s = e.domElement;
213
+ B(2 * Math.PI * d.x / s.clientHeight), se(2 * Math.PI * d.y / s.clientHeight), w.copy(y);
214
+ }
215
+ function be(t) {
216
+ if (l.length === 1)
217
+ P.set(t.pageX, t.pageY);
218
+ else {
219
+ const s = q(t), M = 0.5 * (t.pageX + s.x), O = 0.5 * (t.pageY + s.y);
220
+ P.set(M, O);
221
+ }
222
+ u.subVectors(P, C).multiplyScalar(e.panSpeed), N(u.x, u.y), C.copy(P);
223
+ }
224
+ function ye(t) {
225
+ const s = q(t), M = t.pageX - s.x, O = t.pageY - s.y, A = Math.sqrt(M * M + O * O);
226
+ g.set(0, A), L.set(0, Math.pow(g.y / T.y, e.zoomSpeed)), V(L.y), T.copy(g);
227
+ }
228
+ function Qe(t) {
229
+ e.enableZoom && ye(t), e.enablePan && be(t);
230
+ }
231
+ function Je(t) {
232
+ e.enableZoom && ye(t), e.enableRotate && ge(t);
233
+ }
234
+ function Ee(t) {
235
+ e.enabled !== !1 && (l.length === 0 && (e.domElement.setPointerCapture(t.pointerId), e.domElement.addEventListener("pointermove", K), e.domElement.addEventListener("pointerup", W)), at(t), t.pointerType === "touch" ? nt(t) : et(t));
236
+ }
237
+ function K(t) {
238
+ e.enabled !== !1 && (t.pointerType === "touch" ? ot(t) : tt(t));
239
+ }
240
+ function W(t) {
241
+ Oe(t), l.length === 0 && (e.domElement.releasePointerCapture(t.pointerId), e.domElement.removeEventListener("pointermove", K), e.domElement.removeEventListener("pointerup", W)), e.dispatchEvent(Ie), r = n.NONE;
242
+ }
243
+ function we(t) {
244
+ Oe(t);
245
+ }
246
+ function et(t) {
247
+ let s;
248
+ switch (t.button) {
249
+ case 0:
250
+ s = e.mouseButtons.LEFT;
251
+ break;
252
+ case 1:
253
+ s = e.mouseButtons.MIDDLE;
254
+ break;
255
+ case 2:
256
+ s = e.mouseButtons.RIGHT;
257
+ break;
258
+ default:
259
+ s = -1;
260
+ }
261
+ switch (s) {
262
+ case j.DOLLY:
263
+ if (e.enableZoom === !1)
264
+ return;
265
+ Xe(t), r = n.DOLLY;
266
+ break;
267
+ case j.ROTATE:
268
+ if (t.ctrlKey || t.metaKey || t.shiftKey) {
269
+ if (e.enablePan === !1)
270
+ return;
271
+ fe(t), r = n.PAN;
272
+ } else {
273
+ if (e.enableRotate === !1)
274
+ return;
275
+ pe(t), r = n.ROTATE;
276
+ }
277
+ break;
278
+ case j.PAN:
279
+ if (t.ctrlKey || t.metaKey || t.shiftKey) {
280
+ if (e.enableRotate === !1)
281
+ return;
282
+ pe(t), r = n.ROTATE;
283
+ } else {
284
+ if (e.enablePan === !1)
285
+ return;
286
+ fe(t), r = n.PAN;
287
+ }
288
+ break;
289
+ default:
290
+ r = n.NONE;
291
+ }
292
+ r !== n.NONE && e.dispatchEvent(J);
293
+ }
294
+ function tt(t) {
295
+ switch (r) {
296
+ case n.ROTATE:
297
+ if (e.enableRotate === !1)
298
+ return;
299
+ Be(t);
300
+ break;
301
+ case n.DOLLY:
302
+ if (e.enableZoom === !1)
303
+ return;
304
+ Ve(t);
305
+ break;
306
+ case n.PAN:
307
+ if (e.enablePan === !1)
308
+ return;
309
+ Ke(t);
310
+ break;
311
+ }
312
+ }
313
+ function Pe(t) {
314
+ e.enabled === !1 || e.enableZoom === !1 || r !== n.NONE || (t.preventDefault(), e.dispatchEvent(J), We(t), e.dispatchEvent(Ie));
315
+ }
316
+ function Me(t) {
317
+ e.enabled === !1 || e.enablePan === !1 || qe(t);
318
+ }
319
+ function nt(t) {
320
+ switch (Ce(t), l.length) {
321
+ case 1:
322
+ switch (e.touches.ONE) {
323
+ case I.ROTATE:
324
+ if (e.enableRotate === !1)
325
+ return;
326
+ de(), r = n.TOUCH_ROTATE;
327
+ break;
328
+ case I.PAN:
329
+ if (e.enablePan === !1)
330
+ return;
331
+ me(), r = n.TOUCH_PAN;
332
+ break;
333
+ default:
334
+ r = n.NONE;
335
+ }
336
+ break;
337
+ case 2:
338
+ switch (e.touches.TWO) {
339
+ case I.DOLLY_PAN:
340
+ if (e.enableZoom === !1 && e.enablePan === !1)
341
+ return;
342
+ Ge(), r = n.TOUCH_DOLLY_PAN;
343
+ break;
344
+ case I.DOLLY_ROTATE:
345
+ if (e.enableZoom === !1 && e.enableRotate === !1)
346
+ return;
347
+ $e(), r = n.TOUCH_DOLLY_ROTATE;
348
+ break;
349
+ default:
350
+ r = n.NONE;
351
+ }
352
+ break;
353
+ default:
354
+ r = n.NONE;
355
+ }
356
+ r !== n.NONE && e.dispatchEvent(J);
357
+ }
358
+ function ot(t) {
359
+ switch (Ce(t), r) {
360
+ case n.TOUCH_ROTATE:
361
+ if (e.enableRotate === !1)
362
+ return;
363
+ ge(t), e.update();
364
+ break;
365
+ case n.TOUCH_PAN:
366
+ if (e.enablePan === !1)
367
+ return;
368
+ be(t), e.update();
369
+ break;
370
+ case n.TOUCH_DOLLY_PAN:
371
+ if (e.enableZoom === !1 && e.enablePan === !1)
372
+ return;
373
+ Qe(t), e.update();
374
+ break;
375
+ case n.TOUCH_DOLLY_ROTATE:
376
+ if (e.enableZoom === !1 && e.enableRotate === !1)
377
+ return;
378
+ Je(t), e.update();
379
+ break;
380
+ default:
381
+ r = n.NONE;
382
+ }
383
+ }
384
+ function Te(t) {
385
+ e.enabled !== !1 && t.preventDefault();
386
+ }
387
+ function at(t) {
388
+ l.push(t);
389
+ }
390
+ function Oe(t) {
391
+ delete v[t.pointerId];
392
+ for (let s = 0; s < l.length; s++)
393
+ if (l[s].pointerId == t.pointerId) {
394
+ l.splice(s, 1);
395
+ return;
396
+ }
397
+ }
398
+ function Ce(t) {
399
+ let s = v[t.pointerId];
400
+ s === void 0 && (s = new R(), v[t.pointerId] = s), s.set(t.pageX, t.pageY);
401
+ }
402
+ function q(t) {
403
+ const s = t.pointerId === l[0].pointerId ? l[1] : l[0];
404
+ return v[s.pointerId];
405
+ }
406
+ e.domElement.addEventListener("contextmenu", Te), e.domElement.addEventListener("pointerdown", Ee), e.domElement.addEventListener("pointercancel", we), e.domElement.addEventListener("wheel", Pe, { passive: !1 }), this.update();
407
+ }
408
+ }
409
+ let ee = { ...mt };
410
+ function Lt() {
411
+ return {
412
+ extend: (a) => {
413
+ ee = Object.assign(ee, a);
414
+ },
415
+ catalogue: ee
416
+ };
417
+ }
418
+ const At = (o) => typeof o < "u", He = (o) => !!o && o.constructor === Array;
419
+ function Ue(o) {
420
+ return typeof o == "number" ? [o, o, o] : o instanceof D ? [o.x, o.y, o.z] : o;
421
+ }
422
+ function Rt(o) {
423
+ return o instanceof Q ? o : Array.isArray(o) ? new Q(...o) : new Q(o);
424
+ }
425
+ const _e = "[TresJS \u25B2 \u25A0 \u25CF] ";
426
+ function ie() {
427
+ function o(e, n) {
428
+ console.error(`${_e} ${e}`, n);
429
+ }
430
+ function a(e) {
431
+ console.warn(`${_e} ${e}`);
432
+ }
433
+ function b(e, n) {
434
+ }
435
+ return {
436
+ logError: o,
437
+ logWarning: a,
438
+ logMessage: b
439
+ };
440
+ }
441
+ const z = new bt(), te = Z(!1);
442
+ function X() {
443
+ const { logMessage: o } = ie();
444
+ function a() {
445
+ z == null || z.clear(), te.value = !te.value, o("clear Scene", z);
446
+ }
447
+ return {
448
+ isSceneReset: te,
449
+ clearScene: a,
450
+ scene: z
451
+ };
452
+ }
453
+ const xt = ["rotation", "scale", "position"];
454
+ function St() {
455
+ const { catalogue: o } = Lt(), { logMessage: a, logError: b } = ie();
456
+ function e() {
457
+ return Object.entries(o).filter(([n, r]) => {
458
+ var p, i;
459
+ return (i = (p = r == null ? void 0 : r.prototype) == null ? void 0 : p.constructor) == null ? void 0 : i.toString().includes("class");
460
+ }).map(([n, r]) => {
461
+ const p = Fe({
462
+ name: n,
463
+ setup(i, { slots: c, attrs: h, ...E }) {
464
+ a(n, {
465
+ props: i,
466
+ slots: c,
467
+ attrs: h,
468
+ ctx: E
469
+ });
470
+ let f;
471
+ const { scene: w } = X(), { pushCamera: y } = re();
472
+ function d() {
473
+ if ((c == null ? void 0 : c.default) && (c == null ? void 0 : c.default())) {
474
+ const P = c.default().map((u) => {
475
+ var g;
476
+ let T;
477
+ return (g = u == null ? void 0 : u.props) != null && g.args ? T = new o[u.type.name](...u.props.args) : T = new o[u.type.name](), u != null && u.props && C(u.props, T), T;
478
+ });
479
+ f = new r(...P);
480
+ } else
481
+ h.args ? f = new r(...h.args) : f = new r();
482
+ C(h, f), n === "PerspectiveCamera" || n === "OrtographicCamera" ? y(f) : w == null || w.add(f), a("Instance added", w), E.expose(f);
483
+ }
484
+ function C(P, u) {
485
+ Object.entries(P).forEach(([T, g]) => {
486
+ const L = T.replace(/(-\w)/g, (l) => l[1].toUpperCase());
487
+ if (!(L === "args" || g === void 0)) {
488
+ xt.includes(T) && g && (g = Ue(g));
489
+ try {
490
+ u[L] && At(u[L].set) ? He(g) ? u[L].set(...g) : u[L].set(g) : (g === "" && (g = !0), u[L] = g);
491
+ } catch (l) {
492
+ b(`There was an error setting ${L} property`, l);
493
+ }
494
+ }
495
+ }), P.ref && (P.ref = u);
496
+ }
497
+ return d(), () => {
498
+ };
499
+ }
500
+ });
501
+ return [n, p];
502
+ });
503
+ }
504
+ return {
505
+ createComponentInstances: e
506
+ };
507
+ }
508
+ let Ye;
509
+ function Dt(o, a, b) {
510
+ const e = new yt(), { scene: n } = X(), r = () => {
511
+ const i = e.getElapsedTime(), c = e.getDelta();
512
+ n && (a && a(c, i), o(c, i), b && b(c, i)), Ye = requestAnimationFrame(r);
513
+ };
514
+ r();
515
+ function p() {
516
+ cancelAnimationFrame(Ye);
517
+ }
518
+ return {
519
+ disposeLoop: p
520
+ };
521
+ }
522
+ function Nt() {
523
+ const o = new Et(), a = Z(o);
524
+ return { loadingManager: o, loadingManagerRef: a };
525
+ }
526
+ async function zt(o) {
527
+ const { loadingManager: a } = Nt(), b = new wt(a), e = (n) => new Promise((r, p) => {
528
+ b.load(
529
+ n,
530
+ (i) => r(i),
531
+ () => null,
532
+ () => {
533
+ p(new Error("[useTextures] - Failed to load texture"));
534
+ }
535
+ );
536
+ });
537
+ if (He(o)) {
538
+ const n = await Promise.all(o.map((r) => e(r)));
539
+ return o.length > 1 ? n : n[0];
540
+ } else {
541
+ const { map: n, displacementMap: r, normalMap: p, roughnessMap: i, metalnessMap: c, aoMap: h } = o;
542
+ return {
543
+ map: n ? await e(n) : null,
544
+ displacementMap: r ? await e(r) : null,
545
+ normalMap: p ? await e(p) : null,
546
+ roughnessMap: i ? await e(i) : null,
547
+ metalnessMap: c ? await e(c) : null,
548
+ aoMap: h ? await e(h) : null
549
+ };
550
+ }
551
+ }
552
+ let m, ne, ze;
553
+ function kt(o, a) {
554
+ const { width: b, height: e } = ve(), { logMessage: n } = ie(), r = oe(() => b.value / e.value), { scene: p } = X(), { activeCamera: i } = re();
555
+ function c() {
556
+ m && (m.shadowMap.enabled = !0, m.shadowMap.type = Mt);
557
+ }
558
+ function h() {
559
+ m && (m.setSize(b.value, e.value), m.setPixelRatio(Math.min(window.devicePixelRatio, 2)));
560
+ }
561
+ function E() {
562
+ m && (m.dispose(), m = null), n("disposeRenderer", m), ze();
563
+ }
564
+ ae(r, h);
565
+ function f() {
566
+ if (n("Render init", {
567
+ renderer: m,
568
+ canvas: o,
569
+ scene: p
570
+ }), !m && o.value && p) {
571
+ const y = {
572
+ canvas: o.value,
573
+ ...a
574
+ };
575
+ a != null && a.context && (y.context = a.context), m = new Pt(y), a != null && a.shadows && c(), m.physicallyCorrectLights = (a == null ? void 0 : a.physicallyCorrectLights) || !1, a != null && a.outputEncoding && (m.outputEncoding = a.outputEncoding), a != null && a.toneMapping && (m.toneMapping = a.toneMapping, m.toneMappingExposure = 1), h(), m.render(p, i.value), ne = new Ct(i.value, m.domElement), ne.enableDamping = !0, ze = Dt(() => {
576
+ p && m && m.render(p, i.value), ne.update();
577
+ }).disposeLoop;
578
+ }
579
+ }
580
+ function w(y) {
581
+ m && m.setClearColor(Rt(y));
582
+ }
583
+ return f(), {
584
+ renderer: m,
585
+ setClearColor: w,
586
+ updateRenderer: h,
587
+ disposeRenderer: E
588
+ };
589
+ }
590
+ const jt = /* @__PURE__ */ Fe({
591
+ __name: "TresCanvas",
592
+ props: {
593
+ camera: null,
594
+ ortographic: { type: Boolean },
595
+ gl: null,
596
+ shadows: { type: Boolean, default: !1 },
597
+ physicallyCorrectLights: { type: Boolean, default: !1 },
598
+ outputEncoding: { default: Tt },
599
+ alpha: { type: Boolean, default: !1 },
600
+ background: null,
601
+ async: { type: Boolean, default: !1 }
602
+ },
603
+ setup(o) {
604
+ const a = o;
605
+ let b, e = () => {
606
+ };
607
+ const n = Z(), r = Z(!0), { scene: p, clearScene: i } = X(), c = rt(), h = it(), { createCamera: E } = re();
608
+ let f;
609
+ const w = c.default ? c == null ? void 0 : c.default().some(
610
+ (d) => d.type.name === "PerspectiveCamera" || d.type.name === "OrtographicCamera"
611
+ ) : !1;
612
+ if (p && !w)
613
+ if (a.camera) {
614
+ const { position: d, ...C } = a.camera;
615
+ if (f = E(a.ortographic === !0 ? F.Orthographic : F.Perspective, C || {}), d) {
616
+ const P = Ue(d);
617
+ f.position.set(...P);
618
+ }
619
+ p.add(f);
620
+ } else
621
+ f = E(a.ortographic === !0 ? F.Orthographic : F.Perspective, {}), f.position.set(5, 5, 5), p.add(f);
622
+ ae(a, () => {
623
+ b && (e(), i(), y());
624
+ });
625
+ function y() {
626
+ const d = kt(n, {
627
+ antialias: !0,
628
+ physicallyCorrectLights: a.physicallyCorrectLights,
629
+ shadows: a.shadows,
630
+ context: a.gl || null,
631
+ alpha: a.alpha
632
+ });
633
+ b = d.renderer, e = d.disposeRenderer, a.background && d.setClearColor(a.background);
634
+ }
635
+ return st(() => {
636
+ y();
637
+ }), ct(() => {
638
+ i(), e();
639
+ }), (d, C) => {
640
+ var P, u, T, g;
641
+ return G(), Ae("div", {
642
+ id: "tres-container",
643
+ style: Re({
644
+ position: "relative",
645
+ top: 0,
646
+ left: 0,
647
+ right: 0,
648
+ bottom: 0,
649
+ overflow: "hidden",
650
+ width: ((u = (P = xe(h)) == null ? void 0 : P.style) == null ? void 0 : u.width) || "100%",
651
+ height: "100%"
652
+ })
653
+ }, [
654
+ lt("canvas", {
655
+ ref_key: "canvasRef",
656
+ ref: n,
657
+ style: Re({ width: ((g = (T = xe(h)) == null ? void 0 : T.style) == null ? void 0 : g.width) || "100%", height: "100%" })
658
+ }, null, 4),
659
+ o.async ? (G(), ut(pt, { key: 0 }, {
660
+ default: ft(() => [
661
+ r.value ? Se(d.$slots, "default", { key: 0 }) : De("", !0)
662
+ ]),
663
+ _: 3
664
+ })) : (G(), Ae(dt, { key: 1 }, [
665
+ r.value ? Se(d.$slots, "default", { key: 0 }) : De("", !0)
666
+ ], 64))
667
+ ], 4);
668
+ };
669
+ }
670
+ }), Ft = {
671
+ install(o) {
672
+ o.component("TresCanvas", jt);
673
+ const { createComponentInstances: a } = St();
674
+ a().forEach(([e, n]) => {
675
+ o.component(e, n);
676
+ });
677
+ }
678
+ };
679
+ export {
680
+ F as CameraType,
681
+ Ft as default,
682
+ re as useCamera,
683
+ Lt as useCatalog,
684
+ St as useInstanceCreator,
685
+ Nt as useLoadingManager,
686
+ Dt as useLoop,
687
+ kt as useRenderer,
688
+ X as useScene,
689
+ zt as useTexture
690
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * name: @tres/core
3
+ * version: v0.1.0
4
+ * (c) 2022
5
+ * description: Declarative ThreeJS using Vue Components
6
+ * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
+ */
8
+ (function(O,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("vue"),require("three"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","three","@vueuse/core"],l):(O=typeof globalThis<"u"?globalThis:O||self,l(O.tres={},O.Vue,O.Three,O.VueUseCore))})(this,function(O,l,r,ee){"use strict";function Ie(n){if(n&&n.__esModule)return n;const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const g in n)if(g!=="default"){const e=Object.getOwnPropertyDescriptor(n,g);Object.defineProperty(a,g,e.get?e:{enumerable:!0,get:()=>n[g]})}}return a.default=n,Object.freeze(a)}const _e=Ie(r);var I=(n=>(n.Perspective="Perspective",n.Orthographic="Orthographic",n))(I||{});const Y={cameras:[]},Ve=45;let _;function E(){const{width:n,height:a}=ee.useWindowSize();function g(s="Perspective",u){if(s==="Perspective"){const{near:y,far:M,fov:m}=u||{near:.1,far:1e3,fov:Ve};_=new r.PerspectiveCamera(m,e.value,y,M),Y.cameras.push(_)}else{const{left:y,right:M,top:m,bottom:C,near:P,far:b}=u||{left:-100,right:100,top:100,bottom:-100,near:.1,far:1e3};_=new r.OrthographicCamera(y,M,m,C,P,b),Y.cameras.push(_)}return Y.cameras.push(_),_}const e=l.computed(()=>n.value/a.value),o=l.computed(()=>Y.cameras[0]);function i(){o.value instanceof r.PerspectiveCamera&&(o.value.aspect=e.value),o.value.updateProjectionMatrix()}function d(s){Y.cameras.push(s),s instanceof r.PerspectiveCamera&&(s.aspect=e.value),s.updateProjectionMatrix()}return l.watch(e,i),{activeCamera:o,createCamera:g,updateCamera:i,pushCamera:d}}const te={type:"change"},X={type:"start"},ne={type:"end"};class Ue extends r.EventDispatcher{constructor(a,g){super(),this.object=a,this.domElement=g,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new r.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:r.MOUSE.ROTATE,MIDDLE:r.MOUSE.DOLLY,RIGHT:r.MOUSE.PAN},this.touches={ONE:r.TOUCH.ROTATE,TWO:r.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return s.phi},this.getAzimuthalAngle=function(){return s.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.listenToKeyEvents=function(t){t.addEventListener("keydown",De),this._domElementKeyEvents=t},this.saveState=function(){e.target0.copy(e.target),e.position0.copy(e.object.position),e.zoom0=e.object.zoom},this.reset=function(){e.target.copy(e.target0),e.object.position.copy(e.position0),e.object.zoom=e.zoom0,e.object.updateProjectionMatrix(),e.dispatchEvent(te),e.update(),i=o.NONE},this.update=function(){const t=new r.Vector3,c=new r.Quaternion().setFromUnitVectors(a.up,new r.Vector3(0,1,0)),L=c.clone().invert(),x=new r.Vector3,k=new r.Quaternion,U=2*Math.PI;return function(){const Te=e.object.position;t.copy(Te).sub(e.target),t.applyQuaternion(c),s.setFromVector3(t),e.autoRotate&&i===o.NONE&&$(Re()),e.enableDamping?(s.theta+=u.theta*e.dampingFactor,s.phi+=u.phi*e.dampingFactor):(s.theta+=u.theta,s.phi+=u.phi);let N=e.minAzimuthAngle,T=e.maxAzimuthAngle;return isFinite(N)&&isFinite(T)&&(N<-Math.PI?N+=U:N>Math.PI&&(N-=U),T<-Math.PI?T+=U:T>Math.PI&&(T-=U),N<=T?s.theta=Math.max(N,Math.min(T,s.theta)):s.theta=s.theta>(N+T)/2?Math.max(N,s.theta):Math.min(T,s.theta)),s.phi=Math.max(e.minPolarAngle,Math.min(e.maxPolarAngle,s.phi)),s.makeSafe(),s.radius*=y,s.radius=Math.max(e.minDistance,Math.min(e.maxDistance,s.radius)),e.enableDamping===!0?e.target.addScaledVector(M,e.dampingFactor):e.target.add(M),t.setFromSpherical(s),t.applyQuaternion(L),Te.copy(e.target).add(t),e.object.lookAt(e.target),e.enableDamping===!0?(u.theta*=1-e.dampingFactor,u.phi*=1-e.dampingFactor,M.multiplyScalar(1-e.dampingFactor)):(u.set(0,0,0),M.set(0,0,0)),y=1,m||x.distanceToSquared(e.object.position)>d||8*(1-k.dot(e.object.quaternion))>d?(e.dispatchEvent(te),x.copy(e.object.position),k.copy(e.object.quaternion),m=!1,!0):!1}}(),this.dispose=function(){e.domElement.removeEventListener("contextmenu",je),e.domElement.removeEventListener("pointerdown",Le),e.domElement.removeEventListener("pointercancel",Ae),e.domElement.removeEventListener("wheel",xe),e.domElement.removeEventListener("pointermove",v),e.domElement.removeEventListener("pointerup",J),e._domElementKeyEvents!==null&&e._domElementKeyEvents.removeEventListener("keydown",De)};const e=this,o={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let i=o.NONE;const d=1e-6,s=new r.Spherical,u=new r.Spherical;let y=1;const M=new r.Vector3;let m=!1;const C=new r.Vector2,P=new r.Vector2,b=new r.Vector2,D=new r.Vector2,S=new r.Vector2,f=new r.Vector2,A=new r.Vector2,w=new r.Vector2,j=new r.Vector2,p=[],Z={};function Re(){return 2*Math.PI/60/60*e.autoRotateSpeed}function B(){return Math.pow(.95,e.zoomSpeed)}function $(t){u.theta-=t}function de(t){u.phi-=t}const me=function(){const t=new r.Vector3;return function(L,x){t.setFromMatrixColumn(x,0),t.multiplyScalar(-L),M.add(t)}}(),he=function(){const t=new r.Vector3;return function(L,x){e.screenSpacePanning===!0?t.setFromMatrixColumn(x,1):(t.setFromMatrixColumn(x,0),t.crossVectors(e.object.up,t)),t.multiplyScalar(L),M.add(t)}}(),V=function(){const t=new r.Vector3;return function(L,x){const k=e.domElement;if(e.object.isPerspectiveCamera){const U=e.object.position;t.copy(U).sub(e.target);let R=t.length();R*=Math.tan(e.object.fov/2*Math.PI/180),me(2*L*R/k.clientHeight,e.object.matrix),he(2*x*R/k.clientHeight,e.object.matrix)}else e.object.isOrthographicCamera?(me(L*(e.object.right-e.object.left)/e.object.zoom/k.clientWidth,e.object.matrix),he(x*(e.object.top-e.object.bottom)/e.object.zoom/k.clientHeight,e.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),e.enablePan=!1)}}();function Q(t){e.object.isPerspectiveCamera?y/=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom*t)),e.object.updateProjectionMatrix(),m=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function ge(t){e.object.isPerspectiveCamera?y*=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom/t)),e.object.updateProjectionMatrix(),m=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function be(t){C.set(t.clientX,t.clientY)}function Xe(t){A.set(t.clientX,t.clientY)}function ye(t){D.set(t.clientX,t.clientY)}function Ke(t){P.set(t.clientX,t.clientY),b.subVectors(P,C).multiplyScalar(e.rotateSpeed);const c=e.domElement;$(2*Math.PI*b.x/c.clientHeight),de(2*Math.PI*b.y/c.clientHeight),C.copy(P),e.update()}function We(t){w.set(t.clientX,t.clientY),j.subVectors(w,A),j.y>0?Q(B()):j.y<0&&ge(B()),A.copy(w),e.update()}function qe(t){S.set(t.clientX,t.clientY),f.subVectors(S,D).multiplyScalar(e.panSpeed),V(f.x,f.y),D.copy(S),e.update()}function Ge(t){t.deltaY<0?ge(B()):t.deltaY>0&&Q(B()),e.update()}function $e(t){let c=!1;switch(t.code){case e.keys.UP:V(0,e.keyPanSpeed),c=!0;break;case e.keys.BOTTOM:V(0,-e.keyPanSpeed),c=!0;break;case e.keys.LEFT:V(e.keyPanSpeed,0),c=!0;break;case e.keys.RIGHT:V(-e.keyPanSpeed,0),c=!0;break}c&&(t.preventDefault(),e.update())}function we(){if(p.length===1)C.set(p[0].pageX,p[0].pageY);else{const t=.5*(p[0].pageX+p[1].pageX),c=.5*(p[0].pageY+p[1].pageY);C.set(t,c)}}function Pe(){if(p.length===1)D.set(p[0].pageX,p[0].pageY);else{const t=.5*(p[0].pageX+p[1].pageX),c=.5*(p[0].pageY+p[1].pageY);D.set(t,c)}}function Oe(){const t=p[0].pageX-p[1].pageX,c=p[0].pageY-p[1].pageY,L=Math.sqrt(t*t+c*c);A.set(0,L)}function Qe(){e.enableZoom&&Oe(),e.enablePan&&Pe()}function ve(){e.enableZoom&&Oe(),e.enableRotate&&we()}function Me(t){if(p.length==1)P.set(t.pageX,t.pageY);else{const L=H(t),x=.5*(t.pageX+L.x),k=.5*(t.pageY+L.y);P.set(x,k)}b.subVectors(P,C).multiplyScalar(e.rotateSpeed);const c=e.domElement;$(2*Math.PI*b.x/c.clientHeight),de(2*Math.PI*b.y/c.clientHeight),C.copy(P)}function Ce(t){if(p.length===1)S.set(t.pageX,t.pageY);else{const c=H(t),L=.5*(t.pageX+c.x),x=.5*(t.pageY+c.y);S.set(L,x)}f.subVectors(S,D).multiplyScalar(e.panSpeed),V(f.x,f.y),D.copy(S)}function Se(t){const c=H(t),L=t.pageX-c.x,x=t.pageY-c.y,k=Math.sqrt(L*L+x*x);w.set(0,k),j.set(0,Math.pow(w.y/A.y,e.zoomSpeed)),Q(j.y),A.copy(w)}function Je(t){e.enableZoom&&Se(t),e.enablePan&&Ce(t)}function He(t){e.enableZoom&&Se(t),e.enableRotate&&Me(t)}function Le(t){e.enabled!==!1&&(p.length===0&&(e.domElement.setPointerCapture(t.pointerId),e.domElement.addEventListener("pointermove",v),e.domElement.addEventListener("pointerup",J)),at(t),t.pointerType==="touch"?nt(t):et(t))}function v(t){e.enabled!==!1&&(t.pointerType==="touch"?ot(t):tt(t))}function J(t){ke(t),p.length===0&&(e.domElement.releasePointerCapture(t.pointerId),e.domElement.removeEventListener("pointermove",v),e.domElement.removeEventListener("pointerup",J)),e.dispatchEvent(ne),i=o.NONE}function Ae(t){ke(t)}function et(t){let c;switch(t.button){case 0:c=e.mouseButtons.LEFT;break;case 1:c=e.mouseButtons.MIDDLE;break;case 2:c=e.mouseButtons.RIGHT;break;default:c=-1}switch(c){case r.MOUSE.DOLLY:if(e.enableZoom===!1)return;Xe(t),i=o.DOLLY;break;case r.MOUSE.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enablePan===!1)return;ye(t),i=o.PAN}else{if(e.enableRotate===!1)return;be(t),i=o.ROTATE}break;case r.MOUSE.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enableRotate===!1)return;be(t),i=o.ROTATE}else{if(e.enablePan===!1)return;ye(t),i=o.PAN}break;default:i=o.NONE}i!==o.NONE&&e.dispatchEvent(X)}function tt(t){switch(i){case o.ROTATE:if(e.enableRotate===!1)return;Ke(t);break;case o.DOLLY:if(e.enableZoom===!1)return;We(t);break;case o.PAN:if(e.enablePan===!1)return;qe(t);break}}function xe(t){e.enabled===!1||e.enableZoom===!1||i!==o.NONE||(t.preventDefault(),e.dispatchEvent(X),Ge(t),e.dispatchEvent(ne))}function De(t){e.enabled===!1||e.enablePan===!1||$e(t)}function nt(t){switch(Ne(t),p.length){case 1:switch(e.touches.ONE){case r.TOUCH.ROTATE:if(e.enableRotate===!1)return;we(),i=o.TOUCH_ROTATE;break;case r.TOUCH.PAN:if(e.enablePan===!1)return;Pe(),i=o.TOUCH_PAN;break;default:i=o.NONE}break;case 2:switch(e.touches.TWO){case r.TOUCH.DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;Qe(),i=o.TOUCH_DOLLY_PAN;break;case r.TOUCH.DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;ve(),i=o.TOUCH_DOLLY_ROTATE;break;default:i=o.NONE}break;default:i=o.NONE}i!==o.NONE&&e.dispatchEvent(X)}function ot(t){switch(Ne(t),i){case o.TOUCH_ROTATE:if(e.enableRotate===!1)return;Me(t),e.update();break;case o.TOUCH_PAN:if(e.enablePan===!1)return;Ce(t),e.update();break;case o.TOUCH_DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;Je(t),e.update();break;case o.TOUCH_DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;He(t),e.update();break;default:i=o.NONE}}function je(t){e.enabled!==!1&&t.preventDefault()}function at(t){p.push(t)}function ke(t){delete Z[t.pointerId];for(let c=0;c<p.length;c++)if(p[c].pointerId==t.pointerId){p.splice(c,1);return}}function Ne(t){let c=Z[t.pointerId];c===void 0&&(c=new r.Vector2,Z[t.pointerId]=c),c.set(t.pageX,t.pageY)}function H(t){const c=t.pointerId===p[0].pointerId?p[1]:p[0];return Z[c.pointerId]}e.domElement.addEventListener("contextmenu",je),e.domElement.addEventListener("pointerdown",Le),e.domElement.addEventListener("pointercancel",Ae),e.domElement.addEventListener("wheel",xe,{passive:!1}),this.update()}}let K={..._e};function oe(){return{extend:a=>{K=Object.assign(K,a)},catalogue:K}}const Ye=n=>typeof n<"u",ae=n=>!!n&&n.constructor===Array;function re(n){return typeof n=="number"?[n,n,n]:n instanceof r.Vector3?[n.x,n.y,n.z]:n}function ze(n){return n instanceof r.Color?n:Array.isArray(n)?new r.Color(...n):new r.Color(n)}const ie="[TresJS \u25B2 \u25A0 \u25CF] ";function W(){function n(e,o){console.error(`${ie} ${e}`,o)}function a(e){console.warn(`${ie} ${e}`)}function g(e,o){}return{logError:n,logWarning:a,logMessage:g}}const z=new r.Scene,q=l.ref(!1);function F(){const{logMessage:n}=W();function a(){z==null||z.clear(),q.value=!q.value,n("clear Scene",z)}return{isSceneReset:q,clearScene:a,scene:z}}const Fe=["rotation","scale","position"];function se(){const{catalogue:n}=oe(),{logMessage:a,logError:g}=W();function e(){return Object.entries(n).filter(([o,i])=>{var d,s;return(s=(d=i==null?void 0:i.prototype)==null?void 0:d.constructor)==null?void 0:s.toString().includes("class")}).map(([o,i])=>{const d=l.defineComponent({name:o,setup(s,{slots:u,attrs:y,...M}){a(o,{props:s,slots:u,attrs:y,ctx:M});let m;const{scene:C}=F(),{pushCamera:P}=E();function b(){if((u==null?void 0:u.default)&&(u==null?void 0:u.default())){const S=u.default().map(f=>{var w;let A;return(w=f==null?void 0:f.props)!=null&&w.args?A=new n[f.type.name](...f.props.args):A=new n[f.type.name],f!=null&&f.props&&D(f.props,A),A});m=new i(...S)}else y.args?m=new i(...y.args):m=new i;D(y,m),o==="PerspectiveCamera"||o==="OrtographicCamera"?P(m):C==null||C.add(m),a("Instance added",C),M.expose(m)}function D(S,f){Object.entries(S).forEach(([A,w])=>{const j=A.replace(/(-\w)/g,p=>p[1].toUpperCase());if(!(j==="args"||w===void 0)){Fe.includes(A)&&w&&(w=re(w));try{f[j]&&Ye(f[j].set)?ae(w)?f[j].set(...w):f[j].set(w):(w===""&&(w=!0),f[j]=w)}catch(p){g(`There was an error setting ${j} property`,p)}}}),S.ref&&(S.ref=f)}return b(),()=>{}}});return[o,d]})}return{createComponentInstances:e}}let ce;function le(n,a,g){const e=new r.Clock,{scene:o}=F(),i=()=>{const s=e.getElapsedTime(),u=e.getDelta();o&&(a&&a(u,s),n(u,s),g&&g(u,s)),ce=requestAnimationFrame(i)};i();function d(){cancelAnimationFrame(ce)}return{disposeLoop:d}}function ue(){const n=new r.LoadingManager,a=l.ref(n);return{loadingManager:n,loadingManagerRef:a}}async function Ee(n){const{loadingManager:a}=ue(),g=new r.TextureLoader(a),e=o=>new Promise((i,d)=>{g.load(o,s=>i(s),()=>null,()=>{d(new Error("[useTextures] - Failed to load texture"))})});if(ae(n)){const o=await Promise.all(n.map(i=>e(i)));return n.length>1?o:o[0]}else{const{map:o,displacementMap:i,normalMap:d,roughnessMap:s,metalnessMap:u,aoMap:y}=n;return{map:o?await e(o):null,displacementMap:i?await e(i):null,normalMap:d?await e(d):null,roughnessMap:s?await e(s):null,metalnessMap:u?await e(u):null,aoMap:y?await e(y):null}}}let h,G,pe;function fe(n,a){const{width:g,height:e}=ee.useWindowSize(),{logMessage:o}=W(),i=l.computed(()=>g.value/e.value),{scene:d}=F(),{activeCamera:s}=E();function u(){h&&(h.shadowMap.enabled=!0,h.shadowMap.type=r.PCFSoftShadowMap)}function y(){h&&(h.setSize(g.value,e.value),h.setPixelRatio(Math.min(window.devicePixelRatio,2)))}function M(){h&&(h.dispose(),h=null),o("disposeRenderer",h),pe()}l.watch(i,y);function m(){if(o("Render init",{renderer:h,canvas:n,scene:d}),!h&&n.value&&d){const P={canvas:n.value,...a};a!=null&&a.context&&(P.context=a.context),h=new r.WebGLRenderer(P),a!=null&&a.shadows&&u(),h.physicallyCorrectLights=(a==null?void 0:a.physicallyCorrectLights)||!1,a!=null&&a.outputEncoding&&(h.outputEncoding=a.outputEncoding),a!=null&&a.toneMapping&&(h.toneMapping=a.toneMapping,h.toneMappingExposure=1),y(),h.render(d,s.value),G=new Ue(s.value,h.domElement),G.enableDamping=!0,pe=le(()=>{d&&h&&h.render(d,s.value),G.update()}).disposeLoop}}function C(P){h&&h.setClearColor(ze(P))}return m(),{renderer:h,setClearColor:C,updateRenderer:y,disposeRenderer:M}}const Ze=l.defineComponent({__name:"TresCanvas",props:{camera:null,ortographic:{type:Boolean},gl:null,shadows:{type:Boolean,default:!1},physicallyCorrectLights:{type:Boolean,default:!1},outputEncoding:{default:r.sRGBEncoding},alpha:{type:Boolean,default:!1},background:null,async:{type:Boolean,default:!1}},setup(n){const a=n;let g,e=()=>{};const o=l.ref(),i=l.ref(!0),{scene:d,clearScene:s}=F(),u=l.useSlots(),y=l.useAttrs(),{createCamera:M}=E();let m;const C=u.default?u==null?void 0:u.default().some(b=>b.type.name==="PerspectiveCamera"||b.type.name==="OrtographicCamera"):!1;if(d&&!C)if(a.camera){const{position:b,...D}=a.camera;if(m=M(a.ortographic===!0?I.Orthographic:I.Perspective,D||{}),b){const S=re(b);m.position.set(...S)}d.add(m)}else m=M(a.ortographic===!0?I.Orthographic:I.Perspective,{}),m.position.set(5,5,5),d.add(m);l.watch(a,()=>{g&&(e(),s(),P())});function P(){const b=fe(o,{antialias:!0,physicallyCorrectLights:a.physicallyCorrectLights,shadows:a.shadows,context:a.gl||null,alpha:a.alpha});g=b.renderer,e=b.disposeRenderer,a.background&&b.setClearColor(a.background)}return l.onMounted(()=>{P()}),l.onBeforeUnmount(()=>{s(),e()}),(b,D)=>{var S,f,A,w;return l.openBlock(),l.createElementBlock("div",{id:"tres-container",style:l.normalizeStyle({position:"relative",top:0,left:0,right:0,bottom:0,overflow:"hidden",width:((f=(S=l.unref(y))==null?void 0:S.style)==null?void 0:f.width)||"100%",height:"100%"})},[l.createElementVNode("canvas",{ref_key:"canvasRef",ref:o,style:l.normalizeStyle({width:((w=(A=l.unref(y))==null?void 0:A.style)==null?void 0:w.width)||"100%",height:"100%"})},null,4),n.async?(l.openBlock(),l.createBlock(l.Suspense,{key:0},{default:l.withCtx(()=>[i.value?l.renderSlot(b.$slots,"default",{key:0}):l.createCommentVNode("",!0)]),_:3})):(l.openBlock(),l.createElementBlock(l.Fragment,{key:1},[i.value?l.renderSlot(b.$slots,"default",{key:0}):l.createCommentVNode("",!0)],64))],4)}}}),Be={install(n){n.component("TresCanvas",Ze);const{createComponentInstances:a}=se();a().forEach(([e,o])=>{n.component(e,o)})}};O.CameraType=I,O.default=Be,O.useCamera=E,O.useCatalog=oe,O.useInstanceCreator=se,O.useLoadingManager=ue,O.useLoop=le,O.useRenderer=fe,O.useScene=F,O.useTexture=Ee,Object.defineProperties(O,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,14 @@
1
+ import { Object3D } from 'three';
2
+ import { VNode, VNodeTypes } from 'vue';
3
+ export declare type TresInstance = Object3D<Event> & {
4
+ [key: string]: any;
5
+ };
6
+ export declare type TresVNodeType = VNodeTypes & {
7
+ name?: string | Array<string>;
8
+ __name?: string;
9
+ setup?: (props: Readonly<any>) => void;
10
+ };
11
+ export declare type TresVNode = VNode & {
12
+ children?: Array<VNode>;
13
+ type: TresVNodeType;
14
+ };
@@ -0,0 +1,17 @@
1
+ import { Vector3, Color } from 'three';
2
+ export declare type SizeFlexibleParams = number[] | {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export interface Vector2PropInterface {
7
+ x?: number;
8
+ y?: number;
9
+ width?: number;
10
+ height?: number;
11
+ }
12
+ export interface Vector3PropInterface extends Vector2PropInterface {
13
+ z?: number;
14
+ }
15
+ export declare type VectorFlexibleParams = Vector3 | number[] | Vector3PropInterface | number;
16
+ export declare function normalizeVectorFlexibleParam(value: VectorFlexibleParams): Array<number>;
17
+ export declare function normalizeColor(value: Color | Array<number> | string | number): Color;
package/dist/vite.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@tresjs/core",
3
+ "description": "Declarative ThreeJS using Vue Components",
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "license": "MIT",
11
+ "main": "./dist/tres.umd.cjs",
12
+ "module": "./dist/tres.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/tres.js",
17
+ "require": "./dist/tres.umd.cjs"
18
+ },
19
+ "./styles": "./dist/style.css",
20
+ "./*": "./dist/tres.js"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "keywords": [
26
+ "vue",
27
+ "3d",
28
+ "threejs",
29
+ "three",
30
+ "threejs-vue"
31
+ ],
32
+ "dependencies": {
33
+ "vue": "^3.2.41"
34
+ },
35
+ "peerDependencies": {
36
+ "three": "latest"
37
+ },
38
+ "devDependencies": {
39
+ "@alvarosabu/utils": "^2.2.0",
40
+ "@histoire/plugin-vue": "0.11.5",
41
+ "@vitejs/plugin-vue": "^3.2.0",
42
+ "@vitest/coverage-c8": "^0.24.5",
43
+ "@vitest/ui": "^0.24.3",
44
+ "@vueuse/core": "^9.3.0",
45
+ "gl": "6.0.1",
46
+ "happy-dom": "^7.6.6",
47
+ "histoire": "0.11.5",
48
+ "kolorist": "^1.6.0",
49
+ "pathe": "^0.3.9",
50
+ "rollup-plugin-analyzer": "^4.0.0",
51
+ "rollup-plugin-visualizer": "^5.8.3",
52
+ "unplugin-vue-components": "^0.22.9",
53
+ "vite": "^3.2.0",
54
+ "vite-plugin-banner": "^0.5.0",
55
+ "vite-plugin-dts": "^1.6.6",
56
+ "vite-plugin-require-transform": "^1.0.4",
57
+ "vitest": "^0.24.0",
58
+ "vue-demi": "^0.13.11"
59
+ },
60
+ "scripts": {
61
+ "dev": "vite",
62
+ "build": "vite build",
63
+ "preview": "vite preview",
64
+ "test": "vitest",
65
+ "test:ci": "vitest run",
66
+ "test:ui": "vitest --ui",
67
+ "coverage": "vitest run --coverage",
68
+ "story:dev": "histoire dev",
69
+ "story:build": "histoire build",
70
+ "story:preview": "histoire preview",
71
+ "lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue"
72
+ }
73
+ }