@needle-tools/engine 4.1.0-beta.8 → 4.1.0-beta.9

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 (75) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/gltf-progressive.js +148 -150
  3. package/dist/gltf-progressive.light.js +148 -150
  4. package/dist/gltf-progressive.light.min.js +6 -6
  5. package/dist/gltf-progressive.light.umd.cjs +7 -7
  6. package/dist/gltf-progressive.min.js +6 -6
  7. package/dist/gltf-progressive.umd.cjs +7 -7
  8. package/dist/needle-engine.bundle.js +4018 -4003
  9. package/dist/needle-engine.bundle.light.js +4018 -4003
  10. package/dist/needle-engine.bundle.light.min.js +109 -109
  11. package/dist/needle-engine.bundle.light.umd.cjs +115 -115
  12. package/dist/needle-engine.bundle.min.js +109 -109
  13. package/dist/needle-engine.bundle.umd.cjs +109 -109
  14. package/dist/needle-engine.d.ts +4 -0
  15. package/dist/needle-engine.js +2 -2
  16. package/dist/needle-engine.light.d.ts +13 -9
  17. package/dist/needle-engine.light.js +2 -2
  18. package/dist/needle-engine.light.min.js +1 -1
  19. package/dist/needle-engine.min.js +1 -1
  20. package/dist/postprocessing.js +1 -1
  21. package/dist/postprocessing.light.js +1 -1
  22. package/dist/postprocessing.light.min.js +1 -1
  23. package/dist/postprocessing.min.js +1 -1
  24. package/dist/three-examples.js +1 -1
  25. package/dist/three-examples.light.js +1 -1
  26. package/dist/three-examples.light.min.js +1 -1
  27. package/dist/three-examples.min.js +1 -1
  28. package/dist/three-mesh-ui.js +1 -1
  29. package/dist/three-mesh-ui.light.js +1 -1
  30. package/dist/three-mesh-ui.light.min.js +1 -1
  31. package/dist/three-mesh-ui.min.js +1 -1
  32. package/dist/three.js +14 -14
  33. package/dist/three.light.js +14 -14
  34. package/dist/three.light.min.js +1 -1
  35. package/dist/three.min.js +1 -1
  36. package/dist/vendor.js +1 -1
  37. package/dist/vendor.light.js +1 -1
  38. package/dist/vendor.light.min.js +1 -1
  39. package/dist/vendor.min.js +1 -1
  40. package/lib/engine/engine_gameobject.d.ts +0 -12
  41. package/lib/engine/engine_gameobject.js +0 -13
  42. package/lib/engine/engine_gameobject.js.map +1 -1
  43. package/lib/engine/engine_types.d.ts +5 -0
  44. package/lib/engine/engine_types.js +6 -0
  45. package/lib/engine/engine_types.js.map +1 -1
  46. package/lib/engine/export/gltf/Writers.js.map +1 -1
  47. package/lib/engine/export/gltf/index.js +11 -1
  48. package/lib/engine/export/gltf/index.js.map +1 -1
  49. package/lib/engine/export/utils.d.ts +2 -0
  50. package/lib/engine/export/utils.js +8 -0
  51. package/lib/engine/export/utils.js.map +1 -0
  52. package/lib/engine/extensions/NEEDLE_gameobject_data.js +1 -1
  53. package/lib/engine/extensions/NEEDLE_gameobject_data.js.map +1 -1
  54. package/lib/engine/js-extensions/Object3D.d.ts +5 -1
  55. package/lib/engine/js-extensions/Object3D.js.map +1 -1
  56. package/lib/engine-components/Component.d.ts +1 -2
  57. package/lib/engine-components/Component.js +3 -3
  58. package/lib/engine-components/Component.js.map +1 -1
  59. package/lib/engine-components/ContactShadows.d.ts +1 -1
  60. package/lib/engine-components/ContactShadows.js +7 -0
  61. package/lib/engine-components/ContactShadows.js.map +1 -1
  62. package/lib/engine-components/export/gltf/GltfExport.js +23 -4
  63. package/lib/engine-components/export/gltf/GltfExport.js.map +1 -1
  64. package/package.json +2 -2
  65. package/src/engine/engine_gameobject.ts +0 -13
  66. package/src/engine/engine_types.ts +6 -0
  67. package/src/engine/export/gltf/Writers.ts +0 -1
  68. package/src/engine/export/gltf/index.ts +13 -3
  69. package/src/engine/export/index.ts +1 -1
  70. package/src/engine/export/utils.ts +10 -0
  71. package/src/engine/extensions/NEEDLE_gameobject_data.ts +1 -2
  72. package/src/engine/js-extensions/Object3D.ts +6 -1
  73. package/src/engine-components/Component.ts +4 -4
  74. package/src/engine-components/ContactShadows.ts +11 -2
  75. package/src/engine-components/export/gltf/GltfExport.ts +26 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "4.1.0-beta.8",
3
+ "version": "4.1.0-beta.9",
4
4
  "description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in",
5
5
  "main": "dist/needle-engine.min.js",
6
6
  "exports": {
@@ -86,7 +86,7 @@
86
86
  ],
87
87
  "dependencies": {
88
88
  "@dimforge/rapier3d-compat": "^0.14.0",
89
- "@needle-tools/gltf-progressive": "^2.1.0-alpha.5",
89
+ "@needle-tools/gltf-progressive": "^2.1.0-alpha.6",
90
90
  "@webxr-input-profiles/motion-controllers": "^1.0.0",
91
91
  "flatbuffers": "2.0.4",
92
92
  "md5": "^2.3.0",
@@ -18,19 +18,6 @@ import { apply } from "./js-extensions/index.js";
18
18
  const debug = getParam("debuggetcomponent");
19
19
  const debugInstantiate = getParam("debuginstantiate");
20
20
 
21
- /** @internal */
22
- export enum HideFlags {
23
- None = 0,
24
- HideInHierarchy = 1,
25
- HideInInspector = 2,
26
- DontSaveInEditor = 4,
27
- NotEditable = 8,
28
- DontSaveInBuild = 16, // 0x00000010
29
- DontUnloadUnusedAsset = 32, // 0x00000020
30
- DontSave = DontUnloadUnusedAsset | DontSaveInBuild | DontSaveInEditor, // 0x00000034
31
- HideAndDontSave = DontSave | NotEditable | HideInHierarchy, // 0x0000003D
32
- }
33
-
34
21
  export type IInstantiateOptions = {
35
22
  idProvider?: UIDProvider;
36
23
  //** parent guid or object */
@@ -90,6 +90,12 @@ export declare interface INeedleEngineComponent extends HTMLElement {
90
90
  onExitAR(session: XRSession);
91
91
  }
92
92
 
93
+ export enum HideFlags {
94
+ None = 0,
95
+ /** When enabled the glTF exporter will omit this object and all children from being exported */
96
+ DontExport = 1 << 0,
97
+ }
98
+
93
99
  export declare interface IGameObject extends Object3D {
94
100
 
95
101
  /** the object's unique identifier */
@@ -1,4 +1,3 @@
1
-
2
1
  import { Object3D, Texture } from 'three';
3
2
  import { GLTFExporterPlugin, GLTFWriter } from 'three/examples/jsm/exporters/GLTFExporter.js';
4
3
 
@@ -6,6 +6,7 @@ import { AnimationUtils } from "../../engine_animation.js";
6
6
  import type { Context } from "../../engine_setup.js";
7
7
  import { registerExportExtensions } from "../../extensions/index.js";
8
8
  import { __isExporting } from "../state.js";
9
+ import { shouldExport_HideFlags } from "../utils.js";
9
10
  import { GizmoWriter as GLTFGizmoWriter, RenderTextureWriter as GLTFRenderTextureWriter } from "./Writers.js";
10
11
 
11
12
  declare type ExportOptions = {
@@ -49,8 +50,7 @@ export async function exportAsGLTF(_opts: ExportOptions): Promise<ArrayBuffer |
49
50
  animations: collectAnimations(context, opts.scene, []),
50
51
  }
51
52
  const state = new ExporterState();
52
-
53
- console.log("Exporting GLTF", exporterOptions);
53
+ console.debug("Exporting GLTF", exporterOptions);
54
54
  state.onBeforeExport(opts);
55
55
  __isExporting(true);
56
56
  const res = await exporter.parseAsync(opts.scene, exporterOptions).catch((e) => {
@@ -108,7 +108,17 @@ class ExporterState {
108
108
  }
109
109
  }
110
110
  mixer.update(0);
111
- })
111
+ });
112
+
113
+ opts.context.scene.traverse(obj => {
114
+ if(!shouldExport_HideFlags(obj)) {
115
+ const parent = obj.parent;
116
+ if(parent) {
117
+ obj.removeFromParent();
118
+ this._undo.push(() => parent.add(obj));
119
+ }
120
+ }
121
+ });
112
122
  }
113
123
 
114
124
  onAfterExport(_opts: Required<ExportOptions>) {
@@ -1,2 +1,2 @@
1
1
  export * from "./gltf/index.js";
2
- export { isExporting } from "./state.js";
2
+ export { isExporting } from "./state.js";
@@ -0,0 +1,10 @@
1
+ import { Object3D } from "three";
2
+
3
+ import { HideFlags } from "../engine_types.js";
4
+
5
+
6
+ export function shouldExport_HideFlags(obj: Object3D) {
7
+ const dontExport = HideFlags.DontExport;
8
+ if (obj.hideFlags & dontExport) return false;
9
+ return true;
10
+ }
@@ -7,7 +7,6 @@ declare type GameObjectData = {
7
7
  layers: number,
8
8
  visible: boolean,
9
9
  tag: string,
10
- hideFlags: number,
11
10
  static: boolean,
12
11
  activeSelf: boolean,
13
12
  guid: string
@@ -71,7 +70,7 @@ export class NEEDLE_gameobject_data implements GLTFLoaderPlugin {
71
70
 
72
71
  node.userData.tag = ext.tag ?? "none";
73
72
 
74
- node.userData.hideFlags = ext.hideFlags ?? 0;
73
+ node.hideFlags = 0;
75
74
 
76
75
  node.userData.static = ext.static ?? false;
77
76
 
@@ -15,7 +15,7 @@ import {
15
15
  setWorldScale
16
16
  }
17
17
  from "../../engine/engine_three_utils.js";
18
- import type { ComponentInit, Constructor, ConstructorConcrete, IComponent as Component, IComponent } from "../../engine/engine_types.js";
18
+ import type { ComponentInit, Constructor, ConstructorConcrete, HideFlags,IComponent as Component, IComponent } from "../../engine/engine_types.js";
19
19
  import { applyPrototypeExtensions, registerPrototypeExtensions } from "./ExtensionUtils.js";
20
20
 
21
21
 
@@ -26,6 +26,11 @@ declare module 'three' {
26
26
  get guid(): string | undefined;
27
27
  set guid(value: string | undefined);
28
28
 
29
+ /**
30
+ * Allows to control e.g. if an object should be exported
31
+ */
32
+ hideFlags: HideFlags;
33
+
29
34
  /**
30
35
  * Add a Needle Engine component to the {@link Object3D}.
31
36
  * @param comp The component instance or constructor to add.
@@ -4,7 +4,7 @@ import { isDevEnvironment } from "../engine/debug/index.js";
4
4
  import { type AssetReference } from "../engine/engine_addressables.js";
5
5
  import { addComponent, destroyComponentInstance, findObjectOfType, findObjectsOfType, getComponent, getComponentInChildren, getComponentInParent, getComponents, getComponentsInChildren, getComponentsInParent, getOrAddComponent, removeComponent } from "../engine/engine_components.js";
6
6
  import { activeInHierarchyFieldName } from "../engine/engine_constants.js";
7
- import { destroy, findByGuid, foreachComponent, HideFlags, type IInstantiateOptions, instantiate, isActiveInHierarchy, isActiveSelf, isDestroyed, isUsingInstancing, markAsInstancedRendered, setActive } from "../engine/engine_gameobject.js";
7
+ import { destroy, findByGuid, foreachComponent, type IInstantiateOptions, instantiate, isActiveInHierarchy, isActiveSelf, isDestroyed, isUsingInstancing, markAsInstancedRendered, setActive } from "../engine/engine_gameobject.js";
8
8
  import * as main from "../engine/engine_mainloop_utils.js";
9
9
  import { syncDestroy, syncInstantiate, SyncInstantiateOptions } from "../engine/engine_networking_instantiate.js";
10
10
  import { Context, FrameEvent } from "../engine/engine_setup.js";
@@ -404,9 +404,9 @@ export abstract class Component implements IComponent, EventTarget,
404
404
  this.gameObject.userData.static = value;
405
405
  }
406
406
  }
407
- get hideFlags(): HideFlags {
408
- return this.gameObject?.userData.hideFlags;
409
- }
407
+ // get hideFlags(): HideFlags {
408
+ // return this.gameObject?.hideFlags;
409
+ // }
410
410
 
411
411
  /** @returns true if the object is enabled and active in the hierarchy */
412
412
  get activeAndEnabled(): boolean {
@@ -9,7 +9,7 @@ import { Gizmos } from "../engine/engine_gizmos.js";
9
9
  import { onStart } from "../engine/engine_lifecycle_api.js";
10
10
  import { serializable } from "../engine/engine_serialization_decorator.js";
11
11
  import { getBoundingBox, getVisibleInCustomShadowRendering } from "../engine/engine_three_utils.js";
12
- import { IGameObject, Vec3 } from "../engine/engine_types.js";
12
+ import { HideFlags, IGameObject, Vec3 } from "../engine/engine_types.js";
13
13
  import { getParam } from "../engine/engine_utils.js"
14
14
  import { setCustomVisibility } from "../engine/js-extensions/Layers.js";
15
15
  import { Behaviour, GameObject } from "./Component.js";
@@ -37,7 +37,7 @@ onStart(ctx => {
37
37
  */
38
38
  export class ContactShadows extends Behaviour {
39
39
 
40
- private static _instances: Map<Context, ContactShadows> = new Map();
40
+ private static readonly _instances: Map<Context, ContactShadows> = new Map();
41
41
  /**
42
42
  * Create contact shadows for the scene. Automatically fits the shadows to the scene.
43
43
  * The instance of contact shadows will be created only once.
@@ -162,10 +162,14 @@ export class ContactShadows extends Behaviour {
162
162
 
163
163
  /** @internal */
164
164
  awake() {
165
+ ContactShadows._instances.set(this.context, this);
166
+ this.shadowsRoot.hideFlags = HideFlags.DontExport;
167
+
165
168
  // ignore self for autofitting
166
169
  setAutoFitEnabled(this.shadowsRoot, false);
167
170
  }
168
171
 
172
+
169
173
  /** @internal */
170
174
  start(): void {
171
175
  if (debug) console.log("Create ContactShadows on " + this.gameObject.name, this)
@@ -280,6 +284,11 @@ export class ContactShadows extends Behaviour {
280
284
 
281
285
  /** @internal */
282
286
  onDestroy(): void {
287
+ const instance = ContactShadows._instances.get(this.context);
288
+ if (instance === this) {
289
+ ContactShadows._instances.delete(this.context);
290
+ }
291
+
283
292
  // dispose the render targets
284
293
  this.renderTarget?.dispose();
285
294
  this.renderTargetBlur?.dispose();
@@ -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
  });