@needle-tools/engine 2.35.5-pre → 2.37.0-pre
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/CHANGELOG.md +31 -0
- package/dist/needle-engine.d.ts +312 -232
- package/dist/needle-engine.js +456 -437
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +81 -76
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/api.d.ts +1 -0
- package/lib/engine/api.js +1 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/debug/debug.d.ts +1 -0
- package/lib/engine/debug/debug.js +3 -0
- package/lib/engine/debug/debug.js.map +1 -1
- package/lib/engine/debug/debug_overlay.js +12 -1
- package/lib/engine/debug/debug_overlay.js.map +1 -1
- package/lib/engine/engine_element_loading.js +1 -1
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gameobject.d.ts +1 -0
- package/lib/engine/engine_gameobject.js +15 -2
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +4 -0
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.d.ts +1 -1
- package/lib/engine/engine_mainloop_utils.js +7 -3
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +49 -57
- package/lib/engine/engine_physics.js +464 -417
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_physics.types.d.ts +16 -0
- package/lib/engine/engine_physics.types.js +19 -0
- package/lib/engine/engine_physics.types.js.map +1 -0
- package/lib/engine/engine_serialization_core.d.ts +3 -0
- package/lib/engine/engine_serialization_core.js +19 -6
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.js +4 -2
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_time.d.ts +1 -0
- package/lib/engine/engine_time.js +1 -0
- package/lib/engine/engine_time.js.map +1 -1
- package/lib/engine/engine_types.d.ts +46 -26
- package/lib/engine/engine_types.js +24 -37
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_typestore.d.ts +1 -0
- package/lib/engine/engine_typestore.js +1 -0
- package/lib/engine/engine_typestore.js.map +1 -1
- package/lib/engine/engine_util_decorator.d.ts +6 -0
- package/lib/engine/engine_util_decorator.js +54 -0
- package/lib/engine/engine_util_decorator.js.map +1 -0
- package/lib/engine/engine_utils.d.ts +1 -1
- package/lib/engine/engine_utils.js +2 -2
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_animator_controller_model.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_gameobject_data.js +2 -0
- package/lib/engine/extensions/NEEDLE_gameobject_data.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js +5 -0
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
- package/lib/engine-components/Animation.d.ts +5 -0
- package/lib/engine-components/Animation.js +14 -0
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimatorController.d.ts +1 -0
- package/lib/engine-components/AnimatorController.js +14 -7
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.d.ts +2 -2
- package/lib/engine-components/BoxHelperComponent.js +28 -9
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +7 -2
- package/lib/engine-components/Collider.js +27 -15
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +8 -16
- package/lib/engine-components/Component.js +18 -117
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.js +9 -6
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/GroundProjection.d.ts +2 -0
- package/lib/engine-components/GroundProjection.js +18 -6
- package/lib/engine-components/GroundProjection.js.map +1 -1
- package/lib/engine-components/NavMesh.d.ts +0 -5
- package/lib/engine-components/NavMesh.js +100 -10
- package/lib/engine-components/NavMesh.js.map +1 -1
- package/lib/engine-components/NestedGltf.js +2 -0
- package/lib/engine-components/NestedGltf.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.d.ts +22 -0
- package/lib/engine-components/ReflectionProbe.js +134 -0
- package/lib/engine-components/ReflectionProbe.js.map +1 -0
- package/lib/engine-components/Renderer.d.ts +13 -2
- package/lib/engine-components/Renderer.js +96 -45
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +40 -25
- package/lib/engine-components/RigidBody.js +253 -142
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.js +1 -1
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.d.ts +1 -0
- package/lib/engine-components/SpectatorCamera.js +9 -2
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SpringJoint.d.ts +0 -13
- package/lib/engine-components/SpringJoint.js +42 -41
- package/lib/engine-components/SpringJoint.js.map +1 -1
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/WebARSessionRoot.d.ts +7 -7
- package/lib/engine-components/WebARSessionRoot.js +7 -7
- package/lib/engine-components/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +10 -8
- package/lib/engine-components/WebXR.js +50 -26
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.d.ts +4 -5
- package/lib/engine-components/WebXRAvatar.js +9 -8
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/WebXRController.d.ts +21 -21
- package/lib/engine-components/WebXRController.js +90 -68
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/WebXRGrabRendering.d.ts +3 -3
- package/lib/engine-components/WebXRGrabRendering.js +2 -2
- package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
- package/lib/engine-components/WebXRSync.d.ts +8 -8
- package/lib/engine-components/WebXRSync.js +15 -15
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +2 -3
- package/lib/engine-components/codegen/components.js +2 -3
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.d.ts +1 -0
- package/lib/engine-components/ui/EventSystem.js +21 -1
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/package.json +3 -4
- package/src/engine/api.ts +2 -1
- package/src/engine/codegen/register_types.js +291 -6
- package/src/engine/debug/debug.ts +4 -0
- package/src/engine/debug/debug_overlay.ts +9 -2
- package/src/engine/engine_element_loading.ts +1 -1
- package/src/engine/engine_gameobject.ts +19 -6
- package/src/engine/engine_gltf_builtin_components.ts +5 -1
- package/src/engine/engine_mainloop_utils.ts +7 -3
- package/src/engine/engine_physics.ts +508 -469
- package/src/engine/engine_physics.types.ts +19 -0
- package/src/engine/engine_serialization_core.ts +22 -8
- package/src/engine/engine_setup.ts +6 -2
- package/src/engine/engine_time.ts +2 -0
- package/src/engine/engine_types.ts +82 -55
- package/src/engine/engine_typestore.ts +2 -0
- package/src/engine/engine_util_decorator.ts +69 -0
- package/src/engine/engine_utils.ts +6 -5
- package/src/engine/extensions/EXT_texture_exr.js +1 -1
- package/src/engine/extensions/NEEDLE_animator_controller_model.ts +2 -1
- package/src/engine/extensions/NEEDLE_gameobject_data.ts +2 -0
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +7 -0
- package/src/engine-components/Animation.ts +14 -1
- package/src/engine-components/AnimatorController.ts +19 -9
- package/src/engine-components/BoxHelperComponent.ts +30 -9
- package/src/engine-components/Collider.ts +29 -29
- package/src/engine-components/Component.ts +26 -135
- package/src/engine-components/DragControls.ts +9 -5
- package/src/engine-components/GroundProjection.ts +22 -7
- package/src/engine-components/NavMesh.ts +114 -115
- package/src/engine-components/NestedGltf.ts +2 -0
- package/src/engine-components/ReflectionProbe.ts +141 -0
- package/src/engine-components/Renderer.ts +796 -737
- package/src/engine-components/RigidBody.ts +258 -149
- package/src/engine-components/SpatialTrigger.ts +1 -1
- package/src/engine-components/SpectatorCamera.ts +10 -2
- package/src/engine-components/SpringJoint.ts +41 -41
- package/src/engine-components/VideoPlayer.ts +1 -2
- package/src/engine-components/WebARSessionRoot.ts +16 -16
- package/src/engine-components/WebXR.ts +65 -50
- package/src/engine-components/WebXRAvatar.ts +16 -16
- package/src/engine-components/WebXRController.ts +143 -112
- package/src/engine-components/WebXRGrabRendering.ts +6 -6
- package/src/engine-components/WebXRSync.ts +20 -20
- package/src/engine-components/codegen/components.ts +2 -3
- package/src/engine-components/ui/EventSystem.ts +26 -3
|
@@ -1,118 +1,117 @@
|
|
|
1
1
|
|
|
2
|
-
import { Behaviour, GameObject } from "./Component";
|
|
3
|
-
/*
|
|
4
|
-
import { Pathfinding, PathfindingHelper } from 'three-pathfinding';
|
|
5
|
-
import * as THREE from 'three';
|
|
6
|
-
import { mergeBufferGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils'
|
|
7
|
-
*/
|
|
8
|
-
export class NavMesh extends Behaviour {
|
|
9
|
-
/*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// import { input } from "../engine/engine_input";
|
|
60
|
-
import { Physics, RaycastOptions } from "../engine/engine_physics"
|
|
61
|
-
// import { time } from "../engine/engine_time";
|
|
62
|
-
// import { scene } from "../engine/engine_setup";
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.currentPath.shift();
|
|
2
|
+
// import { Behaviour, GameObject } from "./Component";
|
|
3
|
+
// /*
|
|
4
|
+
// import { Pathfinding, PathfindingHelper } from 'three-pathfinding';
|
|
5
|
+
// import * as THREE from 'three';
|
|
6
|
+
// import { mergeBufferGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils'
|
|
7
|
+
// */
|
|
8
|
+
// export class NavMesh extends Behaviour {
|
|
9
|
+
// /*
|
|
10
|
+
// public meshes: THREE.Object3D[] = [];
|
|
11
|
+
|
|
12
|
+
// private pathfinding: Pathfinding | null = null;
|
|
13
|
+
// private zones: string[] = [];
|
|
14
|
+
|
|
15
|
+
// onEnable(): void {
|
|
16
|
+
|
|
17
|
+
// this.pathfinding = new Pathfinding();
|
|
18
|
+
// const ZONE = 'zone';
|
|
19
|
+
// const geometries : THREE.BufferGeometry[] = [];
|
|
20
|
+
// if (this.meshes && this.meshes.length > 0) {
|
|
21
|
+
// for (let i = 0; i < this.meshes.length; i++) {
|
|
22
|
+
// const obj = this.meshes[i] as THREE.Mesh;
|
|
23
|
+
// if (!obj) continue;
|
|
24
|
+
// const geo = obj.geometry;
|
|
25
|
+
// if (!geo) continue;
|
|
26
|
+
// const copy : THREE.BufferGeometry = {...geo};
|
|
27
|
+
// // const copy = geo;
|
|
28
|
+
// const attributesCopy = {...copy.attributes};
|
|
29
|
+
// copy.attributes = attributesCopy;
|
|
30
|
+
// if(attributesCopy.uv2) delete attributesCopy.uv2;
|
|
31
|
+
// // copy.applyMatrix4(obj.matrixWorld);
|
|
32
|
+
// geometries.push(copy);
|
|
33
|
+
// // obj.updateMatrixWorld();
|
|
34
|
+
// // singleGeometry.merge(geo);
|
|
35
|
+
// // console.log(singleGeometry, geo);
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
// const mesh = mergeBufferGeometries(geometries);
|
|
39
|
+
// const zone = Pathfinding.createZone(mesh);
|
|
40
|
+
// const name = ZONE;
|
|
41
|
+
// this.zones.push(name);
|
|
42
|
+
// this.pathfinding.setZoneData(name, zone);
|
|
43
|
+
|
|
44
|
+
// // const target = new THREE.Vector3(2, 0, 2);
|
|
45
|
+
// // const groupID = this.pathfinding.getGroup(ZONE, target);
|
|
46
|
+
// // const path = this.pathfinding.findPath(this.worldPosition, target, ZONE, groupID);
|
|
47
|
+
// // console.log(path, this.pathfinding);
|
|
48
|
+
// }
|
|
49
|
+
|
|
50
|
+
// public tryFindPath(from: THREE.Vector3, to: THREE.Vector3): THREE.Vector3[] | null {
|
|
51
|
+
// const zone = this.zones[0];
|
|
52
|
+
// const groupId = this.pathfinding.getGroup(zone, to);
|
|
53
|
+
// const path = this.pathfinding.findPath(from, to, zone, groupId);
|
|
54
|
+
// return path;
|
|
55
|
+
// }
|
|
56
|
+
// */
|
|
57
|
+
// }
|
|
58
|
+
|
|
59
|
+
// // import { input } from "../engine/engine_input";
|
|
60
|
+
// import { Physics, RaycastOptions } from "../engine/engine_physics"
|
|
61
|
+
// // import { time } from "../engine/engine_time";
|
|
62
|
+
// // import { scene } from "../engine/engine_setup";
|
|
63
|
+
// import {SyncedTransform} from "./SyncedTransform";
|
|
64
|
+
|
|
65
|
+
// export class NavMeshAgent extends Behaviour {
|
|
66
|
+
// /*
|
|
67
|
+
// public navMesh: NavMesh | null = null;
|
|
68
|
+
|
|
69
|
+
// private currentPath: THREE.Vector3[] | null = null;
|
|
70
|
+
// private helper : PathfindingHelper | null = null;
|
|
71
|
+
|
|
72
|
+
// onEnable(): void {
|
|
73
|
+
// this.helper = new PathfindingHelper();
|
|
74
|
+
// scene.add(this.helper);
|
|
75
|
+
// }
|
|
76
|
+
|
|
77
|
+
// update(): void {
|
|
78
|
+
// if (input.mouseClick) {
|
|
79
|
+
// if (this.navMesh) {
|
|
80
|
+
// const from = this.worldPosition;
|
|
81
|
+
// const opts = new RaycastOptions();
|
|
82
|
+
// opts.setMask(RaycastOptions.AllLayers);
|
|
83
|
+
// const hits = Physics.raycast(opts);
|
|
84
|
+
// if (hits.length > 0) {
|
|
85
|
+
// const to = hits[0].point;
|
|
86
|
+
// this.helper.setPlayerPosition(from);
|
|
87
|
+
// this.helper.setTargetPosition(to);
|
|
88
|
+
// this.currentPath = this.navMesh.tryFindPath(from, to);
|
|
89
|
+
// this.helper.setPath(this.currentPath);
|
|
90
|
+
// // console.log(...this.currentPath);
|
|
91
|
+
|
|
92
|
+
// const sync = GameObject.getComponent(this.gameObject, SyncedTransform);
|
|
93
|
+
// if(sync) sync.requestOwnership();
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
97
|
+
|
|
98
|
+
// if (this.currentPath && this.currentPath.length > 0) {
|
|
99
|
+
|
|
100
|
+
// const wp = this.worldPosition;
|
|
101
|
+
// const target = this.currentPath[0];
|
|
102
|
+
// this.worldPosition = wp.lerp(target, time.deltaTime*2);
|
|
103
|
+
|
|
104
|
+
// this.gameObject.lookAt(target);
|
|
105
|
+
// // const vec = target.clone().sub(wp);
|
|
106
|
+
// // const wr = this.worldQuaternion;
|
|
107
|
+
// // wr.slerp(rot, time.deltaTime*5);
|
|
108
|
+
// // this.worldQuaternion = wr;
|
|
109
|
+
|
|
110
|
+
// if (wp.distanceTo(this.currentPath[0]) < 0.1)
|
|
111
|
+
// this.currentPath.shift();
|
|
113
112
|
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
114
|
+
// }
|
|
115
|
+
// }
|
|
116
|
+
// */
|
|
117
|
+
// }
|
|
@@ -41,6 +41,8 @@ export class NestedGltf extends Behaviour {
|
|
|
41
41
|
res.matrix.identity();
|
|
42
42
|
res.applyMatrix4(matrix);
|
|
43
43
|
res.matrixAutoUpdate = true;
|
|
44
|
+
res.layers.disableAll();
|
|
45
|
+
res.layers.set(this.layer);
|
|
44
46
|
}
|
|
45
47
|
this.destroy();
|
|
46
48
|
if (debug) console.log("Nested loading done:", this.filePath?.uri ?? this.filePath, res);
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Behaviour } from "./Component";
|
|
2
|
+
import { Box3, Color, EquirectangularReflectionMapping, LineBasicMaterial, Material, MeshStandardMaterial, Object3D, sRGBEncoding, Texture, Vector3, WebGLCubeRenderTarget, WebGLRenderTarget } from "three";
|
|
3
|
+
import { serializeable } from "../engine/engine_serialization";
|
|
4
|
+
import { Context } from "../engine/engine_setup";
|
|
5
|
+
import { getWorldPosition, getWorldScale } from "../engine/engine_three_utils";
|
|
6
|
+
import { IRenderer } from "../engine/engine_types";
|
|
7
|
+
import { BoxHelperComponent } from "./BoxHelperComponent";
|
|
8
|
+
import { getParam } from "../engine/engine_utils";
|
|
9
|
+
|
|
10
|
+
export const debug = getParam("debugreflectionprobe");
|
|
11
|
+
const disable = getParam("noreflectionprobe");
|
|
12
|
+
|
|
13
|
+
export class ReflectionProbe extends Behaviour {
|
|
14
|
+
|
|
15
|
+
private static _probes: Map<Context, ReflectionProbe[]> = new Map();
|
|
16
|
+
|
|
17
|
+
public static get(object: Object3D | null | undefined, context: Context, isAnchor:boolean): ReflectionProbe | null {
|
|
18
|
+
if (!object || object.isObject3D !== true) return null;
|
|
19
|
+
if (disable) return null;
|
|
20
|
+
const probes = ReflectionProbe._probes.get(context);
|
|
21
|
+
if (probes) {
|
|
22
|
+
for (const probe of probes) {
|
|
23
|
+
if (!probe.__didAwake) probe.__internalAwake();
|
|
24
|
+
if (probe.enabled && probe.isInBox(object, isAnchor ? .00000001 : undefined)) {
|
|
25
|
+
if (debug) console.log("Found reflection probe", object.name, probe.name);
|
|
26
|
+
return probe;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (debug)
|
|
31
|
+
console.debug("Did not find reflection probe", object.name, isAnchor, object);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
private _texture!: Texture;
|
|
38
|
+
set texture(tex: Texture) {
|
|
39
|
+
this._texture = tex;
|
|
40
|
+
}
|
|
41
|
+
get texture(): Texture {
|
|
42
|
+
return this._texture;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@serializeable(Vector3)
|
|
46
|
+
center?: Vector3;
|
|
47
|
+
@serializeable(Vector3)
|
|
48
|
+
size?: Vector3;
|
|
49
|
+
|
|
50
|
+
private _boxHelper?: BoxHelperComponent;
|
|
51
|
+
|
|
52
|
+
private isInBox(obj: Object3D, scaleFactor?: number) {
|
|
53
|
+
return this._boxHelper?.isInBox(obj, scaleFactor);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
constructor() {
|
|
57
|
+
super();
|
|
58
|
+
if (!ReflectionProbe._probes.has(this.context)) {
|
|
59
|
+
ReflectionProbe._probes.set(this.context, []);
|
|
60
|
+
}
|
|
61
|
+
ReflectionProbe._probes.get(this.context)?.push(this);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
awake() {
|
|
65
|
+
this._boxHelper = this.gameObject.addNewComponent(BoxHelperComponent) as BoxHelperComponent;
|
|
66
|
+
this._boxHelper.updateBox(true);
|
|
67
|
+
if (debug)
|
|
68
|
+
this._boxHelper.showHelper(0x555500, true);
|
|
69
|
+
|
|
70
|
+
if (this.texture) {
|
|
71
|
+
this.texture.mapping = EquirectangularReflectionMapping;
|
|
72
|
+
this.texture.encoding = sRGBEncoding;
|
|
73
|
+
// this.texture.rotation = Math.PI;
|
|
74
|
+
// this.texture.flipY = true;
|
|
75
|
+
this.texture.needsUpdate = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onDestroy() {
|
|
80
|
+
const probes = ReflectionProbe._probes.get(this.context);
|
|
81
|
+
if (probes) {
|
|
82
|
+
const index = probes.indexOf(this);
|
|
83
|
+
if (index >= 0) {
|
|
84
|
+
probes.splice(index, 1);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
// when objects are rendered and they share material
|
|
91
|
+
// and some need reflection probe and some don't
|
|
92
|
+
// we need to make sure we don't override the material but use a copy
|
|
93
|
+
|
|
94
|
+
private static _rendererMaterialsCache: Map<IRenderer, Array<{ orig: Material, copy: Material }>> = new Map();
|
|
95
|
+
|
|
96
|
+
onSet(_rend: IRenderer) {
|
|
97
|
+
if (disable) return;
|
|
98
|
+
if (_rend.sharedMaterials?.length <= 0) return;
|
|
99
|
+
if (!this.texture) return;
|
|
100
|
+
|
|
101
|
+
let rendererCache = ReflectionProbe._rendererMaterialsCache.get(_rend);
|
|
102
|
+
if (!rendererCache) {
|
|
103
|
+
rendererCache = [];
|
|
104
|
+
ReflectionProbe._rendererMaterialsCache.set(_rend, rendererCache);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// TODO: dont clone material for every renderer that uses reflection probes, we can do it once per material when they use the same reflection texture
|
|
108
|
+
|
|
109
|
+
// need to make sure materials are not shared when using reflection probes
|
|
110
|
+
// otherwise some renderers outside of the probe will be affected or vice versa
|
|
111
|
+
for (let i = 0; i < _rend.sharedMaterials.length; i++) {
|
|
112
|
+
const orig = _rend.sharedMaterials[i];
|
|
113
|
+
if (!orig) continue;
|
|
114
|
+
if (orig["envMap"] === undefined) continue;
|
|
115
|
+
let cached = rendererCache[i];
|
|
116
|
+
let copy = cached?.copy;
|
|
117
|
+
if (!cached) {
|
|
118
|
+
const clone = orig.clone();
|
|
119
|
+
copy = clone;
|
|
120
|
+
rendererCache.push({ orig, copy });
|
|
121
|
+
|
|
122
|
+
copy["__reflection_probe"] = this;
|
|
123
|
+
copy["envMap"] = this.texture;
|
|
124
|
+
|
|
125
|
+
if (debug)
|
|
126
|
+
console.log("Set reflection", _rend.name, _rend.guid);
|
|
127
|
+
}
|
|
128
|
+
_rend.sharedMaterials[i] = copy;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
onUnset(_rend: IRenderer) {
|
|
133
|
+
const rendererCache = ReflectionProbe._rendererMaterialsCache.get(_rend);
|
|
134
|
+
if (rendererCache) {
|
|
135
|
+
for (let i = 0; i < rendererCache.length; i++) {
|
|
136
|
+
const cached = rendererCache[i];
|
|
137
|
+
_rend.sharedMaterials[i] = cached.orig;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|