diff --git a/src/Sim.tsx b/src/Sim.tsx index 442fb524..36e2b7e1 100644 --- a/src/Sim.tsx +++ b/src/Sim.tsx @@ -88,13 +88,25 @@ export class Space { } get scene() { return this.scene_; } + set scene(scene: Scene) { this.scene_ = scene; - if (this.sceneBinding_) this.sceneBinding_.scriptManager.scene = this.scene_; - + if (this.sceneBinding_) { + this.sceneBinding_.scriptManager.scene = this.scene_; + } + + // this.sceneSetting_ is true if we are currently setting the scene + // this.debounceUpdate_ is true if we are currently updating the store + // console.log("Check scene status (setting, debounce, not binding", this.sceneSetting_, this.debounceUpdate_, !this.sceneBinding_); if (this.sceneSetting_ || this.debounceUpdate_ || !this.sceneBinding_) { - if (this.sceneBinding_ && !this.sceneSetting_) this.sceneBinding_.scene = scene; - if (this.sceneSetting_ && !this.debounceUpdate_) this.nextScene_ = scene; + if (this.sceneBinding_ && !this.sceneSetting_) { + // console.log("setting next scene in sim set scene binding", scene); + this.sceneBinding_.scene = scene; + } + if (this.sceneSetting_ && !this.debounceUpdate_) { + // console.log("setting next scene in sim set scene", scene); + this.nextScene_ = scene; + } return; } @@ -328,7 +340,10 @@ export class Space { // Update state with significant changes, if needed this.debounceUpdate_ = true; - if (setNodeBatch.nodeIds.length > 0) this.onSetNodeBatch?.(setNodeBatch); + // if (setNodeBatch.nodeIds.length > 0) { + // console.log("setting node batch in sim updateStore_", setNodeBatch); + // this.onSetNodeBatch?.(setNodeBatch); + // } this.debounceUpdate_ = false; }; diff --git a/src/node-templates/index.ts b/src/node-templates/index.ts index e8c6d043..289b7181 100644 --- a/src/node-templates/index.ts +++ b/src/node-templates/index.ts @@ -101,6 +101,40 @@ const reamTemplate: Node.TemplatedNode = { }, }; +const matATemplate: Node.TemplatedNode = { + type: 'object', + geometryId: 'mat', + physics: { + type: 'box', + restitution: .3, + friction: 1, + }, + material: { + type: 'basic', + color: { + type: "texture", + uri: "/static/textures/KIPR_Surface_A.png" + }, + }, +}; + +const matBTemplate: Node.TemplatedNode = { + type: 'object', + geometryId: 'mat', + physics: { + type: 'box', + restitution: .3, + friction: 1, + }, + material: { + type: 'basic', + color: { + type: "texture", + uri: "/static/textures/KIPR_Surface_B.png" + }, + }, +}; + const sciencePadTemplate: Node.TemplatedNode = { type: 'object', geometryId: 'sciencepad', @@ -282,6 +316,8 @@ export const preBuiltTemplates = Object.freeze>>({ 'radscience': radscienceTemplate, 'noradscience': noradscienceTemplate, 'ream': reamTemplate, + 'matA': matATemplate, + 'matB': matBTemplate, 'basalt': basaltTemplate, 'anorthosite': anorthositeTemplate, 'breccia': brecciaTemplate, @@ -329,6 +365,14 @@ export const preBuiltGeometries = Object.freeze>({ z: Distance.centimeters(21.59), }, }, + 'mat': { + type: 'box', + size: { + x: Distance.feet(2), + y: Distance.centimeters(.1), + z: Distance.feet(4), + } + }, 'basalt': { type: 'sphere', radius: Distance.centimeters(5), diff --git a/src/scenes/jbcBase.ts b/src/scenes/jbcBase.ts index 367cdc0f..d4b0c036 100644 --- a/src/scenes/jbcBase.ts +++ b/src/scenes/jbcBase.ts @@ -83,26 +83,14 @@ export function createBaseSceneSurfaceA(): Scene { }, nodes: { 'robot': ROBOT, - 'mat': { - type: 'object', - geometryId: 'mat', + 'matA': { + type: 'from-jbc-template', + templateId: 'matA', name: tr('JBC Mat A'), startingOrigin: JBC_MAT_ORIGIN, origin: JBC_MAT_ORIGIN, visible: true, editable: true, - physics: { - type: 'box', - restitution: .3, - friction: 1, - }, - material: { - type: 'basic', - color: { - type: "texture", - uri: "/static/textures/KIPR_Surface_A.png" - }, - }, }, 'ground': { type: 'object', @@ -166,26 +154,14 @@ export function createBaseSceneSurfaceB(): Scene { }, nodes: { 'robot': ROBOT, - 'mat': { - type: 'object', - geometryId: 'mat', + 'matB': { + type: 'from-jbc-template', + templateId: 'matB', name: tr('JBC Mat B'), startingOrigin: JBC_MAT_ORIGIN, origin: JBC_MAT_ORIGIN, visible: true, editable: true, - physics: { - type: 'box', - restitution: .3, - friction: 1, - }, - material: { - type: 'basic', - color: { - type: "texture", - uri: "/static/textures/KIPR_Surface_B.png" - }, - }, }, 'ground': { type: 'object',