@needle-tools/engine 2.24.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 +568 -0
- package/LICENSE.md +10 -0
- package/README.md +11 -0
- package/dist/needle-engine.d.ts +5011 -0
- package/dist/needle-engine.js +6605 -0
- package/dist/needle-engine.js.map +7 -0
- package/dist/needle-engine.min.js +167 -0
- package/dist/needle-engine.min.js.map +7 -0
- package/lib/engine/debug/error_overlay.d.ts +1 -0
- package/lib/engine/debug/error_overlay.js +110 -0
- package/lib/engine/debug/error_overlay.js.map +1 -0
- package/lib/engine/engine.d.ts +27 -0
- package/lib/engine/engine.js +13 -0
- package/lib/engine/engine.js.map +1 -0
- package/lib/engine/engine_addressables.d.ts +46 -0
- package/lib/engine/engine_addressables.js +264 -0
- package/lib/engine/engine_addressables.js.map +1 -0
- package/lib/engine/engine_application.d.ts +13 -0
- package/lib/engine/engine_application.js +35 -0
- package/lib/engine/engine_application.js.map +1 -0
- package/lib/engine/engine_assetdatabase.d.ts +54 -0
- package/lib/engine/engine_assetdatabase.js +150 -0
- package/lib/engine/engine_assetdatabase.js.map +1 -0
- package/lib/engine/engine_caching.d.ts +0 -0
- package/lib/engine/engine_caching.js +2 -0
- package/lib/engine/engine_caching.js.map +1 -0
- package/lib/engine/engine_constants.d.ts +2 -0
- package/lib/engine/engine_constants.js +3 -0
- package/lib/engine/engine_constants.js.map +1 -0
- package/lib/engine/engine_coroutine.d.ts +3 -0
- package/lib/engine/engine_coroutine.js +14 -0
- package/lib/engine/engine_coroutine.js.map +1 -0
- package/lib/engine/engine_default_parameters.d.ts +2 -0
- package/lib/engine/engine_default_parameters.js +4 -0
- package/lib/engine/engine_default_parameters.js.map +1 -0
- package/lib/engine/engine_element.d.ts +32 -0
- package/lib/engine/engine_element.js +340 -0
- package/lib/engine/engine_element.js.map +1 -0
- package/lib/engine/engine_element_loading.d.ts +31 -0
- package/lib/engine/engine_element_loading.js +154 -0
- package/lib/engine/engine_element_loading.js.map +1 -0
- package/lib/engine/engine_element_overlay.d.ts +17 -0
- package/lib/engine/engine_element_overlay.js +95 -0
- package/lib/engine/engine_element_overlay.js.map +1 -0
- package/lib/engine/engine_gizmos.d.ts +2 -0
- package/lib/engine/engine_gizmos.js +14 -0
- package/lib/engine/engine_gizmos.js.map +1 -0
- package/lib/engine/engine_gltf.d.ts +2 -0
- package/lib/engine/engine_gltf.js +2 -0
- package/lib/engine/engine_gltf.js.map +1 -0
- package/lib/engine/engine_gltf_builtin_components.d.ts +8 -0
- package/lib/engine/engine_gltf_builtin_components.js +251 -0
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -0
- package/lib/engine/engine_input.d.ts +193 -0
- package/lib/engine/engine_input.js +566 -0
- package/lib/engine/engine_input.js.map +1 -0
- package/lib/engine/engine_input_utils.d.ts +2 -0
- package/lib/engine/engine_input_utils.js +23 -0
- package/lib/engine/engine_input_utils.js.map +1 -0
- package/lib/engine/engine_lightdata.d.ts +21 -0
- package/lib/engine/engine_lightdata.js +85 -0
- package/lib/engine/engine_lightdata.js.map +1 -0
- package/lib/engine/engine_loaders.d.ts +3 -0
- package/lib/engine/engine_loaders.js +20 -0
- package/lib/engine/engine_loaders.js.map +1 -0
- package/lib/engine/engine_mainloop_utils.d.ts +9 -0
- package/lib/engine/engine_mainloop_utils.js +288 -0
- package/lib/engine/engine_mainloop_utils.js.map +1 -0
- package/lib/engine/engine_math.d.ts +11 -0
- package/lib/engine/engine_math.js +40 -0
- package/lib/engine/engine_math.js.map +1 -0
- package/lib/engine/engine_networking.d.ts +133 -0
- package/lib/engine/engine_networking.js +541 -0
- package/lib/engine/engine_networking.js.map +1 -0
- package/lib/engine/engine_networking_auto.d.ts +18 -0
- package/lib/engine/engine_networking_auto.js +252 -0
- package/lib/engine/engine_networking_auto.js.map +1 -0
- package/lib/engine/engine_networking_files.d.ts +23 -0
- package/lib/engine/engine_networking_files.js +173 -0
- package/lib/engine/engine_networking_files.js.map +1 -0
- package/lib/engine/engine_networking_files_default_components.d.ts +3 -0
- package/lib/engine/engine_networking_files_default_components.js +45 -0
- package/lib/engine/engine_networking_files_default_components.js.map +1 -0
- package/lib/engine/engine_networking_instantiate.d.ts +34 -0
- package/lib/engine/engine_networking_instantiate.js +274 -0
- package/lib/engine/engine_networking_instantiate.js.map +1 -0
- package/lib/engine/engine_networking_peer.d.ts +10 -0
- package/lib/engine/engine_networking_peer.js +106 -0
- package/lib/engine/engine_networking_peer.js.map +1 -0
- package/lib/engine/engine_networking_utils.d.ts +1 -0
- package/lib/engine/engine_networking_utils.js +11 -0
- package/lib/engine/engine_networking_utils.js.map +1 -0
- package/lib/engine/engine_networking_websocket.d.ts +0 -0
- package/lib/engine/engine_networking_websocket.js +3 -0
- package/lib/engine/engine_networking_websocket.js.map +1 -0
- package/lib/engine/engine_physics.d.ts +88 -0
- package/lib/engine/engine_physics.js +563 -0
- package/lib/engine/engine_physics.js.map +1 -0
- package/lib/engine/engine_rendererdata.d.ts +48 -0
- package/lib/engine/engine_rendererdata.js +182 -0
- package/lib/engine/engine_rendererdata.js.map +1 -0
- package/lib/engine/engine_scenetools.d.ts +25 -0
- package/lib/engine/engine_scenetools.js +211 -0
- package/lib/engine/engine_scenetools.js.map +1 -0
- package/lib/engine/engine_serialization.d.ts +3 -0
- package/lib/engine/engine_serialization.js +5 -0
- package/lib/engine/engine_serialization.js.map +1 -0
- package/lib/engine/engine_serialization_builtin_serializer.d.ts +49 -0
- package/lib/engine/engine_serialization_builtin_serializer.js +238 -0
- package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -0
- package/lib/engine/engine_serialization_core.d.ts +70 -0
- package/lib/engine/engine_serialization_core.js +417 -0
- package/lib/engine/engine_serialization_core.js.map +1 -0
- package/lib/engine/engine_serialization_decorator.d.ts +9 -0
- package/lib/engine/engine_serialization_decorator.js +44 -0
- package/lib/engine/engine_serialization_decorator.js.map +1 -0
- package/lib/engine/engine_setup.d.ts +129 -0
- package/lib/engine/engine_setup.js +609 -0
- package/lib/engine/engine_setup.js.map +1 -0
- package/lib/engine/engine_shaders.d.ts +31 -0
- package/lib/engine/engine_shaders.js +230 -0
- package/lib/engine/engine_shaders.js.map +1 -0
- package/lib/engine/engine_three_utils.d.ts +20 -0
- package/lib/engine/engine_three_utils.js +247 -0
- package/lib/engine/engine_three_utils.js.map +1 -0
- package/lib/engine/engine_time.d.ts +13 -0
- package/lib/engine/engine_time.js +31 -0
- package/lib/engine/engine_time.js.map +1 -0
- package/lib/engine/engine_typestore.d.ts +7 -0
- package/lib/engine/engine_typestore.js +17 -0
- package/lib/engine/engine_typestore.js.map +1 -0
- package/lib/engine/engine_utils.d.ts +34 -0
- package/lib/engine/engine_utils.js +239 -0
- package/lib/engine/engine_utils.js.map +1 -0
- package/lib/engine/engine_web_api.d.ts +12 -0
- package/lib/engine/engine_web_api.js +114 -0
- package/lib/engine/engine_web_api.js.map +1 -0
- package/lib/engine/extensions/KHR_animation_pointer.d.ts +0 -0
- package/lib/engine/extensions/KHR_animation_pointer.js +385 -0
- package/lib/engine/extensions/KHR_animation_pointer.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_animator_controller.d.ts +0 -0
- package/lib/engine/extensions/NEEDLE_animator_controller.js +59 -0
- package/lib/engine/extensions/NEEDLE_animator_controller.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_animator_controller_model.d.ts +108 -0
- package/lib/engine/extensions/NEEDLE_animator_controller_model.js +92 -0
- package/lib/engine/extensions/NEEDLE_animator_controller_model.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_components.d.ts +32 -0
- package/lib/engine/extensions/NEEDLE_components.js +193 -0
- package/lib/engine/extensions/NEEDLE_components.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_deferred_texture.d.ts +18 -0
- package/lib/engine/extensions/NEEDLE_deferred_texture.js +149 -0
- package/lib/engine/extensions/NEEDLE_deferred_texture.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_gameobject_data.d.ts +10 -0
- package/lib/engine/extensions/NEEDLE_gameobject_data.js +54 -0
- package/lib/engine/extensions/NEEDLE_gameobject_data.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_lighting_settings.d.ts +35 -0
- package/lib/engine/extensions/NEEDLE_lighting_settings.js +136 -0
- package/lib/engine/extensions/NEEDLE_lighting_settings.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_lightmaps.d.ts +17 -0
- package/lib/engine/extensions/NEEDLE_lightmaps.js +69 -0
- package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_persistent_assets.d.ts +11 -0
- package/lib/engine/extensions/NEEDLE_persistent_assets.js +64 -0
- package/lib/engine/extensions/NEEDLE_persistent_assets.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_render_objects.d.ts +12 -0
- package/lib/engine/extensions/NEEDLE_render_objects.js +144 -0
- package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_techniques_webgl.d.ts +39 -0
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js +419 -0
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_timeline.d.ts +0 -0
- package/lib/engine/extensions/NEEDLE_timeline.js +57 -0
- package/lib/engine/extensions/NEEDLE_timeline.js.map +1 -0
- package/lib/engine/extensions/extension_resolver.d.ts +4 -0
- package/lib/engine/extensions/extension_resolver.js +2 -0
- package/lib/engine/extensions/extension_resolver.js.map +1 -0
- package/lib/engine/extensions/extension_utils.d.ts +2 -0
- package/lib/engine/extensions/extension_utils.js +130 -0
- package/lib/engine/extensions/extension_utils.js.map +1 -0
- package/lib/engine/extensions/extensions.d.ts +6 -0
- package/lib/engine/extensions/extensions.js +41 -0
- package/lib/engine/extensions/extensions.js.map +1 -0
- package/lib/engine/shaders/shaderData.d.ts +55 -0
- package/lib/engine/shaders/shaderData.js +59 -0
- package/lib/engine/shaders/shaderData.js.map +1 -0
- package/lib/engine/tests/simulate_avatars.d.ts +0 -0
- package/lib/engine/tests/simulate_avatars.js +3 -0
- package/lib/engine/tests/simulate_avatars.js.map +1 -0
- package/lib/engine/tests/test_utils.d.ts +2 -0
- package/lib/engine/tests/test_utils.js +54 -0
- package/lib/engine/tests/test_utils.js.map +1 -0
- package/lib/engine-components/AlignmentConstraint.d.ts +10 -0
- package/lib/engine-components/AlignmentConstraint.js +27 -0
- package/lib/engine-components/AlignmentConstraint.js.map +1 -0
- package/lib/engine-components/Animation.d.ts +44 -0
- package/lib/engine-components/Animation.js +257 -0
- package/lib/engine-components/Animation.js.map +1 -0
- package/lib/engine-components/AnimationCurve.d.ts +15 -0
- package/lib/engine-components/AnimationCurve.js +62 -0
- package/lib/engine-components/AnimationCurve.js.map +1 -0
- package/lib/engine-components/Animator.d.ts +48 -0
- package/lib/engine-components/Animator.js +126 -0
- package/lib/engine-components/Animator.js.map +1 -0
- package/lib/engine-components/AnimatorController.d.ts +39 -0
- package/lib/engine-components/AnimatorController.js +687 -0
- package/lib/engine-components/AnimatorController.js.map +1 -0
- package/lib/engine-components/AudioListener.d.ts +7 -0
- package/lib/engine-components/AudioListener.js +29 -0
- package/lib/engine-components/AudioListener.js.map +1 -0
- package/lib/engine-components/AudioSource.d.ts +61 -0
- package/lib/engine-components/AudioSource.js +377 -0
- package/lib/engine-components/AudioSource.js.map +1 -0
- package/lib/engine-components/AvatarLoader.d.ts +22 -0
- package/lib/engine-components/AvatarLoader.js +203 -0
- package/lib/engine-components/AvatarLoader.js.map +1 -0
- package/lib/engine-components/AxesHelper.d.ts +9 -0
- package/lib/engine-components/AxesHelper.js +43 -0
- package/lib/engine-components/AxesHelper.js.map +1 -0
- package/lib/engine-components/BasicIKConstraint.d.ts +9 -0
- package/lib/engine-components/BasicIKConstraint.js +44 -0
- package/lib/engine-components/BasicIKConstraint.js.map +1 -0
- package/lib/engine-components/BoxCollider.d.ts +2 -0
- package/lib/engine-components/BoxCollider.js +3 -0
- package/lib/engine-components/BoxCollider.js.map +1 -0
- package/lib/engine-components/BoxHelperComponent.d.ts +16 -0
- package/lib/engine-components/BoxHelperComponent.js +72 -0
- package/lib/engine-components/BoxHelperComponent.js.map +1 -0
- package/lib/engine-components/Camera.d.ts +38 -0
- package/lib/engine-components/Camera.js +258 -0
- package/lib/engine-components/Camera.js.map +1 -0
- package/lib/engine-components/Collider.d.ts +21 -0
- package/lib/engine-components/Collider.js +65 -0
- package/lib/engine-components/Collider.js.map +1 -0
- package/lib/engine-components/Component.d.ts +165 -0
- package/lib/engine-components/Component.js +895 -0
- package/lib/engine-components/Component.js.map +1 -0
- package/lib/engine-components/ComponentExtensions.d.ts +2 -0
- package/lib/engine-components/ComponentExtensions.js +3 -0
- package/lib/engine-components/ComponentExtensions.js.map +1 -0
- package/lib/engine-components/DeleteBox.d.ts +9 -0
- package/lib/engine-components/DeleteBox.js +27 -0
- package/lib/engine-components/DeleteBox.js.map +1 -0
- package/lib/engine-components/DeviceFlag.d.ts +12 -0
- package/lib/engine-components/DeviceFlag.js +50 -0
- package/lib/engine-components/DeviceFlag.js.map +1 -0
- package/lib/engine-components/DragControls.d.ts +44 -0
- package/lib/engine-components/DragControls.js +465 -0
- package/lib/engine-components/DragControls.js.map +1 -0
- package/lib/engine-components/DropListener.d.ts +15 -0
- package/lib/engine-components/DropListener.js +102 -0
- package/lib/engine-components/DropListener.js.map +1 -0
- package/lib/engine-components/Duplicatable.d.ts +16 -0
- package/lib/engine-components/Duplicatable.js +150 -0
- package/lib/engine-components/Duplicatable.js.map +1 -0
- package/lib/engine-components/EventList.d.ts +22 -0
- package/lib/engine-components/EventList.js +97 -0
- package/lib/engine-components/EventList.js.map +1 -0
- package/lib/engine-components/EventTrigger.d.ts +3 -0
- package/lib/engine-components/EventTrigger.js +4 -0
- package/lib/engine-components/EventTrigger.js.map +1 -0
- package/lib/engine-components/EventType.d.ts +19 -0
- package/lib/engine-components/EventType.js +72 -0
- package/lib/engine-components/EventType.js.map +1 -0
- package/lib/engine-components/FlyControls.d.ts +7 -0
- package/lib/engine-components/FlyControls.js +22 -0
- package/lib/engine-components/FlyControls.js.map +1 -0
- package/lib/engine-components/Gizmos.d.ts +12 -0
- package/lib/engine-components/Gizmos.js +61 -0
- package/lib/engine-components/Gizmos.js.map +1 -0
- package/lib/engine-components/GltfExport.d.ts +28 -0
- package/lib/engine-components/GltfExport.js +201 -0
- package/lib/engine-components/GltfExport.js.map +1 -0
- package/lib/engine-components/GridHelper.d.ts +11 -0
- package/lib/engine-components/GridHelper.js +41 -0
- package/lib/engine-components/GridHelper.js.map +1 -0
- package/lib/engine-components/GroundProjection.d.ts +18 -0
- package/lib/engine-components/GroundProjection.js +77 -0
- package/lib/engine-components/GroundProjection.js.map +1 -0
- package/lib/engine-components/Interactable.d.ts +10 -0
- package/lib/engine-components/Interactable.js +13 -0
- package/lib/engine-components/Interactable.js.map +1 -0
- package/lib/engine-components/LODGroup.d.ts +29 -0
- package/lib/engine-components/LODGroup.js +176 -0
- package/lib/engine-components/LODGroup.js.map +1 -0
- package/lib/engine-components/Light.d.ts +69 -0
- package/lib/engine-components/Light.js +407 -0
- package/lib/engine-components/Light.js.map +1 -0
- package/lib/engine-components/LookAtConstraint.d.ts +7 -0
- package/lib/engine-components/LookAtConstraint.js +18 -0
- package/lib/engine-components/LookAtConstraint.js.map +1 -0
- package/lib/engine-components/MeshCollider.d.ts +4 -0
- package/lib/engine-components/MeshCollider.js +8 -0
- package/lib/engine-components/MeshCollider.js.map +1 -0
- package/lib/engine-components/NavMesh.d.ts +5 -0
- package/lib/engine-components/NavMesh.js +11 -0
- package/lib/engine-components/NavMesh.js.map +1 -0
- package/lib/engine-components/NestedGltf.d.ts +10 -0
- package/lib/engine-components/NestedGltf.js +61 -0
- package/lib/engine-components/NestedGltf.js.map +1 -0
- package/lib/engine-components/Networking.d.ts +9 -0
- package/lib/engine-components/Networking.js +47 -0
- package/lib/engine-components/Networking.js.map +1 -0
- package/lib/engine-components/OffsetConstraint.d.ts +11 -0
- package/lib/engine-components/OffsetConstraint.js +31 -0
- package/lib/engine-components/OffsetConstraint.js.map +1 -0
- package/lib/engine-components/OrbitControls.d.ts +45 -0
- package/lib/engine-components/OrbitControls.js +247 -0
- package/lib/engine-components/OrbitControls.js.map +1 -0
- package/lib/engine-components/ParticleSystem.d.ts +34 -0
- package/lib/engine-components/ParticleSystem.js +216 -0
- package/lib/engine-components/ParticleSystem.js.map +1 -0
- package/lib/engine-components/ParticleSystemModules.d.ts +93 -0
- package/lib/engine-components/ParticleSystemModules.js +167 -0
- package/lib/engine-components/ParticleSystemModules.js.map +1 -0
- package/lib/engine-components/PlayerColor.d.ts +13 -0
- package/lib/engine-components/PlayerColor.js +85 -0
- package/lib/engine-components/PlayerColor.js.map +1 -0
- package/lib/engine-components/Renderer.d.ts +72 -0
- package/lib/engine-components/Renderer.js +678 -0
- package/lib/engine-components/Renderer.js.map +1 -0
- package/lib/engine-components/RendererLightmap.d.ts +23 -0
- package/lib/engine-components/RendererLightmap.js +128 -0
- package/lib/engine-components/RendererLightmap.js.map +1 -0
- package/lib/engine-components/Rigidbody.d.ts +42 -0
- package/lib/engine-components/Rigidbody.js +170 -0
- package/lib/engine-components/Rigidbody.js.map +1 -0
- package/lib/engine-components/ScreenCapture.d.ts +9 -0
- package/lib/engine-components/ScreenCapture.js +44 -0
- package/lib/engine-components/ScreenCapture.js.map +1 -0
- package/lib/engine-components/ShadowCatcher.d.ts +15 -0
- package/lib/engine-components/ShadowCatcher.js +94 -0
- package/lib/engine-components/ShadowCatcher.js.map +1 -0
- package/lib/engine-components/Skybox.d.ts +16 -0
- package/lib/engine-components/Skybox.js +121 -0
- package/lib/engine-components/Skybox.js.map +1 -0
- package/lib/engine-components/SmoothFollow.d.ts +13 -0
- package/lib/engine-components/SmoothFollow.js +57 -0
- package/lib/engine-components/SmoothFollow.js.map +1 -0
- package/lib/engine-components/SpatialTrigger.d.ts +27 -0
- package/lib/engine-components/SpatialTrigger.js +145 -0
- package/lib/engine-components/SpatialTrigger.js.map +1 -0
- package/lib/engine-components/SpectatorCamera.d.ts +36 -0
- package/lib/engine-components/SpectatorCamera.js +311 -0
- package/lib/engine-components/SpectatorCamera.js.map +1 -0
- package/lib/engine-components/SphereCollider.d.ts +2 -0
- package/lib/engine-components/SphereCollider.js +3 -0
- package/lib/engine-components/SphereCollider.js.map +1 -0
- package/lib/engine-components/SpringJoint.d.ts +13 -0
- package/lib/engine-components/SpringJoint.js +42 -0
- package/lib/engine-components/SpringJoint.js.map +1 -0
- package/lib/engine-components/SpriteRenderer.d.ts +33 -0
- package/lib/engine-components/SpriteRenderer.js +141 -0
- package/lib/engine-components/SpriteRenderer.js.map +1 -0
- package/lib/engine-components/SyncedCamera.d.ts +23 -0
- package/lib/engine-components/SyncedCamera.js +188 -0
- package/lib/engine-components/SyncedCamera.js.map +1 -0
- package/lib/engine-components/SyncedRoom.d.ts +20 -0
- package/lib/engine-components/SyncedRoom.js +151 -0
- package/lib/engine-components/SyncedRoom.js.map +1 -0
- package/lib/engine-components/SyncedTransform.d.ts +35 -0
- package/lib/engine-components/SyncedTransform.js +268 -0
- package/lib/engine-components/SyncedTransform.js.map +1 -0
- package/lib/engine-components/TestRunner.d.ts +13 -0
- package/lib/engine-components/TestRunner.js +100 -0
- package/lib/engine-components/TestRunner.js.map +1 -0
- package/lib/engine-components/TransformGizmo.d.ts +15 -0
- package/lib/engine-components/TransformGizmo.js +166 -0
- package/lib/engine-components/TransformGizmo.js.map +1 -0
- package/lib/engine-components/VideoPlayer.d.ts +55 -0
- package/lib/engine-components/VideoPlayer.js +307 -0
- package/lib/engine-components/VideoPlayer.js.map +1 -0
- package/lib/engine-components/Voip.d.ts +22 -0
- package/lib/engine-components/Voip.js +400 -0
- package/lib/engine-components/Voip.js.map +1 -0
- package/lib/engine-components/Volume.d.ts +30 -0
- package/lib/engine-components/Volume.js +86 -0
- package/lib/engine-components/Volume.js.map +1 -0
- package/lib/engine-components/WebARSessionRoot.d.ts +21 -0
- package/lib/engine-components/WebARSessionRoot.js +105 -0
- package/lib/engine-components/WebARSessionRoot.js.map +1 -0
- package/lib/engine-components/WebXR.d.ts +90 -0
- package/lib/engine-components/WebXR.js +498 -0
- package/lib/engine-components/WebXR.js.map +1 -0
- package/lib/engine-components/WebXRAvatar.d.ts +59 -0
- package/lib/engine-components/WebXRAvatar.js +263 -0
- package/lib/engine-components/WebXRAvatar.js.map +1 -0
- package/lib/engine-components/WebXRController.d.ts +145 -0
- package/lib/engine-components/WebXRController.js +924 -0
- package/lib/engine-components/WebXRController.js.map +1 -0
- package/lib/engine-components/WebXRGrabRendering.d.ts +42 -0
- package/lib/engine-components/WebXRGrabRendering.js +138 -0
- package/lib/engine-components/WebXRGrabRendering.js.map +1 -0
- package/lib/engine-components/WebXRRig.d.ts +4 -0
- package/lib/engine-components/WebXRRig.js +8 -0
- package/lib/engine-components/WebXRRig.js.map +1 -0
- package/lib/engine-components/WebXRSync.d.ts +54 -0
- package/lib/engine-components/WebXRSync.js +405 -0
- package/lib/engine-components/WebXRSync.js.map +1 -0
- package/lib/engine-components/XRFlag.d.ts +32 -0
- package/lib/engine-components/XRFlag.js +115 -0
- package/lib/engine-components/XRFlag.js.map +1 -0
- package/lib/engine-components/avatar/AvatarBlink_Simple.d.ts +10 -0
- package/lib/engine-components/avatar/AvatarBlink_Simple.js +76 -0
- package/lib/engine-components/avatar/AvatarBlink_Simple.js.map +1 -0
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.d.ts +13 -0
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js +75 -0
- package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js.map +1 -0
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.d.ts +27 -0
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.js +120 -0
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.js.map +1 -0
- package/lib/engine-components/avatar/Avatar_MouthShapes.d.ts +13 -0
- package/lib/engine-components/avatar/Avatar_MouthShapes.js +77 -0
- package/lib/engine-components/avatar/Avatar_MouthShapes.js.map +1 -0
- package/lib/engine-components/avatar/Avatar_MustacheShake.d.ts +8 -0
- package/lib/engine-components/avatar/Avatar_MustacheShake.js +29 -0
- package/lib/engine-components/avatar/Avatar_MustacheShake.js.map +1 -0
- package/lib/engine-components/codegen/exports.d.ts +140 -0
- package/lib/engine-components/codegen/exports.js +142 -0
- package/lib/engine-components/codegen/exports.js.map +1 -0
- package/lib/engine-components/debug/LogStats.d.ts +5 -0
- package/lib/engine-components/debug/LogStats.js +19 -0
- package/lib/engine-components/debug/LogStats.js.map +1 -0
- package/lib/engine-components/js-extensions/RGBAColor.d.ts +9 -0
- package/lib/engine-components/js-extensions/RGBAColor.js +35 -0
- package/lib/engine-components/js-extensions/RGBAColor.js.map +1 -0
- package/lib/engine-components/timeline/PlayableDirector.d.ts +66 -0
- package/lib/engine-components/timeline/PlayableDirector.js +460 -0
- package/lib/engine-components/timeline/PlayableDirector.js.map +1 -0
- package/lib/engine-components/timeline/SignalAsset.d.ts +19 -0
- package/lib/engine-components/timeline/SignalAsset.js +87 -0
- package/lib/engine-components/timeline/SignalAsset.js.map +1 -0
- package/lib/engine-components/timeline/TimelineModels.d.ts +86 -0
- package/lib/engine-components/timeline/TimelineModels.js +23 -0
- package/lib/engine-components/timeline/TimelineModels.js.map +1 -0
- package/lib/engine-components/timeline/TimelineTracks.d.ts +73 -0
- package/lib/engine-components/timeline/TimelineTracks.js +573 -0
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -0
- package/lib/engine-components/ui/BaseUIComponent.d.ts +24 -0
- package/lib/engine-components/ui/BaseUIComponent.js +129 -0
- package/lib/engine-components/ui/BaseUIComponent.js.map +1 -0
- package/lib/engine-components/ui/Button.d.ts +55 -0
- package/lib/engine-components/ui/Button.js +217 -0
- package/lib/engine-components/ui/Button.js.map +1 -0
- package/lib/engine-components/ui/Canvas.d.ts +39 -0
- package/lib/engine-components/ui/Canvas.js +169 -0
- package/lib/engine-components/ui/Canvas.js.map +1 -0
- package/lib/engine-components/ui/CanvasGroup.d.ts +14 -0
- package/lib/engine-components/ui/CanvasGroup.js +53 -0
- package/lib/engine-components/ui/CanvasGroup.js.map +1 -0
- package/lib/engine-components/ui/EventSystem.d.ts +44 -0
- package/lib/engine-components/ui/EventSystem.js +480 -0
- package/lib/engine-components/ui/EventSystem.js.map +1 -0
- package/lib/engine-components/ui/Graphic.d.ts +33 -0
- package/lib/engine-components/ui/Graphic.js +145 -0
- package/lib/engine-components/ui/Graphic.js.map +1 -0
- package/lib/engine-components/ui/Image.d.ts +20 -0
- package/lib/engine-components/ui/Image.js +61 -0
- package/lib/engine-components/ui/Image.js.map +1 -0
- package/lib/engine-components/ui/InputField.d.ts +25 -0
- package/lib/engine-components/ui/InputField.js +179 -0
- package/lib/engine-components/ui/InputField.js.map +1 -0
- package/lib/engine-components/ui/Interfaces.d.ts +7 -0
- package/lib/engine-components/ui/Interfaces.js +2 -0
- package/lib/engine-components/ui/Interfaces.js.map +1 -0
- package/lib/engine-components/ui/Keyboard.d.ts +31 -0
- package/lib/engine-components/ui/Keyboard.js +177 -0
- package/lib/engine-components/ui/Keyboard.js.map +1 -0
- package/lib/engine-components/ui/Layout.d.ts +10 -0
- package/lib/engine-components/ui/Layout.js +11 -0
- package/lib/engine-components/ui/Layout.js.map +1 -0
- package/lib/engine-components/ui/PointerEvents.d.ts +35 -0
- package/lib/engine-components/ui/PointerEvents.js +20 -0
- package/lib/engine-components/ui/PointerEvents.js.map +1 -0
- package/lib/engine-components/ui/Raycaster.d.ts +20 -0
- package/lib/engine-components/ui/Raycaster.js +40 -0
- package/lib/engine-components/ui/Raycaster.js.map +1 -0
- package/lib/engine-components/ui/RectTransform.d.ts +39 -0
- package/lib/engine-components/ui/RectTransform.js +173 -0
- package/lib/engine-components/ui/RectTransform.js.map +1 -0
- package/lib/engine-components/ui/SpatialHtml.d.ts +6 -0
- package/lib/engine-components/ui/SpatialHtml.js +58 -0
- package/lib/engine-components/ui/SpatialHtml.js.map +1 -0
- package/lib/engine-components/ui/Text.d.ts +68 -0
- package/lib/engine-components/ui/Text.js +631 -0
- package/lib/engine-components/ui/Text.js.map +1 -0
- package/lib/engine-components/ui/Utils.d.ts +19 -0
- package/lib/engine-components/ui/Utils.js +85 -0
- package/lib/engine-components/ui/Utils.js.map +1 -0
- package/lib/engine-schemes/schemes.d.ts +4 -0
- package/lib/engine-schemes/schemes.js +20 -0
- package/lib/engine-schemes/schemes.js.map +1 -0
- package/lib/engine-schemes/synced-camera-model.d.ts +25 -0
- package/lib/engine-schemes/synced-camera-model.js +68 -0
- package/lib/engine-schemes/synced-camera-model.js.map +1 -0
- package/lib/engine-schemes/synced-transform-model.d.ts +31 -0
- package/lib/engine-schemes/synced-transform-model.js +67 -0
- package/lib/engine-schemes/synced-transform-model.js.map +1 -0
- package/lib/engine-schemes/transform.d.ts +12 -0
- package/lib/engine-schemes/transform.js +40 -0
- package/lib/engine-schemes/transform.js.map +1 -0
- package/lib/engine-schemes/vec3.d.ts +11 -0
- package/lib/engine-schemes/vec3.js +30 -0
- package/lib/engine-schemes/vec3.js.map +1 -0
- package/lib/engine-schemes/vec4.d.ts +12 -0
- package/lib/engine-schemes/vec4.js +34 -0
- package/lib/engine-schemes/vec4.js.map +1 -0
- package/lib/engine-schemes/vr-user-state-buffer.d.ts +36 -0
- package/lib/engine-schemes/vr-user-state-buffer.js +104 -0
- package/lib/engine-schemes/vr-user-state-buffer.js.map +1 -0
- package/lib/needle-engine.d.ts +5 -0
- package/lib/needle-engine.js +34 -0
- package/lib/needle-engine.js.map +1 -0
- package/package.json +63 -0
- package/src/engine/codegen/register_types.js +297 -0
- package/src/engine/debug/error_overlay.ts +122 -0
- package/src/engine/engine.ts +15 -0
- package/src/engine/engine_addressables.ts +297 -0
- package/src/engine/engine_application.ts +42 -0
- package/src/engine/engine_assetdatabase.ts +215 -0
- package/src/engine/engine_caching.ts +0 -0
- package/src/engine/engine_components.js +202 -0
- package/src/engine/engine_constants.ts +3 -0
- package/src/engine/engine_coroutine.ts +16 -0
- package/src/engine/engine_default_parameters.ts +4 -0
- package/src/engine/engine_element.ts +380 -0
- package/src/engine/engine_element_loading.ts +178 -0
- package/src/engine/engine_element_overlay.ts +108 -0
- package/src/engine/engine_fileloader.js +9 -0
- package/src/engine/engine_generic_utils.js +14 -0
- package/src/engine/engine_gizmos.ts +15 -0
- package/src/engine/engine_gltf.ts +4 -0
- package/src/engine/engine_gltf_builtin_components.ts +298 -0
- package/src/engine/engine_input.ts +581 -0
- package/src/engine/engine_input_utils.ts +24 -0
- package/src/engine/engine_lightdata.ts +111 -0
- package/src/engine/engine_loaders.ts +26 -0
- package/src/engine/engine_mainloop_utils.ts +292 -0
- package/src/engine/engine_math.ts +43 -0
- package/src/engine/engine_networking.ts +664 -0
- package/src/engine/engine_networking_auto.ts +300 -0
- package/src/engine/engine_networking_files.ts +198 -0
- package/src/engine/engine_networking_files_default_components.ts +54 -0
- package/src/engine/engine_networking_instantiate.ts +321 -0
- package/src/engine/engine_networking_peer.ts +128 -0
- package/src/engine/engine_networking_utils.ts +12 -0
- package/src/engine/engine_networking_websocket.ts +1 -0
- package/src/engine/engine_physics.ts +652 -0
- package/src/engine/engine_rendererdata.ts +214 -0
- package/src/engine/engine_scenetools.ts +231 -0
- package/src/engine/engine_serialization.ts +4 -0
- package/src/engine/engine_serialization_builtin_serializer.ts +266 -0
- package/src/engine/engine_serialization_core.ts +513 -0
- package/src/engine/engine_serialization_decorator.ts +55 -0
- package/src/engine/engine_setup.ts +705 -0
- package/src/engine/engine_shaders.ts +243 -0
- package/src/engine/engine_three_utils.ts +290 -0
- package/src/engine/engine_time.ts +38 -0
- package/src/engine/engine_typestore.ts +21 -0
- package/src/engine/engine_utils.ts +268 -0
- package/src/engine/engine_web_api.ts +122 -0
- package/src/engine/extensions/EXT_texture_exr.js +42 -0
- package/src/engine/extensions/KHR_animation_pointer.ts +484 -0
- package/src/engine/extensions/NEEDLE_animator_controller.ts +68 -0
- package/src/engine/extensions/NEEDLE_animator_controller_model.ts +185 -0
- package/src/engine/extensions/NEEDLE_components.ts +234 -0
- package/src/engine/extensions/NEEDLE_deferred_texture.ts +175 -0
- package/src/engine/extensions/NEEDLE_gameobject_data.ts +76 -0
- package/src/engine/extensions/NEEDLE_lighting_settings.ts +161 -0
- package/src/engine/extensions/NEEDLE_lightmaps.ts +93 -0
- package/src/engine/extensions/NEEDLE_persistent_assets.ts +76 -0
- package/src/engine/extensions/NEEDLE_render_objects.ts +197 -0
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +482 -0
- package/src/engine/extensions/NEEDLE_timeline.ts +68 -0
- package/src/engine/extensions/extension_resolver.ts +5 -0
- package/src/engine/extensions/extension_utils.ts +138 -0
- package/src/engine/extensions/extensions.ts +49 -0
- package/src/engine/shaders/shaderData.ts +68 -0
- package/src/engine/tests/simulate_avatars.ts +2 -0
- package/src/engine/tests/test_utils.ts +63 -0
- package/src/engine-components/AlignmentConstraint.ts +33 -0
- package/src/engine-components/Animation.ts +282 -0
- package/src/engine-components/AnimationCurve.ts +42 -0
- package/src/engine-components/Animator.ts +148 -0
- package/src/engine-components/AnimatorController.ts +799 -0
- package/src/engine-components/AudioListener.ts +32 -0
- package/src/engine-components/AudioSource.ts +383 -0
- package/src/engine-components/AvatarLoader.ts +240 -0
- package/src/engine-components/AxesHelper.ts +32 -0
- package/src/engine-components/BasicIKConstraint.ts +54 -0
- package/src/engine-components/BoxCollider.ts +2 -0
- package/src/engine-components/BoxHelperComponent.ts +83 -0
- package/src/engine-components/Camera.ts +261 -0
- package/src/engine-components/Collider.ts +72 -0
- package/src/engine-components/Component.ts +1042 -0
- package/src/engine-components/ComponentExtensions.ts +7 -0
- package/src/engine-components/DeleteBox.ts +34 -0
- package/src/engine-components/DeviceFlag.ts +46 -0
- package/src/engine-components/DragControls.ts +534 -0
- package/src/engine-components/DropListener.ts +101 -0
- package/src/engine-components/Duplicatable.ts +146 -0
- package/src/engine-components/EventList.ts +116 -0
- package/src/engine-components/EventTrigger.ts +28 -0
- package/src/engine-components/EventType.ts +88 -0
- package/src/engine-components/FlyControls.ts +27 -0
- package/src/engine-components/Gizmos.ts +53 -0
- package/src/engine-components/GltfExport.ts +232 -0
- package/src/engine-components/GridHelper.ts +32 -0
- package/src/engine-components/GroundProjection.ts +75 -0
- package/src/engine-components/Interactable.ts +28 -0
- package/src/engine-components/LODGroup.ts +173 -0
- package/src/engine-components/Light.ts +418 -0
- package/src/engine-components/LookAtConstraint.ts +12 -0
- package/src/engine-components/MeshCollider.ts +12 -0
- package/src/engine-components/NavMesh.ts +118 -0
- package/src/engine-components/NestedGltf.ts +56 -0
- package/src/engine-components/Networking.ts +58 -0
- package/src/engine-components/OffsetConstraint.ts +32 -0
- package/src/engine-components/OrbitControls.ts +270 -0
- package/src/engine-components/ParticleSystem.ts +249 -0
- package/src/engine-components/ParticleSystemModules.ts +173 -0
- package/src/engine-components/PlayerColor.ts +93 -0
- package/src/engine-components/Renderer.ts +732 -0
- package/src/engine-components/RendererLightmap.ts +152 -0
- package/src/engine-components/RigidBody.ts +177 -0
- package/src/engine-components/ScreenCapture.ts +47 -0
- package/src/engine-components/ShadowCatcher.ts +93 -0
- package/src/engine-components/Skybox.ts +116 -0
- package/src/engine-components/SmoothFollow.ts +55 -0
- package/src/engine-components/SpatialTrigger.ts +142 -0
- package/src/engine-components/SpectatorCamera.ts +350 -0
- package/src/engine-components/SphereCollider.ts +2 -0
- package/src/engine-components/SpringJoint.ts +45 -0
- package/src/engine-components/SpriteRenderer.ts +143 -0
- package/src/engine-components/SyncedCamera.ts +206 -0
- package/src/engine-components/SyncedRoom.ts +157 -0
- package/src/engine-components/SyncedTransform.ts +339 -0
- package/src/engine-components/TestRunner.ts +116 -0
- package/src/engine-components/TransformGizmo.ts +185 -0
- package/src/engine-components/VideoPlayer.ts +308 -0
- package/src/engine-components/Voip.ts +455 -0
- package/src/engine-components/Volume.ts +86 -0
- package/src/engine-components/WebARSessionRoot.ts +109 -0
- package/src/engine-components/WebXR.ts +586 -0
- package/src/engine-components/WebXRAvatar.ts +326 -0
- package/src/engine-components/WebXRController.ts +1049 -0
- package/src/engine-components/WebXRGrabRendering.ts +151 -0
- package/src/engine-components/WebXRRig.ts +9 -0
- package/src/engine-components/WebXRSync.ts +458 -0
- package/src/engine-components/XRFlag.ts +134 -0
- package/src/engine-components/avatar/AvatarBlink_Simple.ts +68 -0
- package/src/engine-components/avatar/AvatarEyeLook_Rotation.ts +69 -0
- package/src/engine-components/avatar/Avatar_Brain_LookAt.ts +137 -0
- package/src/engine-components/avatar/Avatar_MouthShapes.ts +81 -0
- package/src/engine-components/avatar/Avatar_MustacheShake.ts +29 -0
- package/src/engine-components/codegen/exports.ts +141 -0
- package/src/engine-components/debug/LogStats.ts +22 -0
- package/src/engine-components/js-extensions/RGBAColor.ts +36 -0
- package/src/engine-components/timeline/PlayableDirector.ts +485 -0
- package/src/engine-components/timeline/SignalAsset.ts +108 -0
- package/src/engine-components/timeline/TimelineModels.ts +91 -0
- package/src/engine-components/timeline/TimelineTracks.ts +627 -0
- package/src/engine-components/ui/BaseUIComponent.ts +153 -0
- package/src/engine-components/ui/Button.ts +251 -0
- package/src/engine-components/ui/Canvas.ts +166 -0
- package/src/engine-components/ui/CanvasGroup.ts +47 -0
- package/src/engine-components/ui/EventSystem.ts +523 -0
- package/src/engine-components/ui/Graphic.ts +157 -0
- package/src/engine-components/ui/Image.ts +57 -0
- package/src/engine-components/ui/InputField.ts +235 -0
- package/src/engine-components/ui/Interfaces.ts +8 -0
- package/src/engine-components/ui/Keyboard.ts +203 -0
- package/src/engine-components/ui/Layout.ts +17 -0
- package/src/engine-components/ui/PointerEvents.ts +54 -0
- package/src/engine-components/ui/Raycaster.ts +47 -0
- package/src/engine-components/ui/RectTransform.ts +180 -0
- package/src/engine-components/ui/SpatialHtml.ts +63 -0
- package/src/engine-components/ui/Text.ts +634 -0
- package/src/engine-components/ui/Utils.ts +105 -0
- package/src/engine-components-experimental/Presentation.ts +13 -0
- package/src/engine-components-experimental/annotation/LineDrawer.ts +191 -0
- package/src/engine-components-experimental/annotation/LinesManager.ts +218 -0
- package/src/engine-components-experimental/networking/PlayerSync.ts +131 -0
- package/src/engine-schemes/COMPILE_SCHEMES.bat +4 -0
- package/src/engine-schemes/COMPILE_TS.bat +12 -0
- package/src/engine-schemes/schemes.ts +29 -0
- package/src/engine-schemes/synced-camera-model.ts +92 -0
- package/src/engine-schemes/synced-transform-model.ts +90 -0
- package/src/engine-schemes/syncedCamera.fbs +11 -0
- package/src/engine-schemes/transform.ts +50 -0
- package/src/engine-schemes/transforms.fbs +26 -0
- package/src/engine-schemes/vec.fbs +19 -0
- package/src/engine-schemes/vec2.ts +33 -0
- package/src/engine-schemes/vec3.ts +38 -0
- package/src/engine-schemes/vec4.ts +43 -0
- package/src/engine-schemes/vr-user-state-buffer.ts +138 -0
- package/src/engine-schemes/vrUserStateBuffer.fbs +17 -0
- package/src/needle-engine.ts +39 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
import * as CANNON from 'cannon-es'
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import { Context } from './engine_setup';
|
|
4
|
+
import cannonDebugger from 'cannon-es-debugger'
|
|
5
|
+
import { Rigidbody } from '../engine-components/Rigidbody';
|
|
6
|
+
import * as utils from "./engine_utils"
|
|
7
|
+
import * as threeutils from "./engine_three_utils"
|
|
8
|
+
import { InstancingUtil } from '../engine-components/Renderer';
|
|
9
|
+
import { GameObject } from '../engine-components/Component';
|
|
10
|
+
import { Shape } from 'cannon-es';
|
|
11
|
+
|
|
12
|
+
const debugPhysics = utils.getParam("debugphysics");
|
|
13
|
+
const debugCollisions = utils.getParam("debugcollisions");
|
|
14
|
+
|
|
15
|
+
export interface ICollisionEventReceiver {
|
|
16
|
+
onCollision(data: CollisionData);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class BodyOptions {
|
|
20
|
+
mass: number = 1;
|
|
21
|
+
kinematic: boolean = false;
|
|
22
|
+
physicsEvents: boolean = false;
|
|
23
|
+
drag: number = 0;
|
|
24
|
+
angularDrag: number = 0.05;
|
|
25
|
+
sleepThreshold: number = .01;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// TODO: refactor to return some kind of handle for adding/removing
|
|
29
|
+
class PhysicsObject {
|
|
30
|
+
obj: THREE.Object3D;
|
|
31
|
+
parent: THREE.Object3D | null;
|
|
32
|
+
body: CANNON.Body | null;
|
|
33
|
+
shapes: Array<Shape> = [];
|
|
34
|
+
collisonCallback: Function | null = null;
|
|
35
|
+
|
|
36
|
+
_hasRigidbody: boolean = false;
|
|
37
|
+
_didSleepLastStep: boolean = false;
|
|
38
|
+
|
|
39
|
+
constructor(obj: THREE.Object3D, body: CANNON.Body | null) {
|
|
40
|
+
this.obj = obj;
|
|
41
|
+
this.parent = obj.parent;
|
|
42
|
+
this.body = body;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class CollisionData {
|
|
47
|
+
obj: THREE.Object3D | null;
|
|
48
|
+
contact: CANNON.ContactEquation;
|
|
49
|
+
target: THREE.Object3D | null;
|
|
50
|
+
type: string;
|
|
51
|
+
|
|
52
|
+
constructor(contact: CANNON.ContactEquation, type: string) {
|
|
53
|
+
this.contact = contact;
|
|
54
|
+
this.type = type;
|
|
55
|
+
this.obj = null;
|
|
56
|
+
this.target = null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class CannonCollision {
|
|
60
|
+
body: CANNON.Body;
|
|
61
|
+
contact: CANNON.ContactEquation;
|
|
62
|
+
target: CANNON.Body;
|
|
63
|
+
type: string;
|
|
64
|
+
constructor(body: CANNON.Body, contact: CANNON.ContactEquation, target: CANNON.Body, type: string) {
|
|
65
|
+
this.body = body;
|
|
66
|
+
this.contact = contact;
|
|
67
|
+
this.target = target;
|
|
68
|
+
this.type = type;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class RaycastOptions {
|
|
73
|
+
ray: THREE.Ray | undefined = undefined;
|
|
74
|
+
screenPoint: THREE.Vector2 | undefined = undefined;
|
|
75
|
+
raycaster: THREE.Raycaster | undefined = undefined;
|
|
76
|
+
results: Array<THREE.Intersection> | undefined = undefined;
|
|
77
|
+
targets: Array<THREE.Object3D> | undefined = undefined;
|
|
78
|
+
recursive: boolean | undefined = true;
|
|
79
|
+
minDistance: number | undefined = undefined;
|
|
80
|
+
maxDistance: number | undefined = undefined;
|
|
81
|
+
lineThreshold: number | undefined = undefined;
|
|
82
|
+
layerMask: THREE.Layers | number | undefined = undefined;
|
|
83
|
+
ignore: THREE.Object3D[] | undefined = undefined;
|
|
84
|
+
|
|
85
|
+
screenPointFromOffset(ox: number, oy: number) {
|
|
86
|
+
if (this.screenPoint === undefined) this.screenPoint = new THREE.Vector2();
|
|
87
|
+
this.screenPoint.x = ox / window.innerWidth * 2 - 1;
|
|
88
|
+
this.screenPoint.y = -(oy / window.innerHeight) * 2 + 1;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setMask(mask: number) {
|
|
92
|
+
if (!this.layerMask) this.layerMask = new THREE.Layers();
|
|
93
|
+
const lm = this.layerMask as THREE.Layers;
|
|
94
|
+
if (lm)
|
|
95
|
+
lm.mask = mask;
|
|
96
|
+
else this.layerMask = mask;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public static AllLayers = 0xFFFFFFFF;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class SphereIntersection implements THREE.Intersection {
|
|
103
|
+
distance: number;
|
|
104
|
+
point: THREE.Vector3;
|
|
105
|
+
object: THREE.Object3D;
|
|
106
|
+
constructor(object: THREE.Object3D, distance: number, point: THREE.Vector3) {
|
|
107
|
+
this.object = object;
|
|
108
|
+
this.distance = distance;
|
|
109
|
+
this.point = point;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class Physics {
|
|
114
|
+
|
|
115
|
+
// raycasting
|
|
116
|
+
|
|
117
|
+
private readonly raycaster: THREE.Raycaster = new THREE.Raycaster();
|
|
118
|
+
private readonly defaultRaycastOptions: RaycastOptions = new RaycastOptions();
|
|
119
|
+
private readonly targetBuffer: Array<THREE.Object3D> = new Array<THREE.Object3D>(1);
|
|
120
|
+
private readonly defaultThresholds = {
|
|
121
|
+
Mesh: {},
|
|
122
|
+
Line: { threshold: 0 },
|
|
123
|
+
LOD: {},
|
|
124
|
+
Points: { threshold: 0 },
|
|
125
|
+
Sprite: {}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
private sphereResults: Array<THREE.Intersection> = new Array<THREE.Intersection>();
|
|
130
|
+
private sphereMask: THREE.Layers = new THREE.Layers();
|
|
131
|
+
public sphereOverlap(spherePos: THREE.Vector3, radius: number): Array<THREE.Intersection> {
|
|
132
|
+
this.sphereResults.length = 0;
|
|
133
|
+
if (!this.context.scene) return this.sphereResults;
|
|
134
|
+
const sphere = new THREE.Sphere(spherePos, radius);
|
|
135
|
+
const mask = this.sphereMask;
|
|
136
|
+
mask.enableAll();
|
|
137
|
+
mask.disable(2);
|
|
138
|
+
// mask testing
|
|
139
|
+
// const dummy = new THREE.Layers();
|
|
140
|
+
// dummy.set(2);
|
|
141
|
+
// console.log(dummy.mask, mask.test(dummy))
|
|
142
|
+
for (const ch of this.context.scene.children) {
|
|
143
|
+
const i = this.onSphereOverlap(ch, sphere, mask);
|
|
144
|
+
if (i) this.sphereResults.push(i);
|
|
145
|
+
}
|
|
146
|
+
return this.sphereResults.sort((a, b) => a.distance - b.distance);
|
|
147
|
+
}
|
|
148
|
+
private tempBoundingBox: THREE.Box3 = new THREE.Box3();
|
|
149
|
+
private onSphereOverlap(obj: THREE.Object3D, sp: THREE.Sphere, mask: THREE.Layers): THREE.Intersection | null {
|
|
150
|
+
if (obj.type === "Mesh") {
|
|
151
|
+
if (!obj.layers.test(mask)) return null;
|
|
152
|
+
const mesh = obj as THREE.Mesh;
|
|
153
|
+
const geo = mesh.geometry;
|
|
154
|
+
if (!geo.boundingBox)
|
|
155
|
+
geo.computeBoundingBox();
|
|
156
|
+
if (!geo.boundingBox) return null;
|
|
157
|
+
if (mesh.matrixWorldNeedsUpdate) mesh.updateMatrixWorld();
|
|
158
|
+
const test = this.tempBoundingBox.copy(geo.boundingBox).applyMatrix4(mesh.matrixWorld);
|
|
159
|
+
if (sp.intersectsBox(test)) {
|
|
160
|
+
// console.log(obj, obj.layers.test(mask), obj.layers.mask, mask.mask);
|
|
161
|
+
const wp = threeutils.getWorldPosition(obj);
|
|
162
|
+
const dist = wp.distanceTo(sp.center);
|
|
163
|
+
const int = new SphereIntersection(obj, dist, sp.center.clone());
|
|
164
|
+
return int;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else if (obj.children) {
|
|
168
|
+
for (const ch of obj.children) {
|
|
169
|
+
const i = this.onSphereOverlap(ch, sp, mask);
|
|
170
|
+
if (i) return i;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public raycastFromRay(ray: THREE.Ray, options: RaycastOptions | null = null): Array<THREE.Intersection> {
|
|
177
|
+
const opts = options ?? this.defaultRaycastOptions;
|
|
178
|
+
opts.ray = ray;
|
|
179
|
+
return this.raycast(opts);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public raycast(options: RaycastOptions | null = null): Array<THREE.Intersection> {
|
|
183
|
+
if (!options) options = this.defaultRaycastOptions;
|
|
184
|
+
const mp = options.screenPoint ?? this.context.input.mousePositionRC;
|
|
185
|
+
const rc = options.raycaster ?? this.raycaster;
|
|
186
|
+
rc.near = options.minDistance ?? 0;
|
|
187
|
+
rc.far = options.maxDistance ?? Infinity;
|
|
188
|
+
rc.params = this.defaultThresholds;
|
|
189
|
+
if (options.lineThreshold)
|
|
190
|
+
rc.params.Line = { threshold: options.lineThreshold };
|
|
191
|
+
else rc.params.Line = { threshold: 0 };
|
|
192
|
+
if (options.ray) {
|
|
193
|
+
rc.ray.copy(options.ray);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
const cam = this.context.mainCamera;
|
|
197
|
+
if (!cam) {
|
|
198
|
+
console.error("Can not perform raycast - no main camera found");
|
|
199
|
+
if (this.defaultRaycastOptions.results) this.defaultRaycastOptions.results.length = 0;
|
|
200
|
+
return this.defaultRaycastOptions.results ?? [];
|
|
201
|
+
}
|
|
202
|
+
rc.setFromCamera(mp, cam);
|
|
203
|
+
}
|
|
204
|
+
let targets = options.targets;
|
|
205
|
+
if (!targets) {
|
|
206
|
+
targets = this.targetBuffer;
|
|
207
|
+
targets[0] = this.context.scene;
|
|
208
|
+
}
|
|
209
|
+
let results = options.results;
|
|
210
|
+
if (!results) {
|
|
211
|
+
if (!this.defaultRaycastOptions.results)
|
|
212
|
+
this.defaultRaycastOptions.results = new Array<THREE.Intersection>();
|
|
213
|
+
results = this.defaultRaycastOptions.results;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// layermask
|
|
217
|
+
// https://github.com/mrdoob/three.js/blob/master/src/core/Layers.js
|
|
218
|
+
if (options.layerMask !== undefined) {
|
|
219
|
+
if (options.layerMask instanceof THREE.Layers)
|
|
220
|
+
rc.layers.mask = options.layerMask.mask;
|
|
221
|
+
else
|
|
222
|
+
rc.layers.mask = options.layerMask;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
rc.layers.enableAll();
|
|
226
|
+
rc.layers.disable(2);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// console.log(rc)
|
|
230
|
+
// console.log(targets);
|
|
231
|
+
|
|
232
|
+
// shoot
|
|
233
|
+
results.length = 0;
|
|
234
|
+
rc.intersectObjects(targets, options.recursive, results);
|
|
235
|
+
|
|
236
|
+
const ignorelist = options.ignore;
|
|
237
|
+
if (ignorelist !== undefined && ignorelist.length > 0) {
|
|
238
|
+
results = results.filter(r => !ignorelist.includes(r.object));
|
|
239
|
+
}
|
|
240
|
+
return results;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
// physics simulation
|
|
247
|
+
|
|
248
|
+
get isUpdating() : boolean { return this._isUpdatingPhysicsWorld; }
|
|
249
|
+
|
|
250
|
+
private _isUpdatingPhysicsWorld : boolean = false;
|
|
251
|
+
|
|
252
|
+
private context: Context;
|
|
253
|
+
|
|
254
|
+
private world: CANNON.World = new CANNON.World();
|
|
255
|
+
private objects: Array<PhysicsObject> = [];
|
|
256
|
+
|
|
257
|
+
private tempPosition: THREE.Vector3 = new THREE.Vector3();
|
|
258
|
+
private tempQuaternion: THREE.Quaternion = new THREE.Quaternion();
|
|
259
|
+
|
|
260
|
+
constructor(context: Context) {
|
|
261
|
+
this.context = context;
|
|
262
|
+
this.world.gravity.set(0, -9.82, 0);
|
|
263
|
+
if (debugPhysics) {
|
|
264
|
+
// https://www.npmjs.com/package/cannon-es-debugger
|
|
265
|
+
const opts = {};
|
|
266
|
+
opts["onInit"] = (_body: CANNON.Body, mesh: THREE.Mesh, _shape: CANNON.Shape) => {
|
|
267
|
+
// ignore in raycast
|
|
268
|
+
mesh.layers.set(-1);
|
|
269
|
+
};
|
|
270
|
+
cannonDebugger(context.scene, this.world.bodies, opts);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
public addPreStepListener(listener: (evt) => void) {
|
|
275
|
+
this.world.addEventListener("preStep", listener);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
public addPostStepListener(listener: (evt) => void) {
|
|
279
|
+
this.world.addEventListener("postStep", listener);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
public addConstraint(constraint: CANNON.Constraint) {
|
|
283
|
+
this.world.addConstraint(constraint);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
public setGravity(vec: THREE.Vector3) {
|
|
287
|
+
this.world.gravity.set(vec.x, vec.y, vec.z);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public multiplyGravity(vec: THREE.Vector3) {
|
|
291
|
+
this.world.gravity.x *= vec.x;
|
|
292
|
+
this.world.gravity.y *= vec.y;
|
|
293
|
+
this.world.gravity.z *= vec.z;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
public addBody(go: GameObject, body: CANNON.Body) {
|
|
297
|
+
for (let i = 0; i < this.objects.length; i++) {
|
|
298
|
+
const reg = this.objects[i];
|
|
299
|
+
if (reg.obj === go) {
|
|
300
|
+
reg._hasRigidbody = true;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
this.world.addBody(body);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
public removeBody(go: GameObject, body: CANNON.Body, removeCompletely: boolean = true) {
|
|
308
|
+
this.world.removeBody(body);
|
|
309
|
+
for (let i = 0; i < this.objects.length; i++) {
|
|
310
|
+
const reg = this.objects[i];
|
|
311
|
+
if (reg.obj === go) {
|
|
312
|
+
reg._hasRigidbody = false;
|
|
313
|
+
if (removeCompletely)
|
|
314
|
+
this.objects.splice(i, 1);
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public removeShape(obj: THREE.Object3D, shape: CANNON.Shape) {
|
|
321
|
+
for (const reg of this.objects) {
|
|
322
|
+
if (reg.obj === obj) {
|
|
323
|
+
if (reg.body) {
|
|
324
|
+
reg.body.removeShape(shape);
|
|
325
|
+
reg.body.updateMassProperties();
|
|
326
|
+
}
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// TODO: make it work with rigibody in parent
|
|
333
|
+
public createBody(obj: THREE.Object3D, settings: BodyOptions): CANNON.Body {
|
|
334
|
+
const body = this.internalCreateBody(obj, null);
|
|
335
|
+
if (settings.mass)
|
|
336
|
+
body.mass = settings.mass;
|
|
337
|
+
if (settings.kinematic)
|
|
338
|
+
body.type = CANNON.Body.KINEMATIC;
|
|
339
|
+
else body.type = CANNON.Body.DYNAMIC;
|
|
340
|
+
if (settings.drag)
|
|
341
|
+
body.linearDamping = settings.drag;
|
|
342
|
+
if (settings.angularDrag)
|
|
343
|
+
body.angularDamping = settings.angularDrag;
|
|
344
|
+
if (settings.sleepThreshold)
|
|
345
|
+
body.sleepSpeedLimit = settings.sleepThreshold;
|
|
346
|
+
|
|
347
|
+
this.world.addBody(body);
|
|
348
|
+
const po = new PhysicsObject(obj, body);
|
|
349
|
+
po._hasRigidbody = true;
|
|
350
|
+
this.objects.push(po);
|
|
351
|
+
|
|
352
|
+
if (debugPhysics) {
|
|
353
|
+
console.log("created new body", obj.name, body, body.sleepState, this.world.gravity);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (settings.physicsEvents)
|
|
357
|
+
this.registerCollisionEvents(po);
|
|
358
|
+
|
|
359
|
+
return body;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
public addBoxCollider(obj: THREE.Object3D, trigger: boolean, center: THREE.Vector3, size: THREE.Vector3, rb: Rigidbody | null): CANNON.Shape {
|
|
363
|
+
|
|
364
|
+
const scale = this.tempPosition;
|
|
365
|
+
obj.getWorldScale(scale);
|
|
366
|
+
|
|
367
|
+
const pos = new CANNON.Vec3(
|
|
368
|
+
.5 * scale.x * size.x,
|
|
369
|
+
.5 * scale.y * size.y,
|
|
370
|
+
.5 * scale.z * size.z
|
|
371
|
+
);
|
|
372
|
+
const shape = new CANNON.Box(pos);
|
|
373
|
+
shape.collisionResponse = !trigger;
|
|
374
|
+
|
|
375
|
+
center = center.clone();
|
|
376
|
+
center.multiply(scale);
|
|
377
|
+
|
|
378
|
+
const body = this.addShape(obj, shape, center, rb);
|
|
379
|
+
if (body !== null) {
|
|
380
|
+
if (this.isAlreadyRegistered(body)) return shape;
|
|
381
|
+
const po = new PhysicsObject(obj, body);
|
|
382
|
+
this.objects.push(po);
|
|
383
|
+
}
|
|
384
|
+
return shape;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
public addSphereCollider(obj: THREE.Object3D, center: THREE.Vector3, radius: number, rb: Rigidbody | null): CANNON.Shape {
|
|
388
|
+
const scale = this.tempPosition;
|
|
389
|
+
obj.getWorldScale(scale);
|
|
390
|
+
|
|
391
|
+
const factor = Math.max(scale.x, scale.y, scale.z);
|
|
392
|
+
const shape = new CANNON.Sphere(radius * factor);
|
|
393
|
+
// shape.collisionResponse = !trigger;
|
|
394
|
+
|
|
395
|
+
center = center.clone();
|
|
396
|
+
center.multiply(scale);
|
|
397
|
+
|
|
398
|
+
const body = this.addShape(obj, shape, center, rb);
|
|
399
|
+
if (body !== null) {
|
|
400
|
+
if (this.isAlreadyRegistered(body)) return shape;
|
|
401
|
+
const po = new PhysicsObject(obj, body);
|
|
402
|
+
this.objects.push(po);
|
|
403
|
+
}
|
|
404
|
+
return shape;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
public addMeshCollider(_obj: THREE.Object3D) {
|
|
408
|
+
// see https://github.com/schteppe/cannon.js/blob/master/demos/bunny.html
|
|
409
|
+
if (debugPhysics)
|
|
410
|
+
console.warn("TODO mesh collider not yet supported")
|
|
411
|
+
// const geometry: THREE.BufferGeometry = obj["geometry"];
|
|
412
|
+
// console.log(geometry);
|
|
413
|
+
// const size = geometry.boundingBox.max.clone();
|
|
414
|
+
// size.sub(geometry.boundingBox.min);
|
|
415
|
+
// console.log(size);
|
|
416
|
+
// this.addBoxCollider(obj, size);
|
|
417
|
+
|
|
418
|
+
// const verts = geometry.getAttribute("position").array;
|
|
419
|
+
// const faces = new Array<Array<number>>();
|
|
420
|
+
|
|
421
|
+
// console.log(geometry);
|
|
422
|
+
|
|
423
|
+
// for (let i = 0; i < geometry.index.array.length; i += 3) {
|
|
424
|
+
// const i0 = geometry.index.array[i];
|
|
425
|
+
// const i1 = geometry.index.array[i + 1];
|
|
426
|
+
// const i2 = geometry.index.array[i + 2];
|
|
427
|
+
// const v0 = new THREE.Vector3(verts[i0 * 3], verts[i0 * 3 + 1], verts[i0 * 3 + 2]);
|
|
428
|
+
// const v1 = new THREE.Vector3(verts[i1 * 3], verts[i1 * 3 + 1], verts[i1 * 3 + 2]);
|
|
429
|
+
// const v2 = new THREE.Vector3(verts[i2 * 3], verts[i2 * 3 + 1], verts[i2 * 3 + 2]);
|
|
430
|
+
// const face = [v0, v1, v2];
|
|
431
|
+
// faces.push(face);
|
|
432
|
+
// }
|
|
433
|
+
// const convex = new THREE.ConvexBufferGeometry(faces);
|
|
434
|
+
|
|
435
|
+
// var shape = new CANNON.ConvexPolyhedron({ verts, faces });
|
|
436
|
+
// this.addShape(obj, shape);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
private isAlreadyRegistered(body: CANNON.Body): boolean {
|
|
440
|
+
for (const obj of this.objects) {
|
|
441
|
+
if (obj.body === body) return true;
|
|
442
|
+
}
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
private addShape(obj: THREE.Object3D, shape: CANNON.Shape, center: THREE.Vector3, rb: Rigidbody | null): CANNON.Body | null {
|
|
447
|
+
|
|
448
|
+
let body: CANNON.Body | null = null;
|
|
449
|
+
|
|
450
|
+
if (rb) {
|
|
451
|
+
// if (debugPhysics)
|
|
452
|
+
// console.log("get rb body", rb);
|
|
453
|
+
rb.initialize();
|
|
454
|
+
console.assert(rb.body ? true : false, "rigidbody didn't initialize / produce a physics body", rb);
|
|
455
|
+
body = rb.body;
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
// console.log("has no rb", obj);
|
|
459
|
+
body = this.internalCreateBody(obj, null);
|
|
460
|
+
body.type = CANNON.Body.KINEMATIC;
|
|
461
|
+
this.world.addBody(body);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (body) {
|
|
465
|
+
center.x *= -1;
|
|
466
|
+
|
|
467
|
+
const wr = threeutils.getWorldQuaternion(obj);
|
|
468
|
+
// get rotation difference
|
|
469
|
+
|
|
470
|
+
const wp = threeutils.getWorldPosition(obj);
|
|
471
|
+
wp.add(center);
|
|
472
|
+
|
|
473
|
+
const r = new THREE.Quaternion(body.quaternion.x, body.quaternion.y, body.quaternion.z, body.quaternion.w);
|
|
474
|
+
wr.multiply(r.invert());
|
|
475
|
+
|
|
476
|
+
// wp.applyQuaternion(wr);
|
|
477
|
+
|
|
478
|
+
const bp = body.position;
|
|
479
|
+
const pos = new CANNON.Vec3(wp.x - bp.x, wp.y - bp.y, wp.z - bp.z);
|
|
480
|
+
const rot = new CANNON.Quaternion(wr.x, wr.y, wr.z, wr.w);
|
|
481
|
+
body.addShape(shape, pos, rot);
|
|
482
|
+
body.updateMassProperties();
|
|
483
|
+
}
|
|
484
|
+
return body;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// private _lastStepTime: number | undefined = 0;
|
|
488
|
+
|
|
489
|
+
public step(deltaTime: number) {
|
|
490
|
+
this._isUpdatingPhysicsWorld = true;
|
|
491
|
+
deltaTime = Math.min(deltaTime, 1 / 30);
|
|
492
|
+
this.world.step(deltaTime);
|
|
493
|
+
this._isUpdatingPhysicsWorld = false;
|
|
494
|
+
if(debugPhysics && this.context.time.frameCount % 60 === 0){
|
|
495
|
+
console.log("physics world has " + this.world.bodies.length + " bodies", this.world);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
private temp : THREE.Vector3 = new THREE.Vector3();
|
|
500
|
+
private tempQuat : THREE.Quaternion = new THREE.Quaternion();
|
|
501
|
+
|
|
502
|
+
public postStep() {
|
|
503
|
+
this._isUpdatingPhysicsWorld = true;
|
|
504
|
+
for (let i = 0; i < this.objects.length; i++) {
|
|
505
|
+
const entry = this.objects[i];
|
|
506
|
+
const body = entry.body;
|
|
507
|
+
if (!body || !body.world) continue;
|
|
508
|
+
|
|
509
|
+
body.sleepTick(this.context.time.time);
|
|
510
|
+
|
|
511
|
+
if (debugPhysics) {
|
|
512
|
+
if (!entry._didSleepLastStep && body.sleepState === CANNON.Body.SLEEPING) {
|
|
513
|
+
console.log("BODY SLEEPING", body);
|
|
514
|
+
}
|
|
515
|
+
else if (entry._didSleepLastStep && body.sleepState !== CANNON.Body.SLEEPING) {
|
|
516
|
+
console.log("BODY WOKE UP", body);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
entry._didSleepLastStep = body.sleepState === CANNON.Body.SLEEPING;
|
|
520
|
+
// if(body.sleepState === CANNON.Body.SLEEPING) {
|
|
521
|
+
// console.log("SLEEP", body.name);
|
|
522
|
+
// }
|
|
523
|
+
// if (body.type == CANNON.Body.KINEMATIC) continue;
|
|
524
|
+
const obj = entry.obj;
|
|
525
|
+
|
|
526
|
+
if (body.type === CANNON.Body.KINEMATIC) {
|
|
527
|
+
const wp = threeutils.getWorldPosition(obj, this.temp);
|
|
528
|
+
body.position.set(wp.x, wp.y, wp.z);
|
|
529
|
+
const rot = threeutils.getWorldQuaternion(obj, this.tempQuat);
|
|
530
|
+
body.quaternion.set(rot.x, rot.y, rot.z, rot.w);
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
// when reparenting (e.g. attached to controller) I think it doesnt work with previous parent? need to test again, to tired now
|
|
537
|
+
if (entry.parent && obj.parent === entry.parent) {
|
|
538
|
+
|
|
539
|
+
threeutils.setWorldQuaternionXYZW(obj,
|
|
540
|
+
body.quaternion.x, body.quaternion.y, body.quaternion.z, body.quaternion.w
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
const p = body.position;
|
|
544
|
+
threeutils.setWorldPositionXYZ(obj, p.x, p.y, p.z);
|
|
545
|
+
|
|
546
|
+
if (body.velocity.length() > body.sleepSpeedLimit) {
|
|
547
|
+
InstancingUtil.markDirty(obj);
|
|
548
|
+
}
|
|
549
|
+
// this.worldToLocal.x = body.position.x;
|
|
550
|
+
// this.worldToLocal.y = body.position.y;
|
|
551
|
+
// this.worldToLocal.z = body.position.z;
|
|
552
|
+
// const pos = entry.parent.worldToLocal(this.worldToLocal);
|
|
553
|
+
// obj.position.x = pos.x;
|
|
554
|
+
// obj.position.y = pos.y;
|
|
555
|
+
// obj.position.z = pos.z;
|
|
556
|
+
|
|
557
|
+
// if (entry.center) {
|
|
558
|
+
// this.rotatedCenter.copy(entry.center);
|
|
559
|
+
// const rot = this.tempQuaternion;
|
|
560
|
+
// rot.copy(obj.quaternion);
|
|
561
|
+
// // obj.getWorldQuaternion(this.tempQuaternion)
|
|
562
|
+
// this.rotatedCenter.applyQuaternion(rot);
|
|
563
|
+
// obj.getWorldScale(this.tempVector);
|
|
564
|
+
// this.rotatedCenter.divide(this.tempVector);
|
|
565
|
+
// obj.position.sub(this.rotatedCenter);
|
|
566
|
+
// }
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
this._isUpdatingPhysicsWorld = false;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
private internalCreateBody(obj: THREE.Object3D, shape: CANNON.Shape | undefined | null): CANNON.Body {
|
|
573
|
+
|
|
574
|
+
const body = new CANNON.Body();
|
|
575
|
+
body["_owner"] = obj;
|
|
576
|
+
body["_name"] = obj.name;
|
|
577
|
+
obj.getWorldPosition(this.tempPosition);
|
|
578
|
+
const pos = this.tempPosition;
|
|
579
|
+
body.position = new CANNON.Vec3(pos.x, pos.y, pos.z);
|
|
580
|
+
|
|
581
|
+
const quat = this.tempQuaternion;
|
|
582
|
+
obj.getWorldQuaternion(quat);
|
|
583
|
+
body.quaternion = new CANNON.Quaternion(quat.x, quat.y, quat.z, quat.w);
|
|
584
|
+
|
|
585
|
+
body.type = CANNON.Body.KINEMATIC;
|
|
586
|
+
if (shape) {
|
|
587
|
+
body.addShape(shape);
|
|
588
|
+
body.updateMassProperties();
|
|
589
|
+
}
|
|
590
|
+
return body;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// private findObject(obj: THREE.Object3D): PhysicsObject | null {
|
|
594
|
+
// for (let i = 0; i < this.objects.length; i++) {
|
|
595
|
+
// const entry = this.objects[i];
|
|
596
|
+
// if (entry.obj == obj)
|
|
597
|
+
// return entry;
|
|
598
|
+
// }
|
|
599
|
+
// return null;
|
|
600
|
+
// }
|
|
601
|
+
|
|
602
|
+
private registerCollisionEvents(obj: PhysicsObject) {
|
|
603
|
+
if (obj.collisonCallback) this.unregisterCollisionEvents(obj);
|
|
604
|
+
if (!obj.body) return;
|
|
605
|
+
const evt = evt => this.raiseCollisionEvents(obj.obj, evt);
|
|
606
|
+
obj.collisonCallback = evt.bind(this);
|
|
607
|
+
obj.body.addEventListener("collide", obj.collisonCallback);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
private unregisterCollisionEvents(obj: PhysicsObject) {
|
|
611
|
+
if (!obj.collisonCallback) return;
|
|
612
|
+
if (!obj.body) return;
|
|
613
|
+
obj.body.removeEventListener("collide", obj.collisonCallback);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
private raiseCollisionEvents(obj: THREE.Object3D, event: CannonCollision) {
|
|
617
|
+
|
|
618
|
+
const resolved = new CollisionData(event.contact, event.type);
|
|
619
|
+
|
|
620
|
+
let addedData = 0;
|
|
621
|
+
const objs = this.objects;
|
|
622
|
+
function requestData() {
|
|
623
|
+
if (addedData > 0) return;
|
|
624
|
+
for (let i = 0; i < objs.length; i++) {
|
|
625
|
+
if (addedData == 2) return;
|
|
626
|
+
const entry = objs[i];
|
|
627
|
+
if (entry.body == event.body) {
|
|
628
|
+
resolved.obj = entry.obj;
|
|
629
|
+
++addedData;
|
|
630
|
+
}
|
|
631
|
+
else if (entry.body == event.target) {
|
|
632
|
+
resolved.target = entry.obj;
|
|
633
|
+
++addedData;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
if (debugCollisions)
|
|
639
|
+
console.log("collision between", event.contact.bi, event.contact.bj, obj, event);
|
|
640
|
+
|
|
641
|
+
for (let i = 0; i < obj.userData?.components?.length; i++) {
|
|
642
|
+
const component = obj.userData.components[i];
|
|
643
|
+
if (component.onCollision) {
|
|
644
|
+
requestData();
|
|
645
|
+
component.onCollision(resolved);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
|