@needle-tools/engine 4.1.0-experimental.13 → 4.1.1

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.
Files changed (238) hide show
  1. package/CHANGELOG.md +75 -10
  2. package/README.md +28 -17
  3. package/components.needle.json +1 -1
  4. package/dist/gltf-progressive.js +220 -221
  5. package/dist/gltf-progressive.light.js +220 -221
  6. package/dist/gltf-progressive.light.min.js +6 -6
  7. package/dist/gltf-progressive.light.umd.cjs +7 -7
  8. package/dist/gltf-progressive.min.js +6 -6
  9. package/dist/gltf-progressive.umd.cjs +7 -7
  10. package/dist/needle-engine.bundle.js +8241 -7948
  11. package/dist/needle-engine.bundle.light.js +8194 -7901
  12. package/dist/needle-engine.bundle.light.min.js +140 -141
  13. package/dist/needle-engine.bundle.light.umd.cjs +138 -139
  14. package/dist/needle-engine.bundle.min.js +140 -141
  15. package/dist/needle-engine.bundle.umd.cjs +134 -135
  16. package/dist/needle-engine.d.ts +140 -0
  17. package/dist/needle-engine.js +597 -590
  18. package/dist/needle-engine.light.d.ts +140 -0
  19. package/dist/needle-engine.light.js +597 -590
  20. package/dist/needle-engine.light.min.js +1 -1
  21. package/dist/needle-engine.light.umd.cjs +1 -1
  22. package/dist/needle-engine.min.js +1 -1
  23. package/dist/needle-engine.umd.cjs +1 -1
  24. package/dist/postprocessing.js +1 -1
  25. package/dist/postprocessing.light.js +1 -1
  26. package/dist/postprocessing.light.min.js +1 -1
  27. package/dist/postprocessing.min.js +1 -1
  28. package/dist/three-examples.js +2809 -2450
  29. package/dist/three-examples.light.js +2809 -2450
  30. package/dist/three-examples.light.min.js +47 -15
  31. package/dist/three-examples.light.umd.cjs +47 -15
  32. package/dist/three-examples.min.js +47 -15
  33. package/dist/three-examples.umd.cjs +47 -15
  34. package/dist/three-mesh-ui.js +1 -1
  35. package/dist/three-mesh-ui.light.js +1 -1
  36. package/dist/three-mesh-ui.light.min.js +1 -1
  37. package/dist/three-mesh-ui.min.js +1 -1
  38. package/dist/three.js +577 -572
  39. package/dist/three.light.js +577 -572
  40. package/dist/three.light.min.js +170 -170
  41. package/dist/three.light.umd.cjs +170 -170
  42. package/dist/three.min.js +170 -170
  43. package/dist/three.umd.cjs +170 -170
  44. package/dist/vendor.js +1327 -1331
  45. package/dist/vendor.light.js +1327 -1331
  46. package/dist/vendor.light.min.js +33 -33
  47. package/dist/vendor.light.umd.cjs +33 -33
  48. package/dist/vendor.min.js +33 -33
  49. package/dist/vendor.umd.cjs +33 -33
  50. package/lib/engine/assets/index.js.map +1 -1
  51. package/lib/engine/engine.d.ts +4 -0
  52. package/lib/engine/engine.js +12 -0
  53. package/lib/engine/engine.js.map +1 -0
  54. package/lib/engine/engine_addressables.d.ts +6 -4
  55. package/lib/engine/engine_addressables.js +8 -1
  56. package/lib/engine/engine_addressables.js.map +1 -1
  57. package/lib/engine/engine_context.d.ts +3 -2
  58. package/lib/engine/engine_context.js +28 -4
  59. package/lib/engine/engine_context.js.map +1 -1
  60. package/lib/engine/engine_gameobject.d.ts +2 -12
  61. package/lib/engine/engine_gameobject.js +5 -15
  62. package/lib/engine/engine_gameobject.js.map +1 -1
  63. package/lib/engine/engine_gltf_builtin_components.js +5 -0
  64. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  65. package/lib/engine/engine_input.d.ts +23 -6
  66. package/lib/engine/engine_input.js +4 -10
  67. package/lib/engine/engine_input.js.map +1 -1
  68. package/lib/engine/engine_license.js +1 -1
  69. package/lib/engine/engine_license.js.map +1 -1
  70. package/lib/engine/engine_modules.d.ts +7 -0
  71. package/lib/engine/engine_modules.js +7 -0
  72. package/lib/engine/engine_modules.js.map +1 -1
  73. package/lib/engine/engine_networking_auto.js +6 -11
  74. package/lib/engine/engine_networking_auto.js.map +1 -1
  75. package/lib/engine/engine_networking_instantiate.d.ts +1 -1
  76. package/lib/engine/engine_physics_rapier.d.ts +6 -4
  77. package/lib/engine/engine_physics_rapier.js +38 -24
  78. package/lib/engine/engine_physics_rapier.js.map +1 -1
  79. package/lib/engine/engine_scenetools.js +6 -2
  80. package/lib/engine/engine_scenetools.js.map +1 -1
  81. package/lib/engine/engine_types.d.ts +9 -2
  82. package/lib/engine/engine_types.js +6 -0
  83. package/lib/engine/engine_types.js.map +1 -1
  84. package/lib/engine/engine_web_api.d.ts +12 -0
  85. package/lib/engine/engine_web_api.js +113 -0
  86. package/lib/engine/engine_web_api.js.map +1 -0
  87. package/lib/engine/export/gltf/Writers.js.map +1 -1
  88. package/lib/engine/export/gltf/index.js +11 -1
  89. package/lib/engine/export/gltf/index.js.map +1 -1
  90. package/lib/engine/export/utils.d.ts +2 -0
  91. package/lib/engine/export/utils.js +8 -0
  92. package/lib/engine/export/utils.js.map +1 -0
  93. package/lib/engine/extensions/NEEDLE_gameobject_data.js +1 -1
  94. package/lib/engine/extensions/NEEDLE_gameobject_data.js.map +1 -1
  95. package/lib/engine/js-extensions/Object3D.d.ts +5 -1
  96. package/lib/engine/js-extensions/Object3D.js.map +1 -1
  97. package/lib/engine/webcomponents/needle menu/needle-menu.js +8 -2
  98. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  99. package/lib/engine/xr/NeedleXRSession.js +3 -0
  100. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  101. package/lib/engine-components/AvatarLoader.js.map +1 -1
  102. package/lib/engine-components/Camera.d.ts +7 -4
  103. package/lib/engine-components/Camera.js +13 -10
  104. package/lib/engine-components/Camera.js.map +1 -1
  105. package/lib/engine-components/Collider.js +4 -5
  106. package/lib/engine-components/Collider.js.map +1 -1
  107. package/lib/engine-components/Component.d.ts +4 -3
  108. package/lib/engine-components/Component.js +6 -7
  109. package/lib/engine-components/Component.js.map +1 -1
  110. package/lib/engine-components/ContactShadows.d.ts +1 -1
  111. package/lib/engine-components/ContactShadows.js +7 -0
  112. package/lib/engine-components/ContactShadows.js.map +1 -1
  113. package/lib/engine-components/FlyControls.d.ts +10 -0
  114. package/lib/engine-components/FlyControls.js +29 -0
  115. package/lib/engine-components/FlyControls.js.map +1 -0
  116. package/lib/engine-components/GroundProjection.d.ts +1 -1
  117. package/lib/engine-components/GroundProjection.js +39 -32
  118. package/lib/engine-components/GroundProjection.js.map +1 -1
  119. package/lib/engine-components/OrbitControls.js +9 -1
  120. package/lib/engine-components/OrbitControls.js.map +1 -1
  121. package/lib/engine-components/RigidBody.d.ts +1 -0
  122. package/lib/engine-components/RigidBody.js +11 -4
  123. package/lib/engine-components/RigidBody.js.map +1 -1
  124. package/lib/engine-components/SceneSwitcher.d.ts +1 -1
  125. package/lib/engine-components/SceneSwitcher.js +1 -1
  126. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  127. package/lib/engine-components/SpatialTrigger.d.ts +2 -2
  128. package/lib/engine-components/SpatialTrigger.js +4 -4
  129. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  130. package/lib/engine-components/TransformGizmo.d.ts +7 -1
  131. package/lib/engine-components/TransformGizmo.js +39 -32
  132. package/lib/engine-components/TransformGizmo.js.map +1 -1
  133. package/lib/engine-components/VideoPlayer.js +0 -1
  134. package/lib/engine-components/VideoPlayer.js.map +1 -1
  135. package/lib/engine-components/export/gltf/GltfExport.js +23 -4
  136. package/lib/engine-components/export/gltf/GltfExport.js.map +1 -1
  137. package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +1 -1
  138. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +2 -2
  139. package/lib/engine-components/export/usdz/index.d.ts +1 -1
  140. package/lib/engine-components/export/usdz/index.js +1 -1
  141. package/lib/engine-components/export/usdz/index.js.map +1 -1
  142. package/lib/engine-components/particlesystem/ParticleSystem.d.ts +5 -6
  143. package/lib/engine-components/particlesystem/ParticleSystem.js +24 -9
  144. package/lib/engine-components/particlesystem/ParticleSystem.js.map +1 -1
  145. package/lib/engine-components/particlesystem/ParticleSystemModules.js +8 -2
  146. package/lib/engine-components/particlesystem/ParticleSystemModules.js.map +1 -1
  147. package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
  148. package/lib/engine-components/postprocessing/Effects/BloomEffect.js.map +1 -1
  149. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -1
  150. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
  151. package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -1
  152. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -1
  153. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
  154. package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +2 -0
  155. package/lib/engine-components/postprocessing/Effects/Sharpening.js +15 -6
  156. package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
  157. package/lib/engine-components/postprocessing/Effects/TiltShiftEffect.js.map +1 -1
  158. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
  159. package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -1
  160. package/lib/engine-components/postprocessing/PostProcessingHandler.js +1 -1
  161. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  162. package/lib/engine-components/webxr/Avatar.js +3 -3
  163. package/lib/engine-components/webxr/Avatar.js.map +1 -1
  164. package/lib/engine-components/webxr/WebXR.js +22 -13
  165. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  166. package/lib/engine-components/webxr/WebXRImageTracking.d.ts +4 -0
  167. package/lib/engine-components/webxr/WebXRImageTracking.js +14 -4
  168. package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
  169. package/lib/engine-components/webxr/WebXRRig.d.ts +11 -1
  170. package/lib/engine-components/webxr/WebXRRig.js +13 -1
  171. package/lib/engine-components/webxr/WebXRRig.js.map +1 -1
  172. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +4 -1
  173. package/lib/engine-components-experimental/networking/PlayerSync.js +18 -30
  174. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  175. package/lib/needle-engine.js +5 -5
  176. package/lib/needle-engine.js.map +1 -1
  177. package/package.json +14 -8
  178. package/plugins/common/config.cjs +22 -6
  179. package/plugins/common/config.js +27 -11
  180. package/plugins/next/next.js +47 -4
  181. package/plugins/vite/transform.js +3 -3
  182. package/src/engine/assets/index.ts +1 -0
  183. package/src/engine/codegen/register_types.ts +2 -2
  184. package/src/engine/engine_addressables.ts +19 -12
  185. package/src/engine/engine_context.ts +33 -8
  186. package/src/engine/engine_gameobject.ts +12 -16
  187. package/src/engine/engine_gltf_builtin_components.ts +7 -1
  188. package/src/engine/engine_input.ts +16 -5
  189. package/src/engine/engine_license.ts +2 -1
  190. package/src/engine/engine_modules.ts +7 -0
  191. package/src/engine/engine_networking_auto.ts +7 -22
  192. package/src/engine/engine_networking_instantiate.ts +1 -1
  193. package/src/engine/engine_physics_rapier.ts +48 -26
  194. package/src/engine/engine_scenetools.ts +6 -2
  195. package/src/engine/engine_types.ts +10 -2
  196. package/src/engine/export/gltf/Writers.ts +0 -1
  197. package/src/engine/export/gltf/index.ts +13 -3
  198. package/src/engine/export/index.ts +1 -1
  199. package/src/engine/export/utils.ts +10 -0
  200. package/src/engine/extensions/NEEDLE_gameobject_data.ts +1 -2
  201. package/src/engine/js-extensions/Object3D.ts +6 -1
  202. package/src/engine/webcomponents/needle menu/needle-menu.ts +16 -10
  203. package/src/engine/xr/NeedleXRSession.ts +4 -1
  204. package/src/engine-components/AvatarLoader.ts +1 -1
  205. package/src/engine-components/Camera.ts +14 -11
  206. package/src/engine-components/Collider.ts +4 -4
  207. package/src/engine-components/Component.ts +13 -7
  208. package/src/engine-components/ContactShadows.ts +11 -2
  209. package/src/engine-components/GroundProjection.ts +46 -38
  210. package/src/engine-components/OrbitControls.ts +9 -1
  211. package/src/engine-components/RigidBody.ts +13 -5
  212. package/src/engine-components/SceneSwitcher.ts +1 -1
  213. package/src/engine-components/SpatialTrigger.ts +6 -6
  214. package/src/engine-components/TransformGizmo.ts +41 -33
  215. package/src/engine-components/VideoPlayer.ts +0 -1
  216. package/src/engine-components/export/gltf/GltfExport.ts +26 -6
  217. package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +2 -2
  218. package/src/engine-components/export/usdz/index.ts +1 -1
  219. package/src/engine-components/particlesystem/ParticleSystem.ts +27 -10
  220. package/src/engine-components/particlesystem/ParticleSystemModules.ts +10 -3
  221. package/src/engine-components/postprocessing/Effects/Antialiasing.ts +0 -1
  222. package/src/engine-components/postprocessing/Effects/BloomEffect.ts +1 -1
  223. package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +1 -1
  224. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +1 -1
  225. package/src/engine-components/postprocessing/Effects/Pixelation.ts +1 -1
  226. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +1 -1
  227. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -1
  228. package/src/engine-components/postprocessing/Effects/Sharpening.ts +17 -7
  229. package/src/engine-components/postprocessing/Effects/TiltShiftEffect.ts +0 -1
  230. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +1 -1
  231. package/src/engine-components/postprocessing/Effects/Vignette.ts +1 -1
  232. package/src/engine-components/postprocessing/PostProcessingHandler.ts +2 -3
  233. package/src/engine-components/webxr/Avatar.ts +3 -3
  234. package/src/engine-components/webxr/WebXR.ts +23 -14
  235. package/src/engine-components/webxr/WebXRImageTracking.ts +23 -8
  236. package/src/engine-components/webxr/WebXRRig.ts +15 -2
  237. package/src/engine-components-experimental/networking/PlayerSync.ts +18 -37
  238. package/src/needle-engine.ts +5 -5
@@ -3,7 +3,7 @@ import { GroundedSkybox as GroundProjection } from 'three/examples/jsm/objects/G
3
3
 
4
4
  import { Gizmos } from "../engine/engine_gizmos.js";
5
5
  import { serializable } from "../engine/engine_serialization_decorator.js";
6
- import { getBoundingBox, getTempVector, getWorldScale, Graphics, setVisibleInCustomShadowRendering,setWorldPosition } from "../engine/engine_three_utils.js";
6
+ import { getBoundingBox, getTempVector, getWorldScale, Graphics, setVisibleInCustomShadowRendering, setWorldPosition } from "../engine/engine_three_utils.js";
7
7
  import { delayForFrames, getParam, Watch as Watch } from "../engine/engine_utils.js";
8
8
  import { Behaviour } from "./Component.js";
9
9
 
@@ -37,7 +37,7 @@ export class GroundProjectedEnv extends Behaviour {
37
37
  @serializable()
38
38
  set radius(val: number) {
39
39
  this._radius = val;
40
- this.updateProjection();
40
+ if (this._projection) this.updateProjection();
41
41
  }
42
42
  get radius(): number { return this._radius; }
43
43
  private _radius: number = 50;
@@ -49,7 +49,7 @@ export class GroundProjectedEnv extends Behaviour {
49
49
  @serializable()
50
50
  set height(val: number) {
51
51
  this._height = val;
52
- this.updateProjection();
52
+ if (this._projection) this.updateProjection();
53
53
  }
54
54
  get height(): number { return this._height; }
55
55
  private _height: number = 3;
@@ -68,7 +68,7 @@ export class GroundProjectedEnv extends Behaviour {
68
68
  get arBlending(): number { return this._arblending; }
69
69
  private _arblending = 0;
70
70
 
71
- private _lastEnvironment?: Texture;
71
+ private _lastBackground?: Texture;
72
72
  private _lastRadius?: number;
73
73
  private _lastHeight?: number;
74
74
  private _projection?: GroundProjection;
@@ -88,9 +88,10 @@ export class GroundProjectedEnv extends Behaviour {
88
88
  this.updateAndCreate();
89
89
  }
90
90
  if (!this._watcher) {
91
- this._watcher = new Watch(this.context.scene, "environment");
91
+ this._watcher = new Watch(this.context.scene, "background");
92
92
  this._watcher.subscribeWrite(_ => {
93
- this.updateProjection();
93
+ if (debug) console.log("Background changed", this.context.scene.background);
94
+ this._needsTextureUpdate = true;
94
95
  });
95
96
  }
96
97
  }
@@ -101,13 +102,13 @@ export class GroundProjectedEnv extends Behaviour {
101
102
  }
102
103
  /** @internal */
103
104
  onEnterXR(): void {
104
- if(!this.activeAndEnabled) return;
105
+ if (!this.activeAndEnabled) return;
105
106
  this._needsTextureUpdate = true;
106
107
  this.updateProjection();
107
108
  }
108
109
  /** @internal */
109
110
  async onLeaveXR() {
110
- if(!this.activeAndEnabled) return;
111
+ if (!this.activeAndEnabled) return;
111
112
  await delayForFrames(1);
112
113
  this.updateProjection();
113
114
  }
@@ -121,8 +122,8 @@ export class GroundProjectedEnv extends Behaviour {
121
122
  if (blurrinessChanged) {
122
123
  this.updateProjection();
123
124
  }
124
- else if (this._needsTextureUpdate) {
125
- this.updateBlurriness();
125
+ else if (this._needsTextureUpdate && this.context.scene.background instanceof Texture) {
126
+ this.updateBlurriness(this.context.scene.background, this.context.scene.backgroundBlurriness);
126
127
  }
127
128
  }
128
129
 
@@ -138,10 +139,16 @@ export class GroundProjectedEnv extends Behaviour {
138
139
  * Updates the ground projection. This is called automatically when the environment or settings change.
139
140
  */
140
141
  updateProjection() {
141
- if (!this.context.scene.environment) {
142
+ if (!this.context.scene.background) {
143
+ this._projection?.removeFromParent();
144
+ return;
145
+ }
146
+ const backgroundTexture = this.context.scene.background;
147
+ if (!(backgroundTexture instanceof Texture)) {
142
148
  this._projection?.removeFromParent();
143
149
  return;
144
150
  }
151
+
145
152
  if (this.context.xr?.isPassThrough || this.context.xr?.isAR) {
146
153
  if (this.arBlending === 0) {
147
154
  this._projection?.removeFromParent();
@@ -152,25 +159,25 @@ export class GroundProjectedEnv extends Behaviour {
152
159
  if (!this.gameObject || this.destroyed) {
153
160
  return;
154
161
  }
155
-
162
+
156
163
  let needsNewAutoFit = true;
157
164
  // offset here must be zero (and not .01) because the plane occlusion (when mesh tracking is active) is otherwise not correct
158
165
  const offset = 0;
159
- if (!this._projection || this.context.scene.environment !== this._lastEnvironment || this._height !== this._lastHeight || this._radius !== this._lastRadius) {
160
- if (debug)
161
- console.log("Create/Update Ground Projection", this.context.scene.environment.name);
166
+
167
+ const hasChanged = backgroundTexture !== this._lastBackground || this._height !== this._lastHeight || this._radius !== this._lastRadius;
168
+
169
+ if (!this._projection || hasChanged) {
170
+ if (debug) console.log("Create/Update Ground Projection", backgroundTexture.name);
171
+
162
172
  this._projection?.removeFromParent();
163
- if (!this._projection || (this.context.scene.environment !== this._lastEnvironment || this._lastHeight !== this._height || this._lastRadius !== this._radius)) {
164
- try {
165
- this._projection = new GroundProjection(this.context.scene.environment, this._height, this.radius, 64);
166
- }
167
- catch (e) {
168
- console.error("Failed to enable GroundProjection for environment", e);
169
- return;
170
- }
173
+
174
+ try {
175
+ this._projection = new GroundProjection(backgroundTexture, this._height, this._radius, 64);
176
+ }
177
+ catch (e) {
178
+ console.error("Error creating three GroundProjection", e);
179
+ return;
171
180
  }
172
- else
173
- needsNewAutoFit = false;
174
181
  this._projection.position.y = this._height - offset;
175
182
  this._projection.name = "GroundProjection";
176
183
  setVisibleInCustomShadowRendering(this._projection, false);
@@ -205,35 +212,35 @@ export class GroundProjectedEnv extends Behaviour {
205
212
  this.env.radius = this._radius;
206
213
  this.env.height = this._height;
207
214
  */
208
-
215
+
209
216
  if (this.context.scene.backgroundBlurriness > 0.001 && this._needsTextureUpdate) {
210
- this.updateBlurriness();
217
+ this.updateBlurriness(backgroundTexture, this.context.scene.backgroundBlurriness);
211
218
  }
212
219
 
213
- this._lastEnvironment = this.context.scene.environment;
220
+ this._lastBackground = backgroundTexture;
214
221
  this._lastHeight = this._height;
215
222
  this._lastRadius = this._radius;
216
-
217
223
  this._needsTextureUpdate = false;
218
224
  }
219
225
 
220
226
  private _blurrynessShader: ShaderMaterial | null = null;
221
227
  private _lastBlurriness: number = -1;
222
228
 
223
- private updateBlurriness() {
229
+ private updateBlurriness(texture: Texture, blurriness: number) {
224
230
  if (!this._projection) {
225
231
  return;
226
232
  }
227
- else if (!this.context.scene.environment) {
233
+ else if (!texture) {
228
234
  return;
229
235
  }
236
+
230
237
  this._needsTextureUpdate = false;
231
- if (debug) console.log("Update Blurriness", this.context.scene.backgroundBlurriness);
238
+ if (debug) console.log("Update Blurriness", blurriness);
232
239
  this._blurrynessShader ??= new ShaderMaterial({
233
240
  name: "GroundProjectionBlurriness",
234
241
  uniforms: {
235
- map: { value: this.context.scene.environment },
236
- blurriness: { value: this.context.scene.backgroundBlurriness },
242
+ map: { value: texture },
243
+ blurriness: { value: blurriness },
237
244
  blending: { value: 0 },
238
245
  alphaFactor: { value: 1 }
239
246
  },
@@ -241,9 +248,10 @@ export class GroundProjectedEnv extends Behaviour {
241
248
  fragmentShader: blurFragmentShader
242
249
  });
243
250
  this._blurrynessShader.depthWrite = false;
244
- this._blurrynessShader.uniforms.blurriness.value = this.context.scene.backgroundBlurriness;
245
- this._lastBlurriness = this.context.scene.backgroundBlurriness;
246
- this.context.scene.environment.needsPMREMUpdate = true;
251
+ this._blurrynessShader.uniforms.map.value = texture;
252
+ this._blurrynessShader.uniforms.blurriness.value = 1;//blurriness;
253
+ this._lastBlurriness = blurriness;
254
+ texture.needsUpdate = true;
247
255
 
248
256
  const wasTransparent = this._projection.material.transparent;
249
257
  this._projection.material.transparent = (this.context.xr?.isAR === true && this.arBlending > 0.000001) ?? false;
@@ -266,7 +274,7 @@ export class GroundProjectedEnv extends Behaviour {
266
274
  }
267
275
 
268
276
  // Update the texture
269
- this._projection.material.map = Graphics.copyTexture(this.context.scene.environment, this._blurrynessShader);
277
+ this._projection.material.map = Graphics.copyTexture(texture, this._blurrynessShader);
270
278
  this._projection.material.depthTest = true;
271
279
  this._projection.material.depthWrite = false;
272
280
  }
@@ -287,7 +287,7 @@ export class OrbitControls extends Behaviour implements ICameraController {
287
287
  cam = this.gameObject;
288
288
  }
289
289
  if (cam) setCameraController(cam, this, true);
290
- if (!this._controls && cam instanceof PerspectiveCamera) {
290
+ if (!this._controls && cam instanceof Object3D) {
291
291
  this._cameraObject = cam;
292
292
  // Using the parent if possible to make it possible to disable input on the canvas
293
293
  // for having HTML content behind it and still receive input
@@ -297,6 +297,14 @@ export class OrbitControls extends Behaviour implements ICameraController {
297
297
  this._controls = new ThreeOrbitControls(cam!, element);
298
298
  cam?.quaternion.copy(mat!)
299
299
  if (defaultKeys === undefined) defaultKeys = { ...this._controls.keys };
300
+ // set controls look point in front of the current camera by default
301
+ // it may be overriden by the autoTarget feature
302
+ // but if we don't do this and autoTarget is OFF then the camera will turn to look at 0 0 0 of the scene
303
+ const worldPosition = getWorldPosition(cam);
304
+ const forward = this.gameObject.worldForward;
305
+ const dist = 2.5;
306
+ const lookAt = worldPosition.clone().sub(forward.multiplyScalar(dist));
307
+ this._controls.target.copy(lookAt);
300
308
  }
301
309
 
302
310
  if (this._controls) {
@@ -1,13 +1,14 @@
1
1
  import { Matrix4, Object3D, Quaternion, Vector3, Vector3Like } from "three";
2
2
 
3
3
  import { isDevEnvironment } from "../engine/debug/index.js";
4
+ import { MODULES } from "../engine/engine_modules.js";
4
5
  import { CollisionDetectionMode, RigidbodyConstraints } from "../engine/engine_physics.types.js";
5
6
  import { serializable } from "../engine/engine_serialization_decorator.js";
6
7
  import { Context, FrameEvent } from "../engine/engine_setup.js";
7
8
  import { getWorldPosition } from "../engine/engine_three_utils.js";
8
9
  import type { IRigidbody, Vec3 } from "../engine/engine_types.js";
9
10
  import { validate } from "../engine/engine_util_decorator.js";
10
- import { Watch } from "../engine/engine_utils.js";
11
+ import { delayForFrames, Watch } from "../engine/engine_utils.js";
11
12
  import { Behaviour } from "./Component.js";
12
13
 
13
14
  class TransformWatch {
@@ -139,6 +140,8 @@ class TransformWatch {
139
140
  */
140
141
  export class Rigidbody extends Behaviour implements IRigidbody {
141
142
 
143
+ get isRigidbody() { return true; }
144
+
142
145
  /** When true the mass will be automatically calculated by the attached colliders */
143
146
  @validate()
144
147
  autoMass: boolean = true;
@@ -316,11 +319,16 @@ export class Rigidbody extends Behaviour implements IRigidbody {
316
319
  }
317
320
  this._watch.start(true, true);
318
321
  this.startCoroutine(this.beforePhysics(), FrameEvent.LateUpdate);
319
- if (isDevEnvironment() && !this.context.physics.engine?.getBody(this)) {
322
+ if (isDevEnvironment()) {
320
323
  if (!globalThis["NEEDLE_USE_RAPIER"])
321
324
  console.warn(`Rigidbody could not be created: Rapier physics are explicitly disabled.`);
322
- else
323
- console.warn(`Rigidbody could not be created. Ensure \"(${this.name}\" has a Collider component.`);
325
+ else {
326
+ MODULES.RAPIER_PHYSICS.ready().then(async () => {
327
+ await delayForFrames(3);
328
+ if (!this.context.physics.engine?.getBody(this))
329
+ console.warn(`Rigidbody could not be created. Ensure \"${this.name}\" has a Collider component.`);
330
+ })
331
+ }
324
332
  }
325
333
  }
326
334
 
@@ -338,7 +346,7 @@ export class Rigidbody extends Behaviour implements IRigidbody {
338
346
  }
339
347
 
340
348
  // need to do this right before updating physics to prevent rendered object glitching through physical bodies
341
- *beforePhysics() {
349
+ * beforePhysics() {
342
350
  while (true) {
343
351
  if (this._propertiesChanged) {
344
352
  this._propertiesChanged = false;
@@ -760,7 +760,7 @@ export class SceneSwitcher extends Behaviour {
760
760
  }
761
761
  this._lastLoadingScene = this.loadingScene;
762
762
  if (!this._loadingScenePromise) {
763
- this._loadingScenePromise = this.loadingScene?.loadAssetAsync();
763
+ this._loadingScenePromise = this.loadingScene?.loadAssetAsync().then(res => res != null);
764
764
  }
765
765
  await this._loadingScenePromise;
766
766
  if (this._isCurrentlyLoading && this.loadingScene?.asset) {
@@ -62,23 +62,23 @@ export class SpatialTriggerReceiver extends Behaviour {
62
62
 
63
63
  }
64
64
 
65
- currentIntersected: SpatialTrigger[] = [];
66
- lastIntersected: SpatialTrigger[] = [];
65
+ readonly currentIntersected: SpatialTrigger[] = [];
66
+ readonly lastIntersected: SpatialTrigger[] = [];
67
67
 
68
68
  onEnterTrigger(trigger: SpatialTrigger): void {
69
69
  if(debug) console.log("ENTER TRIGGER", this.name, trigger.name, this, trigger);
70
70
  trigger.raiseOnEnterEvent(this);
71
- this.onEnter?.invoke(this, trigger);
71
+ this.onEnter?.invoke();
72
72
  }
73
73
  onExitTrigger(trigger: SpatialTrigger): void {
74
- if(debug) console.log("EXIT TRIGGER", this.name, trigger.name, this, trigger);
74
+ if(debug) console.log("EXIT TRIGGER", this.name, trigger.name, );
75
75
  trigger.raiseOnExitEvent(this);
76
- this.onExit?.invoke(this, trigger);
76
+ this.onExit?.invoke();
77
77
  }
78
78
 
79
79
  onStayTrigger(trigger: SpatialTrigger): void {
80
80
  trigger.raiseOnStayEvent(this);
81
- this.onStay?.invoke(this, trigger);
81
+ this.onStay?.invoke();
82
82
  }
83
83
  }
84
84
 
@@ -1,4 +1,4 @@
1
- import { MathUtils,Mesh, MeshBasicMaterial, Object3D } from "three";
1
+ import { MathUtils, Mesh, MeshBasicMaterial, Object3D } from "three";
2
2
  import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
3
3
 
4
4
  import * as params from "../engine/engine_default_parameters.js";
@@ -26,7 +26,15 @@ export class TransformGizmo extends Behaviour {
26
26
  @serializable()
27
27
  public scaleSnap: number = .25;
28
28
 
29
- private control?: TransformControls;
29
+ /**
30
+ * Get the underlying three.js TransformControls instance.
31
+ * @returns The TransformControls instance.
32
+ */
33
+ get control() {
34
+ return this._control;
35
+ }
36
+
37
+ private _control?: TransformControls;
30
38
  private orbit?: OrbitControls;
31
39
 
32
40
  /** @internal */
@@ -35,12 +43,12 @@ export class TransformGizmo extends Behaviour {
35
43
 
36
44
  if (!this.context.mainCamera) return;
37
45
 
38
- if (!this.control) {
39
- this.control = new TransformControls(this.context.mainCamera, this.context.renderer.domElement);
40
- this.control.enabled = true;
41
- this.control.getRaycaster().layers.set(2);
42
- this.control.size = 1;
43
- const obj = ("_root" in this.control ? this.control._root : this.control) as Object3D;
46
+ if (!this._control) {
47
+ this._control = new TransformControls(this.context.mainCamera, this.context.renderer.domElement);
48
+ this._control.enabled = true;
49
+ this._control.getRaycaster().layers.set(2);
50
+ this._control.size = 1;
51
+ const obj = ("_root" in this._control ? this._control._root : this._control) as Object3D;
44
52
  obj.traverse(x => {
45
53
  const mesh = x as Mesh;
46
54
  mesh.layers.set(2);
@@ -54,12 +62,12 @@ export class TransformGizmo extends Behaviour {
54
62
  this.orbit = GameObject.getComponentInParent(this.context.mainCamera, OrbitControls) ?? undefined;
55
63
  }
56
64
 
57
- if (this.control) {
58
- const obj = this.control.getHelper();
65
+ if (this._control) {
66
+ const obj = this._control.getHelper();
59
67
  this.context.scene.add(obj);
60
- this.control.attach(this.gameObject);
68
+ this._control.attach(this.gameObject);
61
69
 
62
- this.control?.addEventListener('dragging-changed', this.onControlChangedEvent);
70
+ this._control?.addEventListener('dragging-changed', this.onControlChangedEvent);
63
71
  window.addEventListener('keydown', this.windowKeyDownListener);
64
72
  window.addEventListener('keyup', this.windowKeyUpListener);
65
73
  }
@@ -67,25 +75,25 @@ export class TransformGizmo extends Behaviour {
67
75
 
68
76
  /** @internal */
69
77
  onDisable() {
70
- this.control?.getHelper()?.removeFromParent();
71
- this.control?.removeEventListener('dragging-changed', this.onControlChangedEvent);
78
+ this._control?.getHelper()?.removeFromParent();
79
+ this._control?.removeEventListener('dragging-changed', this.onControlChangedEvent);
72
80
  window.removeEventListener('keydown', this.windowKeyDownListener);
73
81
  window.removeEventListener('keyup', this.windowKeyUpListener);
74
82
  }
75
83
 
76
84
  enableSnapping() {
77
- if (this.control) {
78
- this.control.setTranslationSnap(this.translationSnap);
79
- this.control.setRotationSnap(MathUtils.degToRad(this.rotationSnapAngle));
80
- this.control.setScaleSnap(this.scaleSnap);
85
+ if (this._control) {
86
+ this._control.setTranslationSnap(this.translationSnap);
87
+ this._control.setRotationSnap(MathUtils.degToRad(this.rotationSnapAngle));
88
+ this._control.setScaleSnap(this.scaleSnap);
81
89
  }
82
90
  }
83
91
 
84
92
  disableSnapping() {
85
- if (this.control) {
86
- this.control.setTranslationSnap(null);
87
- this.control.setRotationSnap(null);
88
- this.control.setScaleSnap(null);
93
+ if (this._control) {
94
+ this._control.setTranslationSnap(null);
95
+ this._control.setRotationSnap(null);
96
+ this._control.setScaleSnap(null);
89
97
  }
90
98
  }
91
99
 
@@ -104,11 +112,11 @@ export class TransformGizmo extends Behaviour {
104
112
 
105
113
  private windowKeyDownListener = (event) => {
106
114
  if (!this.enabled) return;
107
- if (!this.control) return;
115
+ if (!this._control) return;
108
116
  switch (event.keyCode) {
109
117
 
110
118
  case 81: // Q
111
- this.control.setSpace(this.control.space === 'local' ? 'world' : 'local');
119
+ this._control.setSpace(this._control.space === 'local' ? 'world' : 'local');
112
120
  break;
113
121
 
114
122
  case 16: // Shift
@@ -116,40 +124,40 @@ export class TransformGizmo extends Behaviour {
116
124
  break;
117
125
 
118
126
  case 87: // W
119
- this.control.setMode('translate');
127
+ this._control.setMode('translate');
120
128
  break;
121
129
 
122
130
  case 69: // E
123
- this.control.setMode('rotate');
131
+ this._control.setMode('rotate');
124
132
  break;
125
133
 
126
134
  case 82: // R
127
- this.control.setMode('scale');
135
+ this._control.setMode('scale');
128
136
  break;
129
137
  case 187:
130
138
  case 107: // +, =, num+
131
- this.control.setSize(this.control.size + 0.1);
139
+ this._control.setSize(this._control.size + 0.1);
132
140
  break;
133
141
 
134
142
  case 189:
135
143
  case 109: // -, _, num-
136
- this.control.setSize(Math.max(this.control.size - 0.1, 0.1));
144
+ this._control.setSize(Math.max(this._control.size - 0.1, 0.1));
137
145
  break;
138
146
 
139
147
  case 88: // X
140
- this.control.showX = !this.control.showX;
148
+ this._control.showX = !this._control.showX;
141
149
  break;
142
150
 
143
151
  case 89: // Y
144
- this.control.showY = !this.control.showY;
152
+ this._control.showY = !this._control.showY;
145
153
  break;
146
154
 
147
155
  case 90: // Z
148
- this.control.showZ = !this.control.showZ;
156
+ this._control.showZ = !this._control.showZ;
149
157
  break;
150
158
 
151
159
  case 32: // Spacebar
152
- this.control.enabled = !this.control.enabled;
160
+ this._control.enabled = !this._control.enabled;
153
161
  break;
154
162
  }
155
163
  }
@@ -1017,7 +1017,6 @@ class ScreenspaceTexture extends ShaderMaterial {
1017
1017
  else
1018
1018
  {
1019
1019
  vec4 texcolor = texture2D(map, vUv);
1020
- texcolor = LinearTosRGB(texcolor);
1021
1020
  gl_FragColor = texcolor;
1022
1021
  }
1023
1022
  }
@@ -6,6 +6,8 @@ import { SerializationContext } from "../../../engine/engine_serialization_core.
6
6
  import { serializable } from "../../../engine/engine_serialization_decorator.js";
7
7
  import { getWorldPosition } from "../../../engine/engine_three_utils.js";
8
8
  import { getParam } from "../../../engine/engine_utils.js";
9
+ import { RenderTextureWriter } from "../../../engine/export/gltf/Writers.js";
10
+ import { shouldExport_HideFlags } from "../../../engine/export/utils.js";
9
11
  import { registerExportExtensions } from "../../../engine/extensions/index.js";
10
12
  import { NEEDLE_components } from "../../../engine/extensions/NEEDLE_components.js";
11
13
  import GLTFMeshGPUInstancingExtension from '../../../include/three/EXT_mesh_gpu_instancing_exporter.js';
@@ -48,8 +50,8 @@ export class GltfExport extends Behaviour {
48
50
  if (!this.objects || this.objects.length <= 0)
49
51
  this.objects = [this.context.scene];
50
52
 
51
- const options = {
52
- binary: this.binary,
53
+ const options = {
54
+ binary: this.binary,
53
55
  pivot: GltfExport.calculateCenter(this.objects),
54
56
  ...opts
55
57
  };
@@ -74,6 +76,15 @@ export class GltfExport extends Behaviour {
74
76
 
75
77
  async export(objectsToExport: Object3D[], opts?: ExportOptions): Promise<any> {
76
78
 
79
+ // -----------------------
80
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
81
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
82
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
83
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
84
+ // TODO: refactor this to use ../engine/export/index exportAsGLTF function
85
+
86
+ // TODO add filtering / tags for what to export and what not < this is implemented in exportAsGLTF, see TODO above
87
+
77
88
  if (!objectsToExport || objectsToExport.length <= 0) {
78
89
  console.warn("No objects set to export");
79
90
  return;
@@ -82,12 +93,11 @@ export class GltfExport extends Behaviour {
82
93
  // Instantiate a exporter
83
94
  const exporter = new GLTFExporter();
84
95
  exporter.register(writer => new GLTFMeshGPUInstancingExtension(writer));
96
+ exporter.register(writer => new RenderTextureWriter(writer));
85
97
  registerExportExtensions(exporter, this.context);
86
98
 
87
99
  GltfExport.filterTopmostParent(objectsToExport);
88
100
 
89
- // TODO export only worldglb BUT exclude "World" child which contains all build tools
90
- // TODO add filtering / tags for what to export and what not
91
101
 
92
102
  // https://threejs.org/docs/#examples/en/exporters/GLTFExporter
93
103
  const options = {
@@ -102,7 +112,7 @@ export class GltfExport extends Behaviour {
102
112
  ...opts
103
113
  };
104
114
 
105
- // hide objects that we don't want to export
115
+ const undo = new Array<() => void>();
106
116
 
107
117
  const exportScene = new Object3D();
108
118
  // set the pivot position
@@ -112,7 +122,7 @@ export class GltfExport extends Behaviour {
112
122
  // add objects for export
113
123
  if (debugExport) console.log("EXPORT", objectsToExport);
114
124
  objectsToExport.forEach(obj => {
115
- if (obj) {
125
+ if (obj && shouldExport_HideFlags(obj)) {
116
126
  // adding directly does not require us to change parents and mess with the hierarchy actually
117
127
  exportScene.children.push(obj);
118
128
  // TODO: we should probably be doing this before writing nodes?? apply world scale, position, rotation etc for export only
@@ -122,6 +132,15 @@ export class GltfExport extends Behaviour {
122
132
  GameObject.getComponentsInChildren(obj, Renderer).forEach(r => {
123
133
  if (GameObject.isActiveInHierarchy(r.gameObject)) r.setInstancingEnabled(false)
124
134
  });
135
+ obj.traverse(o => {
136
+ if (!shouldExport_HideFlags(o)) {
137
+ const parent = o.parent;
138
+ o.removeFromParent();
139
+ undo.push(() => {
140
+ if (parent) parent.add(o);
141
+ });
142
+ }
143
+ })
125
144
  }
126
145
  });
127
146
 
@@ -159,6 +178,7 @@ export class GltfExport extends Behaviour {
159
178
  reject(err);
160
179
  }
161
180
  finally {
181
+ undo.forEach(u => u());
162
182
  if (debugExport) console.log("Finished glTF export.");
163
183
  }
164
184
  });
@@ -1174,7 +1174,7 @@ declare type ImageReadbackResult = {
1174
1174
  imageBitmap?: ImageBitmap;
1175
1175
  }
1176
1176
 
1177
- /** Reads back a texture from the GPU (can be compressed, a render texture, or aynthing), apply colorScale to it, and return CPU data for further usage.
1177
+ /** Reads back a texture from the GPU (can be compressed, a render texture, or anything), optionally applies RGBA colorScale to it, and returns CPU data for further usage.
1178
1178
  * Note that there are WebGL / WebGPU rules preventing some use of data between WebGL contexts.
1179
1179
  */
1180
1180
  async function decompressGpuTexture( texture, maxTextureSize = Infinity, renderer: WebGLRenderer | null = null, colorScale: Vector4 | undefined = undefined): Promise<ImageReadbackResult> {
@@ -1204,7 +1204,7 @@ async function decompressGpuTexture( texture, maxTextureSize = Infinity, rendere
1204
1204
  gl_FragColor = vec4(vUv.xy, 0, 1);
1205
1205
 
1206
1206
  #ifdef IS_SRGB
1207
- gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) );
1207
+ gl_FragColor = sRGBTransferOETF( texture2D( blitTexture, vUv) );
1208
1208
  #else
1209
1209
  gl_FragColor = texture2D( blitTexture, vUv);
1210
1210
  #endif
@@ -1,3 +1,3 @@
1
1
  export { type UsdzBehaviour } from "./extensions/behavior/Behaviour.js";
2
- export { imageToCanvas, makeNameSafeForUSD, USDZExporter as NeedleUSDZExporter, USDDocument, USDObject, USDWriter,type USDZExporterContext } from "./ThreeUSDZExporter.js";
2
+ export { decompressGpuTexture, imageToCanvas, makeNameSafeForUSD, USDZExporter as NeedleUSDZExporter, USDDocument, USDObject, USDWriter,type USDZExporterContext } from "./ThreeUSDZExporter.js";
3
3
  export { USDZExporter } from "./USDZExporter.js";