Needle Engine

Changes between version 3.27.3-beta and 3.27.4-beta
Files changed (3) hide show
  1. src/engine-components/Component.ts +4 -0
  2. src/engine/engine_context.ts +4 -0
  3. src/engine-components/Renderer.ts +9 -7
src/engine-components/Component.ts CHANGED
@@ -405,6 +405,10 @@
405
405
  * @param field the name of the field that was changed
406
406
  */
407
407
  onValidate?(prop?: string): void;
408
+
409
+ /** Called for all scripts when the context gets paused or unpaused */
410
+ onPausedChanged?(isPaused: boolean, wasPaused: boolean): void;
411
+
408
412
  start?(): void;
409
413
  earlyUpdate?(): void;
410
414
  update?(): void;
src/engine/engine_context.ts CHANGED
@@ -533,6 +533,10 @@
533
533
  }
534
534
 
535
535
  registerCoroutineUpdate(script: IComponent, coroutine: Generator, evt: FrameEvent): Generator {
536
+ if (typeof coroutine?.next !== "function") {
537
+ console.error("Registered invalid coroutine function from " + script.name + "\nCoroutine functions must be generators: \"*myCoroutine() {...}\"\nStart a coroutine from a component by calling \"this.startCoroutine(myCoroutine())\"")
538
+ return coroutine;
539
+ }
536
540
  if (!this.coroutines[evt]) this.coroutines[evt] = [];
537
541
  this.coroutines[evt].push({ comp: script, main: coroutine });
538
542
  return coroutine;
src/engine-components/Renderer.ts CHANGED
@@ -998,13 +998,6 @@
998
998
  }
999
999
  this.inst = new THREE.InstancedMesh(geo, material, count);
1000
1000
  this.inst[$instancingAutoUpdateBounds] = true;
1001
- this.inst.onBeforeRender = () => {
1002
- if (this._needUpdateBounds && this.inst[$instancingAutoUpdateBounds] === true) {
1003
- if (debugInstancing)
1004
- console.log("Update instancing bounds", this.name);
1005
- this.updateBounds();
1006
- }
1007
- };
1008
1001
  this.inst.count = 0;
1009
1002
  this.inst.layers.set(2);
1010
1003
  this.inst.visible = true;
@@ -1012,6 +1005,7 @@
1012
1005
  // this.inst.castShadow = true;
1013
1006
  // this.inst.receiveShadow = true;
1014
1007
  this.context.scene.add(this.inst);
1008
+ context.pre_render_callbacks.push(this.onBeforeRender);
1015
1009
  // console.log(this.inst);
1016
1010
  // this.context.pre_render_callbacks.push(this.onPreRender.bind(this));
1017
1011
 
@@ -1020,6 +1014,14 @@
1020
1014
  // }, 500);
1021
1015
  }
1022
1016
 
1017
+ private onBeforeRender = () => {
1018
+ if (this._needUpdateBounds && this.inst[$instancingAutoUpdateBounds] === true) {
1019
+ if (debugInstancing)
1020
+ console.log("Update instancing bounds", this.name, this.inst.matrixWorldNeedsUpdate);
1021
+ this.updateBounds();
1022
+ }
1023
+ }
1024
+
1023
1025
  private randomColor() {
1024
1026
  return new THREE.Color(Math.random(), Math.random(), Math.random());
1025
1027
  }