@needle-tools/engine 3.2.10-alpha → 3.2.12-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "3.2.10-alpha",
3
+ "version": "3.2.12-alpha",
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.umd.cjs",
6
6
  "type": "module",
@@ -34,6 +34,7 @@ const debug = utils.getParam("debugSetup");
34
34
  const stats = utils.getParam("stats");
35
35
  const debugActive = utils.getParam("debugactive");
36
36
  const debugframerate = utils.getParam("debugframerate");
37
+ const debugCoroutine = utils.getParam("debugcoroutine");
37
38
 
38
39
  // this is where functions that setup unity scenes will be pushed into
39
40
  // those will be accessed from our custom html element to load them into their context
@@ -859,6 +860,7 @@ export class Context implements IContext {
859
860
  // TODO we might want to keep coroutines playing even if the component is disabled or inactive
860
861
  const remove = !evt.comp || evt.comp.destroyed || !evt.main || evt.comp["enabled"] === false;
861
862
  if (remove) {
863
+ if (debugCoroutine) console.log("Removing coroutine", evt.comp, evt.comp["enabled"])
862
864
  evts.splice(i, 1);
863
865
  --i;
864
866
  continue;
@@ -150,7 +150,7 @@ export function processNewScripts(context: IContext) {
150
150
 
151
151
  export function processRemoveFromScene(script: IComponent) {
152
152
  if (!script) return;
153
- script.__internalDisable();
153
+ script.__internalDisable(true);
154
154
  removeScriptFromContext(script, script.context);
155
155
  }
156
156
 
@@ -167,11 +167,14 @@ export function processStart(context: IContext, object?: Object3D) {
167
167
  // keep them in queue until script has started
168
168
  // call awake if the script was inactive before
169
169
  utils.safeInvoke(script.__internalAwake.bind(script));
170
- utils.safeInvoke(script.__internalEnable.bind(script));
171
- // now call start
172
- utils.safeInvoke(script.__internalStart.bind(script));
173
- context.new_script_start.splice(i, 1);
174
- i--;
170
+ if(script.enabled)
171
+ {
172
+ utils.safeInvoke(script.__internalEnable.bind(script));
173
+ // now call start
174
+ utils.safeInvoke(script.__internalStart.bind(script));
175
+ context.new_script_start.splice(i, 1);
176
+ i--;
177
+ }
175
178
  }
176
179
  catch (err) {
177
180
  console.error(err);
@@ -274,7 +277,7 @@ function updateIsActiveInHierarchyRecursiveRuntime(go: Object3D, activeInHierarc
274
277
  }
275
278
  }
276
279
  else {
277
- if (comp["__didAwake"]) {
280
+ if (comp["__didAwake"] && comp.enabled) {
278
281
  comp["__didEnable"] = false;
279
282
  comp.onDisable();
280
283
  }
@@ -123,9 +123,9 @@ export interface IComponent {
123
123
  /** @internal */
124
124
  __internalStart();
125
125
  /** @internal */
126
- __internalEnable();
126
+ __internalEnable(isAddingOrRemovingFromScene?: boolean);
127
127
  /** @internal */
128
- __internalDisable();
128
+ __internalDisable(isAddingOrRemovingFromScene?: boolean);
129
129
  /** @internal */
130
130
  __internalDestroy();
131
131
  /** @internal */
@@ -75,7 +75,7 @@ export class NEEDLE_lighting_settings implements GLTFLoaderPlugin {
75
75
  ContextRegistry.registerCallback(ContextEvent.ContextCreated, e => {
76
76
  const ctx = e.context as Context;
77
77
  const lightingSettings = GameObject.findObjectOfType(SceneLightSettings, ctx as Context);
78
- if (lightingSettings?.sourceId) ctx.sceneLighting.enable(lightingSettings.sourceId);
78
+ if (lightingSettings?.sourceId) lightingSettings.enabled = true;
79
79
  })
80
80
 
81
81
  // exists once per gltf scene root (if it contains reflection)
@@ -130,7 +130,7 @@ export class SceneLightSettings extends Behaviour {
130
130
  }
131
131
 
132
132
  onEnable(): void {
133
- if (debug) console.warn("💡🟡 >>> Enable lighting", this.sourceId, this);
133
+ if (debug) console.warn("💡🟡 >>> Enable lighting", this.sourceId, this.enabled, this);
134
134
 
135
135
  if (this.ambientMode == AmbientMode.Flat) {
136
136
  if (this.ambientLight && !this._ambientLightObj) {
@@ -470,7 +470,7 @@ export class Component implements IComponent, EventTarget {
470
470
 
471
471
 
472
472
  /** @internal */
473
- __internalEnable(): boolean {
473
+ __internalEnable(isAddingToScene?: boolean): boolean {
474
474
  if (this.__destroyed) {
475
475
  if (isDevEnvironment()) {
476
476
  console.warn("[Needle Engine Dev] Trying to enable destroyed component");
@@ -481,7 +481,10 @@ export class Component implements IComponent, EventTarget {
481
481
  // But a user can change enable during awake
482
482
  if (!this.__didAwake) return false;
483
483
  if (this.__didEnable) {
484
- this.__isEnabled = true;
484
+ // We dont want to change the enable state if we are adding to scene
485
+ // But we want to change the state when e.g. a user changes the enable state during awake
486
+ if (isAddingToScene !== true)
487
+ this.__isEnabled = true;
485
488
  return false;
486
489
  }
487
490
  // console.trace("INTERNAL ENABLE");
@@ -492,12 +495,14 @@ export class Component implements IComponent, EventTarget {
492
495
  }
493
496
 
494
497
  /** @internal */
495
- __internalDisable() {
498
+ __internalDisable(isRemovingFromScene?: boolean) {
496
499
  // Don't change enable before awake
497
500
  // But a user can change enable during awake
498
501
  if (!this.__didAwake) return;
499
502
  if (!this.__didEnable) {
500
- this.__isEnabled = false;
503
+ // We dont want to change the enable state if we are removing from a scene
504
+ if (isRemovingFromScene !== true)
505
+ this.__isEnabled = false;
501
506
  return;
502
507
  }
503
508
  this.__didEnable = false;