@needle-tools/engine 2.66.1-pre → 2.67.0-pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/needle-engine.js +34306 -26230
  3. package/dist/needle-engine.umd.cjs +743 -298
  4. package/lib/engine/api.d.ts +4 -0
  5. package/lib/engine/api.js +10 -0
  6. package/lib/engine/api.js.map +1 -1
  7. package/lib/engine/codegen/register_types.js +23 -7
  8. package/lib/engine/codegen/register_types.js.map +1 -1
  9. package/lib/engine/debug/debug_overlay.js +7 -1
  10. package/lib/engine/debug/debug_overlay.js.map +1 -1
  11. package/lib/engine/engine_addressables.js +2 -2
  12. package/lib/engine/engine_addressables.js.map +1 -1
  13. package/lib/engine/engine_assetdatabase.d.ts +17 -51
  14. package/lib/engine/engine_assetdatabase.js +252 -126
  15. package/lib/engine/engine_assetdatabase.js.map +1 -1
  16. package/lib/engine/engine_components.js +13 -1
  17. package/lib/engine/engine_components.js.map +1 -1
  18. package/lib/engine/engine_components_internal.d.ts +8 -0
  19. package/lib/engine/engine_components_internal.js +29 -0
  20. package/lib/engine/engine_components_internal.js.map +1 -0
  21. package/lib/engine/engine_constants.d.ts +1 -0
  22. package/lib/engine/engine_constants.js +1 -0
  23. package/lib/engine/engine_constants.js.map +1 -1
  24. package/lib/engine/engine_context_registry.d.ts +2 -0
  25. package/lib/engine/engine_context_registry.js +6 -0
  26. package/lib/engine/engine_context_registry.js.map +1 -1
  27. package/lib/engine/engine_editor-sync.d.ts +9 -0
  28. package/lib/engine/engine_editor-sync.js +8 -0
  29. package/lib/engine/engine_editor-sync.js.map +1 -0
  30. package/lib/engine/engine_element_loading.js +1 -1
  31. package/lib/engine/engine_element_loading.js.map +1 -1
  32. package/lib/engine/engine_gameobject.js +15 -20
  33. package/lib/engine/engine_gameobject.js.map +1 -1
  34. package/lib/engine/engine_gltf_builtin_components.d.ts +2 -3
  35. package/lib/engine/engine_gltf_builtin_components.js +23 -6
  36. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  37. package/lib/engine/engine_networking_auto.d.ts +1 -0
  38. package/lib/engine/engine_networking_auto.js +42 -9
  39. package/lib/engine/engine_networking_auto.js.map +1 -1
  40. package/lib/engine/engine_patcher.d.ts +8 -0
  41. package/lib/engine/engine_patcher.js +98 -0
  42. package/lib/engine/engine_patcher.js.map +1 -0
  43. package/lib/engine/engine_physics.d.ts +5 -1
  44. package/lib/engine/engine_physics.js +11 -1
  45. package/lib/engine/engine_physics.js.map +1 -1
  46. package/lib/engine/engine_scenetools.js +0 -1
  47. package/lib/engine/engine_scenetools.js.map +1 -1
  48. package/lib/engine/engine_serialization_core.js +4 -0
  49. package/lib/engine/engine_serialization_core.js.map +1 -1
  50. package/lib/engine/engine_setup.d.ts +1 -1
  51. package/lib/engine/engine_setup.js +9 -5
  52. package/lib/engine/engine_setup.js.map +1 -1
  53. package/lib/engine/engine_texture.d.ts +6 -1
  54. package/lib/engine/engine_texture.js +39 -1
  55. package/lib/engine/engine_texture.js.map +1 -1
  56. package/lib/engine/engine_types.d.ts +4 -0
  57. package/lib/engine/engine_types.js.map +1 -1
  58. package/lib/engine/engine_utils.js +3 -2
  59. package/lib/engine/engine_utils.js.map +1 -1
  60. package/lib/engine/extensions/NEEDLE_progressive.d.ts +0 -1
  61. package/lib/engine/extensions/NEEDLE_progressive.js +24 -26
  62. package/lib/engine/extensions/NEEDLE_progressive.js.map +1 -1
  63. package/lib/engine/extensions/extensions.d.ts +4 -1
  64. package/lib/engine/extensions/extensions.js +16 -0
  65. package/lib/engine/extensions/extensions.js.map +1 -1
  66. package/lib/engine/extensions/usage_tracker.d.ts +12 -0
  67. package/lib/engine/extensions/usage_tracker.js +59 -0
  68. package/lib/engine/extensions/usage_tracker.js.map +1 -0
  69. package/lib/engine-components/AnimatorController.js +4 -0
  70. package/lib/engine-components/AnimatorController.js.map +1 -1
  71. package/lib/engine-components/AudioSource.js +2 -1
  72. package/lib/engine-components/AudioSource.js.map +1 -1
  73. package/lib/engine-components/Camera.d.ts +6 -0
  74. package/lib/engine-components/Camera.js +70 -31
  75. package/lib/engine-components/Camera.js.map +1 -1
  76. package/lib/engine-components/Component.d.ts +52 -0
  77. package/lib/engine-components/Component.js +55 -14
  78. package/lib/engine-components/Component.js.map +1 -1
  79. package/lib/engine-components/Networking.js +19 -0
  80. package/lib/engine-components/Networking.js.map +1 -1
  81. package/lib/engine-components/OrbitControls.d.ts +2 -0
  82. package/lib/engine-components/OrbitControls.js +9 -0
  83. package/lib/engine-components/OrbitControls.js.map +1 -1
  84. package/lib/engine-components/ParticleSystem.js +11 -1
  85. package/lib/engine-components/ParticleSystem.js.map +1 -1
  86. package/lib/engine-components/ReflectionProbe.js +18 -6
  87. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  88. package/lib/engine-components/Renderer.d.ts +1 -1
  89. package/lib/engine-components/Renderer.js +24 -6
  90. package/lib/engine-components/Renderer.js.map +1 -1
  91. package/lib/engine-components/Skybox.js +2 -0
  92. package/lib/engine-components/Skybox.js.map +1 -1
  93. package/lib/engine-components/SmoothFollow.js +1 -2
  94. package/lib/engine-components/SmoothFollow.js.map +1 -1
  95. package/lib/engine-components/WebARCameraBackground.d.ts +19 -0
  96. package/lib/engine-components/WebARCameraBackground.js +185 -0
  97. package/lib/engine-components/WebARCameraBackground.js.map +1 -0
  98. package/lib/engine-components/WebXR.d.ts +4 -0
  99. package/lib/engine-components/WebXR.js +11 -8
  100. package/lib/engine-components/WebXR.js.map +1 -1
  101. package/lib/engine-components/WebXRAvatar.js +1 -0
  102. package/lib/engine-components/WebXRAvatar.js.map +1 -1
  103. package/lib/engine-components/codegen/components.d.ts +14 -6
  104. package/lib/engine-components/codegen/components.js +14 -6
  105. package/lib/engine-components/codegen/components.js.map +1 -1
  106. package/lib/engine-components/js-extensions/Object3D.js +4 -1
  107. package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
  108. package/lib/engine-components/postprocessing/Effects/Antialiasing.d.ts +13 -0
  109. package/lib/engine-components/postprocessing/Effects/Antialiasing.js +46 -0
  110. package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -0
  111. package/lib/engine-components/postprocessing/Effects/Bloom.d.ts +12 -0
  112. package/lib/engine-components/postprocessing/Effects/Bloom.js +76 -0
  113. package/lib/engine-components/postprocessing/Effects/Bloom.js.map +1 -0
  114. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +8 -0
  115. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +39 -0
  116. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -0
  117. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +12 -0
  118. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +96 -0
  119. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -0
  120. package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +21 -0
  121. package/lib/engine-components/postprocessing/Effects/DepthOfField.js +87 -0
  122. package/lib/engine-components/postprocessing/Effects/DepthOfField.js.map +1 -0
  123. package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +7 -0
  124. package/lib/engine-components/postprocessing/Effects/Pixelation.js +30 -0
  125. package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -0
  126. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.d.ts +11 -0
  127. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js +70 -0
  128. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -0
  129. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +16 -0
  130. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +52 -0
  131. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -0
  132. package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +11 -0
  133. package/lib/engine-components/postprocessing/Effects/Vignette.js +57 -0
  134. package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -0
  135. package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +29 -0
  136. package/lib/engine-components/postprocessing/PostProcessingEffect.js +89 -0
  137. package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -0
  138. package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +13 -0
  139. package/lib/engine-components/postprocessing/PostProcessingHandler.js +119 -0
  140. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -0
  141. package/lib/engine-components/postprocessing/Volume.d.ts +23 -0
  142. package/lib/engine-components/postprocessing/Volume.js +176 -0
  143. package/lib/engine-components/postprocessing/Volume.js.map +1 -0
  144. package/lib/engine-components/postprocessing/VolumeParameter.d.ts +21 -0
  145. package/lib/engine-components/postprocessing/VolumeParameter.js +75 -0
  146. package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -0
  147. package/lib/engine-components/postprocessing/VolumeProfile.d.ts +7 -0
  148. package/lib/engine-components/postprocessing/VolumeProfile.js +42 -0
  149. package/lib/engine-components/postprocessing/VolumeProfile.js.map +1 -0
  150. package/lib/engine-components/timeline/TimelineTracks.js +14 -15
  151. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  152. package/lib/engine-components/ui/Text.js +28 -170
  153. package/lib/engine-components/ui/Text.js.map +1 -1
  154. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +18 -0
  155. package/lib/engine-components-experimental/networking/PlayerSync.js +61 -7
  156. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  157. package/lib/include/three/ARButton.d.ts +1 -1
  158. package/lib/include/three/ARButton.js +11 -19
  159. package/lib/include/three/ARButton.js.map +1 -1
  160. package/lib/include/three/VRButton.js +1 -4
  161. package/lib/include/three/VRButton.js.map +1 -1
  162. package/package.json +3 -2
  163. package/plugins/vite/drop-client.js +77 -0
  164. package/plugins/vite/drop.js +81 -0
  165. package/plugins/vite/editor-connection.js +121 -0
  166. package/plugins/vite/index.js +9 -4
  167. package/src/engine/api.ts +30 -1
  168. package/src/engine/codegen/register_types.js +25 -9
  169. package/src/engine/debug/debug_overlay.ts +7 -1
  170. package/src/engine/engine_addressables.ts +2 -2
  171. package/src/engine/engine_assetdatabase.ts +291 -184
  172. package/src/engine/engine_components.ts +20 -1
  173. package/src/engine/engine_components_internal.ts +30 -0
  174. package/src/engine/engine_constants.ts +4 -1
  175. package/src/engine/engine_context_registry.ts +7 -0
  176. package/src/engine/engine_editor-sync.ts +21 -0
  177. package/src/engine/engine_element_loading.ts +1 -1
  178. package/src/engine/engine_gameobject.ts +16 -21
  179. package/src/engine/engine_gltf_builtin_components.ts +30 -15
  180. package/src/engine/engine_networking_auto.ts +48 -11
  181. package/src/engine/engine_patcher.ts +113 -0
  182. package/src/engine/engine_physics.ts +15 -2
  183. package/src/engine/engine_scenetools.ts +0 -1
  184. package/src/engine/engine_serialization_core.ts +6 -0
  185. package/src/engine/engine_setup.ts +11 -5
  186. package/src/engine/engine_texture.ts +54 -5
  187. package/src/engine/engine_types.ts +6 -1
  188. package/src/engine/engine_utils.ts +6 -5
  189. package/src/engine/extensions/NEEDLE_progressive.ts +32 -32
  190. package/src/engine/extensions/extensions.ts +22 -1
  191. package/src/engine/extensions/usage_tracker.ts +91 -0
  192. package/src/engine-components/AnimatorController.ts +2 -0
  193. package/src/engine-components/AudioSource.ts +1 -1
  194. package/src/engine-components/Camera.ts +77 -37
  195. package/src/engine-components/Component.ts +74 -30
  196. package/src/engine-components/Networking.ts +9 -1
  197. package/src/engine-components/OrbitControls.ts +11 -2
  198. package/src/engine-components/ParticleSystem.ts +9 -1
  199. package/src/engine-components/ReflectionProbe.ts +17 -7
  200. package/src/engine-components/Renderer.ts +22 -5
  201. package/src/engine-components/Skybox.ts +2 -0
  202. package/src/engine-components/SmoothFollow.ts +4 -4
  203. package/src/engine-components/WebARCameraBackground.ts +215 -0
  204. package/src/engine-components/WebXR.ts +12 -8
  205. package/src/engine-components/WebXRAvatar.ts +1 -0
  206. package/src/engine-components/codegen/components.ts +14 -6
  207. package/src/engine-components/js-extensions/Object3D.ts +6 -1
  208. package/src/engine-components/postprocessing/Effects/Antialiasing.ts +52 -0
  209. package/src/engine-components/postprocessing/Effects/Bloom.ts +75 -0
  210. package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +36 -0
  211. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +114 -0
  212. package/src/engine-components/postprocessing/Effects/DepthOfField.ts +90 -0
  213. package/src/engine-components/postprocessing/Effects/Pixelation.ts +28 -0
  214. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +71 -0
  215. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +55 -0
  216. package/src/engine-components/postprocessing/Effects/Vignette.ts +55 -0
  217. package/src/engine-components/postprocessing/PostProcessingEffect.ts +112 -0
  218. package/src/engine-components/postprocessing/PostProcessingHandler.ts +148 -0
  219. package/src/engine-components/postprocessing/Volume.ts +194 -0
  220. package/src/engine-components/postprocessing/VolumeParameter.ts +85 -0
  221. package/src/engine-components/postprocessing/VolumeProfile.ts +40 -0
  222. package/src/engine-components/timeline/TimelineTracks.ts +16 -17
  223. package/src/engine-components/ui/Text.ts +37 -174
  224. package/src/engine-components-experimental/networking/PlayerSync.ts +68 -7
  225. package/src/include/three/ARButton.js +13 -24
  226. package/src/include/three/VRButton.js +1 -7
  227. package/lib/engine-components/Volume.d.ts +0 -34
  228. package/lib/engine-components/Volume.js +0 -140
  229. package/lib/engine-components/Volume.js.map +0 -1
  230. package/src/engine-components/Volume.ts +0 -141
@@ -1,3 +1,4 @@
1
+ import { RenderTexture } from "./engine_texture";
1
2
  import { Camera, Color, Material, Object3D, Vector3, Quaternion, Ray, Scene, Renderer, WebGLRenderer } from "three";
2
3
  import { RGBAColor } from "../engine-components/js-extensions/RGBAColor";
3
4
  import { CollisionDetectionMode, PhysicsMaterial, RigidbodyConstraints } from "./engine_physics.types";
@@ -72,12 +73,14 @@ export declare interface IGameObject extends Object3D {
72
73
 
73
74
  activeSelf: boolean;
74
75
 
76
+ destroy(): void;
77
+
75
78
  /** NOTE: this is just a wrapper for devs coming from Unity. Please use this.gameObject instead. In Needle Engine this.gameObject is the same as this.gameObject.transform. See the tutorial link below for more information
76
79
  * @augments Object3D
77
80
  * @tutorial https://fwd.needle.tools/needle-engine/docs/transform
78
81
  * */
79
82
  get transform(): Object3D;
80
-
83
+
81
84
  addNewComponent<T>(type: Constructor<T>): T | null;
82
85
  removeComponent(comp: IComponent): IComponent;
83
86
  getOrAddComponent<T>(typeName: Constructor<T> | null): T;
@@ -161,6 +164,7 @@ export interface IComponent {
161
164
  export declare interface ICamera extends IComponent {
162
165
  get isCamera(): boolean;
163
166
  applyClearFlagsIfIsActiveCamera(): unknown;
167
+ applyClearFlags();
164
168
  buildCamera();
165
169
  get cam(): Camera;
166
170
  nearClipPlane: number;
@@ -171,6 +175,7 @@ export declare interface ICamera extends IComponent {
171
175
  aspect: number;
172
176
  fieldOfView?: number;
173
177
  screenPointToRay(x: number, y: number, ray?: Ray): Ray;
178
+ targetTexture: RenderTexture | null;
174
179
  }
175
180
 
176
181
  export declare interface ICameraController {
@@ -44,8 +44,9 @@ export class CircularBuffer<T> {
44
44
  let saveParams: boolean = false;
45
45
  const requestedParams: Array<string> = [];
46
46
  setTimeout(() => {
47
- if (saveParams)
48
- console.log(requestedParams);
47
+ if (saveParams) {
48
+ console.log(requestedParams.sort());
49
+ }
49
50
  }, 100);
50
51
 
51
52
  export function getUrlParams() {
@@ -61,7 +62,7 @@ export function getParam(paramName: string): string | boolean | number {
61
62
  const val = urlParams.get(paramName);
62
63
  if (val) {
63
64
  const num = Number(val);
64
- if (!isNaN(num)) return num;
65
+ if (!isNaN(num)) return num;
65
66
  return val;
66
67
  }
67
68
  else return true;
@@ -83,10 +84,10 @@ export function setParam(paramName: string, paramValue: string): void {
83
84
  export function setParamWithoutReload(paramName: string, paramValue: string | null, appendHistory = true): void {
84
85
  const urlParams = getUrlParams();
85
86
  if (urlParams.has(paramName)) {
86
- if(paramValue === null) urlParams.delete(paramName);
87
+ if (paramValue === null) urlParams.delete(paramName);
87
88
  else urlParams.set(paramName, paramValue);
88
89
  }
89
- else if(paramValue !== null)
90
+ else if (paramValue !== null)
90
91
  urlParams.append(paramName, paramValue);
91
92
  if (appendHistory) pushState(paramName, urlParams);
92
93
  else setState(paramName, urlParams);
@@ -13,6 +13,7 @@ declare type ProgressiveTextureSchema = {
13
13
  uri: string;
14
14
  guid: string;
15
15
  }
16
+ const $progressiveTextureExtension = Symbol("needle-progressive-texture");
16
17
 
17
18
 
18
19
  const debug_toggle_maps: Map<Material, { [key: string]: { original: Texture, lod0: Texture } }> = new Map();
@@ -35,6 +36,7 @@ if (debug) {
35
36
  });
36
37
  }
37
38
 
39
+
38
40
  export class NEEDLE_progressive implements GLTFLoaderPlugin {
39
41
 
40
42
  static assignTextureLOD(context: Context, source: SourceIdentifier | undefined, material: Material, level: number = 0) {
@@ -86,21 +88,6 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
86
88
  this.context = context;
87
89
  }
88
90
 
89
- private _loading: number[] = [];
90
-
91
- // beforeRoot(): null {
92
- // console.log("BEFORE ROOT", this.parser);
93
- // return null;
94
- // }
95
-
96
- // loadTexture(index: number): Promise<Texture> | null {
97
- // console.log(index, this._loading);
98
- // if (this._loading.includes(index)) return null;
99
- // const textureInfo = this.parser.json.textures[index];
100
- // if (debug)
101
- // console.log(index, textureInfo);
102
- // return null;
103
- // }
104
91
 
105
92
  afterRoot(gltf: GLTF): null {
106
93
  if (debug)
@@ -110,10 +97,12 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
110
97
  const ext: ProgressiveTextureSchema = textureInfo?.extensions[EXTENSION_NAME];
111
98
  if (ext) {
112
99
  const prom = this.parser.getDependency("texture", index);
113
- this._loading.splice(this._loading.indexOf(index), 1);
114
100
  prom.then(t => {
115
- if (debug) console.log("register texture", t.name, t.uuid, ext);
116
- t.userData.deferred = ext;
101
+ if (debug) console.log("> Progressive: register", t.name, t.uuid, ext);
102
+ // Put the extension info into the source (seems like tiled textures are cloned and the userdata etc is not properly copied BUT the source of course is not cloned)
103
+ // see https://github.com/needle-tools/needle-engine-support/issues/133
104
+ if (t.source)
105
+ t.source[$progressiveTextureExtension] = ext;
117
106
  NEEDLE_progressive.cache.set(t.uuid, ext);
118
107
  });
119
108
  }
@@ -130,17 +119,24 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
130
119
  private static async getOrLoadTexture(context: Context, source: SourceIdentifier | undefined, material: Material, slot: string, current: Texture, _level: number): Promise<Texture | null> {
131
120
 
132
121
  const key = current.uuid;
133
- const ext: ProgressiveTextureSchema | undefined = NEEDLE_progressive.cache.get(key);// || current.userData.deferred;
134
- if (ext) {
122
+
123
+ let progressiveInfo: ProgressiveTextureSchema | undefined;
124
+
125
+ // See https://github.com/needle-tools/needle-engine-support/issues/133
126
+ if(current.source && current.source[$progressiveTextureExtension])
127
+ progressiveInfo = current.source[$progressiveTextureExtension];
128
+ if(!progressiveInfo) progressiveInfo = NEEDLE_progressive.cache.get(key);
129
+
130
+ if (progressiveInfo) {
135
131
  if (debug)
136
- console.log(key, ext.uri, ext.guid);
137
- const uri = getPath(source, ext.uri);
132
+ console.log(key, progressiveInfo.uri, progressiveInfo.guid);
133
+ const uri = getPath(source, progressiveInfo.uri);
138
134
  if (uri.endsWith(".glb") || uri.endsWith(".gltf")) {
139
- if (!ext.guid) {
140
- console.warn("missing pointer for glb/gltf texture", ext);
135
+ if (!progressiveInfo.guid) {
136
+ console.warn("missing pointer for glb/gltf texture", progressiveInfo);
141
137
  return null;
142
138
  }
143
- const resolveKey = uri + "_" + ext.guid;
139
+ const resolveKey = uri + "_" + progressiveInfo.guid;
144
140
  if (this.resolved[resolveKey]) {
145
141
  if (debug) console.log("Texture has already been loaded: " + resolveKey, material.name, slot, current.name);
146
142
  return this.resolved[resolveKey];
@@ -148,16 +144,18 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
148
144
 
149
145
  const info = this.onProgressiveLoadStart(context, source, uri, material, slot);
150
146
  try {
151
- if(this.currentlyLoading[resolveKey] !== undefined) {
152
- if(debug)
147
+ if (this.currentlyLoading[resolveKey] !== undefined) {
148
+ if (debug)
153
149
  console.log("Already loading:", material.name + "." + slot, resolveKey);
154
150
  const tex = await this.currentlyLoading[resolveKey];
155
151
  return tex;
156
152
  }
153
+ const ext = progressiveInfo;
157
154
  const request = new Promise<Texture | null>(async (resolve, _) => {
158
155
  const loader = new GLTFLoader();
159
156
  addDracoAndKTX2Loaders(loader, context);
160
157
 
158
+
161
159
  if (debug) console.log("Load " + uri, material.name, slot, ext.guid);
162
160
  if (debug) {
163
161
  await delay(Math.random() * 1000);
@@ -183,10 +181,12 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
183
181
  if (!found)
184
182
  return resolve(null);
185
183
 
186
- const tex = await parser.getDependency("texture", index);
187
- tex.encoding = current.encoding;
184
+ const tex = await parser.getDependency("texture", index) as Texture;
185
+ const source = tex.source;
186
+ tex.copy(current);
187
+ tex.source = source;
188
188
  if (tex) {
189
- tex.guid = ext.guid;
189
+ (tex as any).guid = ext.guid;
190
190
  }
191
191
  this.resolved[resolveKey] = tex as Texture;
192
192
  if (debug)
@@ -209,12 +209,12 @@ export class NEEDLE_progressive implements GLTFLoaderPlugin {
209
209
  const loader = new TextureLoader();
210
210
  const tex = await loader.loadAsync(uri);
211
211
  if (tex) {
212
- (tex as any).guid = ext.guid;
212
+ (tex as any).guid = progressiveInfo.guid;
213
213
  tex.flipY = false;
214
214
  tex.needsUpdate = true;
215
215
  tex.encoding = current.encoding;
216
216
  if (debug)
217
- console.log(ext, tex);
217
+ console.log(progressiveInfo, tex);
218
218
  }
219
219
  else if (debug) console.warn("failed loading", uri);
220
220
  return tex;
@@ -8,11 +8,26 @@ import { NEEDLE_gameobject_data } from "./NEEDLE_gameobject_data";
8
8
  import { NEEDLE_persistent_assets } from "./NEEDLE_persistent_assets";
9
9
  // import { KHR_animation_pointer } from "./KHR_animation_pointer";
10
10
  import { NEEDLE_lightmaps } from "../extensions/NEEDLE_lightmaps";
11
- import { SourceIdentifier } from "../engine_types";
11
+ import { Constructor, ConstructorConcrete, SourceIdentifier } from "../engine_types";
12
12
  import { Context } from "../engine_setup";
13
13
  import { NEEDLE_lighting_settings } from "./NEEDLE_lighting_settings";
14
14
  import { NEEDLE_render_objects } from "./NEEDLE_render_objects";
15
15
  import { NEEDLE_progressive } from "./NEEDLE_progressive";
16
+ import { InternalUsageTrackerPlugin } from "./usage_tracker";
17
+ import { isUsageTrackingEnabled } from "../engine_assetdatabase";
18
+ import { GLTFLoaderPlugin } from "three/examples/jsm/loaders/GLTFLoader";
19
+
20
+ const _addedCustomExtension = new Array<ConstructorConcrete<GLTFLoaderPlugin>>();
21
+
22
+ export function addCustomExtension(ext: ConstructorConcrete<GLTFLoaderPlugin>) {
23
+ if (!_addedCustomExtension.includes(ext))
24
+ _addedCustomExtension.push(ext);
25
+ }
26
+ export function removeCustomExtension(ext: ConstructorConcrete<GLTFLoaderPlugin>) {
27
+ const index = _addedCustomExtension.indexOf(ext);
28
+ if (index >= 0)
29
+ _addedCustomExtension.splice(index, 1);
30
+ }
16
31
 
17
32
  export function registerComponentExtension(loader: GLTFLoader): NEEDLE_components {
18
33
  const ext = new NEEDLE_components();
@@ -23,6 +38,8 @@ export function registerComponentExtension(loader: GLTFLoader): NEEDLE_component
23
38
  return ext;
24
39
  }
25
40
 
41
+
42
+
26
43
  class PointerResolver {
27
44
  resolvePath(path: string) {
28
45
  if (path.includes('/extensions/builtin_components/'))
@@ -42,6 +59,10 @@ export function registerExtensions(loader: GLTFLoader, context: Context, sourceI
42
59
  loader.register(p => new NEEDLE_render_objects(p, sourceId));
43
60
  loader.register(p => new NEEDLE_progressive(p, sourceId, context));
44
61
  loader.register(p => new EXT_texture_exr(p));
62
+ if (isUsageTrackingEnabled()) loader.register(p => new InternalUsageTrackerPlugin(p))
63
+
64
+ for (const ext of _addedCustomExtension)
65
+ loader.register(p => new ext(p));
45
66
 
46
67
  const setPointerResolverFunction = loader["setAnimationPointerResolver"];
47
68
  if (typeof setPointerResolverFunction === "function")
@@ -0,0 +1,91 @@
1
+
2
+ import { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
3
+ import { Group, Mesh, Object3D, SkinnedMesh } from "three";
4
+ import { getParam } from "../engine_utils";
5
+
6
+
7
+ const $loadingId = Symbol("gltf-loader-internal-usage-tracker");
8
+ const debug = getParam("debugusers");
9
+
10
+ export class InternalUsageTrackerPlugin implements GLTFLoaderPlugin {
11
+
12
+ static isLoading(object: object) {
13
+ return InternalUsageTrackerPlugin._loadingProcesses > 0;
14
+ return object[$loadingId] !== undefined;
15
+ }
16
+ private static _loadingProcesses = 0;
17
+
18
+ private readonly parser: GLTFParser;
19
+ private readonly _getDependency: any;
20
+ private readonly _loadingId: string;
21
+ private _loadedObjects: Set<object> = new Set();
22
+
23
+ constructor(parser: GLTFParser) {
24
+ this.parser = parser;
25
+ this._getDependency = this.parser.getDependency;
26
+ this._loadingId = Date.now().toString()
27
+ }
28
+
29
+ beforeRoot() {
30
+ InternalUsageTrackerPlugin._loadingProcesses++;
31
+ const self = this;
32
+ // Patch parser get dependency to track all objects that have been loaded or created
33
+ const getDependency = this._getDependency;
34
+ this.parser.getDependency = function (type: string, index: number) {
35
+ const promise = getDependency.call(this, type, index);
36
+ promise.then((result) => {
37
+ if (result) {
38
+ self._loadedObjects.add(result);
39
+ result[$loadingId] = self._loadingId;
40
+ }
41
+ return result;
42
+ });
43
+ return promise;
44
+ };
45
+ return null;
46
+ }
47
+
48
+ afterRoot(_result: GLTF) {
49
+ InternalUsageTrackerPlugin._loadingProcesses--;
50
+ // reset original method
51
+ this.parser.getDependency = this._getDependency;
52
+
53
+ // Cleanup usage of objects that have not been used in a scene
54
+ for (const loaded of this._loadedObjects) {
55
+ delete loaded[$loadingId];
56
+
57
+ if (loaded instanceof Object3D) {
58
+ if (!loaded.parent) {
59
+ if (loaded instanceof Mesh) {
60
+ if (debug) console.warn("> GLTF LOADER: Mesh not used in scene!", loaded);
61
+ loaded.material = null;
62
+ loaded.geometry = null;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ return null;
68
+ }
69
+
70
+
71
+
72
+
73
+
74
+ // private readonly _creatingNodeMesh: Map<number, CreateNodeMesh> = new Map();
75
+
76
+ // createNodeMesh(_nodeIndex: number): CreateNodeMesh | null {
77
+ // // if (!this.parser) return null;
78
+ // // let process = this._creatingNodeMesh.get(nodeIndex);
79
+ // // if (process) return process;
80
+
81
+ // // process = this.parser.createNodeMesh(nodeIndex)?.then((mesh) => {
82
+ // // console.log("createNodeMesh", nodeIndex, mesh);
83
+ // // return mesh;
84
+ // // }) as CreateNodeMesh;
85
+ // // this._creatingNodeMesh.set(nodeIndex, process);
86
+ // // return process;
87
+ // }
88
+
89
+
90
+ }
91
+
@@ -768,6 +768,7 @@ class RootMotionAction {
768
768
  }
769
769
 
770
770
  onAfterUpdate() {
771
+ if (!this.action) return;
771
772
  const weight = this.action.getEffectiveWeight();
772
773
  this.positionChange.multiplyScalar(weight);
773
774
  this.rotationChange.slerp(RootMotionAction.identityQuaternion, 1 - weight);
@@ -836,6 +837,7 @@ class RootMotionHandler {
836
837
 
837
838
  private findRootTrack(clip: AnimationClip, name: string) {
838
839
  const tracks = clip.tracks;
840
+ if (!tracks) return null;
839
841
  for (const track of tracks) {
840
842
  if (track.name.endsWith(name)) {
841
843
  // if (track.name.includes("Hips"))
@@ -65,7 +65,7 @@ export class AudioSource extends Behaviour {
65
65
  if (fn == undefined) return;
66
66
  if (AudioSource._userInteractionRegistered) return;
67
67
  AudioSource._userInteractionRegistered = true;
68
- console.log("registered interaction, can play audio now");
68
+ if(debug) console.log("🔊 registered interaction, can play audio now");
69
69
  document.removeEventListener('pointerdown', fn);
70
70
  document.removeEventListener('click', fn);
71
71
  document.removeEventListener('dragstart', fn);
@@ -5,11 +5,12 @@ import { RGBAColor } from "./js-extensions/RGBAColor";
5
5
  import { Context, XRSessionMode } from "../engine/engine_setup";
6
6
  import { ICamera } from "../engine/engine_types"
7
7
  import { showBalloonMessage } from "../engine/debug/debug";
8
- import { getWorldPosition } from "../engine/engine_three_utils";
8
+ import { getWorldPosition, Graphics } from "../engine/engine_three_utils";
9
9
  import { Gizmos } from "../engine/engine_gizmos";
10
10
 
11
11
  import { EquirectangularReflectionMapping, OrthographicCamera, PerspectiveCamera, Ray, sRGBEncoding, Vector3 } from "three";
12
12
  import { OrbitControls } from "./OrbitControls";
13
+ import { RenderTexture } from "../engine/engine_texture";
13
14
 
14
15
  export enum ClearFlags {
15
16
  Skybox = 1,
@@ -151,6 +152,15 @@ export class Camera extends Behaviour implements ICamera {
151
152
  this.applyClearFlagsIfIsActiveCamera();
152
153
  }
153
154
 
155
+ @serializable(RenderTexture)
156
+ public set targetTexture(rt: RenderTexture | null) {
157
+ this._targetTexture = rt;
158
+ }
159
+ public get targetTexture(): RenderTexture | null {
160
+ return this._targetTexture;
161
+ }
162
+ private _targetTexture: RenderTexture | null = null;
163
+
154
164
  private _backgroundColor?: RGBAColor;
155
165
  private _fov?: number;
156
166
  private _cam: THREE.PerspectiveCamera | THREE.OrthographicCamera | null = null;
@@ -217,6 +227,28 @@ export class Camera extends Behaviour implements ICamera {
217
227
  this.context.removeCamera(this);
218
228
  }
219
229
 
230
+ onBeforeRender() {
231
+ if (this._cam) {
232
+ if (this._targetTexture) {
233
+ if (this.context.isManagedExternally) {
234
+ // TODO: rendering with r3f renderer does throw an shader error for some reason?
235
+ if (!this["_warnedAboutExternalRenderer"]) {
236
+ this["_warnedAboutExternalRenderer"] = true;
237
+ console.warn("Rendering with external renderer is not supported yet. This may not work or throw errors. Please remove the the target texture from your camera: " + this.name, this.targetTexture)
238
+ }
239
+ }
240
+
241
+ // TODO: optimize to not render twice if this is already the main camera. In that case we just want to blit
242
+ const composer = this.context.composer;
243
+ const useNormalRenderer = true;// this.context.isInXR || !composer;
244
+ const renderer = useNormalRenderer ? this.context.renderer : composer;
245
+ if (renderer) {
246
+ this._targetTexture.render(this.context.scene, this._cam, renderer)
247
+ }
248
+ }
249
+ }
250
+ }
251
+
220
252
  buildCamera() {
221
253
  if (this._cam) return;
222
254
 
@@ -262,43 +294,51 @@ export class Camera extends Behaviour implements ICamera {
262
294
  }
263
295
 
264
296
  applyClearFlagsIfIsActiveCamera() {
297
+ if (this.context.mainCameraComponent === this) {
298
+ this.applyClearFlags();
299
+ }
300
+ }
301
+
302
+ applyClearFlags() {
303
+ if (!this._cam) {
304
+ if (debug) console.log("Camera does not exist (apply clear flags)")
305
+ return;
306
+ }
265
307
  if (debug)
266
- showBalloonMessage("apply Camera clear flags");
267
- if (this._cam && this.context.mainCameraComponent === this) {
268
- switch (this._clearFlags) {
269
- case ClearFlags.Skybox:
270
- if (Camera.backgroundShouldBeTransparent(this.context)) {
271
- if (!this.ARBackgroundAlpha || this.ARBackgroundAlpha < 0.001) {
272
- this.context.scene.background = null;
273
- this.context.renderer.setClearColor(0x000000, 0);
274
- return;
275
- }
276
- }
277
- this.enableSkybox();
278
-
279
- if (this._backgroundBlurriness !== undefined)
280
- this.context.scene.backgroundBlurriness = this._backgroundBlurriness;
281
- if (this._backgroundIntensity !== undefined)
282
- //@ts-ignore
283
- this.context.scene.backgroundIntensity = this._backgroundIntensity;
284
-
285
- break;
286
- case ClearFlags.SolidColor:
287
- if (this._backgroundColor) {
288
- let alpha = this._backgroundColor.alpha;
289
- // when in WebXR use ar background alpha override or set to 0
290
- if (Camera.backgroundShouldBeTransparent(this.context)) {
291
- alpha = this.ARBackgroundAlpha ?? 0;
292
- }
308
+ showBalloonMessage("apply Camera clear flags: " + this._clearFlags);
309
+ switch (this._clearFlags) {
310
+ case ClearFlags.Skybox:
311
+ if (Camera.backgroundShouldBeTransparent(this.context)) {
312
+ if (!this.ARBackgroundAlpha || this.ARBackgroundAlpha < 0.001) {
293
313
  this.context.scene.background = null;
294
- this.context.renderer.setClearColor(this._backgroundColor, alpha);
314
+ this.context.renderer.setClearColor(0x000000, 0);
315
+ return;
295
316
  }
296
- break;
297
- case ClearFlags.Uninitialized:
298
- this.context.scene.background = null
299
- this.context.renderer.setClearColor(0x000000, 0);
300
- break;
301
- }
317
+ }
318
+ this.enableSkybox();
319
+
320
+ if (this._backgroundBlurriness !== undefined)
321
+ this.context.scene.backgroundBlurriness = this._backgroundBlurriness;
322
+ if (this._backgroundIntensity !== undefined)
323
+ //@ts-ignore
324
+ this.context.scene.backgroundIntensity = this._backgroundIntensity;
325
+
326
+ break;
327
+ case ClearFlags.SolidColor:
328
+ if (this._backgroundColor) {
329
+ let alpha = this._backgroundColor.alpha;
330
+ // when in WebXR use ar background alpha override or set to 0
331
+ if (Camera.backgroundShouldBeTransparent(this.context)) {
332
+ alpha = this.ARBackgroundAlpha ?? 0;
333
+ }
334
+ this.context.scene.background = null;
335
+ this.context.renderer.setClearColor(this._backgroundColor, alpha);
336
+ }
337
+ break;
338
+ case ClearFlags.Uninitialized:
339
+ this.context.scene.background = null
340
+ this.context.renderer.setClearColor(0x000000, 0);
341
+ break;
302
342
  }
303
343
  }
304
344
 
@@ -309,7 +349,7 @@ export class Camera extends Behaviour implements ICamera {
309
349
  }
310
350
 
311
351
  /** Returns true when in XR on a pass through device where the background shouldbe invisible */
312
- static backgroundShouldBeTransparent(context:Context) {
352
+ static backgroundShouldBeTransparent(context: Context) {
313
353
  const session = context.renderer.xr?.getSession();
314
354
  if (!session) return false;
315
355
  const environmentBlendMode = session.environmentBlendMode;
@@ -330,7 +370,7 @@ export class Camera extends Behaviour implements ICamera {
330
370
  }
331
371
  }
332
372
  }
333
-
373
+
334
374
  return transparent;
335
375
  }
336
376
  }