@needle-tools/engine 2.65.2-pre → 2.67.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 +43 -0
- package/dist/needle-engine.js +34490 -26304
- package/dist/needle-engine.umd.cjs +748 -303
- package/lib/engine/api.d.ts +4 -0
- package/lib/engine/api.js +10 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/codegen/register_types.js +23 -7
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/debug/debug_overlay.js +11 -2
- package/lib/engine/debug/debug_overlay.js.map +1 -1
- package/lib/engine/engine_addressables.js +4 -4
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_assetdatabase.d.ts +17 -51
- package/lib/engine/engine_assetdatabase.js +252 -126
- package/lib/engine/engine_assetdatabase.js.map +1 -1
- package/lib/engine/engine_components.js +13 -1
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_components_internal.d.ts +8 -0
- package/lib/engine/engine_components_internal.js +29 -0
- package/lib/engine/engine_components_internal.js.map +1 -0
- package/lib/engine/engine_constants.d.ts +1 -0
- package/lib/engine/engine_constants.js +1 -0
- package/lib/engine/engine_constants.js.map +1 -1
- package/lib/engine/engine_context_registry.d.ts +2 -0
- package/lib/engine/engine_context_registry.js +6 -0
- package/lib/engine/engine_context_registry.js.map +1 -1
- package/lib/engine/engine_editor-sync.d.ts +9 -0
- package/lib/engine/engine_editor-sync.js +8 -0
- package/lib/engine/engine_editor-sync.js.map +1 -0
- package/lib/engine/engine_element.d.ts +1 -0
- package/lib/engine/engine_element.js +4 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.d.ts +3 -2
- package/lib/engine/engine_element_loading.js +19 -15
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gameobject.js +21 -23
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gizmos.js +3 -1
- package/lib/engine/engine_gizmos.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.d.ts +2 -3
- package/lib/engine/engine_gltf_builtin_components.js +23 -6
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_networking.d.ts +3 -1
- package/lib/engine/engine_networking.js +10 -8
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking_auto.d.ts +1 -0
- package/lib/engine/engine_networking_auto.js +42 -9
- package/lib/engine/engine_networking_auto.js.map +1 -1
- package/lib/engine/engine_patcher.d.ts +8 -0
- package/lib/engine/engine_patcher.js +98 -0
- package/lib/engine/engine_patcher.js.map +1 -0
- package/lib/engine/engine_physics.d.ts +34 -2
- package/lib/engine/engine_physics.js +110 -11
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_scenetools.js +0 -1
- package/lib/engine/engine_scenetools.js.map +1 -1
- package/lib/engine/engine_serialization_core.js +4 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +1 -1
- package/lib/engine/engine_setup.js +12 -5
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_texture.d.ts +6 -1
- package/lib/engine/engine_texture.js +39 -1
- package/lib/engine/engine_texture.js.map +1 -1
- package/lib/engine/engine_types.d.ts +4 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_utils.js +3 -2
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_progressive.d.ts +0 -1
- package/lib/engine/extensions/NEEDLE_progressive.js +24 -26
- package/lib/engine/extensions/NEEDLE_progressive.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_render_objects.js +9 -0
- package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -1
- package/lib/engine/extensions/extensions.d.ts +4 -1
- package/lib/engine/extensions/extensions.js +16 -0
- package/lib/engine/extensions/extensions.js.map +1 -1
- package/lib/engine/extensions/usage_tracker.d.ts +12 -0
- package/lib/engine/extensions/usage_tracker.js +59 -0
- package/lib/engine/extensions/usage_tracker.js.map +1 -0
- package/lib/engine-components/Animator.js +0 -1
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.js +4 -0
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioSource.js +2 -1
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +6 -0
- package/lib/engine-components/Camera.js +70 -31
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CharacterController.d.ts +1 -0
- package/lib/engine-components/CharacterController.js +14 -9
- package/lib/engine-components/CharacterController.js.map +1 -1
- package/lib/engine-components/Collider.js +14 -1
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +52 -0
- package/lib/engine-components/Component.js +55 -14
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Networking.js +19 -0
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +2 -0
- package/lib/engine-components/OrbitControls.js +9 -0
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ParticleSystem.d.ts +5 -1
- package/lib/engine-components/ParticleSystem.js +52 -7
- package/lib/engine-components/ParticleSystem.js.map +1 -1
- package/lib/engine-components/ParticleSystemModules.d.ts +2 -0
- package/lib/engine-components/ParticleSystemModules.js +26 -0
- package/lib/engine-components/ParticleSystemModules.js.map +1 -1
- package/lib/engine-components/ParticleSystemSubEmitter.js +5 -2
- package/lib/engine-components/ParticleSystemSubEmitter.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +18 -6
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +1 -1
- package/lib/engine-components/Renderer.js +33 -11
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/ScreenCapture.js +3 -3
- package/lib/engine-components/ScreenCapture.js.map +1 -1
- package/lib/engine-components/Skybox.js +2 -0
- package/lib/engine-components/Skybox.js.map +1 -1
- package/lib/engine-components/SmoothFollow.js +1 -2
- package/lib/engine-components/SmoothFollow.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.js +3 -3
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedCamera.js +1 -1
- package/lib/engine-components/SyncedCamera.js.map +1 -1
- package/lib/engine-components/SyncedTransform.js +2 -2
- package/lib/engine-components/SyncedTransform.js.map +1 -1
- package/lib/engine-components/TestRunner.js +1 -1
- package/lib/engine-components/TestRunner.js.map +1 -1
- package/lib/engine-components/WebARCameraBackground.d.ts +19 -0
- package/lib/engine-components/WebARCameraBackground.js +185 -0
- package/lib/engine-components/WebARCameraBackground.js.map +1 -0
- package/lib/engine-components/WebARSessionRoot.js +3 -2
- package/lib/engine-components/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +4 -0
- package/lib/engine-components/WebXR.js +11 -8
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.js +1 -0
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/WebXRGrabRendering.js +2 -2
- package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
- package/lib/engine-components/WebXRSync.js +2 -2
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +14 -6
- package/lib/engine-components/codegen/components.js +14 -6
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/js-extensions/Object3D.js +4 -1
- package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.d.ts +13 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js +46 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.d.ts +12 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.js +76 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +8 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +39 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +12 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +96 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +21 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js +87 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +7 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.js +30 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.d.ts +11 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js +70 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +16 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js +52 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +11 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.js +57 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +29 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js +89 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +13 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +119 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -0
- package/lib/engine-components/postprocessing/Volume.d.ts +23 -0
- package/lib/engine-components/postprocessing/Volume.js +176 -0
- package/lib/engine-components/postprocessing/Volume.js.map +1 -0
- package/lib/engine-components/postprocessing/VolumeParameter.d.ts +21 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js +75 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -0
- package/lib/engine-components/postprocessing/VolumeProfile.d.ts +7 -0
- package/lib/engine-components/postprocessing/VolumeProfile.js +42 -0
- package/lib/engine-components/postprocessing/VolumeProfile.js.map +1 -0
- package/lib/engine-components/timeline/TimelineTracks.js +14 -15
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/ui/Text.js +28 -170
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +18 -0
- package/lib/engine-components-experimental/networking/PlayerSync.js +62 -8
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/lib/include/three/ARButton.d.ts +1 -1
- package/lib/include/three/ARButton.js +11 -19
- package/lib/include/three/ARButton.js.map +1 -1
- package/lib/include/three/VRButton.js +1 -4
- package/lib/include/three/VRButton.js.map +1 -1
- package/package.json +3 -2
- package/plugins/vite/drop-client.js +77 -0
- package/plugins/vite/drop.js +81 -0
- package/plugins/vite/editor-connection.js +121 -0
- package/plugins/vite/index.js +9 -4
- package/plugins/vite/meta.js +3 -0
- package/plugins/vite/poster-client.js +6 -4
- package/src/engine/api.ts +30 -1
- package/src/engine/codegen/register_types.js +25 -9
- package/src/engine/debug/debug_overlay.ts +11 -2
- package/src/engine/engine_addressables.ts +4 -4
- package/src/engine/engine_assetdatabase.ts +291 -184
- package/src/engine/engine_components.ts +20 -1
- package/src/engine/engine_components_internal.ts +30 -0
- package/src/engine/engine_constants.ts +4 -1
- package/src/engine/engine_context_registry.ts +7 -0
- package/src/engine/engine_editor-sync.ts +21 -0
- package/src/engine/engine_element.ts +8 -1
- package/src/engine/engine_element_loading.ts +19 -15
- package/src/engine/engine_gameobject.ts +579 -583
- package/src/engine/engine_gizmos.ts +3 -2
- package/src/engine/engine_gltf_builtin_components.ts +30 -15
- package/src/engine/engine_networking.ts +10 -8
- package/src/engine/engine_networking_auto.ts +48 -11
- package/src/engine/engine_patcher.ts +113 -0
- package/src/engine/engine_physics.ts +128 -12
- package/src/engine/engine_scenetools.ts +0 -1
- package/src/engine/engine_serialization_core.ts +6 -0
- package/src/engine/engine_setup.ts +15 -5
- package/src/engine/engine_texture.ts +54 -5
- package/src/engine/engine_types.ts +6 -1
- package/src/engine/engine_utils.ts +6 -5
- package/src/engine/extensions/NEEDLE_progressive.ts +32 -32
- package/src/engine/extensions/NEEDLE_render_objects.ts +10 -1
- package/src/engine/extensions/extensions.ts +22 -1
- package/src/engine/extensions/usage_tracker.ts +91 -0
- package/src/engine-components/Animator.ts +0 -1
- package/src/engine-components/AnimatorController.ts +2 -0
- package/src/engine-components/AudioSource.ts +1 -1
- package/src/engine-components/Camera.ts +77 -37
- package/src/engine-components/CharacterController.ts +12 -9
- package/src/engine-components/Collider.ts +16 -2
- package/src/engine-components/Component.ts +74 -30
- package/src/engine-components/Networking.ts +9 -1
- package/src/engine-components/OrbitControls.ts +11 -2
- package/src/engine-components/ParticleSystem.ts +54 -10
- package/src/engine-components/ParticleSystemModules.ts +28 -1
- package/src/engine-components/ParticleSystemSubEmitter.ts +5 -3
- package/src/engine-components/ReflectionProbe.ts +17 -7
- package/src/engine-components/Renderer.ts +36 -16
- package/src/engine-components/ScreenCapture.ts +3 -3
- package/src/engine-components/Skybox.ts +2 -0
- package/src/engine-components/SmoothFollow.ts +4 -4
- package/src/engine-components/SpectatorCamera.ts +3 -3
- package/src/engine-components/SyncedCamera.ts +1 -1
- package/src/engine-components/SyncedTransform.ts +2 -2
- package/src/engine-components/TestRunner.ts +1 -1
- package/src/engine-components/WebARCameraBackground.ts +215 -0
- package/src/engine-components/WebARSessionRoot.ts +3 -2
- package/src/engine-components/WebXR.ts +12 -8
- package/src/engine-components/WebXRAvatar.ts +1 -1
- package/src/engine-components/WebXRGrabRendering.ts +2 -2
- package/src/engine-components/WebXRSync.ts +2 -2
- package/src/engine-components/codegen/components.ts +14 -6
- package/src/engine-components/js-extensions/Object3D.ts +6 -1
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +52 -0
- package/src/engine-components/postprocessing/Effects/Bloom.ts +75 -0
- package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +36 -0
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +114 -0
- package/src/engine-components/postprocessing/Effects/DepthOfField.ts +90 -0
- package/src/engine-components/postprocessing/Effects/Pixelation.ts +28 -0
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +71 -0
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +55 -0
- package/src/engine-components/postprocessing/Effects/Vignette.ts +55 -0
- package/src/engine-components/postprocessing/PostProcessingEffect.ts +112 -0
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +148 -0
- package/src/engine-components/postprocessing/Volume.ts +194 -0
- package/src/engine-components/postprocessing/VolumeParameter.ts +85 -0
- package/src/engine-components/postprocessing/VolumeProfile.ts +40 -0
- package/src/engine-components/timeline/TimelineTracks.ts +16 -17
- package/src/engine-components/ui/Text.ts +37 -174
- package/src/engine-components-experimental/networking/PlayerSync.ts +69 -8
- package/src/include/three/ARButton.js +13 -24
- package/src/include/three/VRButton.js +1 -7
- package/lib/engine-components/Volume.d.ts +0 -34
- package/lib/engine-components/Volume.js +0 -140
- package/lib/engine-components/Volume.js.map +0 -1
- package/src/engine-components/Volume.ts +0 -141
|
@@ -15,10 +15,11 @@ import {
|
|
|
15
15
|
import { InstancingUtil } from './engine_instancing';
|
|
16
16
|
import { foreachComponent } from './engine_gameobject';
|
|
17
17
|
|
|
18
|
-
import RAPIER, { ActiveEvents, CoefficientCombineRule, Collider, ColliderDesc, EventQueue, JointData, RigidBody, RigidBodyType, World } from '@dimforge/rapier3d-compat';
|
|
18
|
+
import RAPIER, { ActiveEvents, CoefficientCombineRule, Collider, ColliderDesc, EventQueue, JointData, QueryFilterFlags, RigidBody, RigidBodyType, ShapeColliderTOI, World } from '@dimforge/rapier3d-compat';
|
|
19
19
|
import { CollisionDetectionMode, PhysicsMaterialCombine } from '../engine/engine_physics.types';
|
|
20
20
|
import { Gizmos } from './engine_gizmos';
|
|
21
21
|
import { Mathf } from './engine_math';
|
|
22
|
+
import { Layer } from './extensions/NEEDLE_animator_controller_model';
|
|
22
23
|
export type Rapier = typeof RAPIER;
|
|
23
24
|
|
|
24
25
|
|
|
@@ -41,6 +42,8 @@ const $bodyKey = Symbol("physics body");
|
|
|
41
42
|
const $colliderRigidbody = Symbol("rigidbody");
|
|
42
43
|
// const $removed = Symbol("removed");
|
|
43
44
|
|
|
45
|
+
const layerMaskHelper: Layers = new Layers();
|
|
46
|
+
|
|
44
47
|
export class RaycastOptions {
|
|
45
48
|
ray: Ray | undefined = undefined;
|
|
46
49
|
cam: Camera | undefined | null = undefined;
|
|
@@ -52,6 +55,7 @@ export class RaycastOptions {
|
|
|
52
55
|
minDistance: number | undefined = undefined;
|
|
53
56
|
maxDistance: number | undefined = undefined;
|
|
54
57
|
lineThreshold: number | undefined = undefined;
|
|
58
|
+
/** raw layer mask, use setLayer to set an individual layer active */
|
|
55
59
|
layerMask: Layers | number | undefined = undefined;
|
|
56
60
|
ignore: Object3D[] | undefined = undefined;
|
|
57
61
|
|
|
@@ -61,6 +65,13 @@ export class RaycastOptions {
|
|
|
61
65
|
this.screenPoint.y = -(oy / window.innerHeight) * 2 + 1;
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
/** sets one layer for raycasting (e.g. layer 4, only objects on layer 4 will then be hit) */
|
|
69
|
+
setLayer(layer: number) {
|
|
70
|
+
layerMaskHelper.set(layer);
|
|
71
|
+
this.layerMask = layerMaskHelper;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** sets the layer.mask value directly, use setLayer if you want to set e.g. an individual layer only active. See https://threejs.org/docs/#api/en/core/Layers for more information about layers */
|
|
64
75
|
setMask(mask: number) {
|
|
65
76
|
if (!this.layerMask) this.layerMask = new Layers();
|
|
66
77
|
const lm = this.layerMask as Layers;
|
|
@@ -69,7 +80,7 @@ export class RaycastOptions {
|
|
|
69
80
|
else this.layerMask = mask;
|
|
70
81
|
}
|
|
71
82
|
|
|
72
|
-
public static AllLayers = 0xFFFFFFFF;
|
|
83
|
+
public static readonly AllLayers = 0xFFFFFFFF;
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
export class SphereIntersection implements Intersection {
|
|
@@ -83,12 +94,22 @@ export class SphereIntersection implements Intersection {
|
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
96
|
|
|
97
|
+
export class SphereOverlapResult {
|
|
98
|
+
object: Object3D;
|
|
99
|
+
collider: ICollider;
|
|
100
|
+
constructor(object: Object3D, collider: ICollider) {
|
|
101
|
+
this.object = object;
|
|
102
|
+
this.collider = collider;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
86
106
|
declare type PhysicsRaycastResult = {
|
|
87
107
|
point: Vector3,
|
|
88
108
|
normal?: Vector3,
|
|
89
109
|
collider?: ICollider
|
|
90
110
|
}
|
|
91
111
|
|
|
112
|
+
|
|
92
113
|
export class Physics {
|
|
93
114
|
|
|
94
115
|
// raycasting
|
|
@@ -107,6 +128,12 @@ export class Physics {
|
|
|
107
128
|
|
|
108
129
|
private sphereResults: Array<Intersection> = new Array<Intersection>();
|
|
109
130
|
private sphereMask: Layers = new Layers();
|
|
131
|
+
/** Test overlapping of a sphere with the threejs geometry. This does not use colliders. This does not return an exact intersection point (intersections returned contain the object and the world position of the object that is being hit)
|
|
132
|
+
* For a more accurate test use the physics engine's collider overlap test (see sphereOverlapPhysics)
|
|
133
|
+
* @param spherePos the center of the sphere in world space
|
|
134
|
+
* @param radius the radius of the sphere
|
|
135
|
+
* @param traverseChildsAfterHit if false it will stop after the first hit. If true it will continue to traverse and add all hits to the result array
|
|
136
|
+
*/
|
|
110
137
|
public sphereOverlap(spherePos: Vector3, radius: number, traverseChildsAfterHit: boolean = true): Array<Intersection> {
|
|
111
138
|
this.sphereResults.length = 0;
|
|
112
139
|
if (!this.context.scene) return this.sphereResults;
|
|
@@ -130,10 +157,9 @@ export class Physics {
|
|
|
130
157
|
if (mesh.matrixWorldNeedsUpdate) mesh.updateMatrixWorld();
|
|
131
158
|
const test = this.tempBoundingBox.copy(geo.boundingBox).applyMatrix4(mesh.matrixWorld);
|
|
132
159
|
if (sp.intersectsBox(test)) {
|
|
133
|
-
// console.log(obj, obj.layers.test(mask), obj.layers.mask, mask.mask);
|
|
134
160
|
const wp = getWorldPosition(obj);
|
|
135
161
|
const dist = wp.distanceTo(sp.center);
|
|
136
|
-
const int = new SphereIntersection(obj, dist,
|
|
162
|
+
const int = new SphereIntersection(obj, dist, wp);
|
|
137
163
|
results.push(int);
|
|
138
164
|
if (!traverseChildsAfterHit) return;
|
|
139
165
|
}
|
|
@@ -157,6 +183,8 @@ export class Physics {
|
|
|
157
183
|
/** raycast against rendered three objects. This might be very slow depending on your scene complexity.
|
|
158
184
|
* We recommend setting objects to IgnoreRaycast layer (2) when you don't need them to be raycasted.
|
|
159
185
|
* Raycasting SkinnedMeshes is specially expensive.
|
|
186
|
+
* Use raycastPhysics for raycasting against physic colliders only. Depending on your scenario this might be faster.
|
|
187
|
+
* @param options raycast options. If null, default options will be used.
|
|
160
188
|
*/
|
|
161
189
|
public raycast(options: RaycastOptions | null = null): Array<Intersection> {
|
|
162
190
|
if (!options) options = this.defaultRaycastOptions;
|
|
@@ -174,7 +202,8 @@ export class Physics {
|
|
|
174
202
|
else {
|
|
175
203
|
const cam = options.cam ?? this.context.mainCamera;
|
|
176
204
|
if (!cam) {
|
|
177
|
-
|
|
205
|
+
if (debugPhysics)
|
|
206
|
+
console.error("Can not perform raycast - no main camera found");
|
|
178
207
|
if (this.defaultRaycastOptions.results) this.defaultRaycastOptions.results.length = 0;
|
|
179
208
|
return this.defaultRaycastOptions.results ?? [];
|
|
180
209
|
}
|
|
@@ -199,6 +228,7 @@ export class Physics {
|
|
|
199
228
|
rc.layers.mask = options.layerMask.mask;
|
|
200
229
|
else
|
|
201
230
|
rc.layers.mask = options.layerMask;
|
|
231
|
+
console.log(rc.layers.mask, options.layerMask);
|
|
202
232
|
}
|
|
203
233
|
else {
|
|
204
234
|
rc.layers.enableAll();
|
|
@@ -222,8 +252,12 @@ export class Physics {
|
|
|
222
252
|
|
|
223
253
|
private rapierRay = new RAPIER.Ray({ x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 1 });
|
|
224
254
|
private raycastVectorsBuffer = new CircularBuffer(() => new Vector3(), 10);
|
|
225
|
-
|
|
226
|
-
|
|
255
|
+
/** Fast raycast against physics colliders
|
|
256
|
+
* @param origin ray origin in screen or worldspace
|
|
257
|
+
* @param direction ray direction in worldspace
|
|
258
|
+
* @param maxDistance max distance to raycast
|
|
259
|
+
* @param solid if true it will also hit the collider if origin is already inside it
|
|
260
|
+
*/
|
|
227
261
|
public raycastPhysicsFast(origin: Vec2 | Vec3, direction: Vec3 | undefined = undefined, maxDistance: number = Infinity, solid: boolean = true)
|
|
228
262
|
: null | { point: Vector3, collider: ICollider } {
|
|
229
263
|
|
|
@@ -285,6 +319,72 @@ export class Physics {
|
|
|
285
319
|
return ray;
|
|
286
320
|
}
|
|
287
321
|
|
|
322
|
+
|
|
323
|
+
private rapierSphere: RAPIER.Ball | null = null;
|
|
324
|
+
private rapierColliderArray: Array<SphereOverlapResult> = [];
|
|
325
|
+
private readonly rapierIdentityRotation = { x: 0, y: 0, z: 0, w: 1 };
|
|
326
|
+
private readonly rapierForwardVector = { x: 0, y: 0, z: 1 };
|
|
327
|
+
/** Precice sphere overlap detection using rapier against colliders
|
|
328
|
+
* @param point center of the sphere in worldspace
|
|
329
|
+
* @param radius radius of the sphere
|
|
330
|
+
* @returns array of colliders that overlap with the sphere. Note: they currently only contain the collider and the gameobject
|
|
331
|
+
*/
|
|
332
|
+
public sphereOverlapPhysics(point: Vector3, radius: number): Array<SphereOverlapResult> {
|
|
333
|
+
this.rapierColliderArray.length = 0;
|
|
334
|
+
if (!this.world) return this.rapierColliderArray;
|
|
335
|
+
if (!this.rapierSphere)
|
|
336
|
+
this.rapierSphere = new RAPIER.Ball(radius);
|
|
337
|
+
this.rapierSphere.radius = radius;
|
|
338
|
+
|
|
339
|
+
this.world.intersectionsWithShape(point, this.rapierIdentityRotation, this.rapierSphere, col => {
|
|
340
|
+
const collider = col[$componentKey] as ICollider
|
|
341
|
+
// if (collider.gameObject.layers.isEnabled(2)) return true;
|
|
342
|
+
const intersection = new SphereOverlapResult(collider.gameObject, collider);
|
|
343
|
+
this.rapierColliderArray.push(intersection);
|
|
344
|
+
return true; // Return `false` instead if we want to stop searching for other colliders that contain this point.
|
|
345
|
+
}, QueryFilterFlags.EXCLUDE_SENSORS, undefined, undefined, undefined,
|
|
346
|
+
col => {
|
|
347
|
+
const collider = col[$componentKey] as ICollider
|
|
348
|
+
return collider.gameObject.layers.isEnabled(2) == false
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
return this.rapierColliderArray;
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
// TODO: this only returns one hit
|
|
355
|
+
// let filterGroups = 0xffffffff;
|
|
356
|
+
// filterGroups &= ~(1 << 2);
|
|
357
|
+
// const hit: ShapeColliderTOI | null = this.world.castShape(point,
|
|
358
|
+
// this.rapierIdentityRotation,
|
|
359
|
+
// this.rapierForwardVector,
|
|
360
|
+
// this.rapierSphere,
|
|
361
|
+
// 0,
|
|
362
|
+
// QueryFilterFlags.EXCLUDE_SENSORS,
|
|
363
|
+
// // filterGroups,
|
|
364
|
+
// );
|
|
365
|
+
// // console.log(hit);
|
|
366
|
+
// if (hit) {
|
|
367
|
+
// const collider = hit.collider[$componentKey] as ICollider
|
|
368
|
+
// const intersection = new SphereOverlapResult(collider.gameObject);
|
|
369
|
+
// this.rapierColliderArray.push(intersection);
|
|
370
|
+
// // const localpt = hit.witness2;
|
|
371
|
+
// // // const normal = hit.normal2;
|
|
372
|
+
// // const hitPoint = new Vector3(localpt.x, localpt.y, localpt.z);
|
|
373
|
+
// // // collider.gameObject.localToWorld(hitPoint);
|
|
374
|
+
// // // const normalPt = new Vector3(normal.x, normal.y, normal.z);
|
|
375
|
+
// // // const mat = new Matrix4().setPosition(point).scale(new Vector3(radius, radius, radius));
|
|
376
|
+
// // // hitPoint.applyMatrix4(mat);
|
|
377
|
+
// // console.log(hit.witness2)
|
|
378
|
+
// // // hitPoint.add(point);
|
|
379
|
+
// // const dist = hitPoint.distanceTo(point);
|
|
380
|
+
// }
|
|
381
|
+
|
|
382
|
+
// return this.rapierColliderArray;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
288
388
|
// physics simulation
|
|
289
389
|
|
|
290
390
|
enabled: boolean = true;
|
|
@@ -352,42 +452,58 @@ export class Physics {
|
|
|
352
452
|
|
|
353
453
|
addBoxCollider(collider: ICollider, center: Vector3, size: Vector3) {
|
|
354
454
|
if (!this.enabled) {
|
|
355
|
-
if(debugPhysics) console.warn("Physics
|
|
455
|
+
if (debugPhysics) console.warn("Physics are disabled");
|
|
356
456
|
return;
|
|
357
457
|
}
|
|
358
458
|
const obj = collider.gameObject;
|
|
359
459
|
const scale = getWorldScale(obj, this._tempPosition).multiply(size);
|
|
360
460
|
scale.multiplyScalar(0.5);
|
|
461
|
+
|
|
462
|
+
// prevent negative scale
|
|
463
|
+
if (scale.x < 0)
|
|
464
|
+
scale.x = Math.abs(scale.x);
|
|
465
|
+
if (scale.y < 0)
|
|
466
|
+
scale.y = Math.abs(scale.y);
|
|
467
|
+
if (scale.z < 0)
|
|
468
|
+
scale.z = Math.abs(scale.z);
|
|
469
|
+
|
|
361
470
|
const desc = ColliderDesc.cuboid(scale.x, scale.y, scale.z);
|
|
471
|
+
// const objectLayerMask = collider.gameObject.layers.mask;
|
|
472
|
+
// const mask = objectLayerMask & ~2;
|
|
473
|
+
// desc.setCollisionGroups(objectLayerMask);
|
|
362
474
|
this.createCollider(collider, desc, center);
|
|
363
475
|
}
|
|
364
476
|
|
|
365
477
|
addSphereCollider(collider: ICollider, center: Vector3, radius: number) {
|
|
366
478
|
if (!this.enabled) {
|
|
367
|
-
if(debugPhysics) console.warn("Physics
|
|
479
|
+
if (debugPhysics) console.warn("Physics are disabled");
|
|
368
480
|
return;
|
|
369
481
|
}
|
|
370
482
|
const obj = collider.gameObject;
|
|
371
483
|
const scale = getWorldScale(obj, this._tempPosition).multiplyScalar(radius);
|
|
484
|
+
// Prevent negative scales
|
|
485
|
+
scale.x = Math.abs(scale.x);
|
|
372
486
|
const desc = ColliderDesc.ball(scale.x);
|
|
373
487
|
this.createCollider(collider, desc, center);
|
|
374
488
|
}
|
|
375
489
|
|
|
376
490
|
addCapsuleCollider(collider: ICollider, center: Vector3, height: number, radius: number) {
|
|
377
491
|
if (!this.enabled) {
|
|
378
|
-
if(debugPhysics) console.warn("Physics
|
|
492
|
+
if (debugPhysics) console.warn("Physics are disabled");
|
|
379
493
|
return;
|
|
380
494
|
}
|
|
381
495
|
const obj = collider.gameObject;
|
|
382
496
|
const scale = getWorldScale(obj, this._tempPosition);
|
|
383
|
-
|
|
497
|
+
// Prevent negative scales
|
|
498
|
+
scale.x = Math.abs(scale.x);
|
|
499
|
+
scale.y = Math.abs(scale.y);
|
|
384
500
|
const desc = ColliderDesc.capsule(height * .5 * scale.y - radius, radius * scale.x);
|
|
385
501
|
this.createCollider(collider, desc, center);
|
|
386
502
|
}
|
|
387
503
|
|
|
388
504
|
addMeshCollider(collider: ICollider, mesh: Mesh, convex: boolean, scale: Vector3) {
|
|
389
505
|
if (!this.enabled) {
|
|
390
|
-
if(debugPhysics) console.warn("Physics
|
|
506
|
+
if (debugPhysics) console.warn("Physics are disabled");
|
|
391
507
|
return;
|
|
392
508
|
}
|
|
393
509
|
const geo = mesh.geometry;
|
|
@@ -88,7 +88,6 @@ function invokeEvents(type: GltfLoadEventType, event: GltfLoadEvent) {
|
|
|
88
88
|
async function handleLoadedGltf(context: Context, gltfId: string, gltf, seed: number | null | UIDProvider, componentsExtension) {
|
|
89
89
|
if (printGltf)
|
|
90
90
|
console.log(gltf);
|
|
91
|
-
await context.assets.registerGltf(gltf);
|
|
92
91
|
await getLoader().createBuiltinComponents(context, gltfId, gltf, seed, componentsExtension);
|
|
93
92
|
|
|
94
93
|
// load and assign animation
|
|
@@ -614,7 +614,13 @@ export function assign(target: any, source: any, info?: ImplementationInformatio
|
|
|
614
614
|
|
|
615
615
|
for (const key of Object.keys(source)) {
|
|
616
616
|
const desc = getPropertyDescriptor(target, key);
|
|
617
|
+
|
|
617
618
|
if (onlyDeclared && desc === undefined) continue;
|
|
619
|
+
|
|
620
|
+
if (typeof desc?.value == "function") {
|
|
621
|
+
// arrow functions are defined as properties on the object
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
618
624
|
if (!desc || desc.writable === true) {
|
|
619
625
|
target[key] = source[key];
|
|
620
626
|
}
|
|
@@ -8,8 +8,7 @@ import { NetworkConnection } from './engine_networking';
|
|
|
8
8
|
import * as looputils from './engine_mainloop_utils';
|
|
9
9
|
import * as utils from "./engine_utils";
|
|
10
10
|
|
|
11
|
-
import { EffectComposer } from
|
|
12
|
-
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass';
|
|
11
|
+
import { EffectComposer, RenderPass } from "postprocessing";
|
|
13
12
|
|
|
14
13
|
import { AssetDatabase } from './engine_assetdatabase';
|
|
15
14
|
|
|
@@ -323,7 +322,8 @@ export class Context implements IContext {
|
|
|
323
322
|
this.renderer.domElement.style.height = "100%";
|
|
324
323
|
if (this.composer) {
|
|
325
324
|
this.composer.setSize?.call(this.composer, width, height);
|
|
326
|
-
this.composer
|
|
325
|
+
if("setPixelRatio" in this.composer && typeof this.composer.setPixelRatio === "function")
|
|
326
|
+
this.composer.setPixelRatio?.call(this.composer, window.devicePixelRatio);
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
}
|
|
@@ -571,7 +571,7 @@ export class Context implements IContext {
|
|
|
571
571
|
}
|
|
572
572
|
else {
|
|
573
573
|
ContextRegistry.dispatchCallback(ContextEvent.MissingCamera, this);
|
|
574
|
-
if (!this.mainCamera)
|
|
574
|
+
if (!this.mainCamera && !this.isManagedExternally)
|
|
575
575
|
console.error("MISSING camera", this);
|
|
576
576
|
}
|
|
577
577
|
}
|
|
@@ -608,6 +608,7 @@ export class Context implements IContext {
|
|
|
608
608
|
|
|
609
609
|
private render(_, frame) {
|
|
610
610
|
|
|
611
|
+
|
|
611
612
|
this._currentFrameEvent = -1;
|
|
612
613
|
|
|
613
614
|
if (this.onHandlePaused()) return;
|
|
@@ -744,6 +745,10 @@ export class Context implements IContext {
|
|
|
744
745
|
this.connection.sendBufferedMessagesNow();
|
|
745
746
|
|
|
746
747
|
this._stats?.end();
|
|
748
|
+
|
|
749
|
+
if (this.time.frame === 1) {
|
|
750
|
+
this.domElement.dispatchEvent(new CustomEvent("ready"));
|
|
751
|
+
}
|
|
747
752
|
}
|
|
748
753
|
|
|
749
754
|
renderNow(camera?: Camera) {
|
|
@@ -753,10 +758,15 @@ export class Context implements IContext {
|
|
|
753
758
|
}
|
|
754
759
|
this._isRendering = true;
|
|
755
760
|
this.renderRequiredTextures();
|
|
761
|
+
// if (camera === this.mainCameraComponent?.cam) {
|
|
762
|
+
// if (this.mainCameraComponent.activeTexture) {
|
|
763
|
+
|
|
764
|
+
// }
|
|
765
|
+
// }
|
|
756
766
|
if (this.composer && !this.isInXR) {
|
|
757
767
|
this.composer.render();
|
|
758
768
|
}
|
|
759
|
-
else if (
|
|
769
|
+
else if (camera) {
|
|
760
770
|
this.renderer.render(this.scene, camera);
|
|
761
771
|
}
|
|
762
772
|
this._isRendering = false;
|
|
@@ -1,6 +1,55 @@
|
|
|
1
|
-
import { WebGLRenderTarget } from "three"
|
|
1
|
+
import { Camera, Mesh, Object3D, Texture, WebGLRenderer, WebGLRenderTarget } from "three";
|
|
2
|
+
import { EffectComposer } from "postprocessing";
|
|
3
|
+
import { findUsers } from "./engine_assetdatabase";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const _prevVisible = Symbol("previous-visibility");
|
|
7
|
+
|
|
8
|
+
export class RenderTexture extends WebGLRenderTarget {
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
render(scene: Object3D, camera: Camera, renderer: WebGLRenderer | EffectComposer) {
|
|
12
|
+
if (renderer instanceof EffectComposer) {
|
|
13
|
+
if (!this["_unsupported_effectcomposer_warning"]) {
|
|
14
|
+
console.warn("RenderTexture.render() does not yet support EffectComposer");
|
|
15
|
+
this["_unsupported_effectcomposer_warning"] = true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.onBeforeRender();
|
|
20
|
+
const prev = renderer.getRenderTarget();
|
|
21
|
+
renderer.setRenderTarget(this);
|
|
22
|
+
renderer.render(scene, camera);
|
|
23
|
+
renderer.setRenderTarget(prev);
|
|
24
|
+
this.onAfterRender();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
private static _userSet: Set<object> = new Set();
|
|
30
|
+
|
|
31
|
+
private onBeforeRender() {
|
|
32
|
+
RenderTexture._userSet.clear();
|
|
33
|
+
const users = findUsers(this.texture, true, null, RenderTexture._userSet);
|
|
34
|
+
for (const user of users) {
|
|
35
|
+
if (user instanceof Mesh) {
|
|
36
|
+
user[_prevVisible] = user.visible;
|
|
37
|
+
user.visible = false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private onAfterRender() {
|
|
43
|
+
for (const user of RenderTexture._userSet) {
|
|
44
|
+
if (user instanceof Mesh) {
|
|
45
|
+
user.visible = user[_prevVisible];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
RenderTexture._userSet.clear();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
2
55
|
|
|
3
|
-
export class RenderTexture extends WebGLRenderTarget
|
|
4
|
-
{
|
|
5
|
-
|
|
6
|
-
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RenderTexture } from "./engine_texture";
|
|
1
2
|
import { Camera, Color, Material, Object3D, Vector3, Quaternion, Ray, Scene, Renderer, WebGLRenderer } from "three";
|
|
2
3
|
import { RGBAColor } from "../engine-components/js-extensions/RGBAColor";
|
|
3
4
|
import { CollisionDetectionMode, PhysicsMaterial, RigidbodyConstraints } from "./engine_physics.types";
|
|
@@ -72,12 +73,14 @@ export declare interface IGameObject extends Object3D {
|
|
|
72
73
|
|
|
73
74
|
activeSelf: boolean;
|
|
74
75
|
|
|
76
|
+
destroy(): void;
|
|
77
|
+
|
|
75
78
|
/** NOTE: this is just a wrapper for devs coming from Unity. Please use this.gameObject instead. In Needle Engine this.gameObject is the same as this.gameObject.transform. See the tutorial link below for more information
|
|
76
79
|
* @augments Object3D
|
|
77
80
|
* @tutorial https://fwd.needle.tools/needle-engine/docs/transform
|
|
78
81
|
* */
|
|
79
82
|
get transform(): Object3D;
|
|
80
|
-
|
|
83
|
+
|
|
81
84
|
addNewComponent<T>(type: Constructor<T>): T | null;
|
|
82
85
|
removeComponent(comp: IComponent): IComponent;
|
|
83
86
|
getOrAddComponent<T>(typeName: Constructor<T> | null): T;
|
|
@@ -161,6 +164,7 @@ export interface IComponent {
|
|
|
161
164
|
export declare interface ICamera extends IComponent {
|
|
162
165
|
get isCamera(): boolean;
|
|
163
166
|
applyClearFlagsIfIsActiveCamera(): unknown;
|
|
167
|
+
applyClearFlags();
|
|
164
168
|
buildCamera();
|
|
165
169
|
get cam(): Camera;
|
|
166
170
|
nearClipPlane: number;
|
|
@@ -171,6 +175,7 @@ export declare interface ICamera extends IComponent {
|
|
|
171
175
|
aspect: number;
|
|
172
176
|
fieldOfView?: number;
|
|
173
177
|
screenPointToRay(x: number, y: number, ray?: Ray): Ray;
|
|
178
|
+
targetTexture: RenderTexture | null;
|
|
174
179
|
}
|
|
175
180
|
|
|
176
181
|
export declare interface ICameraController {
|
|
@@ -44,8 +44,9 @@ export class CircularBuffer<T> {
|
|
|
44
44
|
let saveParams: boolean = false;
|
|
45
45
|
const requestedParams: Array<string> = [];
|
|
46
46
|
setTimeout(() => {
|
|
47
|
-
if (saveParams)
|
|
48
|
-
console.log(requestedParams);
|
|
47
|
+
if (saveParams) {
|
|
48
|
+
console.log(requestedParams.sort());
|
|
49
|
+
}
|
|
49
50
|
}, 100);
|
|
50
51
|
|
|
51
52
|
export function getUrlParams() {
|
|
@@ -61,7 +62,7 @@ export function getParam(paramName: string): string | boolean | number {
|
|
|
61
62
|
const val = urlParams.get(paramName);
|
|
62
63
|
if (val) {
|
|
63
64
|
const num = Number(val);
|
|
64
|
-
if (!isNaN(num)) return num;
|
|
65
|
+
if (!isNaN(num)) return num;
|
|
65
66
|
return val;
|
|
66
67
|
}
|
|
67
68
|
else return true;
|
|
@@ -83,10 +84,10 @@ export function setParam(paramName: string, paramValue: string): void {
|
|
|
83
84
|
export function setParamWithoutReload(paramName: string, paramValue: string | null, appendHistory = true): void {
|
|
84
85
|
const urlParams = getUrlParams();
|
|
85
86
|
if (urlParams.has(paramName)) {
|
|
86
|
-
if(paramValue === null) urlParams.delete(paramName);
|
|
87
|
+
if (paramValue === null) urlParams.delete(paramName);
|
|
87
88
|
else urlParams.set(paramName, paramValue);
|
|
88
89
|
}
|
|
89
|
-
else if(paramValue !== null)
|
|
90
|
+
else if (paramValue !== null)
|
|
90
91
|
urlParams.append(paramName, paramValue);
|
|
91
92
|
if (appendHistory) pushState(paramName, urlParams);
|
|
92
93
|
else setState(paramName, urlParams);
|
|
@@ -13,6 +13,7 @@ declare type ProgressiveTextureSchema = {
|
|
|
13
13
|
uri: string;
|
|
14
14
|
guid: string;
|
|
15
15
|
}
|
|
16
|
+
const $progressiveTextureExtension = Symbol("needle-progressive-texture");
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
const debug_toggle_maps: Map<Material, { [key: string]: { original: Texture, lod0: Texture } }> = new Map();
|
|
@@ -35,6 +36,7 @@ if (debug) {
|
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
|
|
38
40
|
export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
39
41
|
|
|
40
42
|
static assignTextureLOD(context: Context, source: SourceIdentifier | undefined, material: Material, level: number = 0) {
|
|
@@ -86,21 +88,6 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
86
88
|
this.context = context;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
private _loading: number[] = [];
|
|
90
|
-
|
|
91
|
-
// beforeRoot(): null {
|
|
92
|
-
// console.log("BEFORE ROOT", this.parser);
|
|
93
|
-
// return null;
|
|
94
|
-
// }
|
|
95
|
-
|
|
96
|
-
// loadTexture(index: number): Promise<Texture> | null {
|
|
97
|
-
// console.log(index, this._loading);
|
|
98
|
-
// if (this._loading.includes(index)) return null;
|
|
99
|
-
// const textureInfo = this.parser.json.textures[index];
|
|
100
|
-
// if (debug)
|
|
101
|
-
// console.log(index, textureInfo);
|
|
102
|
-
// return null;
|
|
103
|
-
// }
|
|
104
91
|
|
|
105
92
|
afterRoot(gltf: GLTF): null {
|
|
106
93
|
if (debug)
|
|
@@ -110,10 +97,12 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
110
97
|
const ext: ProgressiveTextureSchema = textureInfo?.extensions[EXTENSION_NAME];
|
|
111
98
|
if (ext) {
|
|
112
99
|
const prom = this.parser.getDependency("texture", index);
|
|
113
|
-
this._loading.splice(this._loading.indexOf(index), 1);
|
|
114
100
|
prom.then(t => {
|
|
115
|
-
if (debug) console.log("register
|
|
116
|
-
|
|
101
|
+
if (debug) console.log("> Progressive: register", t.name, t.uuid, ext);
|
|
102
|
+
// Put the extension info into the source (seems like tiled textures are cloned and the userdata etc is not properly copied BUT the source of course is not cloned)
|
|
103
|
+
// see https://github.com/needle-tools/needle-engine-support/issues/133
|
|
104
|
+
if (t.source)
|
|
105
|
+
t.source[$progressiveTextureExtension] = ext;
|
|
117
106
|
NEEDLE_progressive.cache.set(t.uuid, ext);
|
|
118
107
|
});
|
|
119
108
|
}
|
|
@@ -130,17 +119,24 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
130
119
|
private static async getOrLoadTexture(context: Context, source: SourceIdentifier | undefined, material: Material, slot: string, current: Texture, _level: number): Promise<Texture | null> {
|
|
131
120
|
|
|
132
121
|
const key = current.uuid;
|
|
133
|
-
|
|
134
|
-
|
|
122
|
+
|
|
123
|
+
let progressiveInfo: ProgressiveTextureSchema | undefined;
|
|
124
|
+
|
|
125
|
+
// See https://github.com/needle-tools/needle-engine-support/issues/133
|
|
126
|
+
if(current.source && current.source[$progressiveTextureExtension])
|
|
127
|
+
progressiveInfo = current.source[$progressiveTextureExtension];
|
|
128
|
+
if(!progressiveInfo) progressiveInfo = NEEDLE_progressive.cache.get(key);
|
|
129
|
+
|
|
130
|
+
if (progressiveInfo) {
|
|
135
131
|
if (debug)
|
|
136
|
-
console.log(key,
|
|
137
|
-
const uri = getPath(source,
|
|
132
|
+
console.log(key, progressiveInfo.uri, progressiveInfo.guid);
|
|
133
|
+
const uri = getPath(source, progressiveInfo.uri);
|
|
138
134
|
if (uri.endsWith(".glb") || uri.endsWith(".gltf")) {
|
|
139
|
-
if (!
|
|
140
|
-
console.warn("missing pointer for glb/gltf texture",
|
|
135
|
+
if (!progressiveInfo.guid) {
|
|
136
|
+
console.warn("missing pointer for glb/gltf texture", progressiveInfo);
|
|
141
137
|
return null;
|
|
142
138
|
}
|
|
143
|
-
const resolveKey = uri + "_" +
|
|
139
|
+
const resolveKey = uri + "_" + progressiveInfo.guid;
|
|
144
140
|
if (this.resolved[resolveKey]) {
|
|
145
141
|
if (debug) console.log("Texture has already been loaded: " + resolveKey, material.name, slot, current.name);
|
|
146
142
|
return this.resolved[resolveKey];
|
|
@@ -148,16 +144,18 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
148
144
|
|
|
149
145
|
const info = this.onProgressiveLoadStart(context, source, uri, material, slot);
|
|
150
146
|
try {
|
|
151
|
-
if(this.currentlyLoading[resolveKey] !== undefined) {
|
|
152
|
-
if(debug)
|
|
147
|
+
if (this.currentlyLoading[resolveKey] !== undefined) {
|
|
148
|
+
if (debug)
|
|
153
149
|
console.log("Already loading:", material.name + "." + slot, resolveKey);
|
|
154
150
|
const tex = await this.currentlyLoading[resolveKey];
|
|
155
151
|
return tex;
|
|
156
152
|
}
|
|
153
|
+
const ext = progressiveInfo;
|
|
157
154
|
const request = new Promise<Texture | null>(async (resolve, _) => {
|
|
158
155
|
const loader = new GLTFLoader();
|
|
159
156
|
addDracoAndKTX2Loaders(loader, context);
|
|
160
157
|
|
|
158
|
+
|
|
161
159
|
if (debug) console.log("Load " + uri, material.name, slot, ext.guid);
|
|
162
160
|
if (debug) {
|
|
163
161
|
await delay(Math.random() * 1000);
|
|
@@ -183,10 +181,12 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
183
181
|
if (!found)
|
|
184
182
|
return resolve(null);
|
|
185
183
|
|
|
186
|
-
const tex = await parser.getDependency("texture", index);
|
|
187
|
-
|
|
184
|
+
const tex = await parser.getDependency("texture", index) as Texture;
|
|
185
|
+
const source = tex.source;
|
|
186
|
+
tex.copy(current);
|
|
187
|
+
tex.source = source;
|
|
188
188
|
if (tex) {
|
|
189
|
-
tex.guid = ext.guid;
|
|
189
|
+
(tex as any).guid = ext.guid;
|
|
190
190
|
}
|
|
191
191
|
this.resolved[resolveKey] = tex as Texture;
|
|
192
192
|
if (debug)
|
|
@@ -209,12 +209,12 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
|
|
|
209
209
|
const loader = new TextureLoader();
|
|
210
210
|
const tex = await loader.loadAsync(uri);
|
|
211
211
|
if (tex) {
|
|
212
|
-
(tex as any).guid =
|
|
212
|
+
(tex as any).guid = progressiveInfo.guid;
|
|
213
213
|
tex.flipY = false;
|
|
214
214
|
tex.needsUpdate = true;
|
|
215
215
|
tex.encoding = current.encoding;
|
|
216
216
|
if (debug)
|
|
217
|
-
console.log(
|
|
217
|
+
console.log(progressiveInfo, tex);
|
|
218
218
|
}
|
|
219
219
|
else if (debug) console.warn("failed loading", uri);
|
|
220
220
|
return tex;
|
|
@@ -23,7 +23,10 @@ import {
|
|
|
23
23
|
DecrementWrapStencilOp,
|
|
24
24
|
InvertStencilOp,
|
|
25
25
|
} from "three";
|
|
26
|
-
import { getParam } from "../engine_utils";
|
|
26
|
+
import { getParam, isDebugMode } from "../engine_utils";
|
|
27
|
+
import { showBalloonWarning } from "../debug";
|
|
28
|
+
import { isUsingInstancing } from "../engine_gameobject";
|
|
29
|
+
import { isLocalNetwork } from "../engine_networking_utils";
|
|
27
30
|
|
|
28
31
|
const debug = getParam("debugstencil");
|
|
29
32
|
|
|
@@ -62,6 +65,12 @@ export class NEEDLE_render_objects implements GLTFLoaderPlugin {
|
|
|
62
65
|
const stencil: StencilSettingsModel = settings[i];
|
|
63
66
|
if (matchesLayer(stencil.layer, obj)) {
|
|
64
67
|
if (debug) console.log(stencil);
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
if (isLocalNetwork() && isUsingInstancing(obj.gameObject)) {
|
|
70
|
+
showBalloonWarning("Stencil not supported on instanced objects");
|
|
71
|
+
console.warn("Stencil not supported on instanced objects", obj);
|
|
72
|
+
}
|
|
73
|
+
}, 500)
|
|
65
74
|
for (let i = 0; i < obj.sharedMaterials.length; i++) {
|
|
66
75
|
let mat = obj.sharedMaterials[i];
|
|
67
76
|
if (mat) {
|