Skip to content

Commit

Permalink
Fix for objects not reseting on open of new scene (including mats)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismbirmingham committed Oct 28, 2023
1 parent 1cd05c0 commit 9be2004
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 35 deletions.
25 changes: 20 additions & 5 deletions src/Sim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
};

Expand Down
44 changes: 44 additions & 0 deletions src/node-templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,40 @@ const reamTemplate: Node.TemplatedNode<Node.Obj> = {
},
};

const matATemplate: Node.TemplatedNode<Node.Obj> = {
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<Node.Obj> = {
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<Node.Obj> = {
type: 'object',
geometryId: 'sciencepad',
Expand Down Expand Up @@ -282,6 +316,8 @@ export const preBuiltTemplates = Object.freeze<Dict<Node.TemplatedNode<Node>>>({
'radscience': radscienceTemplate,
'noradscience': noradscienceTemplate,
'ream': reamTemplate,
'matA': matATemplate,
'matB': matBTemplate,
'basalt': basaltTemplate,
'anorthosite': anorthositeTemplate,
'breccia': brecciaTemplate,
Expand Down Expand Up @@ -329,6 +365,14 @@ export const preBuiltGeometries = Object.freeze<Dict<Geometry>>({
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),
Expand Down
36 changes: 6 additions & 30 deletions src/scenes/jbcBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 9be2004

Please sign in to comment.