three-zoo 0.0.2 → 0.0.4

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/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "three-zoo",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "zoo of tiny three js tools",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
7
10
  "exports": {
8
11
  ".": {
9
12
  "import": "./dist/index.js",
10
13
  "types": "./dist/index.d.ts"
11
- }
14
+ },
15
+ "./*": "./dist/*.js"
12
16
  },
13
17
  "scripts": {
14
18
  "build": "tsc"
@@ -1,10 +0,0 @@
1
- import { Material, Object3D } from "three";
2
- type Constructor<T> = abstract new (...args: never[]) => T;
3
- export declare class Object3DEnumerator {
4
- static getObjectByName(object: Object3D, name: string): Object3D | null;
5
- static getMaterialByName(object: Object3D, name: string): Material | null;
6
- static enumerateObjectsByType<T>(object: Object3D, type: Constructor<T>, callback: (instance: T) => void): void;
7
- static enumerateMaterials(object: Object3D, callback: (material: Material) => void): void;
8
- static setShadowRecursive(object: Object3D, castShadow?: boolean, receiveShadow?: boolean): void;
9
- }
10
- export {};
@@ -1,68 +0,0 @@
1
- import { Mesh } from "three";
2
- export class Object3DEnumerator {
3
- static getObjectByName(object, name) {
4
- if (object.name === name)
5
- return object;
6
- for (const child of object.children) {
7
- const result = Object3DEnumerator.getObjectByName(child, name);
8
- if (result)
9
- return result;
10
- }
11
- return null;
12
- }
13
- static getMaterialByName(object, name) {
14
- if (object instanceof Mesh) {
15
- if (Array.isArray(object.material)) {
16
- for (const material of object.material) {
17
- if (material.name === name)
18
- return material;
19
- }
20
- }
21
- else if (object.material.name === name) {
22
- return object.material;
23
- }
24
- }
25
- for (const child of object.children) {
26
- const material = Object3DEnumerator.getMaterialByName(child, name);
27
- if (material)
28
- return material;
29
- }
30
- return null;
31
- }
32
- static enumerateObjectsByType(object, type, callback) {
33
- if (object instanceof type) {
34
- callback(object);
35
- }
36
- for (const child of object.children) {
37
- Object3DEnumerator.enumerateObjectsByType(child, type, callback);
38
- }
39
- }
40
- static enumerateMaterials(object, callback) {
41
- if (object instanceof Mesh) {
42
- if (Array.isArray(object.material)) {
43
- for (const material of object.material) {
44
- callback(material);
45
- }
46
- }
47
- else {
48
- callback(object.material);
49
- }
50
- }
51
- for (const child of object.children) {
52
- Object3DEnumerator.enumerateMaterials(child, callback);
53
- }
54
- }
55
- static setShadowRecursive(object, castShadow = true, receiveShadow = true) {
56
- if ("isMesh" in object) {
57
- object.castShadow = castShadow;
58
- object.receiveShadow = receiveShadow;
59
- }
60
- object.traverse((child) => {
61
- if ("isMesh" in child) {
62
- child.castShadow = castShadow;
63
- child.receiveShadow = receiveShadow;
64
- }
65
- });
66
- }
67
- }
68
- //# sourceMappingURL=Objec3DEnumerator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Objec3DEnumerator.js","sourceRoot":"","sources":["../src/Objec3DEnumerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,IAAI,EAAY,MAAM,OAAO,CAAC;AAIjD,MAAM,OAAO,kBAAkB;IACtB,MAAM,CAAC,eAAe,CAC3B,MAAgB,EAChB,IAAY;QAEZ,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QAExC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG,kBAAkB,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC/D,IAAI,MAAM;gBAAE,OAAO,MAAM,CAAC;QAC5B,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAC7B,MAAgB,EAChB,IAAY;QAEZ,IAAI,MAAM,YAAY,IAAI,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,OAAO,CAAC,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Q,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpC,kBAAkB,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAC9B,MAAgB,EAChB,UAAU,GAAG,IAAI,EACjB,aAAa,GAAG,IAAI;QAEpB,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YACtB,MAAe,CAAC,UAAU,GAAG,UAAU,CAAC;YACxC,MAAe,CAAC,aAAa,GAAG,aAAa,CAAC;QACjD,CAAC;QACD,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;YACxB,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;gBACrB,KAAc,CAAC,UAAU,GAAG,UAAU,CAAC;gBACvC,KAAc,CAAC,aAAa,GAAG,aAAa,CAAC;YAChD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,21 +0,0 @@
1
- import { Box3, Material, Object3D, Vector3 } from "three";
2
- export declare class Object3DToolbox {
3
- private static tempBox3;
4
- private static tempVector3;
5
- static getObjectByName(object: Object3D, name: string): Object3D | null;
6
- static getMaterialByName(object: Object3D, name: string): Material | null;
7
- static enumerateObjectsByType<T>(object: Object3D, type: new (...args: any[]) => T, callback: (instance: T) => void): void;
8
- static enumerateMaterials(object: Object3D, callback: (material: Material) => void): void;
9
- static calculateBounds(object: Object3D): {
10
- readonly box: Box3;
11
- readonly center: Vector3;
12
- readonly size: Vector3;
13
- readonly width: number;
14
- readonly height: number;
15
- readonly depth: number;
16
- readonly localWidth: number;
17
- readonly localHeight: number;
18
- readonly localDepth: number;
19
- };
20
- static setShadowRecursive(object: Object3D, castShadow?: boolean, receiveShadow?: boolean): void;
21
- }
@@ -1,118 +0,0 @@
1
- import { Box3, Mesh, Vector3 } from "three";
2
- export class Object3DToolbox {
3
- static getObjectByName(object, name) {
4
- if (object.name === name)
5
- return object;
6
- for (const child of object.children) {
7
- const result = Object3DToolbox.getObjectByName(child, name);
8
- if (result)
9
- return result;
10
- }
11
- return null;
12
- }
13
- static getMaterialByName(object, name) {
14
- if (object instanceof Mesh) {
15
- if (Array.isArray(object.material)) {
16
- for (const material of object.material) {
17
- if (material.name === name)
18
- return material;
19
- }
20
- }
21
- else if (object.material.name === name) {
22
- return object.material;
23
- }
24
- }
25
- for (const child of object.children) {
26
- const material = Object3DToolbox.getMaterialByName(child, name);
27
- if (material)
28
- return material;
29
- }
30
- return null;
31
- }
32
- static enumerateObjectsByType(object, type, callback) {
33
- if (object instanceof type) {
34
- callback(object);
35
- }
36
- for (const child of object.children) {
37
- Object3DToolbox.enumerateObjectsByType(child, type, callback);
38
- }
39
- }
40
- static enumerateMaterials(object, callback) {
41
- if (object instanceof Mesh) {
42
- if (Array.isArray(object.material)) {
43
- for (const material of object.material) {
44
- callback(material);
45
- }
46
- }
47
- else {
48
- callback(object.material);
49
- }
50
- }
51
- for (const child of object.children) {
52
- Object3DToolbox.enumerateMaterials(child, callback);
53
- }
54
- }
55
- static calculateBounds(object) {
56
- Object3DToolbox.tempBox3.setFromObject(object);
57
- return {
58
- get box() {
59
- return Object3DToolbox.tempBox3.clone();
60
- },
61
- get center() {
62
- return Object3DToolbox.tempBox3
63
- .getCenter(Object3DToolbox.tempVector3)
64
- .clone();
65
- },
66
- get size() {
67
- return Object3DToolbox.tempBox3
68
- .getSize(Object3DToolbox.tempVector3)
69
- .clone();
70
- },
71
- get width() {
72
- return Object3DToolbox.tempBox3.max.x - Object3DToolbox.tempBox3.min.x;
73
- },
74
- get height() {
75
- return Object3DToolbox.tempBox3.max.y - Object3DToolbox.tempBox3.min.y;
76
- },
77
- get depth() {
78
- return Object3DToolbox.tempBox3.max.z - Object3DToolbox.tempBox3.min.z;
79
- },
80
- get localWidth() {
81
- const worldWidth = Object3DToolbox.tempBox3.max.x - Object3DToolbox.tempBox3.min.x;
82
- if (!object.parent)
83
- return worldWidth;
84
- object.parent.getWorldScale(Object3DToolbox.tempVector3);
85
- return worldWidth / Object3DToolbox.tempVector3.x;
86
- },
87
- get localHeight() {
88
- const worldHeight = Object3DToolbox.tempBox3.max.y - Object3DToolbox.tempBox3.min.y;
89
- if (!object.parent)
90
- return worldHeight;
91
- object.parent.getWorldScale(Object3DToolbox.tempVector3);
92
- return worldHeight / Object3DToolbox.tempVector3.y;
93
- },
94
- get localDepth() {
95
- const worldDepth = Object3DToolbox.tempBox3.max.z - Object3DToolbox.tempBox3.min.z;
96
- if (!object.parent)
97
- return worldDepth;
98
- object.parent.getWorldScale(Object3DToolbox.tempVector3);
99
- return worldDepth / Object3DToolbox.tempVector3.z;
100
- },
101
- };
102
- }
103
- static setShadowRecursive(object, castShadow = true, receiveShadow = true) {
104
- if ("isMesh" in object) {
105
- object.castShadow = castShadow;
106
- object.receiveShadow = receiveShadow;
107
- }
108
- object.traverse((child) => {
109
- if ("isMesh" in child) {
110
- child.castShadow = castShadow;
111
- child.receiveShadow = receiveShadow;
112
- }
113
- });
114
- }
115
- }
116
- Object3DToolbox.tempBox3 = new Box3();
117
- Object3DToolbox.tempVector3 = new Vector3();
118
- //# sourceMappingURL=Object3DToolbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Object3DToolbox.js","sourceRoot":"","sources":["../src/Object3DToolbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,IAAI,EAAY,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhE,MAAM,OAAO,eAAe;IAInB,MAAM,CAAC,eAAe,CAC3B,MAAgB,EAChB,IAAY;QAEZ,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QAExC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG,eAAe,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CA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Q,IAAI,MAAM,EAAE,CAAC;YACtB,MAAe,CAAC,UAAU,GAAG,UAAU,CAAC;YACxC,MAAe,CAAC,aAAa,GAAG,aAAa,CAAC;QACjD,CAAC;QACD,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;YACxB,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;gBACrB,KAAc,CAAC,UAAU,GAAG,UAAU,CAAC;gBACvC,KAAc,CAAC,aAAa,GAAG,aAAa,CAAC;YAChD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;;AAnJc,wBAAQ,GAAG,IAAI,IAAI,EAAE,CAAC;AACtB,2BAAW,GAAG,IAAI,OAAO,EAAE,CAAC"}
package/eslint.config.js DELETED
@@ -1,45 +0,0 @@
1
- import tsPlugin from "@typescript-eslint/eslint-plugin";
2
- import tsParser from "@typescript-eslint/parser";
3
-
4
- export default [
5
- {
6
- files: ["src/**/*.ts", "src/**/*.tsx"],
7
- ignores: ["dist/**", "node_modules/**"],
8
- languageOptions: {
9
- parser: tsParser,
10
- parserOptions: {
11
- project: "./tsconfig.json",
12
- tsconfigRootDir: process.cwd(),
13
- sourceType: "module",
14
- },
15
- },
16
- plugins: {
17
- "@typescript-eslint": tsPlugin,
18
- },
19
- rules: {
20
- "no-unused-vars": "off",
21
- "@typescript-eslint/no-unused-vars": [
22
- "error",
23
- { argsIgnorePattern: "^_" },
24
- ],
25
- "no-console": "warn",
26
- eqeqeq: ["error", "always"],
27
-
28
- "@typescript-eslint/explicit-function-return-type": "error",
29
- "@typescript-eslint/explicit-module-boundary-types": "error",
30
- "@typescript-eslint/no-explicit-any": "error",
31
- "@typescript-eslint/no-inferrable-types": "warn",
32
-
33
- "@typescript-eslint/ban-ts-comment": "error",
34
- "@typescript-eslint/no-floating-promises": "error",
35
-
36
- "@typescript-eslint/member-ordering": "warn",
37
- "@typescript-eslint/naming-convention": [
38
- "error",
39
- { selector: "default", format: ["camelCase"] },
40
- { selector: "variableLike", format: ["camelCase", "UPPER_CASE"] },
41
- { selector: "typeLike", format: ["PascalCase"] },
42
- ],
43
- },
44
- },
45
- ];
package/src/Bounds.ts DELETED
@@ -1,22 +0,0 @@
1
- import { Box3, Vector3 } from "three";
2
-
3
- export class Bounds extends Box3 {
4
- private readonly tempVector3: Vector3 = new Vector3();
5
-
6
- public get width(): number {
7
- return this.max.x - this.min.x;
8
- }
9
-
10
- public get height(): number {
11
- return this.max.y - this.min.y;
12
- }
13
-
14
- public get depth(): number {
15
- return this.max.z - this.min.z;
16
- }
17
-
18
- public get diagonal(): number {
19
- this.tempVector3.subVectors(this.max, this.min);
20
- return this.tempVector3.length();
21
- }
22
- }
package/src/Enumerator.ts DELETED
@@ -1,89 +0,0 @@
1
- import { Material, Mesh, Object3D } from "three";
2
-
3
- type Constructor<T> = abstract new (...args: never[]) => T;
4
-
5
- export class Enumerator {
6
- public static getObjectByName(
7
- object: Object3D,
8
- name: string,
9
- ): Object3D | null {
10
- if (object.name === name) return object;
11
-
12
- for (const child of object.children) {
13
- const result = Enumerator.getObjectByName(child, name);
14
- if (result) return result;
15
- }
16
-
17
- return null;
18
- }
19
-
20
- public static getMaterialByName(
21
- object: Object3D,
22
- name: string,
23
- ): Material | null {
24
- if (object instanceof Mesh) {
25
- if (Array.isArray(object.material)) {
26
- for (const material of object.material) {
27
- if (material.name === name) return material;
28
- }
29
- } else if (object.material.name === name) {
30
- return object.material;
31
- }
32
- }
33
-
34
- for (const child of object.children) {
35
- const material = Enumerator.getMaterialByName(child, name);
36
- if (material) return material;
37
- }
38
-
39
- return null;
40
- }
41
-
42
- public static enumerateObjectsByType<T>(
43
- object: Object3D,
44
- type: Constructor<T>,
45
- callback: (instance: T) => void,
46
- ): void {
47
- if (object instanceof type) {
48
- callback(object);
49
- }
50
-
51
- for (const child of object.children) {
52
- Enumerator.enumerateObjectsByType(child, type, callback);
53
- }
54
- }
55
-
56
- public static enumerateMaterials(
57
- object: Object3D,
58
- callback: (material: Material) => void,
59
- ): void {
60
- if (object instanceof Mesh) {
61
- if (Array.isArray(object.material)) {
62
- for (const material of object.material) {
63
- callback(material);
64
- }
65
- } else {
66
- callback(object.material);
67
- }
68
- }
69
-
70
- for (const child of object.children) {
71
- Enumerator.enumerateMaterials(child, callback);
72
- }
73
- }
74
-
75
- public static setShadowRecursive(
76
- object: Object3D,
77
- castShadow = true,
78
- receiveShadow = true,
79
- ): void {
80
- if (object instanceof Mesh || "isMesh" in object) {
81
- (object as Mesh).castShadow = castShadow;
82
- (object as Mesh).receiveShadow = receiveShadow;
83
- }
84
-
85
- for (const child of object.children) {
86
- Enumerator.setShadowRecursive(child, castShadow, receiveShadow);
87
- }
88
- }
89
- }
@@ -1,90 +0,0 @@
1
- import { InstancedMesh, Material, Mesh, Object3D } from "three";
2
- import { Enumerator } from "./Enumerator";
3
-
4
- interface IMeshDescriptor {
5
- meshes: Mesh[];
6
- materials: Material[];
7
- castShadow: boolean;
8
- receiveShadow: boolean;
9
- }
10
-
11
- interface IOptions {
12
- container: Object3D;
13
- filter?: (child: Mesh) => boolean;
14
- disposeOriginal?: boolean;
15
- }
16
-
17
- export class InstanceAssembler {
18
- public static assemble(options: IOptions): void {
19
- const dictionary = new Map<string, IMeshDescriptor>();
20
- const instancedMeshes: InstancedMesh[] = [];
21
-
22
- Enumerator.enumerateObjectsByType(
23
- options.container,
24
- Mesh,
25
- (child: Mesh) => {
26
- if (
27
- child.children.length === 0 &&
28
- (!options.filter || options.filter(child))
29
- ) {
30
- const materials = Array.isArray(child.material)
31
- ? child.material
32
- : [child.material];
33
-
34
- const key = `${child.geometry.uuid}|${materials.map((m) => m.uuid).join(",")}`;
35
- const entry = dictionary.get(key) ?? {
36
- meshes: [],
37
- materials: materials,
38
- castShadow: false,
39
- receiveShadow: false,
40
- };
41
-
42
- if (child.castShadow) entry.castShadow = true;
43
- if (child.receiveShadow) entry.receiveShadow = true;
44
-
45
- dictionary.set(key, entry);
46
- }
47
- },
48
- );
49
-
50
- for (const descriptor of dictionary.values()) {
51
- if (descriptor.meshes.length < 2) continue;
52
- const { meshes, materials, castShadow, receiveShadow } = descriptor;
53
-
54
- const sortedMeshes = meshes.sort((a, b) => a.name.localeCompare(b.name));
55
- const defaultMesh = sortedMeshes[0];
56
-
57
- const instancedMesh = new InstancedMesh(
58
- defaultMesh.geometry,
59
- materials.length === 1 ? materials[0] : materials,
60
- sortedMeshes.length,
61
- );
62
-
63
- instancedMesh.name = defaultMesh.name;
64
- instancedMesh.castShadow = castShadow;
65
- instancedMesh.receiveShadow = receiveShadow;
66
-
67
- for (let i = 0; i < sortedMeshes.length; i++) {
68
- const mesh = sortedMeshes[i];
69
- mesh.updateWorldMatrix(true, false);
70
- instancedMesh.setMatrixAt(i, mesh.matrixWorld);
71
- instancedMesh.userData[mesh.uuid] = mesh.userData;
72
- }
73
-
74
- instancedMesh.instanceMatrix.needsUpdate = true;
75
- instancedMeshes.push(instancedMesh);
76
-
77
- for (const mesh of sortedMeshes) {
78
- mesh.parent?.remove(mesh);
79
- }
80
-
81
- if (options.disposeOriginal === true) {
82
- for (const material of materials) {
83
- material.dispose();
84
- }
85
- }
86
- }
87
-
88
- options.container.add(...instancedMeshes);
89
- }
90
- }
@@ -1,53 +0,0 @@
1
- import { FrontSide, Material, Mesh, Object3D } from "three";
2
- import { Enumerator } from "./Enumerator";
3
- import { InstanceAssembler } from "./InstanceAssembler";
4
-
5
- type IPattern = string | RegExp;
6
-
7
- interface IOptions {
8
- asset: Object3D;
9
- castShadowMeshNames?: IPattern[];
10
- receiveShadowMeshNames?: IPattern[];
11
- transparentMaterialNames?: IPattern[];
12
- noDepthWriteMaterialNames?: IPattern[];
13
- }
14
-
15
- export class SceneProcessor {
16
- public static process(options: IOptions): Object3D[] {
17
- const container = options.asset.clone();
18
- InstanceAssembler.assemble({ container: container });
19
-
20
- Enumerator.enumerateMaterials(container, (material: Material) => {
21
- material.transparent = SceneProcessor.matchesAny(
22
- material.name,
23
- options.transparentMaterialNames,
24
- );
25
- material.depthWrite = !SceneProcessor.matchesAny(
26
- material.name,
27
- options.noDepthWriteMaterialNames,
28
- );
29
- material.side = FrontSide;
30
- material.forceSinglePass = true;
31
- material.depthTest = true;
32
- });
33
-
34
- Enumerator.enumerateObjectsByType(container, Mesh, (child: Mesh) => {
35
- child.castShadow = SceneProcessor.matchesAny(
36
- child.name,
37
- options.castShadowMeshNames,
38
- );
39
- child.receiveShadow = SceneProcessor.matchesAny(
40
- child.name,
41
- options.receiveShadowMeshNames,
42
- );
43
- });
44
-
45
- return container.children;
46
- }
47
-
48
- private static matchesAny(value: string, patterns: IPattern[] = []): boolean {
49
- return patterns.some((p) =>
50
- typeof p === "string" ? value === p : p.test(value),
51
- );
52
- }
53
- }
package/src/Sun.ts DELETED
@@ -1,133 +0,0 @@
1
- import {
2
- Box3,
3
- DirectionalLight,
4
- RGBAFormat,
5
- Spherical,
6
- Texture,
7
- Vector3,
8
- } from "three";
9
-
10
- export class Sun extends DirectionalLight {
11
- private tempVector3D0 = new Vector3();
12
- private tempVector3D1 = new Vector3();
13
- private tempVector3D2 = new Vector3();
14
- private tempVector3D3 = new Vector3();
15
- private tempVector3D4 = new Vector3();
16
- private tempVector3D5 = new Vector3();
17
- private tempVector3D6 = new Vector3();
18
- private tempVector3D7 = new Vector3();
19
-
20
- private tempBox3 = new Box3();
21
- private tempSpherical = new Spherical();
22
-
23
- public get distance(): number {
24
- return this.position.length();
25
- }
26
-
27
- public get elevation(): number {
28
- return this.tempSpherical.setFromVector3(this.position).phi;
29
- }
30
-
31
- public get azimuth(): number {
32
- return this.tempSpherical.setFromVector3(this.position).theta;
33
- }
34
-
35
- public set distance(value: number) {
36
- this.tempSpherical.setFromVector3(this.position);
37
- this.position.setFromSphericalCoords(
38
- value,
39
- this.tempSpherical.phi,
40
- this.tempSpherical.theta,
41
- );
42
- }
43
-
44
- public set elevation(value: number) {
45
- this.tempSpherical.setFromVector3(this.position);
46
- this.position.setFromSphericalCoords(
47
- this.tempSpherical.radius,
48
- value,
49
- this.tempSpherical.theta,
50
- );
51
- }
52
-
53
- public set azimuth(value: number) {
54
- this.tempSpherical.setFromVector3(this.position);
55
- this.position.setFromSphericalCoords(
56
- this.tempSpherical.radius,
57
- this.tempSpherical.phi,
58
- value,
59
- );
60
- }
61
-
62
- public setShadowMapFromBox3(box3: Box3): void {
63
- const camera = this.shadow.camera;
64
-
65
- this.target.updateWorldMatrix(true, false);
66
- this.lookAt(this.target.getWorldPosition(this.tempVector3D0));
67
-
68
- this.updateWorldMatrix(true, false);
69
-
70
- const points: Vector3[] = [
71
- this.tempVector3D0.set(box3.min.x, box3.min.y, box3.min.z),
72
- this.tempVector3D1.set(box3.min.x, box3.min.y, box3.max.z),
73
- this.tempVector3D2.set(box3.min.x, box3.max.y, box3.min.z),
74
- this.tempVector3D3.set(box3.min.x, box3.max.y, box3.max.z),
75
- this.tempVector3D4.set(box3.max.x, box3.min.y, box3.min.z),
76
- this.tempVector3D5.set(box3.max.x, box3.min.y, box3.max.z),
77
- this.tempVector3D6.set(box3.max.x, box3.max.y, box3.min.z),
78
- this.tempVector3D7.set(box3.max.x, box3.max.y, box3.max.z),
79
- ];
80
-
81
- const inverseMatrix = this.matrixWorld.clone().invert();
82
-
83
- for (const point of points) {
84
- point.applyMatrix4(inverseMatrix);
85
- }
86
-
87
- const newBox3 = this.tempBox3.setFromPoints(points);
88
-
89
- camera.left = newBox3.min.x;
90
- camera.bottom = newBox3.min.y;
91
- camera.near = -newBox3.max.z;
92
-
93
- camera.right = newBox3.max.x;
94
- camera.top = newBox3.max.y;
95
- camera.far = -newBox3.min.z;
96
-
97
- camera.updateWorldMatrix(true, false);
98
- camera.updateProjectionMatrix();
99
- }
100
-
101
- public setDirectionFromHDR(texture: Texture, distance = 1): void {
102
- const data = texture.image.data;
103
- const width = texture.image.width;
104
- const height = texture.image.height;
105
-
106
- let maxLuminance = 0;
107
- let maxIndex = 0;
108
-
109
- const step = texture.format === RGBAFormat ? 4 : 3;
110
- for (let i = 0; i < data.length; i += step) {
111
- const r = data[i];
112
- const g = data[i + 1];
113
- const b = data[i + 2];
114
- const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
115
- if (luminance > maxLuminance) {
116
- maxLuminance = luminance;
117
- maxIndex = i;
118
- }
119
- }
120
-
121
- const pixelIndex = maxIndex / step;
122
- const x = pixelIndex % width;
123
- const y = Math.floor(pixelIndex / width);
124
-
125
- const u = x / width;
126
- const v = y / height;
127
-
128
- const elevation = v * Math.PI;
129
- const azimuth = u * -Math.PI * 2 - Math.PI / 2;
130
-
131
- this.position.setFromSphericalCoords(distance, elevation, azimuth);
132
- }
133
- }
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "./Bounds";
2
- export * from "./Enumerator";
3
- export * from "./InstanceAssembler";
4
- export * from "./SceneProcessor";
5
- export * from "./Sun";
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "strict": true,
7
- "noImplicitAny": true,
8
- "strictNullChecks": true,
9
- "strictFunctionTypes": true,
10
- "strictBindCallApply": true,
11
- "noImplicitThis": true,
12
- "alwaysStrict": true,
13
- "esModuleInterop": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "skipLibCheck": false,
16
- "outDir": "./dist",
17
- "declaration": true,
18
- "sourceMap": true
19
- },
20
- "include": ["src/**/*"]
21
- }