@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,1042 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import * as object from "../engine/engine_components"
|
|
3
|
+
import { Mathf } from "../engine/engine_math";
|
|
4
|
+
import * as threeutils from "../engine/engine_three_utils";
|
|
5
|
+
import * as utils from "../engine/engine_utils";
|
|
6
|
+
import { activeInHierarchyFieldName } from "../engine/engine_constants";
|
|
7
|
+
import { Context, FrameEvent } from "../engine/engine_setup";
|
|
8
|
+
import * as main from "../engine/engine_mainloop_utils";
|
|
9
|
+
import { Object3D } from "three";
|
|
10
|
+
import { InstantiateIdProvider, syncDestroy, syncInstantiate } from "../engine/engine_networking_instantiate";
|
|
11
|
+
import { SourceIdentifier } from "../engine/engine_gltf";
|
|
12
|
+
|
|
13
|
+
export interface UIDProvider {
|
|
14
|
+
seed: number;
|
|
15
|
+
generateUUID(): string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// export interface ISerializationCallbackReceiver {
|
|
19
|
+
// onBeforeSerialize?(): object | void;
|
|
20
|
+
// onAfterSerialize?();
|
|
21
|
+
// onBeforeDeserialize?(data?: any);
|
|
22
|
+
// onAfterDeserialize?();
|
|
23
|
+
// onDeserialize?(key: string, value: any): any | void;
|
|
24
|
+
// }
|
|
25
|
+
|
|
26
|
+
const debug = utils.getParam("debugcomponents");
|
|
27
|
+
|
|
28
|
+
export enum HideFlags {
|
|
29
|
+
None = 0,
|
|
30
|
+
HideInHierarchy = 1,
|
|
31
|
+
HideInInspector = 2,
|
|
32
|
+
DontSaveInEditor = 4,
|
|
33
|
+
NotEditable = 8,
|
|
34
|
+
DontSaveInBuild = 16, // 0x00000010
|
|
35
|
+
DontUnloadUnusedAsset = 32, // 0x00000020
|
|
36
|
+
DontSave = DontUnloadUnusedAsset | DontSaveInBuild | DontSaveInEditor, // 0x00000034
|
|
37
|
+
HideAndDontSave = DontSave | NotEditable | HideInHierarchy, // 0x0000003D
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// TODO: figure out what is best here!
|
|
41
|
+
// https://stackoverflow.com/a/67229348
|
|
42
|
+
// https://stackoverflow.com/questions/36886082/abstract-constructor-type-in-typescript
|
|
43
|
+
// type Constructor<T> = Function & { prototype: T } // << this includes abstract constructor types
|
|
44
|
+
export type Constructor<T> = abstract new (...args: any[]) => T; // abstract to support @serializable and also getComponent with abstract types
|
|
45
|
+
export type ConstructorConcrete<T> = new (...args: any[]) => T;
|
|
46
|
+
|
|
47
|
+
export type GuidsMap = { [key: string]: string };
|
|
48
|
+
|
|
49
|
+
type FunctionName = string;
|
|
50
|
+
|
|
51
|
+
export class InstantiateOptions {
|
|
52
|
+
idProvider?: UIDProvider | undefined;
|
|
53
|
+
|
|
54
|
+
//** parent guid */
|
|
55
|
+
parent?: string | undefined | Object3D;
|
|
56
|
+
/** for duplicatable parenting */
|
|
57
|
+
keepWorldPosition?: boolean
|
|
58
|
+
position?: THREE.Vector3 | undefined;
|
|
59
|
+
rotation?: THREE.Quaternion | undefined;
|
|
60
|
+
scale?: THREE.Vector3 | undefined;
|
|
61
|
+
|
|
62
|
+
visible?: boolean | undefined;
|
|
63
|
+
|
|
64
|
+
context?: Context | undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare class NewGameObjectReferenceInfo {
|
|
68
|
+
original: THREE.Object3D;
|
|
69
|
+
clone: THREE.Object3D;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
THREE.Object3D.prototype["SetActive"] = function (active: boolean) {
|
|
73
|
+
this.visible = active;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
abstract class GameObject extends THREE.Object3D implements THREE.Object3D {
|
|
78
|
+
|
|
79
|
+
guid: string | undefined;
|
|
80
|
+
|
|
81
|
+
public static setActive(go: THREE.Object3D, active: boolean) {
|
|
82
|
+
if (!go) return;
|
|
83
|
+
go.visible = active;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public static isActiveSelf(go: THREE.Object3D): boolean {
|
|
87
|
+
return go.visible || GameObject.isUsingInstancing(go);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public static isActiveInHierarchy(go: THREE.Object3D): boolean {
|
|
91
|
+
return go[activeInHierarchyFieldName] || GameObject.isUsingInstancing(go);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public static markAsInstancedRendered(go: THREE.Object3D, instanced: boolean) {
|
|
95
|
+
go["__isUsingInstancing"] = instanced;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public static isUsingInstancing(instance: THREE.Object3D): boolean { return instance["__isUsingInstancing"] === true; }
|
|
99
|
+
|
|
100
|
+
public static foreachComponent(instance: THREE.Object3D, cb: (comp: Component) => any, recursive: boolean = true): any {
|
|
101
|
+
if (!instance) return;
|
|
102
|
+
if (instance.userData.components) {
|
|
103
|
+
for (let i = 0; i < instance.userData.components.length; i++) {
|
|
104
|
+
const comp = instance.userData.components[i];
|
|
105
|
+
if (comp instanceof Behaviour) {
|
|
106
|
+
const res = cb(comp);
|
|
107
|
+
if (res !== undefined) return res;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (recursive && instance.children) {
|
|
113
|
+
for (let i = 0; i < instance.children.length; i++) {
|
|
114
|
+
const child = instance.children[i];
|
|
115
|
+
if (!child) continue;
|
|
116
|
+
const res = GameObject.foreachComponent(child, cb, recursive);
|
|
117
|
+
if (res !== undefined) return res;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public static instantiateSynced(instance: GameObject | THREE.Object3D | null, opts: InstantiateOptions): GameObject | null {
|
|
123
|
+
if (!instance) return null;
|
|
124
|
+
return syncInstantiate(instance, opts);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public static instantiate(instance: GameObject | THREE.Object3D | null, opts: InstantiateOptions | null = null): GameObject | null {
|
|
128
|
+
if (instance === null) return null;
|
|
129
|
+
|
|
130
|
+
let options: InstantiateOptions | null = null;
|
|
131
|
+
if (opts !== null) {
|
|
132
|
+
// if x is defined assume this is a vec3 - this is just to not break everything at once and stay a little bit backwards compatible
|
|
133
|
+
if (opts["x"] !== undefined) {
|
|
134
|
+
options = new InstantiateOptions();
|
|
135
|
+
options.position = opts as unknown as THREE.Vector3;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// if (opts instanceof InstantiateOptions)
|
|
139
|
+
options = opts as InstantiateOptions;
|
|
140
|
+
// else {
|
|
141
|
+
// options = new InstantiateOptions();
|
|
142
|
+
// Object.assign(options, opts);
|
|
143
|
+
// }
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let context = Context.Current;
|
|
148
|
+
if (options?.context) context = options.context;
|
|
149
|
+
if (debug && context.alias)
|
|
150
|
+
console.log("context", context.alias);
|
|
151
|
+
|
|
152
|
+
// we need to create the id provider before calling internal instantiate because cloned gameobjects also create new guids
|
|
153
|
+
if (options && !options.idProvider) {
|
|
154
|
+
options.idProvider = new InstantiateIdProvider(Date.now());
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const components: Array<Behaviour> = [];
|
|
158
|
+
const goMapping: { [key: string]: NewGameObjectReferenceInfo } = {}; // used to resolve references on components to components on other gameobjects to their new counterpart
|
|
159
|
+
const skinnedMeshes: { [key: string]: NewGameObjectReferenceInfo } = {};
|
|
160
|
+
const clone = this.internalInstantiate(context, instance, options, components, goMapping, skinnedMeshes);
|
|
161
|
+
|
|
162
|
+
if (clone) {
|
|
163
|
+
this.resolveReferences(goMapping);
|
|
164
|
+
this.resolveAndBindSkinnedMeshBones(skinnedMeshes, goMapping);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (debug) {
|
|
168
|
+
threeutils.logHierarchy(instance, true);
|
|
169
|
+
threeutils.logHierarchy(clone, true);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const guidsMap: GuidsMap = {};
|
|
173
|
+
for (const i in components) {
|
|
174
|
+
const copy = components[i];
|
|
175
|
+
const oldGuid = copy.guid;
|
|
176
|
+
if (options && options.idProvider) {
|
|
177
|
+
copy.guid = options.idProvider.generateUUID();
|
|
178
|
+
guidsMap[oldGuid] = copy.guid;
|
|
179
|
+
if (debug)
|
|
180
|
+
console.log(copy.name, copy.guid)
|
|
181
|
+
}
|
|
182
|
+
object.registerComponent(copy, context);
|
|
183
|
+
if (copy.__internalNewInstanceCreated)
|
|
184
|
+
copy.__internalNewInstanceCreated();
|
|
185
|
+
}
|
|
186
|
+
for (const i in components) {
|
|
187
|
+
const copy = components[i];
|
|
188
|
+
if (copy.resolveGuids)
|
|
189
|
+
copy.resolveGuids(guidsMap);
|
|
190
|
+
if (copy.enabled === false) continue;
|
|
191
|
+
else copy.enabled = true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
main.processNewScripts(context);
|
|
195
|
+
|
|
196
|
+
return clone as GameObject;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private static internalInstantiate(
|
|
200
|
+
context: Context, instance: GameObject | THREE.Object3D, opts: InstantiateOptions | null,
|
|
201
|
+
componentsList: Array<Behaviour>,
|
|
202
|
+
newGameObjectsMap: { [key: string]: NewGameObjectReferenceInfo },
|
|
203
|
+
skinnedMeshesMap: { [key: string]: NewGameObjectReferenceInfo }
|
|
204
|
+
)
|
|
205
|
+
: GameObject | THREE.Object3D | null {
|
|
206
|
+
if (!instance) return null;
|
|
207
|
+
// prepare, remove things that dont work out of the box
|
|
208
|
+
// e.g. user data we want to manually clone
|
|
209
|
+
// also children throw errors (e.g. recursive toJson with nested meshes)
|
|
210
|
+
const userData = instance.userData;
|
|
211
|
+
instance.userData = {};
|
|
212
|
+
const children = instance.children;
|
|
213
|
+
instance.children = [];
|
|
214
|
+
let clone: THREE.Object3D | GameObject;
|
|
215
|
+
clone = instance.clone(false);
|
|
216
|
+
instance.userData = userData;
|
|
217
|
+
instance.children = children;
|
|
218
|
+
|
|
219
|
+
// make reference from old id to new object
|
|
220
|
+
newGameObjectsMap[instance.uuid] = { original: instance, clone: clone };
|
|
221
|
+
|
|
222
|
+
if (instance.type === "SkinnedMesh") {
|
|
223
|
+
skinnedMeshesMap[instance.uuid] = { original: instance, clone: clone };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// DO NOT EVER RENAME BECAUSE IT BREAKS / MIGHT BREAK ANIMATIONS
|
|
227
|
+
// clone.name += " (Clone)";
|
|
228
|
+
|
|
229
|
+
if (opts?.visible !== undefined)
|
|
230
|
+
clone.visible = opts.visible;
|
|
231
|
+
|
|
232
|
+
if (opts?.idProvider) {
|
|
233
|
+
clone.uuid = opts.idProvider.generateUUID();
|
|
234
|
+
const cloneGo: GameObject = clone as GameObject;
|
|
235
|
+
if (cloneGo) cloneGo.guid = clone.uuid;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (instance.animations && instance.animations.length > 0) {
|
|
239
|
+
clone.animations = [...instance.animations];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const parent = instance.parent;
|
|
243
|
+
if (parent) {
|
|
244
|
+
parent.add(clone);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// apply transform
|
|
248
|
+
if (opts?.position) {
|
|
249
|
+
threeutils.setWorldPosition(clone, opts.position);
|
|
250
|
+
}
|
|
251
|
+
else clone.position.copy(instance.position);
|
|
252
|
+
if (opts?.rotation) {
|
|
253
|
+
threeutils.setWorldQuaternion(clone, opts.rotation);
|
|
254
|
+
// clone.quaternion.copy(opts.rotation);
|
|
255
|
+
}
|
|
256
|
+
else clone.quaternion.copy(instance.quaternion);
|
|
257
|
+
if (opts?.scale) {
|
|
258
|
+
// TODO: make set world scale work
|
|
259
|
+
clone.scale.copy(opts.scale);
|
|
260
|
+
}
|
|
261
|
+
else clone.scale.copy(instance.scale);
|
|
262
|
+
|
|
263
|
+
if (opts?.parent && opts.parent !== "scene") {
|
|
264
|
+
let requestedParent: Object3D | null = null;
|
|
265
|
+
if (typeof opts.parent === "string") {
|
|
266
|
+
requestedParent = utils.tryFindObject(opts.parent, context.scene, true);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
requestedParent = opts.parent;
|
|
270
|
+
}
|
|
271
|
+
if (requestedParent) {
|
|
272
|
+
const func = opts.keepWorldPosition === true ? requestedParent.attach : requestedParent.add;
|
|
273
|
+
if (!func) console.error("Invalid parent object", requestedParent, "received when instantiating:", instance);
|
|
274
|
+
else func.call(requestedParent, clone);
|
|
275
|
+
}
|
|
276
|
+
else console.warn("could not find parent:", opts.parent);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
for (const [key, value] of Object.entries(instance.userData)) {
|
|
280
|
+
if (key === "components") continue;
|
|
281
|
+
clone.userData[key] = value;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (instance.userData?.components) {
|
|
285
|
+
const components = instance.userData.components;
|
|
286
|
+
const newComponents: Behaviour[] = [];
|
|
287
|
+
clone.userData.components = newComponents;
|
|
288
|
+
for (let i = 0; i < components.length; i++) {
|
|
289
|
+
const comp = components[i];
|
|
290
|
+
const copy = Object.create(comp);
|
|
291
|
+
Object.assign(copy, comp);
|
|
292
|
+
newComponents.push(copy);
|
|
293
|
+
copy.gameObject = clone;
|
|
294
|
+
// copy.transform = clone;
|
|
295
|
+
componentsList.push(copy);
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// children should just clone the original transform
|
|
301
|
+
if (opts) {
|
|
302
|
+
opts.position = undefined;
|
|
303
|
+
opts.rotation = undefined;
|
|
304
|
+
opts.scale = undefined;
|
|
305
|
+
opts.parent = undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
for (const ch in instance.children) {
|
|
309
|
+
const child = instance.children[ch];
|
|
310
|
+
const newChild = GameObject.internalInstantiate(context, child as GameObject, opts, componentsList, newGameObjectsMap, skinnedMeshesMap);
|
|
311
|
+
if (newChild)
|
|
312
|
+
clone.add(newChild);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return clone;
|
|
316
|
+
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private static resolveAndBindSkinnedMeshBones(
|
|
320
|
+
skinnedMeshes: { [key: string]: NewGameObjectReferenceInfo },
|
|
321
|
+
newObjectsMap: { [key: string]: NewGameObjectReferenceInfo }
|
|
322
|
+
) {
|
|
323
|
+
for (const key in skinnedMeshes) {
|
|
324
|
+
const val = skinnedMeshes[key];
|
|
325
|
+
const original = val.original as THREE.SkinnedMesh;
|
|
326
|
+
const originalSkeleton = original.skeleton;
|
|
327
|
+
const clone = val.clone as THREE.SkinnedMesh;
|
|
328
|
+
// clone.updateWorldMatrix(true, true);
|
|
329
|
+
if (!originalSkeleton) {
|
|
330
|
+
console.warn("Skinned mesh has no skeleton?", val);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const originalBones = originalSkeleton.bones;
|
|
334
|
+
const clonedSkeleton = clone.skeleton.clone();
|
|
335
|
+
|
|
336
|
+
clone.skeleton = clonedSkeleton;
|
|
337
|
+
clone.bindMatrix.clone().copy(original.bindMatrix);
|
|
338
|
+
// console.log(clone.bindMatrix)
|
|
339
|
+
clone.bindMatrixInverse.copy(original.bindMatrixInverse);
|
|
340
|
+
// clone.bindMatrix.multiplyScalar(.025);
|
|
341
|
+
// console.assert(originalSkeleton.uuid !== clonedSkeleton.uuid);
|
|
342
|
+
// console.assert(originalBones.length === clonedSkeleton.bones.length);
|
|
343
|
+
const bones: Array<THREE.Bone> = [];
|
|
344
|
+
clonedSkeleton.bones = bones;
|
|
345
|
+
for (let i = 0; i < originalBones.length; i++) {
|
|
346
|
+
const bone = originalBones[i];
|
|
347
|
+
const newBoneInfo = newObjectsMap[bone.uuid];
|
|
348
|
+
const clonedBone = newBoneInfo.clone as THREE.Bone;
|
|
349
|
+
// console.log("NEW BONE: ", clonedBone, "BEFORE", newBoneInfo.original);
|
|
350
|
+
bones.push(clonedBone);
|
|
351
|
+
}
|
|
352
|
+
// clone.skeleton = new THREE.Skeleton(bones);
|
|
353
|
+
// clone.skeleton.update();
|
|
354
|
+
// clone.pose();
|
|
355
|
+
// clone.scale.set(1,1,1);
|
|
356
|
+
// clone.position.y += .1;
|
|
357
|
+
// console.log("ORIG", original, "CLONE", clone);
|
|
358
|
+
}
|
|
359
|
+
for (const key in skinnedMeshes) {
|
|
360
|
+
const clone = skinnedMeshes[key].clone as THREE.SkinnedMesh;
|
|
361
|
+
clone.skeleton.update();
|
|
362
|
+
// clone.skeleton.calculateInverses();
|
|
363
|
+
clone.bind(clone.skeleton, clone.bindMatrix);
|
|
364
|
+
clone.updateMatrixWorld(true);
|
|
365
|
+
// clone.pose();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// private static bindNewSkinnedMeshBones(source, clone) {
|
|
370
|
+
// const sourceLookup = new Map();
|
|
371
|
+
// const cloneLookup = new Map();
|
|
372
|
+
// // const clone = source.clone(false);
|
|
373
|
+
|
|
374
|
+
// function parallelTraverse(a, b, callback) {
|
|
375
|
+
// callback(a, b);
|
|
376
|
+
// for (let i = 0; i < a.children.length; i++) {
|
|
377
|
+
// parallelTraverse(a.children[i], b.children[i], callback);
|
|
378
|
+
// }
|
|
379
|
+
// }
|
|
380
|
+
// parallelTraverse(source, clone, function (sourceNode, clonedNode) {
|
|
381
|
+
// sourceLookup.set(clonedNode, sourceNode);
|
|
382
|
+
// cloneLookup.set(sourceNode, clonedNode);
|
|
383
|
+
// });
|
|
384
|
+
|
|
385
|
+
// clone.traverse(function (node) {
|
|
386
|
+
// if (!node.isSkinnedMesh) return;
|
|
387
|
+
// const clonedMesh = node;
|
|
388
|
+
// const sourceMesh = sourceLookup.get(node);
|
|
389
|
+
// const sourceBones = sourceMesh.skeleton.bones;
|
|
390
|
+
|
|
391
|
+
// clonedMesh.skeleton = sourceMesh.skeleton.clone();
|
|
392
|
+
// clonedMesh.bindMatrix.copy(sourceMesh.bindMatrix);
|
|
393
|
+
|
|
394
|
+
// clonedMesh.skeleton.bones = sourceBones.map(function (bone) {
|
|
395
|
+
// return cloneLookup.get(bone);
|
|
396
|
+
// });
|
|
397
|
+
// clonedMesh.bind(clonedMesh.skeleton, clonedMesh.bindMatrix);
|
|
398
|
+
// });
|
|
399
|
+
// return clone;
|
|
400
|
+
|
|
401
|
+
// }
|
|
402
|
+
|
|
403
|
+
private static resolveReferences(newObjectsMap: { [key: string]: NewGameObjectReferenceInfo }) {
|
|
404
|
+
// for every object that is newly created we want to update references to their newly created counterparts
|
|
405
|
+
// e.g. a collider instance referencing a rigidbody instance should be updated so that
|
|
406
|
+
// the cloned collider does not reference the cloned rigidbody (instead of the original rigidbody)
|
|
407
|
+
for (const key in newObjectsMap) {
|
|
408
|
+
const val = newObjectsMap[key];
|
|
409
|
+
const clone = val.clone;
|
|
410
|
+
// resolve references
|
|
411
|
+
if (clone.userData?.components) {
|
|
412
|
+
for (let i = 0; i < clone.userData.components.length; i++) {
|
|
413
|
+
const copy = clone.userData.components[i];
|
|
414
|
+
// find referenced within a cloned gameobject
|
|
415
|
+
const entries = Object.entries(copy);
|
|
416
|
+
// console.log(copy, entries);
|
|
417
|
+
for (const [key, value] of entries) {
|
|
418
|
+
if (Array.isArray(value)) {
|
|
419
|
+
const clonedArray: Array<any> = [];
|
|
420
|
+
copy[key] = clonedArray;
|
|
421
|
+
// console.log(copy, key, value, copy[key]);
|
|
422
|
+
for (let i = 0; i < value.length; i++) {
|
|
423
|
+
const entry = value[i];
|
|
424
|
+
// push value types into new array
|
|
425
|
+
if (typeof entry !== "object") {
|
|
426
|
+
clonedArray.push(entry);
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
const res: any = this.postProcessNewInstance(copy, key, entry, newObjectsMap);
|
|
430
|
+
if (res !== undefined)
|
|
431
|
+
clonedArray.push(res);
|
|
432
|
+
else clonedArray.push(entry);
|
|
433
|
+
}
|
|
434
|
+
// console.log(copy[key])
|
|
435
|
+
}
|
|
436
|
+
else if (typeof value === "object") {
|
|
437
|
+
const res = this.postProcessNewInstance(copy, key, value, newObjectsMap);
|
|
438
|
+
if (res !== undefined) {
|
|
439
|
+
copy[key] = res;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
private static postProcessNewInstance(copy: THREE.Object3D, key: string, value, newObjectsMap: { [key: string]: NewGameObjectReferenceInfo }) {
|
|
450
|
+
if (value instanceof Component || value instanceof Behaviour) {
|
|
451
|
+
const originalGameObjectReference = value["gameObject"];
|
|
452
|
+
// console.log(key, value, originalGameObjectReference);
|
|
453
|
+
if (originalGameObjectReference) {
|
|
454
|
+
const id = originalGameObjectReference.uuid;
|
|
455
|
+
const newGameObject = newObjectsMap[id]?.clone;
|
|
456
|
+
if (!newGameObject) {
|
|
457
|
+
// reference has not changed!
|
|
458
|
+
if (debug)
|
|
459
|
+
console.log("reference did not change", key, copy, value);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
const index = originalGameObjectReference.userData.components.indexOf(value);
|
|
463
|
+
if (index >= 0) {
|
|
464
|
+
if (debug)
|
|
465
|
+
console.log(key, id);
|
|
466
|
+
const found = newGameObject.userData.components[index];
|
|
467
|
+
return found;
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
console.warn("could not find component", key, value);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
} else if (value instanceof THREE.Object3D) {
|
|
474
|
+
// console.log(value);
|
|
475
|
+
if (key === "gameObject") return;
|
|
476
|
+
const originalGameObjectReference = value;
|
|
477
|
+
if (originalGameObjectReference) {
|
|
478
|
+
const id = originalGameObjectReference.uuid;
|
|
479
|
+
const newGameObject = newObjectsMap[id]?.clone;
|
|
480
|
+
if (newGameObject) {
|
|
481
|
+
if (debug)
|
|
482
|
+
console.log(key, "old", value, "new", newGameObject);
|
|
483
|
+
return newGameObject;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
public static destroySynced(instance: THREE.Object3D | Component, context?: Context, recursive: boolean = true) {
|
|
490
|
+
if (!instance) return;
|
|
491
|
+
const go = instance as GameObject;
|
|
492
|
+
context = context ?? Context.Current;
|
|
493
|
+
syncDestroy(go, context.connection, recursive);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
public static destroy(instance: THREE.Object3D | Component, recursive: boolean = true, isRoot: boolean = true) {
|
|
497
|
+
const comp = instance as Component;
|
|
498
|
+
if (comp.isComponent) {
|
|
499
|
+
comp.destroy();
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const obj = instance as GameObject;
|
|
504
|
+
if (debug) console.log(obj);
|
|
505
|
+
|
|
506
|
+
if (recursive && obj.children) {
|
|
507
|
+
for (const ch of obj.children) {
|
|
508
|
+
GameObject.destroy(ch, recursive, false);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const components = obj.userData.components;
|
|
513
|
+
if (components) {
|
|
514
|
+
let lastLength = components.length;
|
|
515
|
+
for (let i = 0; i < components.length; i++) {
|
|
516
|
+
const comp: Behaviour = components[i];
|
|
517
|
+
if (comp.destroy) {
|
|
518
|
+
if (debug) console.log("destroying", comp);
|
|
519
|
+
comp.destroy();
|
|
520
|
+
}
|
|
521
|
+
// components will be removed from componentlist in destroy
|
|
522
|
+
if (components.length < lastLength) {
|
|
523
|
+
lastLength = components.length;
|
|
524
|
+
i--;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (isRoot)
|
|
529
|
+
obj.removeFromParent();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Add an object to parent and also ensure all components are being registered
|
|
534
|
+
*/
|
|
535
|
+
public static add(instance: THREE.Object3D | null | undefined, parent: THREE.Object3D, context?: Context) {
|
|
536
|
+
if (!instance || !parent) return;
|
|
537
|
+
if (instance === parent) {
|
|
538
|
+
console.warn("Can not add object to self", instance);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (!context) {
|
|
542
|
+
context = Context.Current;
|
|
543
|
+
}
|
|
544
|
+
parent.add(instance);
|
|
545
|
+
main.updateActiveInHierarchyWithoutEventCall(instance);
|
|
546
|
+
if (context) {
|
|
547
|
+
GameObject.foreachComponent(instance, (comp: Component) => {
|
|
548
|
+
main.addScriptToArrays(comp, context!);
|
|
549
|
+
if (context!.new_script_start.includes(comp) === false) {
|
|
550
|
+
context!.new_script_start.push(comp as Behaviour);
|
|
551
|
+
}
|
|
552
|
+
}, true);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
console.warn("Missing context");
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Removes the object from its parent and deactivates all of its components
|
|
561
|
+
*/
|
|
562
|
+
public static remove(instance: THREE.Object3D | null | undefined) {
|
|
563
|
+
if (!instance) return;
|
|
564
|
+
instance.parent?.remove(instance);
|
|
565
|
+
GameObject.foreachComponent(instance, (comp) => {
|
|
566
|
+
main.processRemoveFromScene(comp);
|
|
567
|
+
}, true);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
public static invokeOnChildren(go: THREE.Object3D | null | undefined, functionName: string | FunctionName, ...args: any) {
|
|
571
|
+
this.invoke(go, functionName, true, args);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
public static invoke(go: THREE.Object3D | null | undefined, functionName: string | FunctionName, children: boolean = false, ...args: any) {
|
|
575
|
+
if (!go) return;
|
|
576
|
+
// console.log(go);
|
|
577
|
+
this.foreachComponent(go, c => {
|
|
578
|
+
const fn = c[functionName];
|
|
579
|
+
if (fn && typeof fn === "function") {
|
|
580
|
+
const bound = fn.bind(c);
|
|
581
|
+
// console.log(c, bound)
|
|
582
|
+
bound(...args)
|
|
583
|
+
}
|
|
584
|
+
}, children);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
public static addNewComponent<T extends Behaviour>(go: GameObject | THREE.Object3D, type: ConstructorConcrete<T>, callAwake: boolean = true): T {
|
|
588
|
+
const instance = new type();
|
|
589
|
+
object.addNewComponentInstance(instance, go, callAwake);
|
|
590
|
+
return instance;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
public static addComponent(go: GameObject, instance: Component): void {
|
|
594
|
+
if (instance.gameObject == null) {
|
|
595
|
+
throw new Error("Did you mean to create a new component? Use addNewComponent");
|
|
596
|
+
}
|
|
597
|
+
object.moveComponentInstance(instance, go);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
public static removeComponent(instance: Component): Component {
|
|
601
|
+
object.removeComponent(instance.gameObject, instance);
|
|
602
|
+
return instance;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
public static getOrAddComponent<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T> | null): T {
|
|
606
|
+
const comp = this.getComponent(go, typeName);
|
|
607
|
+
if (comp) return comp;
|
|
608
|
+
return this.addNewComponent(go, typeName as unknown as ConstructorConcrete<Behaviour>) as unknown as T;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
public static getComponent<T>(go: GameObject | THREE.Object3D | null, typeName: Constructor<T> | null): T | null {
|
|
612
|
+
if (go === null) return null;
|
|
613
|
+
// if names are minified we could also use the type store and work with strings everywhere
|
|
614
|
+
// not ideal, but I dont know a good/sane way to do this otherwise
|
|
615
|
+
// const res = TypeStore.get(typeName);
|
|
616
|
+
// if(res) typeName = res;
|
|
617
|
+
return object.getComponent(typeName, go);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
public static getComponents<T>(go: GameObject | THREE.Object3D | null, typeName: Constructor<T> | null, arr: T[] | null = null): T[] {
|
|
621
|
+
if (go === null) return arr ?? [];
|
|
622
|
+
return object.getComponents(typeName, go, arr);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
public static findByGuid(guid: string, hierarchy: THREE.Object3D): GameObject | Behaviour | null | undefined {
|
|
626
|
+
return utils.tryFindObject(guid, hierarchy, true, true);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
public static findObjectOfType<T>(typeName: Constructor<T> | string, context?: Context | THREE.Object3D, includeInactive: boolean = true): T | null {
|
|
630
|
+
return object.findObjectOfType(typeName, context, includeInactive);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
public static findObjectsOfType<T>(typeName: Constructor<T>, context?: Context | THREE.Object3D): Array<T> {
|
|
634
|
+
const arr = [];
|
|
635
|
+
object.findObjectsOfType(typeName, arr, context);
|
|
636
|
+
return arr;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
public static getComponentInChildren<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T> | null): T | null {
|
|
640
|
+
return object.getComponentInChildren(typeName, go);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
public static getComponentsInChildren<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T> | null, arr: T[] | null = null): Array<T> {
|
|
644
|
+
return object.getComponentsInChildren(typeName, go, arr);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
public static getComponentInParent<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T>): T | null {
|
|
648
|
+
return object.getComponentInParent(typeName, go);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
public static getComponentsInParent<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T>, arr: Array<T> | null = null): Array<T> {
|
|
652
|
+
return object.getComponentsInParent(typeName, go, arr);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
public static getAllComponents(go: GameObject | THREE.Object3D): Behaviour[] {
|
|
656
|
+
const componentsList = go.userData?.components;
|
|
657
|
+
const newList = [...componentsList];
|
|
658
|
+
return newList;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
public static *iterateComponents(go: GameObject | THREE.Object3D) {
|
|
662
|
+
const list = go?.userData?.components;
|
|
663
|
+
if (list && Array.isArray(list)) {
|
|
664
|
+
for (let i = 0; i < list.length; i++) {
|
|
665
|
+
yield list[i];
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
abstract addNewComponent<T>(type: Constructor<T>): T | null;
|
|
672
|
+
abstract removeComponent(comp: Component): Component;
|
|
673
|
+
abstract getOrAddComponent<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T> | null): T;
|
|
674
|
+
abstract getComponent<T>(type: Constructor<T>): T | null;
|
|
675
|
+
abstract getComponents<T>(type: Constructor<T>, arr?: T[]): Array<T>;
|
|
676
|
+
abstract getComponentInChildren<T>(type: Constructor<T>): T | null;
|
|
677
|
+
abstract getComponentsInChildren<T>(type: Constructor<T>, arr?: T[]): Array<T>;
|
|
678
|
+
abstract getComponentInParent<T>(type: Constructor<T>): T | null;
|
|
679
|
+
abstract getComponentsInParent<T>(type: Constructor<T>, arr?: T[]): Array<T>;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
THREE.Object3D.prototype["addNewComponent"] = function <T extends Behaviour>(type: ConstructorConcrete<T>) {
|
|
685
|
+
return GameObject.addNewComponent(this, type);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
THREE.Object3D.prototype["removeComponent"] = function (inst: Component) {
|
|
689
|
+
return GameObject.removeComponent(inst);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
THREE.Object3D.prototype["getOrAddComponent"] = function <T>(typeName: Constructor<T> | null): T {
|
|
693
|
+
return GameObject.getOrAddComponent(this, typeName);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
THREE.Object3D.prototype["getComponent"] = function <T>(type: Constructor<T>) {
|
|
697
|
+
return GameObject.getComponent(this, type);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
THREE.Object3D.prototype["getComponents"] = function <T>(type: Constructor<T>, arr?: []) {
|
|
701
|
+
return GameObject.getComponents(this, type, arr);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
THREE.Object3D.prototype["getComponentInChildren"] = function <T>(type: Constructor<T>) {
|
|
705
|
+
return GameObject.getComponentInChildren(this, type);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
THREE.Object3D.prototype["getComponentsInChildren"] = function <T>(type: Constructor<T>, arr?: []) {
|
|
709
|
+
return GameObject.getComponentsInChildren(this, type, arr);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
THREE.Object3D.prototype["getComponentInParent"] = function <T>(type: Constructor<T>) {
|
|
713
|
+
return GameObject.getComponentInParent(this, type);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
THREE.Object3D.prototype["getComponentsInParent"] = function <T>(type: Constructor<T>, arr?: []) {
|
|
717
|
+
return GameObject.getComponentsInParent(this, type, arr);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// function patch_THREEObject3D() {
|
|
721
|
+
// const props = Object.getOwnPropertyNames(GameObject.prototype);
|
|
722
|
+
// for (const propName in props) {
|
|
723
|
+
// const prop = props[propName];
|
|
724
|
+
// if (prop === "constructor") continue;
|
|
725
|
+
// const fn = GameObject.prototype[prop];
|
|
726
|
+
// THREE.Object3D.prototype[prop] = fn;
|
|
727
|
+
// }
|
|
728
|
+
// }
|
|
729
|
+
// patch_THREEObject3D();
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
class Component implements EventTarget {
|
|
733
|
+
|
|
734
|
+
get isComponent(): boolean { return true; }
|
|
735
|
+
|
|
736
|
+
private __context: Context | undefined;
|
|
737
|
+
get context(): Context {
|
|
738
|
+
return this.__context ?? Context.Current;
|
|
739
|
+
}
|
|
740
|
+
set context(context: Context) {
|
|
741
|
+
this.__context = context;
|
|
742
|
+
}
|
|
743
|
+
get scene(): THREE.Scene { return this.context.scene; }
|
|
744
|
+
|
|
745
|
+
get layer(): number {
|
|
746
|
+
return this.gameObject?.userData?.layer;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
get name(): string {
|
|
750
|
+
return this.gameObject?.userData.name;
|
|
751
|
+
}
|
|
752
|
+
private __name?: string;
|
|
753
|
+
set name(str: string) {
|
|
754
|
+
if (this.gameObject) {
|
|
755
|
+
if (!this.gameObject.userData) this.gameObject.userData = {}
|
|
756
|
+
this.gameObject.userData.name = str;
|
|
757
|
+
this.__name = str;
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
this.__name = str;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
get tag(): string {
|
|
764
|
+
return this.gameObject?.userData.tag;
|
|
765
|
+
}
|
|
766
|
+
set tag(str: string) {
|
|
767
|
+
if (this.gameObject)
|
|
768
|
+
this.gameObject.userData.tag = str;
|
|
769
|
+
}
|
|
770
|
+
get static() {
|
|
771
|
+
return this.gameObject?.userData.static;
|
|
772
|
+
}
|
|
773
|
+
get hideFlags(): HideFlags {
|
|
774
|
+
return this.gameObject?.userData.hideFlags;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
get activeAndEnabled(): boolean {
|
|
779
|
+
if (this.destroyed) return false;
|
|
780
|
+
if (this.__isEnabled === false) return false;
|
|
781
|
+
if (!this.__isActiveInHierarchy) return false;
|
|
782
|
+
// let go = this.gameObject;
|
|
783
|
+
// do {
|
|
784
|
+
// // console.log(go.name, go.visible)
|
|
785
|
+
// if (!go.visible) return false;
|
|
786
|
+
// go = go.parent as GameObject;
|
|
787
|
+
// }
|
|
788
|
+
// while (go);
|
|
789
|
+
return true;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
private get __isActive(): boolean {
|
|
793
|
+
return this.gameObject.visible;
|
|
794
|
+
}
|
|
795
|
+
private get __isActiveInHierarchy(): boolean {
|
|
796
|
+
if (!this.gameObject) return false;
|
|
797
|
+
const res = this.gameObject[activeInHierarchyFieldName];
|
|
798
|
+
if (res === undefined) return true;
|
|
799
|
+
return res;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
gameObject!: GameObject;
|
|
803
|
+
guid: string = "invalid";
|
|
804
|
+
sourceId?: SourceIdentifier;
|
|
805
|
+
// transform: THREE.Object3D = nullObject;
|
|
806
|
+
|
|
807
|
+
/** called on a component with a map of old to new guids (e.g. when instantiate generated new guids and e.g. timeline track bindings needs to remape them) */
|
|
808
|
+
resolveGuids?(guidsMap: GuidsMap): void;
|
|
809
|
+
|
|
810
|
+
// TODO: can we not have these and then check in update loop if they are implemented (magick methods) ?
|
|
811
|
+
awake() { }
|
|
812
|
+
// update() { }
|
|
813
|
+
onEnable() { }
|
|
814
|
+
onDisable() { }
|
|
815
|
+
onDestroy() {
|
|
816
|
+
this.__destroyed = true;
|
|
817
|
+
}
|
|
818
|
+
start?(): void;
|
|
819
|
+
// available update loop events:
|
|
820
|
+
// earlyUpdate, update, lateUpdate, onBeforeRender, onAfterRender
|
|
821
|
+
earlyUpdate?(): void;
|
|
822
|
+
update?(): void;
|
|
823
|
+
lateUpdate?(): void;
|
|
824
|
+
onBeforeRender?(frame: THREE.XRFrame | null): void;
|
|
825
|
+
onAfterRender?(): void;
|
|
826
|
+
|
|
827
|
+
startCoroutine(routine: Generator, evt: FrameEvent = FrameEvent.Update): Generator {
|
|
828
|
+
return this.context.registerCoroutineUpdate(this, routine, evt);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
stopCoroutine(routine: Generator, evt: FrameEvent = FrameEvent.Update): void {
|
|
832
|
+
this.context.unregisterCoroutineUpdate(routine, evt);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
public get destroyed() {
|
|
836
|
+
return this.__destroyed;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
public destroy() {
|
|
840
|
+
if (this.destroyed) return;
|
|
841
|
+
// console.log("destroy", this);
|
|
842
|
+
object.destroyComponentInstance(this);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
protected __didAwake: boolean = false;
|
|
846
|
+
private __didStart: boolean = false;
|
|
847
|
+
protected __didEnable: boolean = false;
|
|
848
|
+
protected __isEnabled: boolean | undefined = undefined;
|
|
849
|
+
private __destroyed: boolean = false;
|
|
850
|
+
|
|
851
|
+
__internalNewInstanceCreated() {
|
|
852
|
+
this.__didAwake = false;
|
|
853
|
+
this.__didStart = false;
|
|
854
|
+
this.__didEnable = false;
|
|
855
|
+
this.__isEnabled = undefined;
|
|
856
|
+
this.__destroyed = false;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
__internalAwake() {
|
|
860
|
+
if (this.__didAwake) return;
|
|
861
|
+
// console.log("__internalAwake");
|
|
862
|
+
this.__didAwake = true;
|
|
863
|
+
// this.gameObject.test();
|
|
864
|
+
|
|
865
|
+
this.awake();
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
__internalStart() {
|
|
869
|
+
if (this.__didStart) return;
|
|
870
|
+
this.__didStart = true;
|
|
871
|
+
if (this.start) this.start();
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
__internalEnable() {
|
|
875
|
+
if (this.__didEnable) return;
|
|
876
|
+
// console.trace("INTERNAL ENABLE");
|
|
877
|
+
this.__didEnable = true;
|
|
878
|
+
this.onEnable();
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
__internalDisable() {
|
|
882
|
+
if (!this.__didEnable) return;
|
|
883
|
+
this.__didEnable = false;
|
|
884
|
+
this.onDisable();
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
constructor() {
|
|
888
|
+
this.__internalNewInstanceCreated();
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
// TODO move this to threeutils
|
|
894
|
+
|
|
895
|
+
// we need a copy for modifying the values to local space
|
|
896
|
+
private static _worldPositionBuffer: THREE.Vector3 = new THREE.Vector3();
|
|
897
|
+
private static _worldQuaternionBuffer: THREE.Quaternion = new THREE.Quaternion();
|
|
898
|
+
private static _worldEulerBuffer: THREE.Euler = new THREE.Euler();
|
|
899
|
+
|
|
900
|
+
private _worldPosition: THREE.Vector3 | undefined = undefined;
|
|
901
|
+
private _worldQuaternion: THREE.Quaternion | undefined = undefined;
|
|
902
|
+
private static _tempQuaternionBuffer2: THREE.Quaternion = new THREE.Quaternion();
|
|
903
|
+
private _worldEuler: THREE.Euler | undefined = undefined;
|
|
904
|
+
private _worldRotation: THREE.Vector3 | undefined = undefined;
|
|
905
|
+
|
|
906
|
+
get worldPosition(): THREE.Vector3 {
|
|
907
|
+
if (!this._worldPosition) this._worldPosition = new THREE.Vector3();
|
|
908
|
+
threeutils.getWorldPosition(this.gameObject, this._worldPosition);
|
|
909
|
+
// this.gameObject.getWorldPosition(this._worldPosition);
|
|
910
|
+
return this._worldPosition;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
set worldPosition(val: THREE.Vector3) {
|
|
914
|
+
threeutils.setWorldPosition(this.gameObject, val);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
setWorldPosition(x: number, y: number, z: number) {
|
|
918
|
+
Component._worldPositionBuffer.set(x, y, z);
|
|
919
|
+
this.worldPosition = Component._worldPositionBuffer;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
get worldQuaternion(): THREE.Quaternion {
|
|
924
|
+
if (!this._worldQuaternion) this._worldQuaternion = new THREE.Quaternion();
|
|
925
|
+
return threeutils.getWorldQuaternion(this.gameObject, this._worldQuaternion);
|
|
926
|
+
}
|
|
927
|
+
set worldQuaternion(val: THREE.Quaternion) {
|
|
928
|
+
threeutils.setWorldQuaternion(this.gameObject, val);
|
|
929
|
+
}
|
|
930
|
+
setWorldQuaternion(x: number, y: number, z: number, w: number) {
|
|
931
|
+
Component._worldQuaternionBuffer.set(x, y, z, w);
|
|
932
|
+
this.worldQuaternion = Component._worldQuaternionBuffer;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
// world euler (in radians)
|
|
937
|
+
get worldEuler(): THREE.Euler {
|
|
938
|
+
if (!this._worldEuler) this._worldEuler = new THREE.Euler();
|
|
939
|
+
this._worldEuler.setFromQuaternion(this.worldQuaternion);
|
|
940
|
+
return this._worldEuler;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// world euler (in radians)
|
|
944
|
+
set worldEuler(val: THREE.Euler) {
|
|
945
|
+
if (!this._worldQuaternion) this._worldQuaternion = new THREE.Quaternion();
|
|
946
|
+
this._worldQuaternion?.setFromEuler(val);
|
|
947
|
+
this.worldQuaternion = this._worldQuaternion;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// returns rotation in degrees
|
|
951
|
+
get worldRotation(): THREE.Vector3 {
|
|
952
|
+
const rot = this.worldEuler;
|
|
953
|
+
if (!this._worldRotation) this._worldRotation = new THREE.Vector3();
|
|
954
|
+
const wr = this._worldRotation;
|
|
955
|
+
wr.set(rot.x, rot.y, rot.z);
|
|
956
|
+
wr.x = Mathf.toDegrees(wr.x);
|
|
957
|
+
wr.y = Mathf.toDegrees(wr.y);
|
|
958
|
+
wr.z = Mathf.toDegrees(wr.z);
|
|
959
|
+
return wr;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
set worldRotation(val: THREE.Vector3) {
|
|
963
|
+
this.setWorldRotation(val.x, val.y, val.z, true);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
setWorldRotation(x: number, y: number, z: number, degrees: boolean = true) {
|
|
967
|
+
if (degrees) {
|
|
968
|
+
x = Mathf.toRadians(x);
|
|
969
|
+
y = Mathf.toRadians(y);
|
|
970
|
+
z = Mathf.toRadians(z);
|
|
971
|
+
}
|
|
972
|
+
Component._worldEulerBuffer.set(x, y, z);
|
|
973
|
+
Component._worldQuaternionBuffer.setFromEuler(Component._worldEulerBuffer);
|
|
974
|
+
this.worldQuaternion = Component._worldQuaternionBuffer;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
private static _forward: THREE.Vector3 = new THREE.Vector3(0, 0, 1);
|
|
978
|
+
public get forward(): THREE.Vector3 {
|
|
979
|
+
|
|
980
|
+
return Component._forward.set(0, 0, 1).applyQuaternion(this.worldQuaternion);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
// EventTarget implementation:
|
|
986
|
+
|
|
987
|
+
private _eventListeners = new Map<string, EventListener[]>();
|
|
988
|
+
|
|
989
|
+
addEventListener(type: string, listener: EventListener) {
|
|
990
|
+
this._eventListeners[type] = this._eventListeners[type] || [];
|
|
991
|
+
this._eventListeners[type].push(listener);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
removeEventListener(type: string, listener: EventListener) {
|
|
995
|
+
if (!this._eventListeners[type]) return;
|
|
996
|
+
const index = this._eventListeners[type].indexOf(listener);
|
|
997
|
+
if (index >= 0) this._eventListeners[type].splice(index, 1);
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
dispatchEvent(evt: Event): boolean {
|
|
1001
|
+
|
|
1002
|
+
if (!this._eventListeners[evt.type]) return false;
|
|
1003
|
+
const listeners = this._eventListeners[evt.type];
|
|
1004
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
1005
|
+
listeners[i](evt);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
return false;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
class Behaviour extends Component {
|
|
1014
|
+
// isActiveAndEnabled: boolean = false;
|
|
1015
|
+
|
|
1016
|
+
get enabled(): boolean {
|
|
1017
|
+
return this.__isEnabled ?? true; // if it has no enabled field it is always enabled
|
|
1018
|
+
}
|
|
1019
|
+
set enabled(val: boolean) {
|
|
1020
|
+
|
|
1021
|
+
// when called from animationclip we receive numbers
|
|
1022
|
+
// due to interpolation they can be anything between 0 and 1
|
|
1023
|
+
if (typeof val === "number") {
|
|
1024
|
+
if(val >= 0.5) val = true;
|
|
1025
|
+
else val = false;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
if (val === this.__isEnabled) return;
|
|
1029
|
+
|
|
1030
|
+
this.__isEnabled = val;
|
|
1031
|
+
// console.log(val);
|
|
1032
|
+
// need to check here because codegen is calling this before everything is setup
|
|
1033
|
+
if (!this.__didAwake) return;
|
|
1034
|
+
if (val) {
|
|
1035
|
+
this.__internalEnable();
|
|
1036
|
+
} else {
|
|
1037
|
+
this.__internalDisable();
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
export { Behaviour, Component, GameObject };
|