@tolokoban/tgd 2.0.0 → 2.0.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.
- package/lib/dist/camera/camera-orthographic.d.ts +2 -8
- package/lib/dist/camera/camera-orthographic.d.ts.map +1 -1
- package/lib/dist/camera/camera-perspective.d.ts +2 -8
- package/lib/dist/camera/camera-perspective.d.ts.map +1 -1
- package/lib/dist/camera/camera.d.ts +13 -2
- package/lib/dist/camera/camera.d.ts.map +1 -1
- package/lib/dist/context/context.d.ts +22 -10
- package/lib/dist/context/context.d.ts.map +1 -1
- package/lib/dist/controller/camera/orbit.d.ts +13 -8
- package/lib/dist/controller/camera/orbit.d.ts.map +1 -1
- package/lib/dist/dataset/dataset.d.ts +3 -2
- package/lib/dist/dataset/dataset.d.ts.map +1 -1
- package/lib/dist/event/index.d.ts +2 -0
- package/lib/dist/event/index.d.ts.map +1 -0
- package/lib/dist/index.d.ts +2 -0
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +2 -1
- package/lib/dist/index.js.map +1 -0
- package/lib/dist/input/index.d.ts +2 -0
- package/lib/dist/input/index.d.ts.map +1 -1
- package/lib/dist/input/inputs.d.ts +11 -0
- package/lib/dist/input/inputs.d.ts.map +1 -0
- package/lib/dist/input/keyboard.d.ts +3 -2
- package/lib/dist/input/keyboard.d.ts.map +1 -1
- package/lib/dist/input/pointer.d.ts +27 -27
- package/lib/dist/input/pointer.d.ts.map +1 -1
- package/lib/dist/math/vec3.d.ts +16 -13
- package/lib/dist/math/vec3.d.ts.map +1 -1
- package/lib/dist/painter/axis/axis.d.ts +26 -0
- package/lib/dist/painter/axis/axis.d.ts.map +1 -0
- package/lib/dist/painter/axis/index.d.ts +2 -0
- package/lib/dist/painter/axis/index.d.ts.map +1 -0
- package/lib/dist/painter/background/background.d.ts +6 -7
- package/lib/dist/painter/background/background.d.ts.map +1 -1
- package/lib/dist/painter/clear.d.ts +5 -5
- package/lib/dist/painter/clear.d.ts.map +1 -1
- package/lib/dist/painter/depth.d.ts +22 -0
- package/lib/dist/painter/depth.d.ts.map +1 -0
- package/lib/dist/painter/group.d.ts +12 -4
- package/lib/dist/painter/group.d.ts.map +1 -1
- package/lib/dist/painter/index.d.ts +8 -5
- package/lib/dist/painter/index.d.ts.map +1 -1
- package/lib/dist/painter/logic.d.ts +1 -2
- package/lib/dist/painter/logic.d.ts.map +1 -1
- package/lib/dist/painter/painter.d.ts +0 -1
- package/lib/dist/painter/painter.d.ts.map +1 -1
- package/lib/dist/painter/segments/index.d.ts +2 -0
- package/lib/dist/painter/segments/index.d.ts.map +1 -0
- package/lib/dist/painter/segments/segments.d.ts +46 -0
- package/lib/dist/painter/segments/segments.d.ts.map +1 -0
- package/lib/dist/painter/skybox/skybox.d.ts +10 -16
- package/lib/dist/painter/skybox/skybox.d.ts.map +1 -1
- package/lib/dist/program/program.d.ts +2 -2
- package/lib/dist/program/program.d.ts.map +1 -1
- package/lib/dist/resource/program.d.ts +2 -2
- package/lib/dist/resource/program.d.ts.map +1 -1
- package/lib/dist/resource/resource.d.ts +4 -4
- package/lib/dist/resource/resource.d.ts.map +1 -1
- package/lib/dist/resource/texture2d.d.ts +7 -9
- package/lib/dist/resource/texture2d.d.ts.map +1 -1
- package/lib/dist/resource/textureCube.d.ts +7 -9
- package/lib/dist/resource/textureCube.d.ts.map +1 -1
- package/lib/dist/texture/texture2d.d.ts +11 -7
- package/lib/dist/texture/texture2d.d.ts.map +1 -1
- package/lib/dist/texture/textureCube.d.ts +4 -5
- package/lib/dist/texture/textureCube.d.ts.map +1 -1
- package/lib/dist/types/context.d.ts +20 -0
- package/lib/dist/types/context.d.ts.map +1 -0
- package/lib/dist/types/index.d.ts +3 -0
- package/lib/dist/types/index.d.ts.map +1 -1
- package/lib/dist/types/input-keyboard.d.ts +5 -0
- package/lib/dist/types/input-keyboard.d.ts.map +1 -0
- package/lib/dist/types/input-pointer.d.ts +29 -0
- package/lib/dist/types/input-pointer.d.ts.map +1 -0
- package/lib/dist/types/painter.d.ts +2 -0
- package/lib/dist/types/painter.d.ts.map +1 -0
- package/lib/dist/types/texture2d.d.ts +6 -2
- package/lib/dist/types/texture2d.d.ts.map +1 -1
- package/lib/dist/types/textureCube.d.ts +3 -3
- package/lib/dist/types/textureCube.d.ts.map +1 -1
- package/lib/dist/types/webgl.d.ts +1 -0
- package/lib/dist/types/webgl.d.ts.map +1 -1
- package/lib/dist/utils/canvas.d.ts +5 -0
- package/lib/dist/utils/canvas.d.ts.map +1 -0
- package/lib/dist/utils/index.d.ts +2 -0
- package/lib/dist/utils/index.d.ts.map +1 -0
- package/lib/dist/vao/vao.d.ts +2 -2
- package/lib/dist/vao/vao.d.ts.map +1 -1
- package/package.json +6 -3
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import { TgdMat4 } from "
|
|
1
|
+
import { TgdMat4 } from "../math";
|
|
2
2
|
import { TgdCamera } from "./camera";
|
|
3
3
|
export declare class TgdCameraOrthographic extends TgdCamera {
|
|
4
|
-
private dirtyProjection;
|
|
5
4
|
private readonly _matrixProjection;
|
|
6
|
-
private _width;
|
|
7
|
-
private _height;
|
|
8
5
|
private _spaceHeight;
|
|
9
6
|
private _near;
|
|
10
7
|
private _far;
|
|
11
8
|
constructor();
|
|
9
|
+
copyProjectionFrom(camera: TgdCameraOrthographic): this;
|
|
12
10
|
get spaceHeight(): number;
|
|
13
11
|
set spaceHeight(v: number);
|
|
14
|
-
get screenWidth(): number;
|
|
15
|
-
set screenWidth(v: number);
|
|
16
|
-
get screenHeight(): number;
|
|
17
|
-
set screenHeight(v: number);
|
|
18
12
|
get near(): number;
|
|
19
13
|
set near(v: number);
|
|
20
14
|
get far(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera-orthographic.d.ts","sourceRoot":"","sources":["../../src/camera/camera-orthographic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"camera-orthographic.d.ts","sourceRoot":"","sources":["../../src/camera/camera-orthographic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAc;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,qBAAa,qBAAsB,SAAQ,SAAS;IAChD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAgB;IAClD,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,IAAI,CAAM;;IAMlB,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI;IAKvD,IAAI,WAAW,IAGI,MAAM,CADxB;IACD,IAAI,WAAW,CAAC,CAAC,EAAE,MAAM,EAKxB;IAED,IAAI,IAAI,IAGI,MAAM,CADjB;IACD,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,EAKjB;IAED,IAAI,GAAG,IAGI,MAAM,CADhB;IACD,IAAI,GAAG,CAAC,CAAC,EAAE,MAAM,EAKhB;IAED,IAAI,gBAAgB,IAAI,OAAO,CAG9B;IAED,OAAO,CAAC,wBAAwB;CA8BnC"}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import { TgdMat4 } from "
|
|
1
|
+
import { TgdMat4 } from "../math";
|
|
2
2
|
import { TgdCamera } from "./camera";
|
|
3
3
|
export declare class TgdCameraPerspective extends TgdCamera {
|
|
4
|
-
private dirtyProjection;
|
|
5
4
|
private readonly _matrixProjection;
|
|
6
|
-
private _width;
|
|
7
|
-
private _height;
|
|
8
5
|
private _fovy;
|
|
9
6
|
private _near;
|
|
10
7
|
private _far;
|
|
11
8
|
constructor();
|
|
12
|
-
|
|
13
|
-
set screenWidth(v: number);
|
|
14
|
-
get screenHeight(): number;
|
|
15
|
-
set screenHeight(v: number);
|
|
9
|
+
copyProjectionFrom(camera: TgdCameraPerspective): this;
|
|
16
10
|
get fovy(): number;
|
|
17
11
|
set fovy(v: number);
|
|
18
12
|
get near(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera-perspective.d.ts","sourceRoot":"","sources":["../../src/camera/camera-perspective.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"camera-perspective.d.ts","sourceRoot":"","sources":["../../src/camera/camera-perspective.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAc;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,qBAAa,oBAAqB,SAAQ,SAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAgB;IAClD,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,IAAI,CAAW;;IAMvB,kBAAkB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;IAOtD,IAAI,IAAI,IAGI,MAAM,CADjB;IACD,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,EAKjB;IACD,IAAI,IAAI,IAGI,MAAM,CADjB;IACD,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,EAKjB;IACD,IAAI,GAAG,IAGI,MAAM,CADhB;IACD,IAAI,GAAG,CAAC,CAAC,EAAE,MAAM,EAKhB;IACD,IAAI,gBAAgB,IAAI,OAAO,CAG9B;IAED,OAAO,CAAC,wBAAwB;CAiCnC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { TgdQuat, TgdVec3, TgdMat4, TgdQuatFace } from "
|
|
1
|
+
import { TgdQuat, TgdVec3, TgdMat4, TgdQuatFace } from "../math";
|
|
2
2
|
export declare abstract class TgdCamera {
|
|
3
|
+
protected dirtyProjection: boolean;
|
|
4
|
+
private _screenWidth;
|
|
5
|
+
private _screenHeight;
|
|
6
|
+
private _screenAspectRatio;
|
|
3
7
|
private dirty;
|
|
4
8
|
private dirtyAxis;
|
|
5
9
|
private readonly axisX;
|
|
@@ -13,8 +17,15 @@ export declare abstract class TgdCamera {
|
|
|
13
17
|
private readonly tmpMat3;
|
|
14
18
|
private readonly tmpVec3;
|
|
15
19
|
constructor();
|
|
20
|
+
get screenAspectRatio(): number;
|
|
21
|
+
get screenWidth(): number;
|
|
22
|
+
set screenWidth(v: number);
|
|
23
|
+
get screenHeight(): number;
|
|
24
|
+
set screenHeight(v: number);
|
|
16
25
|
face(face: TgdQuatFace): void;
|
|
17
|
-
from(
|
|
26
|
+
from(camera: TgdCamera): this;
|
|
27
|
+
abstract copyProjectionFrom(camera: TgdCamera): this;
|
|
28
|
+
copyOrientationFrom({ orientation }: TgdCamera): void;
|
|
18
29
|
toAxisX(axisX: TgdVec3): this;
|
|
19
30
|
toAxisY(axisY: TgdVec3): this;
|
|
20
31
|
toAxisZ(axisZ: TgdVec3): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../../src/camera/camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAW,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../../src/camera/camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAW,WAAW,EAAE,gBAAc;AAGxE,8BAAsB,SAAS;IAC3B,SAAS,CAAC,eAAe,UAAO;IAEhC,OAAO,CAAC,YAAY,CAAO;IAC3B,OAAO,CAAC,aAAa,CAAO;IAC5B,OAAO,CAAC,kBAAkB,CAAc;IAGxC,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IAEtC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IACjD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0B;IACtD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,KAAK,CAAI;IAEjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;;IAMxC,IAAI,iBAAiB,WAEpB;IAED,IAAI,WAAW,IAGI,MAAM,CADxB;IACD,IAAI,WAAW,CAAC,CAAC,EAAE,MAAM,EAMxB;IAED,IAAI,YAAY,IAGI,MAAM,CADzB;IACD,IAAI,YAAY,CAAC,CAAC,EAAE,MAAM,EAMzB;IAED,IAAI,CAAC,IAAI,EAAE,WAAW;IAMtB,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAqB7B,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAKpD,mBAAmB,CAAC,EAAE,WAAW,EAAE,EAAE,SAAS;IAI9C,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAM7B,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAM7B,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAM7B,IAAI,eAAe,IAAI,OAAO,CAG7B;IAED,QAAQ,KAAK,gBAAgB,IAAI,OAAO,CAAA;IAExC,cAAc,CAAC,IAAI,EAAE,OAAO;IAa5B,SAAS,CAAC,GAAG,EAAE,OAAO;IAWtB,IAAI,CAAC,IAGI,MAAM,CADd;IACD,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAMd;IAED,IAAI,CAAC,IAGI,MAAM,CADd;IACD,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAMd;IAED,IAAI,CAAC,IAGI,MAAM,CADd;IACD,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAMd;IAED,IAAI,QAAQ,IAGI,MAAM,CADrB;IACD,IAAI,QAAQ,CAAC,CAAC,EAAE,MAAM,EAKrB;IAED,IAAI,IAAI,IAGI,MAAM,CADjB;IACD,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,EAKjB;IAMD,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAe1C,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAU1C,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAU1C,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAU1C,KAAK,CAAC,OAAO,SAAW;IAIxB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,cAAc;CAqBzB"}
|
|
@@ -1,32 +1,44 @@
|
|
|
1
|
+
import { TgdCamera } from "../camera";
|
|
1
2
|
import { TgdPainter } from "../painter/painter";
|
|
2
|
-
import { TgdProgram } from "
|
|
3
|
-
import { TgdResourceProgram,
|
|
4
|
-
import { TgdBuffer, TgdBufferOptions } from "
|
|
5
|
-
import { TgdDataset } from "
|
|
6
|
-
import { TgdVertexArray } from "
|
|
7
|
-
|
|
3
|
+
import { TgdContextInterface, TgdProgram } from "../types";
|
|
4
|
+
import { TgdResourceProgram, TgdResourceTexture2D, TgdResourceTextureCube } from "../resource";
|
|
5
|
+
import { TgdBuffer, TgdBufferOptions } from "../buffer";
|
|
6
|
+
import { TgdDataset } from "../dataset";
|
|
7
|
+
import { TgdVertexArray } from "../vao";
|
|
8
|
+
import { TgdInputs } from "../input";
|
|
9
|
+
import { TgdPainterFunction as TgdPainterFunctionType } from "../types/painter";
|
|
10
|
+
export type TgdContextOptions = WebGLContextAttributes & {
|
|
8
11
|
onResize?(gl: WebGL2RenderingContext, width: number, height: number): void;
|
|
9
|
-
}
|
|
10
|
-
export declare class TgdContext {
|
|
12
|
+
};
|
|
13
|
+
export declare class TgdContext implements TgdContextInterface {
|
|
11
14
|
readonly canvas: HTMLCanvasElement;
|
|
12
15
|
readonly gl: WebGL2RenderingContext;
|
|
16
|
+
readonly inputs: TgdInputs;
|
|
17
|
+
camera: TgdCamera;
|
|
13
18
|
readonly programs: TgdResourceProgram;
|
|
14
|
-
readonly textures2D:
|
|
15
|
-
|
|
19
|
+
readonly textures2D: TgdResourceTexture2D;
|
|
20
|
+
private _texturesCube;
|
|
16
21
|
private readonly observer;
|
|
17
22
|
private readonly painters;
|
|
18
23
|
private isPlaying;
|
|
19
24
|
private requestAnimationFrame;
|
|
20
25
|
private lastTime;
|
|
21
26
|
constructor(canvas: HTMLCanvasElement, options?: TgdContextOptions);
|
|
27
|
+
get texturesCube(): TgdResourceTextureCube;
|
|
28
|
+
get onEnter(): TgdPainterFunctionType | undefined;
|
|
29
|
+
set onEnter(v: TgdPainterFunctionType | undefined);
|
|
30
|
+
get onExit(): TgdPainterFunctionType | undefined;
|
|
31
|
+
set onExit(v: TgdPainterFunctionType | undefined);
|
|
22
32
|
get width(): number;
|
|
23
33
|
get height(): number;
|
|
24
34
|
get playing(): boolean;
|
|
25
35
|
set playing(value: boolean);
|
|
26
36
|
play(): void;
|
|
27
37
|
pause(): void;
|
|
38
|
+
has(painter: TgdPainter): boolean;
|
|
28
39
|
add(...painters: TgdPainter[]): void;
|
|
29
40
|
remove(...painters: TgdPainter[]): void;
|
|
41
|
+
removeAll(): void;
|
|
30
42
|
createBuffer(data?: BufferSource, options?: Partial<TgdBufferOptions>): TgdBuffer;
|
|
31
43
|
createVAO(program?: TgdProgram, datasets?: TgdDataset<any>[], elements?: Uint8Array | Uint16Array | Uint32Array): TgdVertexArray;
|
|
32
44
|
readonly paint: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwB,kBAAgB;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,iBAAe;AACzD,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACzB,oBAAkB;AACnB,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,kBAAgB;AACtD,OAAO,EAAE,UAAU,EAAE,mBAAiB;AACtC,OAAO,EAAE,cAAc,EAAE,eAAa;AACtC,OAAO,EAAE,SAAS,EAAE,iBAAe;AACnC,OAAO,EAAE,kBAAkB,IAAI,sBAAsB,EAAE,yBAAuB;AAO9E,MAAM,MAAM,iBAAiB,GAAG,sBAAsB,GAAG;IAerD,QAAQ,CAAC,CAAC,EAAE,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7E,CAAA;AAoBD,qBAAa,UAAW,YAAW,mBAAmB;aAsB9B,MAAM,EAAE,iBAAiB;IArB7C,SAAgB,EAAE,EAAE,sBAAsB,CAAA;IAC1C,SAAgB,MAAM,EAAE,SAAS,CAAA;IAC1B,MAAM,EAAE,SAAS,CAAA;IAIxB,SAAgB,QAAQ,EAAE,kBAAkB,CAAA;IAC5C,SAAgB,UAAU,EAAE,oBAAoB,CAAA;IAChD,OAAO,CAAC,aAAa,CAAsC;IAE3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,qBAAqB,CAAK;IAClC,OAAO,CAAC,QAAQ,CAAK;gBAOD,MAAM,EAAE,iBAAiB,EACzC,OAAO,GAAE,iBAAsB;IAoBnC,IAAI,YAAY,IAAI,sBAAsB,CAKzC;IAED,IAAI,OAAO,IAAI,sBAAsB,GAAG,SAAS,CAEhD;IACD,IAAI,OAAO,CAAC,CAAC,EAAE,sBAAsB,GAAG,SAAS,EAEhD;IAED,IAAI,MAAM,IAAI,sBAAsB,GAAG,SAAS,CAE/C;IACD,IAAI,MAAM,CAAC,CAAC,EAAE,sBAAsB,GAAG,SAAS,EAE/C;IAED,IAAI,KAAK,WAER;IAED,IAAI,MAAM,WAET;IAKD,IAAI,OAAO,IAQQ,OAAO,CANzB;IAMD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAKzB;IAQD,IAAI;IAUJ,KAAK;IAOL,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO;IAOjC,GAAG,CAAC,GAAG,QAAQ,EAAE,UAAU,EAAE;IAO7B,MAAM,CAAC,GAAG,QAAQ,EAAE,UAAU,EAAE;IAIhC,SAAS;IAIT,YAAY,CACR,IAAI,CAAC,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GACpC,SAAS;IAIZ,SAAS,CACL,OAAO,CAAC,EAAE,UAAU,EACpB,QAAQ,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,EAC5B,QAAQ,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,WAAW,GAClD,cAAc;IAOjB,QAAQ,CAAC,KAAK,aAKb;IAED,OAAO,CAAC,QAAQ,CAAC,WAAW,CAe3B;IAED,OAAO;CAMV"}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TgdEvent } from "../../event";
|
|
2
|
+
import { TgdContextInterface } from "../../types";
|
|
2
3
|
export interface TgdControllerCameraOrbitOptions {
|
|
3
|
-
|
|
4
|
+
speedOrbit: number;
|
|
5
|
+
speedZoom: number;
|
|
4
6
|
}
|
|
5
7
|
export declare class TgdControllerCameraOrbit {
|
|
6
|
-
private readonly
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
private readonly context;
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
speedZoom: number;
|
|
11
|
+
speedOrbit: number;
|
|
12
|
+
readonly eventZoomChange: TgdEvent<TgdControllerCameraOrbit>;
|
|
13
|
+
readonly eventOrbitChange: TgdEvent<TgdControllerCameraOrbit>;
|
|
14
|
+
constructor(context: TgdContextInterface, { speedZoom, speedOrbit, }?: Partial<TgdControllerCameraOrbitOptions>);
|
|
12
15
|
detach(): void;
|
|
13
16
|
private readonly handleMove;
|
|
17
|
+
private fireOrbitChange;
|
|
14
18
|
private readonly handleZoom;
|
|
19
|
+
private fireZoomChange;
|
|
15
20
|
}
|
|
16
21
|
//# sourceMappingURL=orbit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orbit.d.ts","sourceRoot":"","sources":["../../../src/controller/camera/orbit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"orbit.d.ts","sourceRoot":"","sources":["../../../src/controller/camera/orbit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,oBAAe;AAClC,OAAO,EAAE,mBAAmB,EAAwB,oBAAe;AAEnE,MAAM,WAAW,+BAA+B;IAC5C,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;CACpB;AAED,qBAAa,wBAAwB;IAW7B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAPrB,OAAO,UAAO;IACd,SAAS,SAAI;IACb,UAAU,SAAI;IACrB,SAAgB,eAAe,qCAA2C;IAC1E,SAAgB,gBAAgB,qCAA2C;gBAGtD,OAAO,EAAE,mBAAmB,EAC7C,EACI,SAAa,EACb,UAAc,GACjB,GAAE,OAAO,CAAC,+BAA+B,CAAM;IASpD,MAAM;IAMN,OAAO,CAAC,QAAQ,CAAC,UAAU,CAmC1B;IAED,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAc1B;IAED,OAAO,CAAC,cAAc;CAIzB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TgdProgram } from "
|
|
2
|
-
import { TgdBufferOptionTarget, TgdBufferOptionUsage } from "
|
|
1
|
+
import { TgdProgram } from "../types";
|
|
2
|
+
import { TgdBufferOptionTarget, TgdBufferOptionUsage } from "../buffer";
|
|
3
3
|
export type TgdDatasetType = "float" | "vec2" | "vec3" | "vec4";
|
|
4
4
|
export interface TgdDatasetOptions {
|
|
5
5
|
divisor: number;
|
|
@@ -16,6 +16,7 @@ export declare class TgdDataset<T extends Record<string, TgdDatasetType>> {
|
|
|
16
16
|
usage: TgdBufferOptionUsage;
|
|
17
17
|
constructor(attributesDefinition: T, options?: Partial<TgdDatasetOptions>);
|
|
18
18
|
set(attribName: keyof T, value: ArrayBuffer): void;
|
|
19
|
+
get(attribName: keyof T): ArrayBuffer;
|
|
19
20
|
get dataView(): DataView;
|
|
20
21
|
defineAttributes(gl: WebGL2RenderingContext, prg: TgdProgram): void;
|
|
21
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../../src/dataset/dataset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../../src/dataset/dataset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAe;AACpC,OAAO,EACH,qBAAqB,EACrB,oBAAoB,EAEvB,kBAAgB;AAEjB,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAE/D,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,qBAAqB,CAAA;IAC7B,KAAK,EAAE,oBAAoB,CAAA;CAC9B;AAED,qBAAa,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8B;IAC/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAG3B;IACD,OAAO,CAAC,IAAI,CAAwB;IAE7B,KAAK,SAAI;IACT,MAAM,EAAE,qBAAqB,CAAA;IAC7B,KAAK,EAAE,oBAAoB,CAAA;gBAG9B,oBAAoB,EAAE,CAAC,EACvB,OAAO,GAAE,OAAO,CAAC,iBAAiB,CAAM;IAqC5C,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,WAAW;IAe3C,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,WAAW;IAIrC,IAAI,QAAQ,IAAI,QAAQ,CA2BvB;IAOD,gBAAgB,CAAC,EAAE,EAAE,sBAAsB,EAAE,GAAG,EAAE,UAAU;CAoB/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/event/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
package/lib/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,13 @@ export * from "./camera";
|
|
|
2
2
|
export * from "./context";
|
|
3
3
|
export * from "./controller";
|
|
4
4
|
export * from "./dataset";
|
|
5
|
+
export * from "./event";
|
|
5
6
|
export * from "./input";
|
|
6
7
|
export * from "./math";
|
|
7
8
|
export * from "./painter";
|
|
8
9
|
export * from "./parser";
|
|
9
10
|
export * from "./resource";
|
|
11
|
+
export * from "./utils";
|
|
10
12
|
export * from "./vao";
|
|
11
13
|
export * from "./types";
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,OAAO,CAAA;AAErB,cAAc,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA;AAErB,cAAc,SAAS,CAAA"}
|
package/lib/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
var t={d:(i,e)=>{for(var s in e)t.o(e,s)&&!t.o(i,s)&&Object.defineProperty(i,s,{enumerable:!0,get:e[s]})},o:(t,i)=>Object.prototype.hasOwnProperty.call(t,i)},i={};function e(t,i=6){const e=Math.pow(10,i),s=[];let r=0;for(const n of t){const t=(Math.round(n*e)/e).toFixed(i);r=Math.max(r,t.length),s.push(t)}return s.map((t=>t.padStart(r," ")))}t.d(i,{Uj:()=>L,w1:()=>M,$M:()=>z,aT:()=>m,OY:()=>l,yr:()=>d,Zc:()=>X,tz:()=>S,Yp:()=>D,Wk:()=>r,pD:()=>Z,WM:()=>F,Op:()=>V,ui:()=>g,ts:()=>C,sh:()=>O,a7:()=>k,EK:()=>h,cX:()=>f,qG:()=>b,Ui:()=>s,YE:()=>n,Zk:()=>R});class s extends Float32Array{constructor(t=0,i=0,e=0){if(super(3),"number"!=typeof t)return this.x=t.x,this.y=t.y,void(this.z=t.z);this.x=t,this.y=i,this.z=e}clone(){return new s(this)}isEqual({x:t,y:i,z:e}){return t===this.x&&i===this.y&&e===this.z}isClose({x:t,y:i,z:e},s=1e-6){return!(Math.abs(t-this.x)>s||Math.abs(i-this.y)>s||Math.abs(e-this.z)>s)}rotateAround(t,i){const e=Math.cos(i),s=Math.sin(i),[r,n,h]=this,[o,a,c]=t,u=a*h-c*n,m=c*r-o*h,l=o*n-a*r,d=(r*o+n*a+h*c)*(1-e);return this.x=r*e+u*s+o*d,this.y=n*e+m*s+a*d,this.z=h*e+l*s+c*d,this}applyMatrix(t){const{x:i,y:e,z:s}=this;return this.x=i*t.m00+e*t.m10+s*t.m20,this.y=i*t.m01+e*t.m11+s*t.m21,this.z=i*t.m02+e*t.m12+s*t.m22,this}from({x:t,y:i,z:e}){return this.x=t,this.y=i,this.z=e,this}get x(){return this[0]}set x(t){this[0]=t}get y(){return this[1]}set y(t){this[1]=t}get z(){return this[2]}set z(t){this[2]=t}add(...t){for(const i of t)this[0]+=i[0],this[1]+=i[1],this[2]+=i[2];return this}addWithScale({x:t,y:i,z:e},s=1){return this[0]+=t*s,this[1]+=i*s,this[2]+=e*s,this}subtract(t){return this[0]-=t[0],this[1]-=t[1],this[2]-=t[2],this}scale(t){return this[0]*=t,this[1]*=t,this[2]*=t,this}dot(t){return this[0]*t[0]+this[1]*t[1]+this[2]*t[2]}get size(){return Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2])}normalize(){const t=this[0]*this[0]+this[1]*this[1]+this[2]*this[2];return 0===t?this:this.scale(1/Math.sqrt(t))}debug(t="vec3"){const{x:i,y:e,z:s}=this,r=[i,e,s].map((t=>t.toFixed(6)));console.log(`${t}: `,r.join(" | ")," length:",Math.sqrt(i*i+e*e+s*s))}}class r extends Float32Array{constructor(t=1,i=0,e=0,s=0,r=0,n=1,h=0,o=0,a=0,c=0,u=1,m=0,l=0,d=0,g=0,f=1){super("number"==typeof t?[t,i,e,s,r,n,h,o,a,c,u,m,l,d,g,f]:t)}multiply(t){const[i,e,s,r,n,h,o,a,c,u,m,l,d,g,f,x]=this,[p,y,v,w,b,E,_,T,A,P,U,M,z,I,R,X]=t;return this.m00=i*p+n*y+c*v+d*w,this.m10=i*b+n*E+c*_+d*T,this.m20=i*A+n*P+c*U+d*M,this.m30=i*z+n*I+c*R+d*X,this.m01=e*p+h*y+u*v+g*w,this.m11=e*b+h*E+u*_+g*T,this.m21=e*A+h*P+u*U+g*M,this.m31=e*z+h*I+u*R+g*X,this.m02=s*p+o*y+m*v+f*w,this.m12=s*b+o*E+m*_+f*T,this.m22=s*A+o*P+m*U+f*M,this.m32=s*z+o*I+m*R+f*X,this.m03=r*p+a*y+l*v+x*w,this.m13=r*b+a*E+l*_+x*T,this.m23=r*A+a*P+l*U+x*M,this.m33=r*z+a*I+l*R+x*X,this}invert(){const[t,i,e,s,r,n,h,o,a,c,u,m,l,d,g,f]=this,x=t*n-i*r,p=t*h-e*r,y=t*o-s*r,v=i*h-e*n,w=i*o-s*n,b=e*o-s*h,E=a*d-c*l,_=a*g-u*l,T=a*f-m*l,A=c*g-u*d,P=c*f-m*d,U=u*f-m*g,M=x*U-p*P+y*A+v*T-w*_+b*E;if(!M)return this;const z=1/M;return this[0]=(n*U-h*P+o*A)*z,this[1]=(e*P-i*U-s*A)*z,this[2]=(d*b-g*w+f*v)*z,this[3]=(u*w-c*b-m*v)*z,this[4]=(h*T-r*U-o*_)*z,this[5]=(t*U-e*T+s*_)*z,this[6]=(g*y-l*b-f*p)*z,this[7]=(a*b-u*y+m*p)*z,this[8]=(r*P-n*T+o*E)*z,this[9]=(i*T-t*P-s*E)*z,this[10]=(l*w-d*y+f*x)*z,this[11]=(c*y-a*w-m*x)*z,this[12]=(n*_-r*A-h*E)*z,this[13]=(t*A-i*_+e*E)*z,this[14]=(d*p-l*v-g*x)*z,this[15]=(a*v-c*p+u*x)*z,this}get translation(){const{m30:t,m31:i,m32:e}=this;return new s(t,i,e)}set translation(t){this.m30=t.x,this.m31=t.y,this.m32=t.z}from(t){return this.m00=t.m00,this.m01=t.m01,this.m02=t.m02,this.m03=t.m03,this.m10=t.m10,this.m11=t.m11,this.m12=t.m12,this.m13=t.m13,this.m20=t.m20,this.m21=t.m21,this.m22=t.m22,this.m23=t.m23,this.m30=t.m30,this.m31=t.m31,this.m32=t.m32,this.m33=t.m33,this}fromMat3(t){return this.m00=t.m00,this.m01=t.m01,this.m02=t.m02,this.m10=t.m10,this.m11=t.m11,this.m12=t.m12,this.m20=t.m20,this.m21=t.m21,this.m22=t.m22,this}toAxis(t,i,e){return this.toAxisX(t),this.toAxisY(i),this.toAxisZ(e)}toAxisX(t){return t.x=this.m00,t.y=this.m01,t.z=this.m02,this}toAxisY(t){return t.x=this.m10,t.y=this.m11,t.z=this.m12,this}toAxisZ(t){return t.x=this.m20,t.y=this.m21,t.z=this.m22,this}fromQuat({x:t,y:i,z:e,w:s}){const r=t+t,n=i+i,h=e+e,o=t*r,a=i*r,c=i*n,u=e*r,m=e*n,l=e*h,d=s*r,g=s*n,f=s*h;return this.m00=1-c-l,this.m10=a-f,this.m20=u+g,this.m01=a+f,this.m11=1-o-l,this.m21=m-d,this.m02=u-g,this.m12=m+d,this.m22=1-o-c,this}get m00(){return this[0]}set m00(t){this[0]=t}get m01(){return this[1]}set m01(t){this[1]=t}get m02(){return this[2]}set m02(t){this[2]=t}get m03(){return this[3]}set m03(t){this[3]=t}get m10(){return this[4]}set m10(t){this[4]=t}get m11(){return this[5]}set m11(t){this[5]=t}get m12(){return this[6]}set m12(t){this[6]=t}get m13(){return this[7]}set m13(t){this[7]=t}get m20(){return this[8]}set m20(t){this[8]=t}get m21(){return this[9]}set m21(t){this[9]=t}get m22(){return this[10]}set m22(t){this[10]=t}get m23(){return this[11]}set m23(t){this[11]=t}get m30(){return this[12]}set m30(t){this[12]=t}get m31(){return this[13]}set m31(t){this[13]=t}get m32(){return this[14]}set m32(t){this[14]=t}get m33(){return this[15]}set m33(t){this[15]=t}debug(t="Mat4"){const i=e([this.m00,this.m01,this.m02,this.m03]),s=e([this.m10,this.m11,this.m12,this.m13]),r=e([this.m20,this.m21,this.m22,this.m23]),n=e([this.m30,this.m31,this.m32,this.m33]);console.log(t),console.log(" ",[i[0],s[0],r[0],n[0]].join(" | ")),console.log(" ",[i[1],s[1],r[1],n[1]].join(" | ")),console.log(" ",[i[2],s[2],r[2],n[2]].join(" | ")),console.log(" ",[i[3],s[3],r[3],n[3]].join(" | "))}}class n extends Float32Array{constructor(t=0,i=0,e=0,r=1){return super(4),t instanceof n?(this.x=t.x,this.y=t.y,this.z=t.z,void(this.w=t.w)):t instanceof s?(this.x=t.x,this.y=t.y,this.z=t.z,void(this.w=r)):(this.x=t,this.y=i,this.z=e,void(this.w=r))}reset(t=0,i=0,e=0,s=1){return this.x=t,this.y=i,this.z=e,this.w=s,this}from(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this}clone(){return new n(this)}isEqual({x:t,y:i,z:e,w:s}){return t===this.x&&i===this.y&&e===this.z&&s===this.w}isClose({x:t,y:i,z:e,w:s},r=1e-6){return!(Math.abs(t-this.x)>r||Math.abs(i-this.y)>r||Math.abs(e-this.z)>r||Math.abs(s-this.w)>r)}applyMatrix(t){const{x:i,y:e,z:s,w:r}=this;return this.x=i*t.m00+e*t.m10+s*t.m20+r*t.m30,this.y=i*t.m01+e*t.m11+s*t.m21+r*t.m31,this.z=i*t.m02+e*t.m12+s*t.m22+r*t.m32,this.w=i*t.m03+e*t.m13+s*t.m23+r*t.m33,this}get x(){return this[0]}set x(t){this[0]=t}get y(){return this[1]}set y(t){this[1]=t}get z(){return this[2]}set z(t){this[2]=t}get w(){return this[3]}set w(t){this[3]=t}add(...t){for(const i of t)this[0]+=i[0],this[1]+=i[1],this[2]+=i[2],this[3]+=i[3];return this}subtract(t){return this[0]-=t[0],this[1]-=t[1],this[2]-=t[2],this[3]-=t[3],this}scale(t){return this[0]*=t,this[1]*=t,this[2]*=t,this[3]*=t,this}dot(t){return this[0]*t[0]+this[1]*t[1]+this[2]*t[2]+this[3]*t[3]}get size(){return Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]+this[3]*this[3])}normalize(){const t=this[0]*this[0]+this[1]*this[1]+this[2]*this[2]+this[3]*this[3];return 0===t?this:this.scale(1/Math.sqrt(t))}debug(t="vec4"){const{x:i,y:e,z:s,w:r}=this,n=[i,e,s,r].map((t=>t.toFixed(6)));console.log(`${t}: `,n.join(" | "))}}class h extends n{constructor(t=0,i=0,e=0,s=1){"number"==typeof t?super(t,i,e,s):super(t)}clone(){return new h(this)}multiply(t){const[i,e,s,r]=this,[n,h,o,a]=t;return this[0]=a*i+n*r-h*s+o*e,this[1]=a*e+n*s+h*r-o*i,this[2]=a*s-n*e+h*i+o*r,this[3]=a*r-n*i-h*e-o*s,this}fromAxis(t,i,e){const s=t.x+i.y+e.z;if(s>0){const r=Math.sqrt(s+1);this.w=.5*r;const n=.5/r;this.x=(i.z-e.y)*n,this.y=(e.x-t.z)*n,this.z=(t.y-i.x)*n}else{const s=[t,i,e];let r=0;i.y>t.x&&(r=1),e.z>s[r][r]&&(r=2);const n=(r+1)%3,h=(r+2)%3;let o=Math.sqrt(s[r][r]-s[n][n]-s[h][h]+1);this[r]=.5*o,o=.5/o,this[3]=(s[n][h]-s[h][n])*o,this[n]=(s[n][r]+s[r][n])*o,this[h]=(s[h][r]+s[r][h])*o}return this.normalize()}rotateAroundX(t){const i=.5*t,e=this[0],s=this[1],r=this[2],n=this[3],h=Math.sin(i),o=Math.cos(i);return this[0]=e*o+n*h,this[1]=s*o+r*h,this[2]=r*o-s*h,this[3]=n*o-e*h,this}rotateAroundY(t){const i=.5*t,e=this[0],s=this[1],r=this[2],n=this[3],h=Math.sin(i),o=Math.cos(i);return this[0]=e*o-r*h,this[1]=s*o+n*h,this[2]=r*o+e*h,this[3]=n*o-s*h,this}rotateAroundZ(t){const i=.5*t,e=this[0],s=this[1],r=this[2],n=this[3],h=Math.sin(i),o=Math.cos(i);return this[0]=e*o+s*h,this[1]=s*o-e*h,this[2]=r*o+n*h,this[3]=n*o-r*h,this}toAxisZ(t){const{x:i,y:e,z:s,w:r}=this,n=i+i,h=e+e,o=i*n,a=e*h,c=s*n,u=s*h,m=r*n,l=r*h;return t.x=c+l,t.y=u-m,t.z=1-o-a,t}face(t="+X+Y+Z"){const[i,e,s,r]=c[t];return this.x=i,this.y=e,this.z=s,this.w=r,this}}const o=Math.sqrt(2)/2,a=.5,c={"+X+Y+Z":[0,0,0,1],"-Z+Y+X":[0,+o,0,+o],"-X+Y-Z":[0,1,0,0],"+Z+Y-X":[0,-o,0,+o],"+X+Z-Y":[+o,0,0,+o],"+Y+Z+X":[+a,+a,+a,+a],"-X+Z+Y":[0,+o,+o,0],"-Y+Z-X":[+a,-a,-a,+a],"+X-Y-Z":[1,0,0,0],"+X-Z+Y":[-o,0,0,+o],"-X-Y+Z":[0,0,1,0],"-X-Z-Y":[0,+o,-o,0],"+Y+X-Z":[+o,+o,0,0],"+Y-X+Z":[0,0,+o,+o],"+Y-Z-X":[+a,+a,-a,-a],"-Y+X+Z":[0,0,-o,+o],"-Y-X-Z":[+o,-o,0,0],"-Y-Z+X":[+a,-a,+a,-a],"+Z+X+Y":[+a,+a,+a,-a],"+Z-X-Y":[+a,-a,+a,+a],"+Z-Y+X":[+o,0,+o,0],"-Z+X-Y":[+a,+a,-a,+a],"-Z-X+Y":[+a,-a,-a,-a],"-Z-Y-X":[+o,0,-o,0]};class u extends Float32Array{constructor(t=1,i=0,e=0,s=0,r=1,n=0,h=0,o=0,a=1){super("number"==typeof t?[t,i,e,s,r,n,h,o,a]:t)}transpose(){let t=this.m10;return this.m10=this.m01,this.m01=t,t=this.m20,this.m20=this.m02,this.m02=t,t=this.m21,this.m21=this.m12,this.m12=t,this}fromQuat({x:t,y:i,z:e,w:s}){const r=t+t,n=i+i,h=e+e,o=t*r,a=i*r,c=i*n,u=e*r,m=e*n,l=e*h,d=s*r,g=s*n,f=s*h;return this.m00=1-c-l,this.m10=a-f,this.m20=u+g,this.m01=a+f,this.m11=1-o-l,this.m21=m-d,this.m02=u-g,this.m12=m+d,this.m22=1-o-c,this}toAxis(t,i,e){return this.toAxisX(t),this.toAxisY(i),this.toAxisZ(e)}toAxisX(t){return t.x=this.m00,t.y=this.m01,t.z=this.m02,this}toAxisY(t){return t.x=this.m10,t.y=this.m11,t.z=this.m12,this}toAxisZ(t){return t.x=this.m20,t.y=this.m21,t.z=this.m22,this}scale(t){return this[0]*=t,this[1]*=t,this[2]*=t,this[3]*=t,this[4]*=t,this[5]*=t,this[6]*=t,this[7]*=t,this[8]*=t,this}get m00(){return this[0]}set m00(t){this[0]=t}get m01(){return this[1]}set m01(t){this[1]=t}get m02(){return this[2]}set m02(t){this[2]=t}get m10(){return this[3]}set m10(t){this[3]=t}get m11(){return this[4]}set m11(t){this[4]=t}get m12(){return this[5]}set m12(t){this[5]=t}get m20(){return this[6]}set m20(t){this[6]=t}get m21(){return this[7]}set m21(t){this[7]=t}get m22(){return this[8]}set m22(t){this[8]=t}debug(t="Mat3"){const i=e([this.m00,this.m01,this.m02]),s=e([this.m10,this.m11,this.m12]),r=e([this.m20,this.m21,this.m22]);console.log(t),console.log(" ",[i[0],s[0],r[0]].join(" | ")),console.log(" ",[i[1],s[1],r[1]].join(" | ")),console.log(" ",[i[2],s[2],r[2]].join(" | "))}}class m{constructor(){this.dirty=!0,this.dirtyAxis=!0,this.axisX=new s,this.axisY=new s,this.axisZ=new s,this._matrixViewModel=new r,this.orientation=new h(0,0,0,1),this.target=new s(0,0,0),this._distance=10,this._zoom=1,this.tmpMat3=new u,this.tmpVec3=new s,this.orientation.face("+X+Y+Z"),this.orbitAroundY(Math.PI),this.updateAxisIfNeeded(),console.log("****************************************"),this.axisX.debug("X"),this.axisY.debug("Y"),this.axisZ.debug("Z"),this.matrixViewModel.debug(),this.orientation.debug("Quat");const t=(t,i)=>Math.abs(t-i)<1e-5,i=({x:i,y:e,z:s})=>t(i,1)?"+X":t(i,-1)?"-X":t(e,1)?"+Y":t(e,-1)?"-Y":t(s,1)?"+Z":t(s,-1)?"-Z":"??",e=[new s(1,0,0),new s(-1,0,0),new s(0,1,0),new s(0,-1,0),new s(0,0,1),new s(0,0,-1)],n=Math.sqrt(2)/2,o=({x:i,y:e,z:s,w:r})=>[i,e,s,r].map((i=>t(i,0)?"+0":t(i,1)?"+1":t(i,-1)?"-1":t(i,+n)?"+A":t(i,-n)?"-A":t(i,.5)?"+H":t(i,-.5)?"-H":i)).join(", "),a=([t,i,e],[s,r,n])=>{const h=t*s+i*r+e*n;return Math.abs(h)>.5},c=([t,i,e],[s,r,n],[h,o,a])=>{const c=i*n-r*e+h,u=s*e-t*n+o,m=t*r-s*i+a;return Math.abs(c*c+u*u+m*m)>.01},m=[];for(const t of e)for(const s of e)if(!a(t,s))for(const r of e)a(t,r)||a(s,r)||c(t,s,r)&&(this.orientation.fromAxis(t,s,r),this.updateAxis(),m.push(`\n"${i(t)}${i(s)}${i(r)}": [${o(this.orientation)}],`));console.log(m.join("")),this.orientation.face()}face(t){this.orientation.face(t),this.dirty=!0,this.dirtyAxis=!0}from({orientation:t,target:i,distance:e,zoom:s}){return this.orientation.from(t),this.target.from(i),this.distance=e,this.zoom=s,this.dirty=!0,this.dirtyAxis=!0,this}toAxisX(t){return this.updateAxisIfNeeded(),t.from(this.axisX),this}toAxisY(t){return this.updateAxisIfNeeded(),t.from(this.axisY),this}toAxisZ(t){return this.updateAxisIfNeeded(),t.from(this.axisZ),this}get matrixViewModel(){return this.updateIfNeeded(),this._matrixViewModel}setOrientation(t){const{orientation:i}=this;if(t.isEqual(i))return;const[e,s,r,n]=t;i.x=e,i.y=s,i.z=r,i.w=n,this.dirty=!0,this.dirtyAxis=!0}setTarget(t){const{target:i}=this;if(t.isEqual(i))return;const[e,s,r]=t;i.x=e,i.y=s,i.z=r,this.dirty=!0}get x(){return this.target.x}set x(t){const{target:i}=this;t!==i.x&&(this.x=t,this.dirty=!0)}get y(){return this.target.y}set y(t){const{target:i}=this;t!==i.y&&(this.y=t,this.dirty=!0)}get z(){return this.target.z}set z(t){const{target:i}=this;t!==i.z&&(this.z=t,this.dirty=!0)}get distance(){return this._distance}set distance(t){this._distance!==t&&(this._distance=t,this.dirty=!0)}get zoom(){return this._zoom}set zoom(t){this._zoom!==t&&(this._zoom=t,this.dirty=!0)}moveTarget(t,i,e){const{target:s}=this;this.updateAxisIfNeeded();const{axisX:r,axisY:n,axisZ:h,tmpVec3:o}=this;o.from(r).scale(t).addWithScale(n,i).addWithScale(h,e),s.x+=o.x,s.y+=o.y,s.z+=o.z,this.dirty=!0}orbitAroundX(t){this.updateAxisIfNeeded();const{axisX:i,axisY:e,axisZ:s,orientation:r}=this;return e.rotateAround(i,t),s.rotateAround(i,t),r.fromAxis(i,e,s),this.dirty=!0,this}orbitAroundY(t){this.updateAxisIfNeeded();const{axisX:i,axisY:e,axisZ:s,orientation:r}=this;return i.rotateAround(e,t),s.rotateAround(e,t),r.fromAxis(i,e,s),this.dirty=!0,this}orbitAroundZ(t){this.updateAxisIfNeeded();const{axisX:i,axisY:e,axisZ:s,orientation:r}=this;return i.rotateAround(s,t),e.rotateAround(s,t),r.fromAxis(i,e,s),this.dirty=!0,this}debug(t="Camera"){this.orientation.debug(`${t} quaternion:`)}updateAxisIfNeeded(){this.dirtyAxis&&this.updateAxis()}updateAxis(){const{tmpMat3:t}=this;if(t.fromQuat(this.orientation),t.toAxis(this.axisX,this.axisY,this.axisZ),this.dirtyAxis=!1,Math.abs(1-this.axisX.size)>.1||Math.abs(1-this.axisY.size)>.1||Math.abs(1-this.axisZ.size)>.1)throw this.axisX.debug("Axis X"),this.axisY.debug("Axis Y"),this.axisZ.debug("Axis Z"),Error("STOP!")}updateIfNeeded(){if(!this.dirty)return;const{tmpMat3:t,tmpVec3:i}=this,e=this._matrixViewModel;this.updateAxis();const s=this._distance,{x:r,y:n,z:h}=this.target,{x:o,y:a,z:c}=this.axisZ;i.x=r+s*o,i.y=n+s*a,i.z=h+s*c,i.applyMatrix(t.transpose()).scale(-1),e.m30=i.x,e.m31=i.y,e.m32=i.z;const u=this._zoom;1!==u&&t.scale(u),e.fromMat3(t),this.dirty=!1}}class l extends m{constructor(){super(),this.dirtyProjection=!0,this._matrixProjection=new r,this._width=1920,this._height=1080,this._spaceHeight=10,this._near=.001,this._far=1e3}get spaceHeight(){return this._spaceHeight}set spaceHeight(t){t!==this._spaceHeight&&(this._spaceHeight=t,this.dirtyProjection=!0)}get screenWidth(){return this._width}set screenWidth(t){t!==this._width&&(this._width=t,this.dirtyProjection=!0)}get screenHeight(){return this._height}set screenHeight(t){t!==this._height&&(this._height=t,this.dirtyProjection=!0)}get near(){return this._near}set near(t){t!==this._near&&(this._near=t,this.dirtyProjection=!0)}get far(){return this._far}set far(t){t!==this._far&&(this._far=t,this.dirtyProjection=!0)}get matrixProjection(){return this.updateProjectionIfNeeded(),this._matrixProjection}updateProjectionIfNeeded(){if(!this.dirtyProjection)return;const{near:t,far:i,_width:e,_height:s,_spaceHeight:r}=this,n=.5*r,h=-n,o=n*e/s,a=-o,c=this._matrixProjection,u=1/(a-o),m=1/(h-n),l=1/(t-i);c[0]=-2*u,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=-2*m,c[6]=0,c[7]=0,c[8]=0,c[9]=0,c[10]=l,c[11]=0,c[12]=(a+o)*u,c[13]=(n+h)*m,c[14]=t*l,c[15]=1,this.dirtyProjection=!0}}class d extends m{constructor(){super(),this.dirtyProjection=!0,this._matrixProjection=new r,this._width=1920,this._height=1080,this._fovy=Math.PI/4,this._near=.001,this._far=1/0}get screenWidth(){return this._width}set screenWidth(t){t!==this._width&&(this._width=t,this.dirtyProjection=!0)}get screenHeight(){return this._height}set screenHeight(t){t!==this._height&&(this._height=t,this.dirtyProjection=!0)}get fovy(){return this._fovy}set fovy(t){t!==this._fovy&&(this._fovy=t,this.dirtyProjection=!0)}get near(){return this._near}set near(t){t!==this._near&&(this._near=t,this.dirtyProjection=!0)}get far(){return this._far}set far(t){t!==this._far&&(this._far=t,this.dirtyProjection=!0)}get matrixProjection(){return this.updateProjectionIfNeeded(),this._matrixProjection}updateProjectionIfNeeded(){if(!this.dirtyProjection)return;const t=this._fovy,i=this._width/this._height,e=this._near,s=this._far,r=this._matrixProjection,n=1/Math.tan(t/2);if(r[0]=n/i,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=n,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[11]=-1,r[12]=0,r[13]=0,r[15]=0,s!==1/0){const t=1/(e-s);r[10]=(s+e)*t,r[14]=2*s*e*t}else r[10]=-1,r[14]=-2*e;this.dirtyProjection=!0}}class g{constructor(t=[]){this.enabled=!0,this.painters=[...t]}add(...t){for(const i of t)this.painters.push(i)}remove(...t){for(const i of t){const t=this.painters.indexOf(i);t<0||(this.painters.splice(t,1),i.delete())}}delete(){for(const t of this.painters)t.delete();this.painters.splice(0,this.painters.length)}paint(t,i){if(this.enabled)for(const e of this.painters)e.paint(t,i)}update(t,i){if(this.enabled)for(const e of this.painters)e.update(t,i)}}class f{constructor(){this.keys=new Map,this.objects=new Map,this.references=new Map}create(t){var i;const e=this.makeKeyFromInput(t),s=null!==(i=this.references.get(e))&&void 0!==i?i:0;if(s<1){const i=this.actualCreate(t);return this.keys.set(i,e),this.objects.set(e,i),this.references.set(e,1),i}const r=this.objects.get(e);if(!r)throw Error("[TgdResource.create] Panic!");return this.references.set(e,s+1),r}delete(t){var i;const e=this.keys.get(t);if(!e)return;const s=null!==(i=this.references.get(e))&&void 0!==i?i:0;s<1||(s>1?this.references.set(e,s-1):(this.keys.delete(t),this.objects.delete(e),this.references.delete(e),this.actualDelete(t)))}}class x{constructor(t,i){var e;this.gl=t;const s=t.createProgram();if(!s)throw Error("Unable to create WebGLProgram!");const r=this.createShader("VERTEX_SHADER",i.vert);t.attachShader(s,r);const n=this.createShader("FRAGMENT_SHADER",i.frag);if(t.attachShader(s,n),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){var h=null!==(e=t.getProgramInfoLog(s))&&void 0!==e?e:"";console.warn(h);const r=y(h);throw w("Vertex Shader",i.vert,...r),w("Fragment Shader",i.frag,...r),new Error("Could NOT link WebGL2 program!\n"+h)}this.program=s,this.shaders=[r,n],this.uniformsLocations=this.getUniformsLocations()}getAttribLocation(t){const{gl:i,program:e}=this,s=i.getAttribLocation(e,t);if(s<0)throw Error(`Attribute "${t}" not found!`);return s}getUniformLocation(t){const{uniformsLocations:i}=this,e=Object.keys(i);if(0===t.length)throw Error(`Uniform "${t}" has not been found: there is no active uniform in this program!`);const s=i[t];if(!s)throw Error(`No active uniform found with name "${t}"!\nAvailable names are: ${e.join(", ")}.`);return s}uniform1f(t,i){const{gl:e}=this;e.uniform1f(this.getUniformLocation(t),i)}uniform2f(t,i,e){const{gl:s}=this;s.uniform2f(this.getUniformLocation(t),i,e)}uniform3f(t,i,e,s){const{gl:r}=this;r.uniform3f(this.getUniformLocation(t),i,e,s)}uniform3fv(t,i){const{gl:e}=this;e.uniform3fv(this.getUniformLocation(t),i)}uniform4f(t,i,e,s,r){const{gl:n}=this;n.uniform4f(this.getUniformLocation(t),i,e,s,r)}uniform4fv(t,i){const{gl:e}=this;e.uniform4fv(this.getUniformLocation(t),i)}uniform1i(t,i){const{gl:e}=this;e.uniform1i(this.getUniformLocation(t),i)}uniform2i(t,i,e){const{gl:s}=this;s.uniform2i(this.getUniformLocation(t),i,e)}uniform3i(t,i,e,s){const{gl:r}=this;r.uniform3i(this.getUniformLocation(t),i,e,s)}uniform4i(t,i,e,s,r){const{gl:n}=this;n.uniform4i(this.getUniformLocation(t),i,e,s,r)}uniform1ui(t,i){const{gl:e}=this;e.uniform1ui(this.getUniformLocation(t),i)}uniform2ui(t,i,e){const{gl:s}=this;s.uniform2ui(this.getUniformLocation(t),i,e)}uniform3ui(t,i,e,s){const{gl:r}=this;r.uniform3ui(this.getUniformLocation(t),i,e,s)}uniform4ui(t,i,e,s,r){const{gl:n}=this;n.uniform4ui(this.getUniformLocation(t),i,e,s,r)}uniformMatrix4fv(t,i){const{gl:e}=this;e.uniformMatrix4fv(this.getUniformLocation(t),!1,i)}use(){const{gl:t,program:i}=this;t.useProgram(i)}delete(){const{gl:t}=this;this.shaders.forEach((i=>t.deleteShader(i))),t.deleteProgram(this.program)}createShader(t,i){const{gl:e}=this,s=e.createShader(e[t]);if(!s)throw Error(`Unable to create a WebGLShader of type "${t}"!`);e.shaderSource(s,i),e.compileShader(s);const r=e.getShaderInfoLog(s);if(r)throw console.error(`Error in ${t} code:`,r),w(t,i,...y(r)),Error(`Unable to compile ${t}!`);return s}getUniformsLocations(){const{gl:t,program:i}=this,e=t.getProgramParameter(i,t.ACTIVE_UNIFORMS);if("number"!=typeof e)throw Error("Unable to get the number of uniforms in a WebGLProgram!");const s={};for(let r=0;r<e;r++){const e=t.getActiveUniform(i,r);if(!e)continue;const n=t.getUniformLocation(i,e.name);if(null===n)throw Error(`Unable to get location for uniform "${e.name}"!`);s[e.name]=n}return s}}const p=/^ERROR:[ \t]+([0-9]+):([0-9]+):/g;function y(t){const i=[];for(const e of t.split("\n")){p.lastIndex=-1;const t=p.exec(e);t&&i.push(parseInt(t[2],10))}return i}function v(t,i=!1){return`color:#fff;background:${t};font-family:monospace;font-size:80%;font-weight:${i?"bolder":"100"}`}function w(t,i,...e){console.log(`%c${t}`,"font-weight:bolder;font-size:120%"),i.split("\n").forEach(((t,i)=>{const s=i+1,r=(1e-4*s).toFixed(4).substring(2),n=e.includes(s)?"#f00":"#000";console.log(`%c${r} %c${t}`,v(n),v(n,!0))}))}class b extends f{constructor(t){super(),this.gl=t}actualCreate(t){return new x(this.gl,t)}actualDelete(t){t instanceof x&&t.delete()}makeKeyFromInput(t){return JSON.stringify(t)}}var E=function(t,i,e,s){return new(e||(e=Promise))((function(r,n){function h(t){try{a(s.next(t))}catch(t){n(t)}}function o(t){try{a(s.throw(t))}catch(t){n(t)}}function a(t){var i;t.done?r(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(h,o)}a((s=s.apply(t,i||[])).next())}))};class _{static image(t){return E(this,void 0,void 0,(function*(){return new Promise((i=>{const e=new Image;e.onload=()=>i(e),e.onerror=()=>{console.error("Unable to load image: ",t),i(null)},e.src=t}))}))}static canvas(t){return E(this,void 0,void 0,(function*(){const i=yield _.image(t);if(!i)return null;const e=document.createElement("canvas");e.width=i.naturalWidth,e.height=i.naturalHeight;const s=e.getContext("2d");if(!s)throw Error("Unable to get a 2D context!");return s.drawImage(i,0,0),e}))}}class T{constructor(){this.listeners=new Set}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}dispatch(t){this.listeners.forEach((i=>i(t)))}}const A=new Uint8Array([200,200,200,255]);class P{constructor(t,i,e={}){this.gl=t,this.refresh=i,this.eventImageUpdate=new T,this._width=0,this._height=0,this._image=null,this.options=Object.assign({wrapS:"REPEAT",wrapT:"REPEAT",wrapR:"REPEAT",minFilter:"NEAREST_MIPMAP_LINEAR",magFilter:"LINEAR"},e);const s=t.createTexture();if(!s)throw Error("Unable to create a WebGLTexture!");this.texture=s,t.bindTexture(t.TEXTURE_2D,s),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,A);const{wrapS:r,wrapT:n,wrapR:h,minFilter:o,magFilter:a}=this.options;t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t[r]),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t[n]),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_R,t[h]),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t[o]),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t[a]),e.image&&this.loadImage(e.image)}delete(){this.gl.deleteTexture(this.texture)}get image(){return this._image}get width(){return this._width}get height(){return this._height}bind(){const{gl:t}=this;t.bindTexture(t.TEXTURE_2D,this.texture)}activate(t,i,e=0){const{gl:s,texture:r}=this;s.activeTexture(s.TEXTURE0+e),s.bindTexture(s.TEXTURE_2D,r),t.uniform1i(i,e)}loadImage(t){if("string"==typeof t)return void _.image(t).then((i=>{i?(this.loadImage(i),this.refresh()):console.error("[TgdTexture2D] Unable to load image:",t)})).catch(console.error);const{gl:i,texture:e}=this;i.bindTexture(i.TEXTURE_2D,e),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.generateMipmap(i.TEXTURE_2D),this._width=t.width,this._height=t.height,this._image=t,this.eventImageUpdate.dispatch(this)}}class U{constructor(t,i,e){this.gl=t,this.refresh=i,this._width=0,this._height=0,this.numberOfImagesToLoad=6;const s=t.createTexture();if(!s)throw Error("Unable to create a WebGLTexture!");this.texture=s,this.loadImage(t.TEXTURE_CUBE_MAP_POSITIVE_X,e.imagePosX),this.loadImage(t.TEXTURE_CUBE_MAP_NEGATIVE_X,e.imageNegX),this.loadImage(t.TEXTURE_CUBE_MAP_POSITIVE_Y,e.imagePosY),this.loadImage(t.TEXTURE_CUBE_MAP_NEGATIVE_Y,e.imageNegY),this.loadImage(t.TEXTURE_CUBE_MAP_POSITIVE_Z,e.imagePosZ),this.loadImage(t.TEXTURE_CUBE_MAP_NEGATIVE_Z,e.imageNegZ)}delete(){this.gl.deleteTexture(this.texture)}get ready(){return 0===this.numberOfImagesToLoad}get width(){return this._width}get height(){return this._height}bind(){const{gl:t}=this;t.bindTexture(t.TEXTURE_CUBE_MAP,this.texture)}activate(t,i,e=0){if(!this.ready)return;const{gl:s,texture:r}=this;s.activeTexture(s.TEXTURE0+e),s.bindTexture(s.TEXTURE_CUBE_MAP,r),t.uniform1i(i,e)}loadImage(t,i){if("string"==typeof i)return void _.image(i).then((e=>{e?this.loadImage(t,e):console.error(`[TgdTextureCube] Unable to load image "${i}":`,i)})).catch((t=>{console.error(`[TgdTextureCube] Unable to load image "${i}":`,t)}));const{width:e,height:s}=i;if(e!==s)throw Error(`Images in a CubeMap must be squares, but we got ${e}×${s}!`);if(0===this._width)this._width=e,this._height=s;else if(this._width!==e||this._height!==s)throw Error(`Images in a CubeMap must all have the same size, but we got ${this._width}×${this._height} and ${e}×${s}!`);const{gl:r,texture:n}=this;r.bindTexture(r.TEXTURE_CUBE_MAP,n),r.texImage2D(t,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,i),this.numberOfImagesToLoad--,0===this.numberOfImagesToLoad&&(console.log("All images have been loaded!"),console.log(this.width,this.height),r.generateMipmap(r.TEXTURE_CUBE_MAP),r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_MIN_FILTER,r.LINEAR_MIPMAP_LINEAR),this.refresh())}}class M extends f{constructor(t,i){super(),this.gl=t,this.refresh=i}actualCreate(t){return new P(this.gl,this.refresh,t)}actualDelete(t){t instanceof P&&t.delete()}makeKeyFromInput(t){return t}}class z extends f{constructor(t,i){super(),this.gl=t,this.refresh=i}actualCreate(t){return new U(this.gl,this.refresh,t)}actualDelete(t){t instanceof U&&t.delete()}makeKeyFromInput(t){return t}}class I{constructor(t,i,e){var s,r;this.gl=t;const n=t.createBuffer();if(!n)throw Error("Unable to create WebGLBuffer!");this._target=null!==(s=null==e?void 0:e.target)&&void 0!==s?s:"ARRAY_BUFFER",this._usage=null!==(r=null==e?void 0:e.usage)&&void 0!==r?r:"STATIC_DRAW",this.buffer=n,i&&this.bufferData(i,e)}get target(){return this._target}bind(t){const{gl:i,buffer:e}=this;this._target=null!=t?t:this._target,i.bindBuffer(i[this._target],e)}bufferData(t,i={}){var e;const{gl:s}=this;this.bind(i.target),this._usage=null!==(e=i.usage)&&void 0!==e?e:this._usage,s.bufferData(s[this._target],t,s[this._usage])}delete(){const{gl:t,buffer:i}=this;t.deleteBuffer(i)}}class R{constructor(t,i,e,s){this.gl=t,this.drawBuffers=[],this.elemBuffer=null;const r=t.createVertexArray();if(!r)throw Error("Unable to create VertexArrayObject!");if(this.vao=r,i&&e){if(t.bindVertexArray(r),this.drawBuffers=e.map((e=>{const s=new I(t,e.dataView,{target:e.target,usage:e.usage});return s.bind(),e.defineAttributes(t,i),s})),s){const i=new I(t,s,{target:"ELEMENT_ARRAY_BUFFER"});i.bind(),this.elemBuffer=i}t.bindVertexArray(null)}}bind(){this.gl.bindVertexArray(this.vao)}unbind(){this.gl.bindVertexArray(null)}delete(){const{gl:t,vao:i,drawBuffers:e,elemBuffer:s}=this;t.deleteVertexArray(i),e.forEach((t=>t.delete())),s&&s.delete()}}class X{constructor(t,i={}){var e;this.canvas=t,this.painters=new g,this.isPlaying=!1,this.requestAnimationFrame=-1,this.lastTime=-1,this.paint=()=>{window.cancelAnimationFrame(this.requestAnimationFrame),this.requestAnimationFrame=window.requestAnimationFrame(this.actualPaint)},this.actualPaint=t=>{const{lastTime:i}=this;if(i<0)return this.lastTime=t,void this.paint();const e=t-this.lastTime;this.lastTime=t,this.painters.paint(t,e),this.painters.update(t,e),this.isPlaying&&this.paint()};const s=t.getContext("webgl2",i);if(!s)throw Error("Unable to create a WebGL2 context!");this.gl=s,this.programs=new b(s),this.textures2D=new M(s,this.paint),this.texturesCube=new z(s,this.paint);const r=null!==(e=i.onResize)&&void 0!==e?e:Y;this.observer=new ResizeObserver((()=>{r(s,t.clientWidth,t.clientHeight)})),this.observer.observe(t)}get width(){return this.gl.drawingBufferWidth}get height(){return this.gl.drawingBufferHeight}get playing(){return this.isPlaying}set playing(t){t!==this.isPlaying&&(t&&this.paint(),this.isPlaying=t)}play(){this.playing=!0}pause(){this.playing=!1}add(...t){this.painters.add(...t)}remove(...t){this.painters.remove(...t)}createBuffer(t,i){return new I(this.gl,t,i)}createVAO(t,i,e){return new R(this.gl,t,i,e)}destroy(){window.cancelAnimationFrame(this.requestAnimationFrame),this.playing=!1,this.painters.delete(),this.observer.unobserve(this.canvas)}}function Y(t,i,e){const s=t.canvas;s.width=i,s.height=e,t.viewport(0,0,i,e)}class L{constructor(){this.keysDown=new Set,this.keysUp=new Set,this.attached=!1,this.handleKeyDown=t=>{this.keysDown.add(t.key),this.keysUp.delete(t.key)},this.handleKeyUp=t=>{this.keysDown.delete(t.key),this.keysUp.add(t.key)},document.addEventListener("keydown",this.handleKeyDown),document.addEventListener("keyup",this.handleKeyUp),this.attached=!0}detach(){this.attached&&(document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("keyup",this.handleKeyUp),this.attached=!1)}isPressed(...t){for(const i of t)if(!this.keysDown.has(i))return!1;return!0}hasClicked(t){return!!this.keysUp.has(t)&&(this.keysUp.delete(t),!0)}}class N{constructor(t){var i;this.options=t,this.start={x:0,y:0,t:0},this.current={x:0,y:0,t:0},this.previous={x:0,y:0,t:0},this.canvas=null,this.active=!1,this.canvasX=0,this.canvasY=0,this.screenX=0,this.screenY=0,this.inertiaDirX=0,this.inertiaDirY=0,this.inertiaStart=0,this.inertiaStop=!0,this.inertiaRunning=!1,this.inertiaTimeStamp=0,this.inertiaLastRefresh=0,this.handleCanvasWheel=t=>{const{onZoom:i}=this.options;i&&i(t.deltaY,(()=>t.preventDefault()))},this.handleCanvasPointerDown=t=>{t.isPrimary&&(this.canvasX=t.clientX,this.canvasY=t.clientY,this.active=!0,this.inertiaStop=!0)},this.handlePointerDown=t=>{var i,e;if(!t.isPrimary||!this.active)return;this.screenX=t.clientX,this.screenY=t.clientY;const s=this.getPoint(t);this.start=this.current=s,null===(e=(i=this.options).onMoveStart)||void 0===e||e.call(i,s)},this.handlePointerMove=t=>{var i,e;t.isPrimary&&this.active&&this.canvas&&(this.previous=this.current,this.current=this.getPoint(t),null===(e=(i=this.options).onMove)||void 0===e||e.call(i,this))},this.handlePointerUp=t=>{var i,e;if(!t.isPrimary||!this.active)return;this.current=this.getPoint(t),null===(e=(i=this.options).onMoveEnd)||void 0===e||e.call(i,this.current),this.active=!1,this.inertiaStart=t.timeStamp,this.inertiaStop=!1,this.inertiaRunning=!1;const s=this.current.t-this.previous.t,r=s>0?1/s:0;this.inertiaDirX=r*(this.current.x-this.previous.x),this.inertiaDirY=r*(this.current.y-this.previous.y),window.requestAnimationFrame(this.simulateInertia)},this.simulateInertia=t=>{const{onMove:i}=this.options;if(!i||this.inertiaDuration<=0)return;if(this.inertiaStop)return;this.inertiaRunning||(this.inertiaTimeStamp=t,this.inertiaLastRefresh=t,this.inertiaRunning=!0);const e=t-this.inertiaTimeStamp,s=1-e/this.inertiaDuration;if(s<=0||s>1)return;const r=e-this.inertiaLastRefresh;this.inertiaLastRefresh=e;const n=this.inertiaDirX*r*s,h=this.inertiaDirY*r*s;this.previous=Object.assign({},this.current),this.current.t=this.previous.t+r,this.current.x+=n,this.current.y+=h;const{current:o,previous:a,start:c}=this;i({current:o,previous:a,start:c}),window.requestAnimationFrame(this.simulateInertia)},this.inertiaDuration=null!==(i=t.inertia)&&void 0!==i?i:0,t.canvas&&this.attach(t.canvas)}get element(){return this.canvas}attach(t){this.detach(),this.canvas=t,t.addEventListener("pointerdown",this.handleCanvasPointerDown,!0),t.addEventListener("wheel",this.handleCanvasWheel),document.addEventListener("pointerdown",this.handlePointerDown),document.addEventListener("pointermove",this.handlePointerMove),document.addEventListener("pointerup",this.handlePointerUp)}detach(){const{canvas:t}=this;t&&(t.removeEventListener("pointerdown",this.handleCanvasPointerDown),t.removeEventListener("wheel",this.handleCanvasWheel),document.removeEventListener("pointerdown",this.handlePointerDown),document.removeEventListener("pointermove",this.handlePointerMove),document.removeEventListener("pointerup",this.handlePointerUp),this.canvas=null)}getPoint(t){if(!this.canvas)throw Error("No canvas has been defined!");const{left:i,top:e,width:s,height:r}=this.canvas.getBoundingClientRect();return{x:2*((this.canvasX+t.clientX-this.screenX-i)/s-.5),y:-2*((this.canvasY+t.clientY-this.screenY-e)/r-.5),t:t.timeStamp}}}class S{constructor(t,i={}){this.camera=t,this.pointer=null,this.keyboard=new L,this.handleMove=t=>{const{camera:i,keyboard:e}=this;if(t.current.t-t.previous.t<=0)return;if(e.isPressed("z")){const e=t.previous.x,s=t.previous.y;if(Math.abs(e)+Math.abs(s)===0)return;const r=t.current.x,n=t.current.y;if(Math.abs(r)+Math.abs(n)===0)return;const h=e*r+s*n,o=e*n-s*r,a=Math.atan2(o,h);return void i.orbitAroundZ(-a)}const s=2*(t.current.x-t.previous.x),r=2*(t.current.y-t.previous.y);e.isPressed("x")||i.orbitAroundY(-s),e.isPressed("y")||i.orbitAroundX(r)},this.handleZoom=(t,i)=>{const{camera:e}=this,s=.001*-t;e.zoom=Math.max(1,e.zoom+s),i()},this.options=Object.assign({inertia:500},i)}attach(t){this.pointer&&this.pointer.detach(),this.pointer=new N({canvas:t,onMove:this.handleMove,onZoom:this.handleZoom,inertia:this.options.inertia})}detach(){this.pointer&&(this.pointer.detach(),this.pointer=null)}}class D{constructor(t,i={}){var e,s,r;this.data=null,this.count=0,this.target=null!==(e=i.target)&&void 0!==e?e:"ARRAY_BUFFER",this.usage=null!==(s=i.usage)&&void 0!==s?s:"STATIC_DRAW";const n=null!==(r=i.divisor)&&void 0!==r?r:0;let h=0;const o={},a={};for(const i of Object.keys(t)){const e=i;o[i]=new ArrayBuffer(0);const s={dimension:j[t[e]],bytesOffset:h,bytesPerElement:Float32Array.BYTES_PER_ELEMENT,divisor:n,getter:(t,i)=>(i>=t.byteLength&&(i%=t.byteLength),t.getFloat32(i)),setter(t,i,e){t.setFloat32(i,e)}};a[i]=s,h+=s.bytesPerElement*s.dimension}this.dataPerAttribute=o,this.definitions=a,this.stride=h}set(t,i){var e;if((e=i)&&"object"==typeof e&&i.buffer instanceof ArrayBuffer&&(i=i.buffer),this.dataPerAttribute[t]===i)return;this.dataPerAttribute[t]=i;const{bytesPerElement:s,dimension:r}=this.definitions[t];this.count=Math.max(this.count,Math.ceil(i.byteLength/(s*r))),this.data=null}get dataView(){if(!this.data){const t=new ArrayBuffer(this.stride*this.count),i=new DataView(t);let e=0;const{dataPerAttribute:s,definitions:r}=this;for(let t=0;t<this.count;t++)for(const n of Object.keys(r)){const h=r[n],o=s[n],a=new DataView(o);let c=h.bytesPerElement*h.dimension*t;for(let t=0;t<h.dimension;t++)h.setter(i,e,h.getter(a,c)),c+=h.bytesPerElement,e+=h.bytesPerElement}this.data=new DataView(t)}return this.data}defineAttributes(t,i){let e=0;const{definitions:s}=this;for(const r of Object.keys(s)){const n=s[r],h=i.getAttribLocation(r);t.enableVertexAttribArray(h),t.vertexAttribPointer(h,n.dimension,t.FLOAT,!1,this.stride,e),t.vertexAttribDivisor(h,n.divisor),e+=n.dimension*n.bytesPerElement}}}const j={float:1,vec2:2,vec3:3,vec4:4};class Z{}class F{constructor(t,i,{x:e=0,y:s=0,z:r=1,zoom:n=1}={}){this.context=t,this.zoom=1,this.x=0,this.y=0,this.z=1,this.x=e,this.y=s,this.z=r,this.zoom=n,this.texture=i,this.program=t.programs.create({vert:"#version 300 es\n\nuniform float uniZoom;\nuniform vec2 uniScale;\nuniform vec2 uniScroll;\nuniform float uniZ;\nin vec2 attPoint;\nin vec2 attUV;\nout vec2 varUV;\n\nvoid main() {\n varUV = (attUV + uniScroll) * uniZoom;\n float x = uniScale.x * attPoint.x;\n float y = uniScale.y * attPoint.y;\n gl_Position = vec4(x, y, uniZ, 1.0);\n}",frag:"#version 300 es\n\nprecision mediump float;\n\nuniform sampler2D uniTexture;\nin vec2 varUV;\nout vec4 FragColor;\n\nvoid main() {\n FragColor = texture(uniTexture, varUV);\n}"});const h=new D({attPoint:"vec2",attUV:"vec2"});h.set("attPoint",new Float32Array([-1,1,1,1,-1,-1,1,-1])),h.set("attUV",new Float32Array([0,0,1,0,0,1,1,1])),this.vao=t.createVAO(this.program,[h])}delete(){const{vao:t}=this;t.delete}paint(t,i){const{gl:e}=this.context,{vao:s,program:r,texture:n,zoom:h,x:o,y:a,z:c}=this;r.use();const{width:u,height:m}=this.context,l=n.width*m>n.height*u,d=l?n.width*m/(u*n.height):1,g=l?1:n.height*u/(m*n.width);r.uniform2f("uniScale",d,g),r.uniform2f("uniScroll",o,a),r.uniform1f("uniZoom",1/h),r.uniform1f("uniZ",c),n.activate(r,"uniTexture"),s.bind(),e.drawArrays(e.TRIANGLE_STRIP,0,4)}update(t,i){}}class V{constructor(t,i={}){var e,s;this.context=t,this.clearMask=0,this.red=1,this.green=.7,this.blue=0,this.alpha=1,this.depth=1;const{gl:r}=t,n=null!==(e=i.color)&&void 0!==e?e:[0,0,0,1],h=null!==(s=i.depth)&&void 0!==s?s:1;this.clearMask=0;let o=!1;if(i.color&&(this.clearMask|=r.COLOR_BUFFER_BIT,o=!0),"number"==typeof i.depth&&(this.clearMask|=r.DEPTH_BUFFER_BIT,o=!0),!o)throw Error("[TgdPainterClear] You must give at least a color or a depth in the constructor!");[this.red,this.green,this.blue,this.alpha]=n,this.depth=h}delete(){}paint(t,i){const{clearMask:e,context:s,red:r,green:n,blue:h,alpha:o,depth:a}=this,{gl:c}=s;c.clearColor(r,n,h,o),c.clearDepth(a),c.clear(e)}update(t,i){}}class C{constructor(t){this.logicFunction=t}delete(){}paint(t,i){}update(t,i){this.logicFunction(t,i)}}class O{constructor(t,i){this.context=t,this.matrix=new r,this.tmpMat=new r,this.camera=i.camera,this.texture=t.texturesCube.create(i),this.program=t.programs.create({vert:"#version 300 es\n\nin vec4 attPoint;\n\nout vec4 varPoint;\n\nvoid main() {\n varPoint = attPoint;\n gl_Position = vec4(attPoint.xy, 0.999, 1.0);\n}",frag:"#version 300 es\n\nprecision highp float;\n\nuniform samplerCube uniTexture;\nuniform mat4 uniMatrix;\n\nin vec4 varPoint;\n\nout vec4 FragColor;\n\nvoid main() {\n vec4 t = uniMatrix * varPoint;\n FragColor = texture(uniTexture, normalize(t.xyz / t.w));\n}"});const e=new D({attPoint:"vec2"});e.set("attPoint",new Float32Array([-1,1,1,1,-1,-1,1,-1])),this.vao=t.createVAO(this.program,[e])}delete(){const{vao:t}=this;t.delete}paint(t,i){const{gl:e}=this.context,{vao:s,program:r,texture:n}=this;e.enable(e.DEPTH_TEST),e.depthFunc(e.LESS),e.depthMask(!0),e.depthRange(0,1),r.use(),r.uniformMatrix4fv("uniMatrix",this.matrix),n.activate(r,"uniTexture"),s.bind(),e.drawArrays(e.TRIANGLE_STRIP,0,4)}update(t,i){const{camera:e,matrix:s,tmpMat:r}=this;s.from(e.matrixProjection),r.fromMat3(e.matrixViewModel),r.m30=0,r.m31=0,r.m32=0,r.m33=1,r.m03=0,r.m13=0,r.m23=0,s.multiply(r).invert()}}class k{constructor(){this.name="Mesh",this.attPosition=[],this.attNormal=[],this.attUV=[],this.elements=[],this.elementIndex=0,this.vertices=[],this.normals=[],this.uvs=[],this.map=new Map,this.onObject=t=>{this.name=t},this.onVertex=(t,i,e)=>{this.vertices.push([t,i,e])},this.onNormal=(t,i,e)=>{this.normals.push([t,i,e])},this.onTexture=(t,i)=>{this.uvs.push([t,i])},this.onFace=t=>{if(3!==t.length)throw Error("We can only deal with triangles!");t.forEach((t=>this.elements.push(this.getElem(t))))}}parse(t){this.reset();const{onVertex:i,onNormal:e,onTexture:s,onFace:r,onObject:n,name:h,elements:o}=this;!function(t,i={}){const{onVertex:e,onNormal:s,onTexture:r,onFace:n,onObject:h}=i;for(const i of function*(t){const i=t.length;let e=0,s=0;for(;e>-1&&e<i&&(e=t.indexOf("\n",s),!(e<0));)yield t.substring(s,e).trim(),s=e+1;return t.substring(s).trim()}(t)){const t=i.trimStart();if(e&&t.startsWith("v ")){const i=t.substring(2).split(" ").map((t=>Number(t)));B(i)&&e(...i)}else if(n&&t.startsWith("f "))n(t.substring(2).split(" ").map((t=>{const[i,e,s]=t.split("/");return{vertex:Number(i)-1,normal:s?Number(s)-1:void 0,uv:e?Number(e)-1:void 0}})));else if(s&&t.startsWith("vn ")){const i=t.substring(3).split(" ").map((t=>Number(t)));B(i)&&s(...i)}else if(r&&t.startsWith("vt ")){const[i,e,s]=t.substring(3).split(" ").map((t=>Number(t)));r(i,e,s)}else h&&t.startsWith("o ")&&h(t.substring(2))}}(t,{onVertex:i,onNormal:e,onTexture:s,onFace:r,onObject:n});const a={name:h,count:Math.floor(o.length/3),attPosition:new Float32Array(this.attPosition)};this.attNormal.length>0&&(a.attNormal=new Float32Array(this.attNormal)),this.attUV.length>0&&(a.attUV=new Float32Array(this.attUV)),console.log("🚀 [wavefront] this.attUV = ",this.attUV);const{elementIndex:c}=this;return c<=256?(console.log("UNSIGNED_BYTE"),Object.assign(Object.assign({},a),{type:"UNSIGNED_BYTE",elements:new Uint8Array(o)})):c<=65536?(console.log("UNSIGNED_SHORT"),Object.assign(Object.assign({},a),{type:"UNSIGNED_SHORT",elements:new Uint16Array(o)})):(console.log("UNSIGNED_INT"),Object.assign(Object.assign({},a),{type:"UNSIGNED_INT",elements:new Uint32Array(o)}))}reset(){this.name="Mesh",this.attPosition=[],this.attNormal=[],this.attUV=[],this.elements=[],this.elementIndex=0,this.vertices=[],this.normals=[],this.uvs=[],this.map.clear()}getElem(t){var i;const e=this.key(t),s=null!==(i=this.map.get(e))&&void 0!==i?i:-1;if(s>-1)return s;const[r,n,h]=this.vertices[t.vertex];if(this.attPosition.push(r,n,h),"number"==typeof t.normal){const[i,e,s]=this.normals[t.normal];this.attNormal.push(i,e,s)}if("number"==typeof t.uv){const[i,e]=this.uvs[t.uv];this.attUV.push(i,e)}return this.map.set(e,this.elementIndex),this.elementIndex++}key(t){return`${t.vertex}/${t.normal}`}}function B(t){return 3===t.length}var W=i.Uj,G=i.w1,$=i.$M,q=i.aT,H=i.OY,K=i.yr,Q=i.Zc,J=i.tz,tt=i.Yp,it=i.Wk,et=i.pD,st=i.WM,rt=i.Op,nt=i.ui,ht=i.ts,ot=i.sh,at=i.a7,ct=i.EK,ut=i.cX,mt=i.qG,lt=i.Ui,dt=i.YE,gt=i.Zk;export{W as TdgInputKeyboard,G as TdgResourceTexture2D,$ as TdgResourceTextureCube,q as TgdCamera,H as TgdCameraOrthographic,K as TgdCameraPerspective,Q as TgdContext,J as TgdControllerCameraOrbit,tt as TgdDataset,it as TgdMat4,et as TgdPainter,st as TgdPainterBackground,rt as TgdPainterClear,nt as TgdPainterGroup,ht as TgdPainterLogic,ot as TgdPainterSkybox,at as TgdParserMeshWavefront,ct as TgdQuat,ut as TgdResource,mt as TgdResourceProgram,lt as TgdVec3,dt as TgdVec4,gt as TgdVertexArray};
|
|
1
|
+
var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function i(t,e=6){const i=Math.pow(10,e),s=[];let n=0;for(const r of t){const t=(Math.round(r*i)/i).toFixed(e);n=Math.max(n,t.length),s.push(t)}return s.map((t=>t.padStart(n," ")))}t.d(e,{Ev:()=>m,ch:()=>l,op:()=>d,_G:()=>Z,ED:()=>N,sT:()=>Y,CM:()=>P,WG:()=>X,EL:()=>D,U1:()=>B,wB:()=>n,gR:()=>g,Ku:()=>j,ck:()=>V,Wk:()=>k,kV:()=>W,Yv:()=>f,cL:()=>G,Se:()=>H,Hq:()=>$,ML:()=>q,mI:()=>K,aW:()=>o,W0:()=>p,CV:()=>b,S6:()=>I,aS:()=>S,yo:()=>s,qM:()=>r,y0:()=>L,kH:()=>M});class s extends Float32Array{constructor(t=0,e=0,i=0){if(super(3),"number"!=typeof t)return this.x=t[0],this.y=t[1],void(this.z=t[2]);this.x=t,this.y=e,this.z=i}clone(){return new s(this)}isEqual([t,e,i]){return t===this.x&&e===this.y&&i===this.z}isClose([t,e,i],s=1e-6){return!(Math.abs(t-this.x)>s||Math.abs(e-this.y)>s||Math.abs(i-this.z)>s)}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),[n,r,o]=this,[a,h,c]=t,u=h*o-c*r,m=c*n-a*o,l=a*r-h*n,d=(n*a+r*h+o*c)*(1-i);return this.x=n*i+u*s+a*d,this.y=r*i+m*s+h*d,this.z=o*i+l*s+c*d,this}applyMatrix(t){const{x:e,y:i,z:s}=this;return this.x=e*t.m00+i*t.m10+s*t.m20,this.y=e*t.m01+i*t.m11+s*t.m21,this.z=e*t.m02+i*t.m12+s*t.m22,this}from([t,e,i]){return this.x=t,this.y=e,this.z=i,this}get x(){return this[0]}set x(t){this[0]=t}get y(){return this[1]}set y(t){this[1]=t}get z(){return this[2]}set z(t){this[2]=t}add(...t){for(const e of t)this[0]+=e[0],this[1]+=e[1],this[2]+=e[2];return this}addWithScale([t,e,i],s=1){return this[0]+=t*s,this[1]+=e*s,this[2]+=i*s,this}subtract(t){return this[0]-=t[0],this[1]-=t[1],this[2]-=t[2],this}scale(t){return this[0]*=t,this[1]*=t,this[2]*=t,this}dot(t){return this[0]*t[0]+this[1]*t[1]+this[2]*t[2]}get size(){return Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2])}normalize(){const t=this[0]*this[0]+this[1]*this[1]+this[2]*this[2];return 0===t?this:this.scale(1/Math.sqrt(t))}cross([t,e,i]){const[s,n,r]=this;this[0]=n*i-e*r,this[1]=r*t-i*s,this[2]=s*e-t*n}random(){return this[0]=Math.random()-.5,this[1]=Math.random()-.5,this[2]=Math.random()-.5,this}debug(t="vec3"){const{x:e,y:i,z:s}=this,n=[e,i,s].map((t=>t.toFixed(6)));console.log(`${t}: `,n.join(" | ")," length:",Math.sqrt(e*e+i*i+s*s))}}class n extends Float32Array{constructor(t=1,e=0,i=0,s=0,n=0,r=1,o=0,a=0,h=0,c=0,u=1,m=0,l=0,d=0,g=0,f=1){super("number"==typeof t?[t,e,i,s,n,r,o,a,h,c,u,m,l,d,g,f]:t)}multiply(t){const[e,i,s,n,r,o,a,h,c,u,m,l,d,g,f,x]=this,[p,v,y,w,E,A,b,T,_,P,M,U,R,z,I,S]=t;return this.m00=e*p+r*v+c*y+d*w,this.m10=e*E+r*A+c*b+d*T,this.m20=e*_+r*P+c*M+d*U,this.m30=e*R+r*z+c*I+d*S,this.m01=i*p+o*v+u*y+g*w,this.m11=i*E+o*A+u*b+g*T,this.m21=i*_+o*P+u*M+g*U,this.m31=i*R+o*z+u*I+g*S,this.m02=s*p+a*v+m*y+f*w,this.m12=s*E+a*A+m*b+f*T,this.m22=s*_+a*P+m*M+f*U,this.m32=s*R+a*z+m*I+f*S,this.m03=n*p+h*v+l*y+x*w,this.m13=n*E+h*A+l*b+x*T,this.m23=n*_+h*P+l*M+x*U,this.m33=n*R+h*z+l*I+x*S,this}invert(){const[t,e,i,s,n,r,o,a,h,c,u,m,l,d,g,f]=this,x=t*r-e*n,p=t*o-i*n,v=t*a-s*n,y=e*o-i*r,w=e*a-s*r,E=i*a-s*o,A=h*d-c*l,b=h*g-u*l,T=h*f-m*l,_=c*g-u*d,P=c*f-m*d,M=u*f-m*g,U=x*M-p*P+v*_+y*T-w*b+E*A;if(!U)return this;const R=1/U;return this[0]=(r*M-o*P+a*_)*R,this[1]=(i*P-e*M-s*_)*R,this[2]=(d*E-g*w+f*y)*R,this[3]=(u*w-c*E-m*y)*R,this[4]=(o*T-n*M-a*b)*R,this[5]=(t*M-i*T+s*b)*R,this[6]=(g*v-l*E-f*p)*R,this[7]=(h*E-u*v+m*p)*R,this[8]=(n*P-r*T+a*A)*R,this[9]=(e*T-t*P-s*A)*R,this[10]=(l*w-d*v+f*x)*R,this[11]=(c*v-h*w-m*x)*R,this[12]=(r*b-n*_-o*A)*R,this[13]=(t*_-e*b+i*A)*R,this[14]=(d*p-l*y-g*x)*R,this[15]=(h*y-c*p+u*x)*R,this}get translation(){const{m30:t,m31:e,m32:i}=this;return new s(t,e,i)}set translation(t){this.m30=t.x,this.m31=t.y,this.m32=t.z}from(t){return this.m00=t.m00,this.m01=t.m01,this.m02=t.m02,this.m03=t.m03,this.m10=t.m10,this.m11=t.m11,this.m12=t.m12,this.m13=t.m13,this.m20=t.m20,this.m21=t.m21,this.m22=t.m22,this.m23=t.m23,this.m30=t.m30,this.m31=t.m31,this.m32=t.m32,this.m33=t.m33,this}fromMat3(t){return this.m00=t.m00,this.m01=t.m01,this.m02=t.m02,this.m10=t.m10,this.m11=t.m11,this.m12=t.m12,this.m20=t.m20,this.m21=t.m21,this.m22=t.m22,this}toAxis(t,e,i){return this.toAxisX(t),this.toAxisY(e),this.toAxisZ(i)}toAxisX(t){return t.x=this.m00,t.y=this.m01,t.z=this.m02,this}toAxisY(t){return t.x=this.m10,t.y=this.m11,t.z=this.m12,this}toAxisZ(t){return t.x=this.m20,t.y=this.m21,t.z=this.m22,this}fromQuat({x:t,y:e,z:i,w:s}){const n=t+t,r=e+e,o=i+i,a=t*n,h=e*n,c=e*r,u=i*n,m=i*r,l=i*o,d=s*n,g=s*r,f=s*o;return this.m00=1-c-l,this.m10=h-f,this.m20=u+g,this.m01=h+f,this.m11=1-a-l,this.m21=m-d,this.m02=u-g,this.m12=m+d,this.m22=1-a-c,this}get m00(){return this[0]}set m00(t){this[0]=t}get m01(){return this[1]}set m01(t){this[1]=t}get m02(){return this[2]}set m02(t){this[2]=t}get m03(){return this[3]}set m03(t){this[3]=t}get m10(){return this[4]}set m10(t){this[4]=t}get m11(){return this[5]}set m11(t){this[5]=t}get m12(){return this[6]}set m12(t){this[6]=t}get m13(){return this[7]}set m13(t){this[7]=t}get m20(){return this[8]}set m20(t){this[8]=t}get m21(){return this[9]}set m21(t){this[9]=t}get m22(){return this[10]}set m22(t){this[10]=t}get m23(){return this[11]}set m23(t){this[11]=t}get m30(){return this[12]}set m30(t){this[12]=t}get m31(){return this[13]}set m31(t){this[13]=t}get m32(){return this[14]}set m32(t){this[14]=t}get m33(){return this[15]}set m33(t){this[15]=t}debug(t="Mat4"){const e=i([this.m00,this.m01,this.m02,this.m03]),s=i([this.m10,this.m11,this.m12,this.m13]),n=i([this.m20,this.m21,this.m22,this.m23]),r=i([this.m30,this.m31,this.m32,this.m33]);console.log(t),console.log(" ",[e[0],s[0],n[0],r[0]].join(" | ")),console.log(" ",[e[1],s[1],n[1],r[1]].join(" | ")),console.log(" ",[e[2],s[2],n[2],r[2]].join(" | ")),console.log(" ",[e[3],s[3],n[3],r[3]].join(" | "))}}class r extends Float32Array{constructor(t=0,e=0,i=0,n=1){return super(4),t instanceof r?(this.x=t.x,this.y=t.y,this.z=t.z,void(this.w=t.w)):t instanceof s?(this.x=t.x,this.y=t.y,this.z=t.z,void(this.w=n)):(this.x=t,this.y=e,this.z=i,void(this.w=n))}reset(t=0,e=0,i=0,s=1){return this.x=t,this.y=e,this.z=i,this.w=s,this}from(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this}clone(){return new r(this)}isEqual({x:t,y:e,z:i,w:s}){return t===this.x&&e===this.y&&i===this.z&&s===this.w}isClose({x:t,y:e,z:i,w:s},n=1e-6){return!(Math.abs(t-this.x)>n||Math.abs(e-this.y)>n||Math.abs(i-this.z)>n||Math.abs(s-this.w)>n)}applyMatrix(t){const{x:e,y:i,z:s,w:n}=this;return this.x=e*t.m00+i*t.m10+s*t.m20+n*t.m30,this.y=e*t.m01+i*t.m11+s*t.m21+n*t.m31,this.z=e*t.m02+i*t.m12+s*t.m22+n*t.m32,this.w=e*t.m03+i*t.m13+s*t.m23+n*t.m33,this}get x(){return this[0]}set x(t){this[0]=t}get y(){return this[1]}set y(t){this[1]=t}get z(){return this[2]}set z(t){this[2]=t}get w(){return this[3]}set w(t){this[3]=t}add(...t){for(const e of t)this[0]+=e[0],this[1]+=e[1],this[2]+=e[2],this[3]+=e[3];return this}subtract(t){return this[0]-=t[0],this[1]-=t[1],this[2]-=t[2],this[3]-=t[3],this}scale(t){return this[0]*=t,this[1]*=t,this[2]*=t,this[3]*=t,this}dot(t){return this[0]*t[0]+this[1]*t[1]+this[2]*t[2]+this[3]*t[3]}get size(){return Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]+this[3]*this[3])}normalize(){const t=this[0]*this[0]+this[1]*this[1]+this[2]*this[2]+this[3]*this[3];return 0===t?this:this.scale(1/Math.sqrt(t))}debug(t="vec4"){const{x:e,y:i,z:s,w:n}=this,r=[e,i,s,n].map((t=>t.toFixed(6)));console.log(`${t}: `,r.join(" | "))}}class o extends r{constructor(t=0,e=0,i=0,s=1){"number"==typeof t?super(t,e,i,s):super(t)}clone(){return new o(this)}multiply(t){const[e,i,s,n]=this,[r,o,a,h]=t;return this[0]=h*e+r*n-o*s+a*i,this[1]=h*i+r*s+o*n-a*e,this[2]=h*s-r*i+o*e+a*n,this[3]=h*n-r*e-o*i-a*s,this}fromAxis(t,e,i){const s=t.x+e.y+i.z;if(s>0){const n=Math.sqrt(s+1);this.w=.5*n;const r=.5/n;this.x=(e.z-i.y)*r,this.y=(i.x-t.z)*r,this.z=(t.y-e.x)*r}else{const s=[t,e,i];let n=0;e.y>t.x&&(n=1),i.z>s[n][n]&&(n=2);const r=(n+1)%3,o=(n+2)%3;let a=Math.sqrt(s[n][n]-s[r][r]-s[o][o]+1);this[n]=.5*a,a=.5/a,this[3]=(s[r][o]-s[o][r])*a,this[r]=(s[r][n]+s[n][r])*a,this[o]=(s[o][n]+s[n][o])*a}return this.normalize()}rotateAroundX(t){const e=.5*t,i=this[0],s=this[1],n=this[2],r=this[3],o=Math.sin(e),a=Math.cos(e);return this[0]=i*a+r*o,this[1]=s*a+n*o,this[2]=n*a-s*o,this[3]=r*a-i*o,this}rotateAroundY(t){const e=.5*t,i=this[0],s=this[1],n=this[2],r=this[3],o=Math.sin(e),a=Math.cos(e);return this[0]=i*a-n*o,this[1]=s*a+r*o,this[2]=n*a+i*o,this[3]=r*a-s*o,this}rotateAroundZ(t){const e=.5*t,i=this[0],s=this[1],n=this[2],r=this[3],o=Math.sin(e),a=Math.cos(e);return this[0]=i*a+s*o,this[1]=s*a-i*o,this[2]=n*a+r*o,this[3]=r*a-n*o,this}toAxisZ(t){const{x:e,y:i,z:s,w:n}=this,r=e+e,o=i+i,a=e*r,h=i*o,c=s*r,u=s*o,m=n*r,l=n*o;return t.x=c+l,t.y=u-m,t.z=1-a-h,t}face(t="+X+Y+Z"){const[e,i,s,n]=c[t];return this.x=e,this.y=i,this.z=s,this.w=n,this}}const a=Math.sqrt(2)/2,h=.5,c={"+X+Y+Z":[0,0,0,1],"-Z+Y+X":[0,+a,0,+a],"-X+Y-Z":[0,1,0,0],"+Z+Y-X":[0,-a,0,+a],"+X+Z-Y":[+a,0,0,+a],"+Y+Z+X":[+h,+h,+h,+h],"-X+Z+Y":[0,+a,+a,0],"-Y+Z-X":[+h,-h,-h,+h],"+X-Y-Z":[1,0,0,0],"+X-Z+Y":[-a,0,0,+a],"-X-Y+Z":[0,0,1,0],"-X-Z-Y":[0,+a,-a,0],"+Y+X-Z":[+a,+a,0,0],"+Y-X+Z":[0,0,+a,+a],"+Y-Z-X":[+h,+h,-h,-h],"-Y+X+Z":[0,0,-a,+a],"-Y-X-Z":[+a,-a,0,0],"-Y-Z+X":[+h,-h,+h,-h],"+Z+X+Y":[+h,+h,+h,-h],"+Z-X-Y":[+h,-h,+h,+h],"+Z-Y+X":[+a,0,+a,0],"-Z+X-Y":[+h,+h,-h,+h],"-Z-X+Y":[+h,-h,-h,-h],"-Z-Y-X":[+a,0,-a,0]};class u extends Float32Array{constructor(t=1,e=0,i=0,s=0,n=1,r=0,o=0,a=0,h=1){super("number"==typeof t?[t,e,i,s,n,r,o,a,h]:t)}transpose(){let t=this.m10;return this.m10=this.m01,this.m01=t,t=this.m20,this.m20=this.m02,this.m02=t,t=this.m21,this.m21=this.m12,this.m12=t,this}fromQuat({x:t,y:e,z:i,w:s}){const n=t+t,r=e+e,o=i+i,a=t*n,h=e*n,c=e*r,u=i*n,m=i*r,l=i*o,d=s*n,g=s*r,f=s*o;return this.m00=1-c-l,this.m10=h-f,this.m20=u+g,this.m01=h+f,this.m11=1-a-l,this.m21=m-d,this.m02=u-g,this.m12=m+d,this.m22=1-a-c,this}toAxis(t,e,i){return this.toAxisX(t),this.toAxisY(e),this.toAxisZ(i)}toAxisX(t){return t.x=this.m00,t.y=this.m01,t.z=this.m02,this}toAxisY(t){return t.x=this.m10,t.y=this.m11,t.z=this.m12,this}toAxisZ(t){return t.x=this.m20,t.y=this.m21,t.z=this.m22,this}scale(t){return this[0]*=t,this[1]*=t,this[2]*=t,this[3]*=t,this[4]*=t,this[5]*=t,this[6]*=t,this[7]*=t,this[8]*=t,this}get m00(){return this[0]}set m00(t){this[0]=t}get m01(){return this[1]}set m01(t){this[1]=t}get m02(){return this[2]}set m02(t){this[2]=t}get m10(){return this[3]}set m10(t){this[3]=t}get m11(){return this[4]}set m11(t){this[4]=t}get m12(){return this[5]}set m12(t){this[5]=t}get m20(){return this[6]}set m20(t){this[6]=t}get m21(){return this[7]}set m21(t){this[7]=t}get m22(){return this[8]}set m22(t){this[8]=t}debug(t="Mat3"){const e=i([this.m00,this.m01,this.m02]),s=i([this.m10,this.m11,this.m12]),n=i([this.m20,this.m21,this.m22]);console.log(t),console.log(" ",[e[0],s[0],n[0]].join(" | ")),console.log(" ",[e[1],s[1],n[1]].join(" | ")),console.log(" ",[e[2],s[2],n[2]].join(" | "))}}class m{constructor(){this.dirtyProjection=!0,this._screenWidth=1920,this._screenHeight=1080,this._screenAspectRatio=1920/1080,this.dirty=!0,this.dirtyAxis=!0,this.axisX=new s,this.axisY=new s,this.axisZ=new s,this._matrixViewModel=new n,this.orientation=new o(0,0,0,1),this.target=new s(0,0,0),this._distance=10,this._zoom=1,this.tmpMat3=new u,this.tmpVec3=new s,this.face("+X+Y+Z")}get screenAspectRatio(){return this._screenAspectRatio}get screenWidth(){return this._screenWidth}set screenWidth(t){t!==this._screenWidth&&(this._screenWidth=t,this.dirtyProjection=!0,this._screenAspectRatio=this._screenWidth/this._screenHeight)}get screenHeight(){return this._screenHeight}set screenHeight(t){t!==this._screenHeight&&(this._screenHeight=t,this.dirtyProjection=!0,this._screenAspectRatio=this._screenWidth/this._screenHeight)}face(t){this.orientation.face(t),this.dirty=!0,this.dirtyAxis=!0}from(t){const{orientation:e,target:i,distance:s,zoom:n,screenWidth:r,screenHeight:o}=t;return this.orientation.from(e),this.target.from(i),this.distance=s,this.zoom=n,this.screenWidth=r,this.screenHeight=o,this.dirty=!0,this.dirtyAxis=!0,this.copyProjectionFrom(t),this}copyOrientationFrom({orientation:t}){this.setOrientation(t)}toAxisX(t){return this.updateAxisIfNeeded(),t.from(this.axisX),this}toAxisY(t){return this.updateAxisIfNeeded(),t.from(this.axisY),this}toAxisZ(t){return this.updateAxisIfNeeded(),t.from(this.axisZ),this}get matrixViewModel(){return this.updateIfNeeded(),this._matrixViewModel}setOrientation(t){const{orientation:e}=this;if(t.isEqual(e))return;const[i,s,n,r]=t;e.x=i,e.y=s,e.z=n,e.w=r,this.dirty=!0,this.dirtyAxis=!0}setTarget(t){const{target:e}=this;if(t.isEqual(e))return;const[i,s,n]=t;e.x=i,e.y=s,e.z=n,this.dirty=!0}get x(){return this.target.x}set x(t){const{target:e}=this;t!==e.x&&(e.x=t,this.dirty=!0)}get y(){return this.target.y}set y(t){const{target:e}=this;t!==e.y&&(e.y=t,this.dirty=!0)}get z(){return this.target.z}set z(t){const{target:e}=this;t!==e.z&&(e.z=t,this.dirty=!0)}get distance(){return this._distance}set distance(t){this._distance!==t&&(this._distance=t,this.dirty=!0)}get zoom(){return this._zoom}set zoom(t){this._zoom!==t&&(this._zoom=t,this.dirty=!0)}moveTarget(t,e,i){const{target:s}=this;this.updateAxisIfNeeded();const{axisX:n,axisY:r,axisZ:o,tmpVec3:a}=this;a.from(n).scale(t).addWithScale(r,e).addWithScale(o,i),s.x+=a.x,s.y+=a.y,s.z+=a.z,this.dirty=!0}orbitAroundX(t){this.updateAxisIfNeeded();const{axisX:e,axisY:i,axisZ:s,orientation:n}=this;return i.rotateAround(e,t),s.rotateAround(e,t),n.fromAxis(e,i,s),this.dirty=!0,this}orbitAroundY(t){this.updateAxisIfNeeded();const{axisX:e,axisY:i,axisZ:s,orientation:n}=this;return e.rotateAround(i,t),s.rotateAround(i,t),n.fromAxis(e,i,s),this.dirty=!0,this}orbitAroundZ(t){this.updateAxisIfNeeded();const{axisX:e,axisY:i,axisZ:s,orientation:n}=this;return e.rotateAround(s,t),i.rotateAround(s,t),n.fromAxis(e,i,s),this.dirty=!0,this}debug(t="Camera"){this.orientation.debug(`${t} quaternion:`)}updateAxisIfNeeded(){this.dirtyAxis&&this.updateAxis()}updateAxis(){const{tmpMat3:t}=this;if(t.fromQuat(this.orientation),t.toAxis(this.axisX,this.axisY,this.axisZ),this.dirtyAxis=!1,Math.abs(1-this.axisX.size)>.1||Math.abs(1-this.axisY.size)>.1||Math.abs(1-this.axisZ.size)>.1)throw this.axisX.debug("Axis X"),this.axisY.debug("Axis Y"),this.axisZ.debug("Axis Z"),Error("STOP!")}updateIfNeeded(){if(!this.dirty)return;const{tmpMat3:t,tmpVec3:e}=this,i=this._matrixViewModel;this.updateAxis();const s=this._distance,{x:n,y:r,z:o}=this.target,{x:a,y:h,z:c}=this.axisZ;e.x=n+s*a,e.y=r+s*h,e.z=o+s*c,e.applyMatrix(t.transpose()).scale(-1/this.zoom),i.m30=e.x,i.m31=e.y,i.m32=e.z;const u=this._zoom;1!==u&&t.scale(u),i.fromMat3(t),this.dirty=!1}}class l extends m{constructor(){super(),this._matrixProjection=new n,this._spaceHeight=10,this._near=.001,this._far=1e3}copyProjectionFrom(t){return this.spaceHeight=t.spaceHeight,this}get spaceHeight(){return this._spaceHeight}set spaceHeight(t){t!==this._spaceHeight&&(this._spaceHeight=t,this.dirtyProjection=!0)}get near(){return this._near}set near(t){t!==this._near&&(this._near=t,this.dirtyProjection=!0)}get far(){return this._far}set far(t){t!==this._far&&(this._far=t,this.dirtyProjection=!0)}get matrixProjection(){return this.updateProjectionIfNeeded(),this._matrixProjection}updateProjectionIfNeeded(){if(!this.dirtyProjection)return;const{near:t,far:e,screenAspectRatio:i,_spaceHeight:s}=this,n=.5*s,r=-n,o=n*i,a=-o,h=this._matrixProjection,c=1/(a-o),u=1/(r-n),m=1/(t-e);h[0]=-2*c,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=-2*u,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[10]=m,h[11]=0,h[12]=(a+o)*c,h[13]=(n+r)*u,h[14]=t*m,h[15]=1,this.dirtyProjection=!0}}class d extends m{constructor(){super(),this._matrixProjection=new n,this._fovy=Math.PI/4,this._near=.001,this._far=1/0}copyProjectionFrom(t){return this.fovy=t.fovy,this.near=t.near,this.far=t.far,this}get fovy(){return this._fovy}set fovy(t){t!==this._fovy&&(this._fovy=t,this.dirtyProjection=!0)}get near(){return this._near}set near(t){t!==this._near&&(this._near=t,this.dirtyProjection=!0)}get far(){return this._far}set far(t){t!==this._far&&(this._far=t,this.dirtyProjection=!0)}get matrixProjection(){return this.updateProjectionIfNeeded(),this._matrixProjection}updateProjectionIfNeeded(){if(!this.dirtyProjection)return;const t=this._fovy,e=this.screenAspectRatio,i=this._near,s=this._far,n=this._matrixProjection,r=1/Math.tan(t/2);if(n[0]=r/e,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=r,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[11]=-1,n[12]=0,n[13]=0,n[15]=0,s!==1/0){const t=1/(i-s);n[10]=(s+i)*t,n[14]=2*s*i*t}else n[10]=-1,n[14]=-2*i;this.dirtyProjection=!0}}class g{}class f extends g{constructor(t=[],{onEnter:e,onExit:i}={}){super(),this.active=!0,this.onEnter=e,this.onExit=i,this.painters=[...t]}has(t){return this.painters.includes(t)}add(...t){for(const e of t)this.painters.push(e)}remove(...t){for(const e of t){const t=this.painters.indexOf(e);t<0||(this.painters.splice(t,1),e.delete())}}removeAll(){for(const t of this.painters)t.delete();this.painters.splice(0,this.painters.length)}delete(){for(const t of this.painters)t.delete();this.painters.splice(0,this.painters.length)}paint(t,e){var i,s;if(this.active){null===(i=this.onEnter)||void 0===i||i.call(this,t,e);for(const i of this.painters)i.paint(t,e);null===(s=this.onExit)||void 0===s||s.call(this,t,e)}}}let x=1;class p{constructor(){this.keys=new Map,this.objects=new Map,this.references=new Map}create(t,e){var i,s;const n=null!==(i=null!=e?e:this.makeKeyFromInput(t))&&void 0!==i?i:"TgdResource:"+x++,r=null!==(s=this.references.get(n))&&void 0!==s?s:0;if(r<1){const e=this.actualCreate(t,n);return this.keys.set(e,n),this.objects.set(n,e),this.references.set(n,1),e}const o=this.objects.get(n);if(!o)throw Error("[TgdResource.create] Panic!");return this.references.set(n,r+1),o}delete(t){var e;const i=this.keys.get(t);if(!i)return;const s=null!==(e=this.references.get(i))&&void 0!==e?e:0;s<1||(s>1?this.references.set(i,s-1):(this.keys.delete(t),this.objects.delete(i),this.references.delete(i),this.actualDelete(t)))}makeKeyFromInput(t){return null}}class v{constructor(t,e){var i;this.gl=t;const s=t.createProgram();if(!s)throw Error("Unable to create WebGLProgram!");const n=this.createShader("VERTEX_SHADER",e.vert);t.attachShader(s,n);const r=this.createShader("FRAGMENT_SHADER",e.frag);if(t.attachShader(s,r),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){var o=null!==(i=t.getProgramInfoLog(s))&&void 0!==i?i:"";console.warn(o);const n=w(o);throw A("Vertex Shader",e.vert,n),A("Fragment Shader",e.frag,n),new Error("Could NOT link WebGL2 program!\n"+o)}this.program=s,this.shaders=[n,r],this.uniformsLocations=this.getUniformsLocations()}getAttribLocation(t){const{gl:e,program:i}=this,s=e.getAttribLocation(i,t);if(s<0)throw Error(`Attribute "${t}" not found!`);return s}getUniformLocation(t){const{uniformsLocations:e}=this,i=Object.keys(e);if(0===t.length)throw Error(`Uniform "${t}" has not been found: there is no active uniform in this program!`);const s=e[t];if(!s)throw Error(`No active uniform found with name "${t}"!\nAvailable names are: ${i.join(", ")}.`);return s}uniform1f(t,e){const{gl:i}=this;i.uniform1f(this.getUniformLocation(t),e)}uniform2f(t,e,i){const{gl:s}=this;s.uniform2f(this.getUniformLocation(t),e,i)}uniform3f(t,e,i,s){const{gl:n}=this;n.uniform3f(this.getUniformLocation(t),e,i,s)}uniform3fv(t,e){const{gl:i}=this;i.uniform3fv(this.getUniformLocation(t),e)}uniform4f(t,e,i,s,n){const{gl:r}=this;r.uniform4f(this.getUniformLocation(t),e,i,s,n)}uniform4fv(t,e){const{gl:i}=this;i.uniform4fv(this.getUniformLocation(t),e)}uniform1i(t,e){const{gl:i}=this;i.uniform1i(this.getUniformLocation(t),e)}uniform2i(t,e,i){const{gl:s}=this;s.uniform2i(this.getUniformLocation(t),e,i)}uniform3i(t,e,i,s){const{gl:n}=this;n.uniform3i(this.getUniformLocation(t),e,i,s)}uniform4i(t,e,i,s,n){const{gl:r}=this;r.uniform4i(this.getUniformLocation(t),e,i,s,n)}uniform1ui(t,e){const{gl:i}=this;i.uniform1ui(this.getUniformLocation(t),e)}uniform2ui(t,e,i){const{gl:s}=this;s.uniform2ui(this.getUniformLocation(t),e,i)}uniform3ui(t,e,i,s){const{gl:n}=this;n.uniform3ui(this.getUniformLocation(t),e,i,s)}uniform4ui(t,e,i,s,n){const{gl:r}=this;r.uniform4ui(this.getUniformLocation(t),e,i,s,n)}uniformMatrix4fv(t,e){const{gl:i}=this;i.uniformMatrix4fv(this.getUniformLocation(t),!1,e)}use(){const{gl:t,program:e}=this;t.useProgram(e)}delete(){const{gl:t}=this;this.shaders.forEach((e=>t.deleteShader(e))),t.deleteProgram(this.program)}createShader(t,e){const{gl:i}=this,s=i.createShader(i[t]);if(!s)throw Error(`Unable to create a WebGLShader of type "${t}"!`);i.shaderSource(s,e),i.compileShader(s);const n=i.getShaderInfoLog(s);if(n)throw console.error(`Error in ${t} code:`,n),A(t,e,w(n)),Error(`Unable to compile ${t}!`);return s}getUniformsLocations(){const{gl:t,program:e}=this,i=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);if("number"!=typeof i)throw Error("Unable to get the number of uniforms in a WebGLProgram!");const s={};for(let n=0;n<i;n++){const i=t.getActiveUniform(e,n);if(!i)continue;const r=t.getUniformLocation(e,i.name);if(null===r)throw Error(`Unable to get location for uniform "${i.name}"!`);s[i.name]=r}return s}}const y=/^ERROR:[ \t]+([0-9]+):([0-9]+):/g;function w(t){const e=[],i=[];for(const s of t.split("\n")){y.lastIndex=-1;const t=y.exec(s);t&&(e.push(parseInt(t[2],10)),i.push(s.substring(t[0].length).trim()))}return{lines:e,messages:i}}function E(t,e=!1){return`color:#fff;background:${t};font-family:monospace;font-size:80%;font-weight:${e?"bolder":"100"}`}function A(t,e,i){console.log(`%c${t}`,"font-weight:bolder;font-size:120%"),e.split("\n").forEach(((t,e)=>{const s=e+1,n=(1e-4*s).toFixed(4).substring(2),r=i.lines.includes(s)?"#f00":"#000";console.log(`%c${n} %c${t}`,E(r),E(r,!0)),i.lines.includes(s)&&console.error(i.messages[i.lines.indexOf(s)])}))}class b extends p{constructor(t){super(),this.gl=t}actualCreate(t){return new v(this.gl,t)}actualDelete(t){t instanceof v&&t.delete()}makeKeyFromInput(t){return JSON.stringify(t)}}var T=function(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{h(s.next(t))}catch(t){r(t)}}function a(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))};class _{static image(t){return T(this,void 0,void 0,(function*(){return new Promise((e=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>{console.error("Unable to load image: ",t),e(null)},i.src=t}))}))}static canvas(t){return T(this,void 0,void 0,(function*(){const e=yield _.image(t);if(!e)return null;const i=document.createElement("canvas");i.width=e.naturalWidth,i.height=e.naturalHeight;const s=i.getContext("2d");if(!s)throw Error("Unable to get a 2D context!");return s.drawImage(e,0,0),i}))}}class P{constructor(){this.listeners=new Set}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}dispatch(t){this.listeners.forEach((e=>e(t)))}}function M(t,e,i){const s=document.createElement("canvas");s.width=t,s.height=e;const n=s.getContext("2d",i);if(!n)throw Error("Unable to create 2D context!");return{canvas:s,ctx:n}}const U=new Uint8Array([200,200,200,255]);class R{constructor(t,e,i={}){this.context=t,this.id=e,this.eventImageUpdate=new P,this._width=0,this._height=0,this._image=null;const{gl:s}=t;this.options=Object.assign({wrapS:"REPEAT",wrapT:"REPEAT",wrapR:"REPEAT",minFilter:"NEAREST_MIPMAP_LINEAR",magFilter:"LINEAR"},i);const n=s.createTexture();if(!n)throw Error("Unable to create a WebGLTexture!");this.texture=n,s.bindTexture(s.TEXTURE_2D,n),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,1,1,0,s.RGBA,s.UNSIGNED_BYTE,U);const{wrapS:r,wrapT:o,wrapR:a,minFilter:h,magFilter:c}=this.options;s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s[r]),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s[o]),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_R,s[a]),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s[h]),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s[c]),i.image&&this.loadImage(i.image)}makePalette(t,e=0){const i=e>0?e:t.length,s=Math.ceil(t.length/i),{canvas:n,ctx:r}=M(i,s);let o=0;for(let e=0;e<s;e++)for(let s=0;s<i;s++)r.fillStyle=t[o++],r.fillRect(s,e,1,1);this.loadImage(n)}fillHorizontalGradient(t,...e){this.fillGradient(t,1,1,0,...e)}fillverticalGradient(t,...e){this.fillGradient(1,t,0,1,...e)}fillGradient(t,e,i,s,...n){const{canvas:r,ctx:o}=M(t,e),a=o.createLinearGradient(0,0,t*i,e*s);for(let t=0;t<n.length;t++)a.addColorStop(t/(n.length-1),n[t]);o.fillStyle=a,o.fillRect(0,0,t,e),this.loadImage(r),r.style.position="fixed"}delete(){this.context.gl.deleteTexture(this.texture)}get image(){return this._image}get width(){return this._width}get height(){return this._height}bind(){const{gl:t}=this.context;t.bindTexture(t.TEXTURE_2D,this.texture)}activate(t,e,i=0){const{context:s,texture:n}=this,{gl:r}=s;r.activeTexture(r.TEXTURE0+i),r.bindTexture(r.TEXTURE_2D,n),t.uniform1i(e,i)}loadImage(t){if("string"==typeof t)return void _.image(t).then((e=>{e?(this.loadImage(e),this.context.paint()):console.error("[TgdTexture2D] Unable to load image:",t)})).catch(console.error);const{context:e,texture:i}=this,{gl:s}=e;s.bindTexture(s.TEXTURE_2D,i),t instanceof Image&&s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!0),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,t),s.generateMipmap(s.TEXTURE_2D),this._width=t.width,this._height=t.height,this._image=t,this.eventImageUpdate.dispatch(this)}}class z{constructor(t,e){this.context=t,this._width=0,this._height=0,this.numberOfImagesToLoad=6;const{gl:i}=t,s=i.createTexture();if(!s)throw Error("Unable to create a WebGLTexture!");this.texture=s,this.loadImage(i.TEXTURE_CUBE_MAP_POSITIVE_X,e.imagePosX),this.loadImage(i.TEXTURE_CUBE_MAP_NEGATIVE_X,e.imageNegX),this.loadImage(i.TEXTURE_CUBE_MAP_POSITIVE_Y,e.imagePosY),this.loadImage(i.TEXTURE_CUBE_MAP_NEGATIVE_Y,e.imageNegY),this.loadImage(i.TEXTURE_CUBE_MAP_POSITIVE_Z,e.imagePosZ),this.loadImage(i.TEXTURE_CUBE_MAP_NEGATIVE_Z,e.imageNegZ)}delete(){this.context.gl.deleteTexture(this.texture)}get ready(){return 0===this.numberOfImagesToLoad}get width(){return this._width}get height(){return this._height}bind(){const{gl:t}=this.context;t.bindTexture(t.TEXTURE_CUBE_MAP,this.texture)}activate(t,e,i=0){if(!this.ready)return;const{context:s,texture:n}=this,{gl:r}=s;r.activeTexture(r.TEXTURE0+i),r.bindTexture(r.TEXTURE_CUBE_MAP,n),t.uniform1i(e,i)}loadImage(t,e){if("string"==typeof e)return void _.image(e).then((i=>{i?this.loadImage(t,i):console.error(`[TgdTextureCube] Unable to load image "${e}":`,e)})).catch((t=>{console.error(`[TgdTextureCube] Unable to load image "${e}":`,t)}));const{width:i,height:s}=e;if(i!==s)throw Error(`Images in a CubeMap must be squares, but we got ${i}×${s}!`);if(0===this._width)this._width=i,this._height=s;else if(this._width!==i||this._height!==s)throw Error(`Images in a CubeMap must all have the same size, but we got ${this._width}×${this._height} and ${i}×${s}!`);const{context:n,texture:r}=this,{gl:o}=n;o.bindTexture(o.TEXTURE_CUBE_MAP,r),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,e instanceof Image),o.texImage2D(t,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,e),this.numberOfImagesToLoad--,0===this.numberOfImagesToLoad&&(console.log("All images have been loaded!"),console.log(this.width,this.height),o.generateMipmap(o.TEXTURE_CUBE_MAP),o.texParameteri(o.TEXTURE_CUBE_MAP,o.TEXTURE_MIN_FILTER,o.LINEAR_MIPMAP_LINEAR),n.paint())}}class I extends p{constructor(t){super(),this.context=t}actualCreate(t,e){return new R(this.context,e,t)}actualDelete(t){t instanceof R&&t.delete()}}class S extends p{constructor(t){super(),this.context=t}actualCreate(t){return new z(this.context,t)}actualDelete(t){t instanceof z&&t.delete()}}class C{constructor(t,e,i){var s,n;this.gl=t;const r=t.createBuffer();if(!r)throw Error("Unable to create WebGLBuffer!");this._target=null!==(s=null==i?void 0:i.target)&&void 0!==s?s:"ARRAY_BUFFER",this._usage=null!==(n=null==i?void 0:i.usage)&&void 0!==n?n:"STATIC_DRAW",this.buffer=r,e&&this.bufferData(e,i)}get target(){return this._target}bind(t){const{gl:e,buffer:i}=this;this._target=null!=t?t:this._target,e.bindBuffer(e[this._target],i)}bufferData(t,e={}){var i;const{gl:s}=this;this.bind(e.target),this._usage=null!==(i=e.usage)&&void 0!==i?i:this._usage,s.bufferData(s[this._target],t,s[this._usage])}delete(){const{gl:t,buffer:e}=this;t.deleteBuffer(e)}}class L{constructor(t,e,i,s){this.gl=t,this.drawBuffers=[],this.elemBuffer=null;const n=t.createVertexArray();if(!n)throw Error("Unable to create VertexArrayObject!");if(this.vao=n,e&&i){if(t.bindVertexArray(n),this.drawBuffers=i.map((i=>{const s=new C(t,i.dataView,{target:i.target,usage:i.usage});return s.bind(),i.defineAttributes(t,e),s})),s){const e=new C(t,s,{target:"ELEMENT_ARRAY_BUFFER"});e.bind(),this.elemBuffer=e}t.bindVertexArray(null)}}bind(){this.gl.bindVertexArray(this.vao)}unbind(){this.gl.bindVertexArray(null)}delete(){const{gl:t,vao:e,drawBuffers:i,elemBuffer:s}=this;t.deleteVertexArray(e),i.forEach((t=>t.delete())),s&&s.delete()}}class X{constructor(){this.keysDown=new Set,this.keysUp=new Set,this.attached=!1,this.handleKeyDown=t=>{this.keysDown.add(t.key),this.keysUp.delete(t.key)},this.handleKeyUp=t=>{this.keysDown.delete(t.key),this.keysUp.add(t.key)},document.addEventListener("keydown",this.handleKeyDown),document.addEventListener("keyup",this.handleKeyUp),this.attached=!0}detach(){this.attached&&(document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("keyup",this.handleKeyUp),this.attached=!1)}isDown(...t){for(const e of t)if(!this.keysDown.has(e))return!1;return!0}hasClicked(t){return!!this.keysUp.has(t)&&(this.keysUp.delete(t),!0)}}class D{constructor(t){this.canvas=t,this.eventMoveStart=new P,this.eventMove=new P,this.eventMoveEnd=new P,this.eventZoom=new P,this.inertia=0,this.start={x:0,y:0,t:0,fingersCount:1},this.current={x:0,y:0,t:0,fingersCount:1},this.previous={x:0,y:0,t:0,fingersCount:1},this.active=!1,this.canvasX=0,this.canvasY=0,this.screenX=0,this.screenY=0,this.inertiaDirX=0,this.inertiaDirY=0,this.inertiaStop=!0,this.inertiaRunning=!1,this.inertiaTimeStamp=0,this.inertiaLastRefresh=0,this.handleCanvasWheel=t=>{let e=t.deltaX+t.deltaY+t.deltaZ;e=e>0?1:-1,this.eventZoom.dispatch({current:this.getPoint(t),direction:e,preventDefault:()=>t.preventDefault()})},this.handleCanvasPointerDown=t=>{t.isPrimary&&(this.canvasX=t.clientX,this.canvasY=t.clientY,this.active=!0,this.inertiaStop=!0)},this.handlePointerDown=t=>{if(!t.isPrimary||!this.active)return;this.screenX=t.clientX,this.screenY=t.clientY;const e=this.getPoint(t);this.start=this.current=this.previous=e,this.eventMoveStart.dispatch({start:e})},this.handlePointerMove=t=>{t.isPrimary&&this.active&&this.canvas&&(this.previous=this.current,this.current=this.getPoint(t),this.eventMove.dispatch({start:this.start,current:this.current,previous:this.previous}))},this.handlePointerUp=t=>{if(!t.isPrimary||!this.active)return;this.current=this.getPoint(t),this.eventMoveEnd.dispatch({start:this.start,current:this.current,previous:this.previous}),this.active=!1,this.inertiaStop=!1,this.inertiaRunning=!1;const e=this.current.t-this.previous.t,i=e>0?1/e:0;this.inertiaDirX=i*(this.current.x-this.previous.x),this.inertiaDirY=i*(this.current.y-this.previous.y),window.requestAnimationFrame(this.simulateInertia)},this.simulateInertia=t=>{if(this.inertia<=0||this.inertiaStop)return;this.inertiaRunning||(this.inertiaTimeStamp=t,this.inertiaLastRefresh=t,this.inertiaRunning=!0);const e=t-this.inertiaTimeStamp,i=1-e/this.inertia;if(i<=0||i>1)return;const s=e-this.inertiaLastRefresh;this.inertiaLastRefresh=e;const n=this.inertiaDirX*s*i,r=this.inertiaDirY*s*i;this.previous=Object.assign({},this.current),this.current.t=this.previous.t+s,this.current.x+=n,this.current.y+=r;const{current:o,previous:a,start:h}=this;this.eventMove.dispatch({current:o,previous:a,start:h}),window.requestAnimationFrame(this.simulateInertia)},t.addEventListener("pointerdown",this.handleCanvasPointerDown,!0),t.addEventListener("wheel",this.handleCanvasWheel),document.addEventListener("pointerdown",this.handlePointerDown),document.addEventListener("pointermove",this.handlePointerMove),document.addEventListener("pointerup",this.handlePointerUp)}detach(){const{canvas:t}=this;t&&(t.removeEventListener("pointerdown",this.handleCanvasPointerDown),t.removeEventListener("wheel",this.handleCanvasWheel),document.removeEventListener("pointerdown",this.handlePointerDown),document.removeEventListener("pointermove",this.handlePointerMove),document.removeEventListener("pointerup",this.handlePointerUp))}getPoint(t){const{left:e,top:i,width:s,height:n}=this.canvas.getBoundingClientRect();return{x:2*((this.canvasX+t.clientX-this.screenX-e)/s-.5),y:-2*((this.canvasY+t.clientY-this.screenY-i)/n-.5),t:t.timeStamp,fingersCount:1}}}class B{constructor(t){this.canvas=t,this._keyboard=null,this._pointer=null}get keyboard(){return this._keyboard||(this._keyboard=new X),this._keyboard}get pointer(){return this._pointer||(this._pointer=new D(this.canvas)),this._pointer}}class Z{constructor(t,e={}){var i;this.canvas=t,this._texturesCube=null,this.isPlaying=!1,this.requestAnimationFrame=-1,this.lastTime=-1,this.paint=()=>{window.cancelAnimationFrame(this.requestAnimationFrame),this.requestAnimationFrame=window.requestAnimationFrame(this.actualPaint)},this.actualPaint=t=>{const{lastTime:e,gl:i}=this;if(e<0)return this.lastTime=t,void this.paint();const s=t-this.lastTime;this.lastTime=t,this.camera.screenWidth=i.drawingBufferWidth,this.camera.screenHeight=i.drawingBufferHeight,this.painters.paint(t,s),this.isPlaying&&this.paint()};const s=t.getContext("webgl2",e);if(!s)throw Error("Unable to create a WebGL2 context!");this.gl=s,this.programs=new b(s),this.textures2D=new I(this);const n=null!==(i=e.onResize)&&void 0!==i?i:F;this.observer=new ResizeObserver((()=>{n(s,t.clientWidth,t.clientHeight)})),this.observer.observe(t),this.inputs=new B(t),this.camera=new d,this.painters=new f,t.style.touchAction="none"}get texturesCube(){return this._texturesCube||(this._texturesCube=new S(this)),this._texturesCube}get onEnter(){return this.painters.onEnter}set onEnter(t){this.painters.onEnter=t}get onExit(){return this.painters.onExit}set onExit(t){this.painters.onExit=t}get width(){return this.gl.drawingBufferWidth}get height(){return this.gl.drawingBufferHeight}get playing(){return this.isPlaying}set playing(t){t!==this.isPlaying&&(t&&this.paint(),this.isPlaying=t)}play(){this.playing=!0}pause(){this.playing=!1}has(t){return this.painters.has(t)}add(...t){this.painters.add(...t)}remove(...t){this.painters.remove(...t)}removeAll(){this.painters.removeAll()}createBuffer(t,e){return new C(this.gl,t,e)}createVAO(t,e,i){return new L(this.gl,t,e,i)}destroy(){window.cancelAnimationFrame(this.requestAnimationFrame),this.playing=!1,this.painters.delete(),this.observer.unobserve(this.canvas)}}function F(t,e,i){const s=t.canvas;s.width=e,s.height=i,t.viewport(0,0,e,i)}class N{constructor(t,{speedZoom:e=1,speedOrbit:i=1}={}){this.context=t,this.enabled=!0,this.speedZoom=1,this.speedOrbit=1,this.eventZoomChange=new P,this.eventOrbitChange=new P,this.handleMove=t=>{if(!this.enabled)return;const{context:e}=this;if(t.current.t-t.previous.t<=0)return;const{keyboard:i}=e.inputs;if(i.isDown("z")){const i=t.previous.x,s=t.previous.y;if(Math.abs(i)+Math.abs(s)===0)return;const n=t.current.x,r=t.current.y;if(Math.abs(n)+Math.abs(r)===0)return;const o=i*n+s*r,a=i*r-s*n,h=Math.atan2(a,o)*this.speedOrbit;return e.camera.orbitAroundZ(-h),void this.fireOrbitChange()}const s=3*(i.isDown("Shift")?.1:1)*this.speedOrbit,n=(t.current.x-t.previous.x)*s,r=(t.current.y-t.previous.y)*s;i.isDown("x")||e.camera.orbitAroundY(-n),i.isDown("y")||e.camera.orbitAroundX(r),this.fireOrbitChange()},this.handleZoom=t=>{if(!this.enabled)return;const{camera:e}=this.context;let i=.05*this.speedZoom;this.context.inputs.keyboard.isDown("Shift")&&(i*=.1);const s=-t.direction*i;e.zoom=Math.max(1e-5,e.zoom+s),t.preventDefault(),this.fireZoomChange()};const{inputs:s}=t;s.pointer.eventMove.addListener(this.handleMove),s.pointer.eventZoom.addListener(this.handleZoom),this.speedOrbit=i,this.speedZoom=e}detach(){const{inputs:t}=this.context;t.pointer.eventMove.removeListener(this.handleMove),t.pointer.eventZoom.removeListener(this.handleZoom)}fireOrbitChange(){this.eventOrbitChange.dispatch(this),this.context.paint()}fireZoomChange(){this.eventZoomChange.dispatch(this),this.context.paint()}}class Y{constructor(t,e={}){var i,s,n;this.data=null,this.count=0,this.target=null!==(i=e.target)&&void 0!==i?i:"ARRAY_BUFFER",this.usage=null!==(s=e.usage)&&void 0!==s?s:"STATIC_DRAW";const r=null!==(n=e.divisor)&&void 0!==n?n:0;let o=0;const a={},h={};for(const e of Object.keys(t)){const i=e;a[e]=new ArrayBuffer(0);const s={dimension:O[t[i]],bytesOffset:o,bytesPerElement:Float32Array.BYTES_PER_ELEMENT,divisor:r,getter:(t,e)=>(e>=t.byteLength&&(e%=t.byteLength),t.getFloat32(e)),setter(t,e,i){t.setFloat32(e,i)}};h[e]=s,o+=s.bytesPerElement*s.dimension}this.dataPerAttribute=a,this.definitions=h,this.stride=o}set(t,e){var i;if((i=e)&&"object"==typeof i&&e.buffer instanceof ArrayBuffer&&(e=e.buffer),this.dataPerAttribute[t]===e)return;this.dataPerAttribute[t]=e;const{bytesPerElement:s,dimension:n}=this.definitions[t];this.count=Math.max(this.count,Math.ceil(e.byteLength/(s*n))),this.data=null}get(t){var e;return null!==(e=this.dataPerAttribute[t])&&void 0!==e?e:new ArrayBuffer(0)}get dataView(){if(!this.data){const t=new ArrayBuffer(this.stride*this.count),e=new DataView(t);let i=0;const{dataPerAttribute:s,definitions:n}=this;for(let t=0;t<this.count;t++)for(const r of Object.keys(n)){const o=n[r],a=s[r],h=new DataView(a);let c=o.bytesPerElement*o.dimension*t;for(let t=0;t<o.dimension;t++)o.setter(e,i,o.getter(h,c)),c+=o.bytesPerElement,i+=o.bytesPerElement}this.data=new DataView(t)}return this.data}defineAttributes(t,e){let i=0;const{definitions:s}=this;for(const n of Object.keys(s)){const r=s[n],o=e.getAttribLocation(n);t.enableVertexAttribArray(o),t.vertexAttribPointer(o,r.dimension,t.FLOAT,!1,this.stride,i),t.vertexAttribDivisor(o,r.divisor),i+=r.dimension*r.bytesPerElement}}}const O={float:1,vec2:2,vec3:3,vec4:4};class j extends g{constructor(t,{x:e=0,y:i=0,z:s=0,scale:n=1}={}){super(),this.context=t;const o=t.programs.create({vert:"#version 300 es\n\nprecision mediump float;\n\nuniform vec4 uniTS;\nuniform mat4 uniModelViewMatrix;\nuniform mat4 uniProjectionMatrix;\n\nin vec3 attPos;\nin vec4 attColor;\n\nout vec4 varColor;\n\nvoid main() {\n varColor = attColor;\n vec3 translate = uniTS.xyz;\n float scale = uniTS.w;\n gl_Position = uniProjectionMatrix \n * uniModelViewMatrix \n * vec4(attPos * scale + translate, 1.0);\n}\n",frag:"#version 300 es\n\nprecision mediump float;\n\nin vec4 varColor;\n\nout vec4 FragColor;\n\nvoid main() {\n FragColor = varColor;\n}"});this.prg=o;const a=new Y({attPos:"vec3",attColor:"vec4"});a.set("attPos",new Float32Array([0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,-1,-0,-0,0,0,0,-0,-1,-0,0,0,0,-0,-0,-1]));const h=.25;a.set("attColor",new Float32Array([1,0,0,1,1,0,0,1,0,1,0,1,0,1,0,1,0,0,1,1,0,0,1,1,h,0,0,1,h,0,0,1,0,h,0,1,0,h,0,1,0,0,h,1,0,0,h,1])),this.vao=t.createVAO(o,[a]),this.translateAndScale=new r(e,i,s,n)}get x(){return this.translateAndScale.x}set x(t){this.translateAndScale.x=t}get y(){return this.translateAndScale.y}set y(t){this.translateAndScale.y=t}get z(){return this.translateAndScale.z}set z(t){this.translateAndScale.z=t}get scale(){return this.translateAndScale.w}set scale(t){this.translateAndScale.w=t}delete(){this.vao.delete()}paint(t,e){const{context:i,prg:s,vao:n,translateAndScale:r}=this,{gl:o,camera:a}=i;s.use(),s.uniform4fv("uniTS",r),s.uniformMatrix4fv("uniModelViewMatrix",a.matrixViewModel),s.uniformMatrix4fv("uniProjectionMatrix",a.matrixProjection),n.bind(),o.drawArrays(o.LINES,0,12)}}class V extends g{constructor(t,e,{x:i=0,y:s=0,z:n=1,zoom:r=1}={}){super(),this.context=t,this.zoom=1,this.x=0,this.y=0,this.z=1,this.x=i,this.y=s,this.z=n,this.zoom=r,this.texture=e,this.program=t.programs.create({vert:"#version 300 es\n\nuniform float uniZoom;\nuniform vec2 uniScale;\nuniform vec2 uniScroll;\nuniform float uniZ;\nin vec2 attPoint;\nin vec2 attUV;\nout vec2 varUV;\n\nvoid main() {\n varUV = (attUV + uniScroll) * uniZoom;\n float x = uniScale.x * attPoint.x;\n float y = uniScale.y * attPoint.y;\n gl_Position = vec4(x, y, uniZ, 1.0);\n}",frag:"#version 300 es\n\nprecision mediump float;\n\nuniform sampler2D uniTexture;\nin vec2 varUV;\nout vec4 FragColor;\n\nvoid main() {\n FragColor = texture(uniTexture, varUV);\n}"});const o=new Y({attPoint:"vec2",attUV:"vec2"});o.set("attPoint",new Float32Array([-1,1,1,1,-1,-1,1,-1])),o.set("attUV",new Float32Array([0,0,1,0,0,1,1,1])),this.vao=t.createVAO(this.program,[o])}delete(){const{vao:t}=this;t.delete}paint(t,e){const{gl:i}=this.context,{vao:s,program:n,texture:r,zoom:o,x:a,y:h,z:c}=this;n.use();const{width:u,height:m}=this.context,l=r.width*m>r.height*u,d=l?r.width*m/(u*r.height):1,g=l?1:r.height*u/(m*r.width);n.uniform2f("uniScale",d,g),n.uniform2f("uniScroll",a,h),n.uniform1f("uniZoom",1/o),n.uniform1f("uniZ",c),r.activate(n,"uniTexture"),s.bind(),i.drawArrays(i.TRIANGLE_STRIP,0,4)}}class k{constructor(t,e={}){var i,s;this.context=t,this.clearMask=0,this.red=1,this.green=.7,this.blue=0,this.alpha=1,this.depth=1;const{gl:n}=t,r=null!==(i=e.color)&&void 0!==i?i:[0,0,0,1],o=null!==(s=e.depth)&&void 0!==s?s:1;this.clearMask=0;let a=!1;if(e.color&&(this.clearMask|=n.COLOR_BUFFER_BIT,a=!0),"number"==typeof e.depth&&(this.clearMask|=n.DEPTH_BUFFER_BIT,a=!0),!a)throw Error("[TgdPainterClear] You must give at least a color or a depth in the constructor!");[this.red,this.green,this.blue,this.alpha]=r,this.depth=o}delete(){}paint(t,e){const{clearMask:i,context:s,red:n,green:r,blue:o,alpha:a,depth:h}=this,{gl:c}=s;c.clearColor(n,r,o,a),c.clearDepth(h),c.clear(i)}update(t,e){}}class W extends g{constructor(t,{enabled:e=!0,func:i="LESS",mask:s=!0,rangeMin:n=0,rangeMax:r=1}={}){super(),this.context=t,this.enabled=e,this.func=i,this.mask=s,this.rangeMin=n,this.rangeMax=r}delete(){}paint(){const{gl:t}=this.context,{enabled:e}=this;if(!e)return void t.disable(t.DEPTH_TEST);const{func:i,mask:s,rangeMin:n,rangeMax:r}=this;t.enable(t.DEPTH_TEST),t.depthFunc(t[i]),t.depthMask(s),t.depthRange(n,r)}update(){}}class G extends g{constructor(t){super(),this.logicFunction=t}delete(){}paint(t,e){this.logicFunction(t,e)}}class H extends g{constructor(t,e,{roundness:i=3,minRadius:s=0}={}){if(super(),this.context=t,this.minRadius=0,this.radiusMultiplier=1,this.light=1,this.shiftZ=0,this.minRadius=s,i>125)throw Error("[TgdPainterSegments] Max roundness is 125!");if(i<0)throw Error("[TgdPainterSegments] Min roundness is 0!");const n=t.textures2D.create({magFilter:"NEAREST",minFilter:"NEAREST",wrapR:"CLAMP_TO_EDGE",wrapS:"CLAMP_TO_EDGE",wrapT:"CLAMP_TO_EDGE"});n.makePalette(["#f00","#0f0","#00f"]),this.colorTexture=n;const r=t.programs.create({vert:"#version 300 es\n\nprecision mediump float;\n\nuniform sampler2D uniTexture;\nuniform mat4 uniModelViewMatrix;\nuniform mat4 uniProjectionMatrix;\n// camera.zoom\nuniform float uniCameraZoom;\n// Minimal value for the radius.\nuniform float uniMinRadius;\n// Multiply all radii by this value.\nuniform float uniRadiusMultiplier;\n// Multiply the color by this value;\nuniform float uniLight;\n// Push the segments away from camera of `uniShiftZ`.\n// This can be used if you want contours on the segments:\n// just increase `uniRadiusMultiplier`, set a low `uniLight`,\n// and set a small positive `uniShiftZ`.\nuniform float uniShiftZ;\n\n//===================\n// Vertex attributes\n//-------------------\n\n// Position of the vertex, relative to\n// the current center and assuming a\n// radius of 1.\n// Z tells you what tip is your center: 0 for A and 1 for B.\nin vec3 attOffset;\n\n//=====================\n// Instance attributes\n//---------------------\n\n// Coords and radious of tip A.\nin vec4 attAxyzr;\n// Coords and radious of tip B.\nin vec4 attBxyzr;\n// // The color is taken from a texture.\nin vec2 attAuv;\nin vec2 attBuv;\n\n\nout vec4 varColor;\n\n\nvec3 worldToCamera(vec3 v);\nfloat getRadius(float tip);\nmat3 getTransfoMatrix(float tip, vec3 camA, vec3 camB);\n\nvoid main() {\n vec3 camA = worldToCamera(attAxyzr.xyz);\n vec3 camB = worldToCamera(attBxyzr.xyz);\n float tip = attOffset.z;\n varColor = texture(uniTexture, mix(attAuv, attBuv, tip))\n * vec4(uniLight, uniLight, uniLight, 1.0);\n float radius = getRadius(tip);\n mat3 transfo = getTransfoMatrix(tip, camA, camB);\n vec3 point = transfo * vec3(attOffset.xy * radius, 1.0);\n point.z -= uniShiftZ;\n gl_Position = \n uniProjectionMatrix \n * vec4(point, 1);\n}\n\nfloat getRadius(float tip) {\n float radius = mix(\n attAxyzr.w,\n attBxyzr.w,\n tip\n ) * uniRadiusMultiplier;\n return max(uniMinRadius, radius * uniCameraZoom);\n}\n\nvec3 worldToCamera(vec3 v) {\n vec4 result = uniModelViewMatrix * vec4(v, 1.0);\n return result.xyz;\n}\n\nmat3 getTransfoMatrix(float tip, vec3 camA, vec3 camB) {\n // What is the current tip?\n vec3 camO = mix(camA, camB, tip);\n vec2 A = camA.xy;\n vec2 B = camB.xy;\n vec3 Y = vec3(\n A == B ? vec2(0, 1) : normalize(A - B),\n 0\n );\n vec3 X = vec3(Y.y, -Y.x, 0);\n return mat3(X, Y, camO);\n}",frag:"#version 300 es\n\nprecision mediump float;\n\nin vec4 varColor;\nout vec4 FragColor;\n\n\nvoid main() {\n FragColor = varColor;\n}\n"});this.prg=r;const{capsule:o,elements:a}=function(t){const e=[0,0,0,1,0,0,-1,0,0,0,0,1,1,0,1,-1,0,1],i=[0,3,1,3,4,1,0,2,5,3,0,5];if(t>0){const s=(t,s,n,r)=>{const o=3*i[s],a=3*i[n],h=3*i[r];console.log(t,`(${e[o]}, ${e[o+1]}, ${e[o+2]}) (${e[a]}, ${e[a+1]}, ${e[a+2]}) (${e[h]}, ${e[h+1]}, ${e[h+2]})`)};let n=1,r=4,o=6;for(let a=0;a<t;a++){const h=Math.PI*(a+1)/(t+1),c=Math.cos(h),u=Math.sin(h);e.push(c,u,0),s("A",0,n,o),i.push(0,n,o),n=o,o++,e.push(c,-u,1),s("B",3,o,r),i.push(3,o,r),r=o,o++}i.push(0,n,2),i.push(3,5,r)}const s=new Y({attOffset:"vec3"});return s.set("attOffset",new Float32Array(e)),{capsule:s,elements:new Uint8Array(i)}}(i),h=e.makeDataset();this.vao=t.createVAO(r,[o,h],a),this.vertexCount=a.length,this.instanceCount=h.count}delete(){throw new Error("Method not implemented.")}paint(t,e){const{context:i,prg:s,vao:n,colorTexture:r,vertexCount:o,instanceCount:a,light:h,radiusMultiplier:c,shiftZ:u}=this,{gl:m,camera:d}=i;s.use();let g=this.minRadius;d instanceof l&&(g*=d.spaceHeight/d.screenHeight),s.uniform1f("uniMinRadius",g),s.uniform1f("uniLight",h),s.uniform1f("uniShiftZ",u),s.uniform1f("uniRadiusMultiplier",c),r.activate(s,"uniTexture"),s.uniform1f("uniCameraZoom",d.zoom),s.uniformMatrix4fv("uniModelViewMatrix",d.matrixViewModel),s.uniformMatrix4fv("uniProjectionMatrix",d.matrixProjection),n.bind(),m.drawElementsInstanced(m.TRIANGLES,o,m.UNSIGNED_BYTE,0,a)}}class ${constructor(){this._count=0,this.attAxyzr=[],this.attAuv=[],this.attBxyzr=[],this.attBuv=[]}get count(){return this._count}add([t,e,i,s],[n,r],[o,a,h,c],[u,m]){this.attAxyzr.push(t,e,i,s),this.attAuv.push(n,r),this.attBxyzr.push(o,a,h,c),this.attBuv.push(u,m),this._count++}makeDataset(){const t=new Y({attAxyzr:"vec4",attAuv:"vec2",attBxyzr:"vec4",attBuv:"vec2"},{divisor:1});return t.set("attAxyzr",new Float32Array(this.attAxyzr)),t.set("attAuv",new Float32Array(this.attAuv)),t.set("attBxyzr",new Float32Array(this.attBxyzr)),t.set("attBuv",new Float32Array(this.attBuv)),t}}class q extends g{constructor(t,e){var i;super(),this.context=t,this.matrix=new n,this.tmpMat=new n,this.camera=null!==(i=e.camera)&&void 0!==i?i:new d,this.texture=t.texturesCube.create(e),this.program=t.programs.create({vert:"#version 300 es\n\nin vec4 attPoint;\n\nout vec4 varPoint;\n\nvoid main() {\n varPoint = attPoint;\n gl_Position = vec4(attPoint.xy, 0.99999, 1.0);\n}",frag:"#version 300 es\n\nprecision highp float;\n\nuniform samplerCube uniTexture;\nuniform mat4 uniMatrix;\n\nin vec4 varPoint;\n\nout vec4 FragColor;\n\nvoid main() {\n vec4 t = uniMatrix * varPoint;\n FragColor = texture(uniTexture, normalize(t.xyz / t.w));\n}"});const s=new Y({attPoint:"vec2"});s.set("attPoint",new Float32Array([-1,1,1,1,-1,-1,1,-1])),this.vao=t.createVAO(this.program,[s])}delete(){const{vao:t}=this;t.delete}paint(t,e){const{context:i,vao:s,program:n,texture:r}=this,{gl:o}=i;n.use(),n.uniformMatrix4fv("uniMatrix",this.matrix),r.activate(n,"uniTexture"),s.bind(),o.drawArrays(o.TRIANGLE_STRIP,0,4);const{camera:a,matrix:h,tmpMat:c}=this;a!==i.camera&&a.copyOrientationFrom(i.camera),h.from(a.matrixProjection),c.fromMat3(a.matrixViewModel),c.m30=0,c.m31=0,c.m32=0,c.m33=1,c.m03=0,c.m13=0,c.m23=0,h.multiply(c).invert()}}class K{constructor(){this.name="Mesh",this.attPosition=[],this.attNormal=[],this.attUV=[],this.elements=[],this.elementIndex=0,this.vertices=[],this.normals=[],this.uvs=[],this.map=new Map,this.onObject=t=>{this.name=t},this.onVertex=(t,e,i)=>{this.vertices.push([t,e,i])},this.onNormal=(t,e,i)=>{this.normals.push([t,e,i])},this.onTexture=(t,e)=>{this.uvs.push([t,e])},this.onFace=t=>{if(3!==t.length)throw Error("We can only deal with triangles!");t.forEach((t=>this.elements.push(this.getElem(t))))}}parse(t){this.reset();const{onVertex:e,onNormal:i,onTexture:s,onFace:n,onObject:r,name:o,elements:a}=this;!function(t,e={}){const{onVertex:i,onNormal:s,onTexture:n,onFace:r,onObject:o}=e;for(const e of function*(t){const e=t.length;let i=0,s=0;for(;i>-1&&i<e&&(i=t.indexOf("\n",s),!(i<0));)yield t.substring(s,i).trim(),s=i+1;return t.substring(s).trim()}(t)){const t=e.trimStart();if(i&&t.startsWith("v ")){const e=t.substring(2).split(" ").map((t=>Number(t)));Q(e)&&i(...e)}else if(r&&t.startsWith("f "))r(t.substring(2).split(" ").map((t=>{const[e,i,s]=t.split("/");return{vertex:Number(e)-1,normal:s?Number(s)-1:void 0,uv:i?Number(i)-1:void 0}})));else if(s&&t.startsWith("vn ")){const e=t.substring(3).split(" ").map((t=>Number(t)));Q(e)&&s(...e)}else if(n&&t.startsWith("vt ")){const[e,i,s]=t.substring(3).split(" ").map((t=>Number(t)));n(e,i,s)}else o&&t.startsWith("o ")&&o(t.substring(2))}}(t,{onVertex:e,onNormal:i,onTexture:s,onFace:n,onObject:r});const h={name:o,count:Math.floor(a.length/3),attPosition:new Float32Array(this.attPosition)};this.attNormal.length>0&&(h.attNormal=new Float32Array(this.attNormal)),this.attUV.length>0&&(h.attUV=new Float32Array(this.attUV)),console.log("🚀 [wavefront] this.attUV = ",this.attUV);const{elementIndex:c}=this;return c<=256?(console.log("UNSIGNED_BYTE"),Object.assign(Object.assign({},h),{type:"UNSIGNED_BYTE",elements:new Uint8Array(a)})):c<=65536?(console.log("UNSIGNED_SHORT"),Object.assign(Object.assign({},h),{type:"UNSIGNED_SHORT",elements:new Uint16Array(a)})):(console.log("UNSIGNED_INT"),Object.assign(Object.assign({},h),{type:"UNSIGNED_INT",elements:new Uint32Array(a)}))}reset(){this.name="Mesh",this.attPosition=[],this.attNormal=[],this.attUV=[],this.elements=[],this.elementIndex=0,this.vertices=[],this.normals=[],this.uvs=[],this.map.clear()}getElem(t){var e;const i=this.key(t),s=null!==(e=this.map.get(i))&&void 0!==e?e:-1;if(s>-1)return s;const[n,r,o]=this.vertices[t.vertex];if(this.attPosition.push(n,r,o),"number"==typeof t.normal){const[e,i,s]=this.normals[t.normal];this.attNormal.push(e,i,s)}if("number"==typeof t.uv){const[e,i]=this.uvs[t.uv];this.attUV.push(e,i)}return this.map.set(i,this.elementIndex),this.elementIndex++}key(t){return`${t.vertex}/${t.normal}`}}function Q(t){return 3===t.length}var J=e.Ev,tt=e.ch,et=e.op,it=e._G,st=e.ED,nt=e.sT,rt=e.CM,ot=e.WG,at=e.EL,ht=e.U1,ct=e.wB,ut=e.gR,mt=e.Ku,lt=e.ck,dt=e.Wk,gt=e.kV,ft=e.Yv,xt=e.cL,pt=e.Se,vt=e.Hq,yt=e.ML,wt=e.mI,Et=e.aW,At=e.W0,bt=e.CV,Tt=e.S6,_t=e.aS,Pt=e.yo,Mt=e.qM,Ut=e.y0,Rt=e.kH;export{J as TgdCamera,tt as TgdCameraOrthographic,et as TgdCameraPerspective,it as TgdContext,st as TgdControllerCameraOrbit,nt as TgdDataset,rt as TgdEvent,ot as TgdInputKeyboardImpl,at as TgdInputPointerImpl,ht as TgdInputs,ct as TgdMat4,ut as TgdPainter,mt as TgdPainterAxis,lt as TgdPainterBackground,dt as TgdPainterClear,gt as TgdPainterDepth,ft as TgdPainterGroup,xt as TgdPainterLogic,pt as TgdPainterSegments,vt as TgdPainterSegmentsData,yt as TgdPainterSkybox,wt as TgdParserMeshWavefront,Et as TgdQuat,At as TgdResource,bt as TgdResourceProgram,Tt as TgdResourceTexture2D,_t as TgdResourceTextureCube,Pt as TgdVec3,Mt as TgdVec4,Ut as TgdVertexArray,Rt as tgdCreateCanvas2D};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|