Skip to content

Commit

Permalink
Reorg and fix for object reset issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismbirmingham committed Nov 16, 2023
1 parent 357f33b commit 4ea1f86
Show file tree
Hide file tree
Showing 155 changed files with 559 additions and 430 deletions.
2 changes: 1 addition & 1 deletion src/AbstractRobot/WriteCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import construct from '../util/construct';
import construct from '../util/redux/construct';
import Motor from './Motor';

namespace WriteCommand {
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractRobot/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import deepNeq from '../util/deepNeq';
import Patch from '../util/Patch';
import deepNeq from '../util/redux/deepNeq';
import Patch from '../util/redux/Patch';
import Motor from './Motor';
import Servo from './Servo';
import WriteCommand from './WriteCommand';
Expand Down
2 changes: 1 addition & 1 deletion src/Bindings/CameraBinding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArcRotateCamera, Scene as babylScene, Camera as babylCamera } from '@babylonjs/core';

import Camera from "../state/State/Scene/Camera";
import { Vector3wUnits } from "../util/unit-math";
import { Vector3wUnits } from "../util/math/UnitMath";



Expand Down
6 changes: 3 additions & 3 deletions src/Bindings/Lightbinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { ShadowGenerator, IShadowLight, PointLight, SpotLight, DirectionalLight
Scene as babylScene } from '@babylonjs/core';

import Node from "../state/State/Scene/Node";
import Dict from "../util/Dict";
import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from "../util/unit-math";
import { RawQuaternion, RawVector2, RawVector3 } from "../util/math";
import Dict from "../util/objectOps/Dict";
import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from "../util/math/UnitMath";
import { RawQuaternion, RawVector2, RawVector3 } from "../util/math/math";
import LocalizedString from '../util/LocalizedString';
import { Angle, Distance, Mass, SetOps } from "../util";

Expand Down
2 changes: 1 addition & 1 deletion src/Bindings/MaterialBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Texture, DynamicTexture, StandardMaterial, Color3, PBRMaterial,

import Material from '../state/State/Scene/Material';
import { Color } from '../state/State/Scene/Color';
import Patch from "../util/Patch";
import Patch from "../util/redux/Patch";



Expand Down
4 changes: 2 additions & 2 deletions src/Bindings/MotorBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Scene as babylScene, Quaternion, Vector3, Mesh,
} from '@babylonjs/core';

import Node from '../state/State/Robot/Node';
import { Vector3wUnits } from '../util/unit-math';
import { Vector3wUnits } from '../util/math/UnitMath';
import { RENDER_SCALE } from '../components/Constants/renderConstants';
import { RawVector3 } from '../util/math';
import { RawVector3 } from '../util/math/math';



Expand Down
4 changes: 2 additions & 2 deletions src/Bindings/ObjectBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { PhysicsShapeType, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, Physi
GlowLayer, Observer, BoundingBox } from '@babylonjs/core';

import Geometry from "../state/State/Scene/Geometry";
import { RawQuaternion, RawVector2, RawVector3 } from "../util/math";
import { RawQuaternion, RawVector2, RawVector3 } from "../util/math/math";
import { Angle, Distance, Mass, SetOps } from "../util";
import Node from "../state/State/Scene/Node";
import Scene from "../state/State/Scene";
import LocalizedString from '../util/LocalizedString';
import { apply } from './helpers';
import { createMaterial } from './MaterialBinding';
import { preBuiltGeometries, preBuiltTemplates } from "../NodeTemplates";
import { preBuiltGeometries, preBuiltTemplates } from "../SimulatorDefinitions/NodeTemplates";

export type FrameLike = TransformNode | AbstractMesh;

Expand Down
8 changes: 4 additions & 4 deletions src/Bindings/RobotBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import '@babylonjs/core/Physics/physicsEngineComponent';
import SceneNode from '../state/State/Scene/Node';
import Robot from '../state/State/Robot';
import Node from '../state/State/Robot/Node';
import { RawQuaternion, RawVector3, clamp, RawEuler } from '../util/math';
import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from '../util/unit-math';
import { Angle, Distance, Mass } from '../util/Value';
import { RawQuaternion, RawVector3, clamp, RawEuler } from '../util/math/math';
import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from '../util/math/UnitMath';
import { Angle, Distance, Mass } from '../util/math/Value';
import { SceneMeshMetadata } from './SceneBinding';
import Dict from '../util/Dict';
import Dict from '../util/objectOps/Dict';
import { RENDER_SCALE, RENDER_SCALE_METERS_MULTIPLIER } from '../components/Constants/renderConstants';
import WriteCommand from '../AbstractRobot/WriteCommand';
import AbstractRobot from '../AbstractRobot';
Expand Down
2 changes: 1 addition & 1 deletion src/Bindings/RobotLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Geometry from '../state/State/Robot/Geometry';
import Node from '../state/State/Robot/Node';
import { RENDER_SCALE_METERS_MULTIPLIER } from '../components/Constants/renderConstants';
import Robot from '../state/State/Robot';
import { Mass } from '../util/Value';
import { Mass } from '../util/math/Value';


interface BuiltGeometry {
Expand Down
52 changes: 35 additions & 17 deletions src/Bindings/SceneBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import { PhysicsShapeType, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, Physi
import '@babylonjs/core/Engines/Extensions/engine.views';
import '@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent';

import Dict from "../util/Dict";
import { RawQuaternion, RawVector2, RawVector3 } from "../util/math";
import Dict from "../util/objectOps/Dict";
import { RawQuaternion, RawVector2, RawVector3 } from "../util/math/math";
import Scene from "../state/State/Scene";
import Camera from "../state/State/Scene/Camera";
import Geometry from "../state/State/Scene/Geometry";
import Node from "../state/State/Scene/Node";
import Patch from "../util/Patch";
import Patch from "../util/redux/Patch";

import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from "../util/unit-math";
import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from "../util/math/UnitMath";
import { Angle, Distance, Mass, SetOps } from "../util";
import { Color } from '../state/State/Scene/Color';
import Material from '../state/State/Scene/Material';
import { preBuiltGeometries, preBuiltTemplates } from "../NodeTemplates";
import { preBuiltGeometries, preBuiltTemplates } from "../SimulatorDefinitions/NodeTemplates";
import RobotBinding from './RobotBinding';
import Robot from '../state/State/Robot';
import AbstractRobot from '../AbstractRobot';
Expand Down Expand Up @@ -264,7 +264,10 @@ class SceneBinding {

if (!ret) return null;

this.updateNodePosition_(nodeToCreate, ret);
if (nodeToCreate.name['en-US'] === 'Can 4') {
console.log('createNode_ -> updateNodePosition_', nodeToCreate.name, nodeToCreate);
}
this.updateNodePosition_(nodeToCreate, ret, id, nextScene);
ret.id = id;

ret.metadata = { id } as SceneMeshMetadata;
Expand All @@ -279,21 +282,28 @@ class SceneBinding {
return ret;
};

private updateNodePosition_ = (node: Node, bNode: babylNode) => {
if (node.origin && bNode instanceof TransformNode || bNode instanceof AbstractMesh) {
private updateNodePosition_ = (node: Node, bNode: babylNode, nodeId: string, scene: Scene) => {
// if (node.origin && bNode instanceof TransformNode || bNode instanceof AbstractMesh) {
if (node.origin && bNode instanceof AbstractMesh) {
this.removePhysicsFromObject(bNode);
const origin = node.origin || {};
const position: Vector3wUnits = origin.position ?? Vector3wUnits.zero();
const orientation: RotationwUnits = origin.orientation ?? RotationwUnits.EulerwUnits.identity();
const scale = origin.scale ?? RawVector3.ONE;

bNode.position.set(
Distance.toCentimetersValue(position.x || Distance.centimeters(0)),
Distance.toCentimetersValue(position.y || Distance.centimeters(0)),
Distance.toCentimetersValue(position.z || Distance.centimeters(0))
);
// bNode.position.set(
// Distance.toCentimetersValue(position.x || Distance.centimeters(0)),
// Distance.toCentimetersValue(position.y || Distance.centimeters(0)),
// Distance.toCentimetersValue(position.z || Distance.centimeters(0))
// );
bNode.position.x = Distance.toCentimetersValue(position.x || Distance.centimeters(0));
bNode.position.y = Distance.toCentimetersValue(position.y || Distance.centimeters(0));
bNode.position.z = Distance.toCentimetersValue(position.z || Distance.centimeters(0));

bNode.rotationQuaternion = RawQuaternion.toBabylon(RotationwUnits.toRawQuaternion(orientation));
bNode.scaling.set(scale.x, scale.y, scale.z);

this.restorePhysicsToObject(bNode, node as Node.Obj, nodeId, scene);
}
};

Expand All @@ -310,7 +320,7 @@ class SceneBinding {
}

if (node.inner.origin.type === Patch.Type.OuterChange) {
this.updateNodePosition_(node.next, bNode);
this.updateNodePosition_(node.next, bNode, id, this.scene);
}

return bNode;
Expand Down Expand Up @@ -354,9 +364,14 @@ class SceneBinding {
m.material = bMaterial;
});



// TODO: Handle changes to faceUvs when we fully support it
if (node.inner.origin.type === Patch.Type.OuterChange) {
this.updateNodePosition_(node.next, bNode);
// if (node.next.name['en-US'] === 'Can 4') {
// console.log('updateObject_ -> updateNodePosition_', node.next.name, node.next);
// }
this.updateNodePosition_(node.next, bNode, id, nextScene);
}

if (node.inner.physics.type === Patch.Type.OuterChange) {
Expand Down Expand Up @@ -477,6 +492,9 @@ class SceneBinding {
faceUvs: Patch.none(nodeTemplate.faceUvs),
},
};
// if (id === 'can4') {
// console.log('updateFromTemplate_ -> updateObject_', id, objectChange);
// }
return this.updateObject_(id, objectChange, nextScene);
}
case 'directional-light': {
Expand Down Expand Up @@ -550,7 +568,7 @@ class SceneBinding {
this.destroyNode_(id);
return this.createNode_(id, node.prev, nextScene);
}

// console.log('updateNode_ -> updateObject_', node.next.name, node.next);
return this.updateObject_(id, node as Patch.InnerChange<Node.Obj>, nextScene);
}
case 'directional-light': return this.updateDirectionalLight_(id, node as Patch.InnerChange<Node.DirectionalLight>);
Expand Down Expand Up @@ -676,7 +694,7 @@ class SceneBinding {
this.syncCollisionFilters_();
};


private removePhysicsFromObject = (mesh: AbstractMesh) => {
if (!mesh.physicsBody) return;

Expand Down
6 changes: 3 additions & 3 deletions src/Bindings/WeightBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Scene as babylScene, CreateSphere, Vector3, Mesh,
} from '@babylonjs/core';

import Node from '../state/State/Robot/Node';
import { ReferenceFramewUnits } from '../util/unit-math';
import { ReferenceFramewUnits } from '../util/math/UnitMath';
import { RENDER_SCALE } from '../components/Constants/renderConstants';
import { Mass } from '../util/Value';
import { Mass } from '../util/math/Value';
import Robot from '../state/State/Robot';
import Dict from '../util/Dict';
import Dict from '../util/objectOps/Dict';

// Adds an invisible weight to a parent link.
export const createWeight_ = (id: string, weight: Node.Weight, bScene_: babylScene, robot_: Robot, links_: Dict<Mesh>) => {
Expand Down
7 changes: 1 addition & 6 deletions src/Bindings/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@

import { PhysicsShapeType, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsAggregate,
TransformNode, AbstractMesh, PhysicsViewer, ShadowGenerator, CreateBox, CreateSphere, CreateCylinder,
CreatePlane, Vector4, Vector3, Texture, DynamicTexture, StandardMaterial, GizmoManager, ArcRotateCamera,
IShadowLight, PointLight, SpotLight, DirectionalLight, Color3, PBRMaterial, Mesh, SceneLoader, EngineView,
Scene as babylScene, Node as babylNode, Camera as babylCamera, Material as babylMaterial,
GlowLayer, Observer, BoundingBox } from '@babylonjs/core';
import { AbstractMesh, Node as babylNode } from '@babylonjs/core';


export const apply = (g: babylNode, f: (m: AbstractMesh) => void) => {
Expand Down
4 changes: 2 additions & 2 deletions src/ScriptManager/ScriptSceneBinding.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Dict from '../util/Dict';
import Dict from '../util/objectOps/Dict';
import Camera from '../state/State/Scene/Camera';
import Geometry from '../state/State/Scene/Geometry';
import Node from '../state/State/Scene/Node';
import { Vector3wUnits } from '../util/unit-math';
import { Vector3wUnits } from '../util/math/UnitMath';

export type Ids = string | string[] | Set<string>;

Expand Down
10 changes: 5 additions & 5 deletions src/ScriptManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Dict from '../util/Dict';
import Dict from '../util/objectOps/Dict';
import Scene from '../state/State/Scene';
import Camera from '../state/State/Scene/Camera';
import Geometry from '../state/State/Scene/Geometry';
import Node from '../state/State/Scene/Node';
import Script from '../state/State/Scene/Script';
import { RotationwUnits, Vector3wUnits } from '../util/unit-math';
import { RotationwUnits, Vector3wUnits } from '../util/math/UnitMath';

import { v4 as uuid } from 'uuid';
import construct from '../util/construct';
import construct from '../util/redux/construct';
import { Ids, ScriptSceneBinding } from './ScriptSceneBinding';
import { RawAxisAngle, RawQuaternion, RawReferenceFrame, RawVector3 } from '../util/math';
import { Angle, Mass, Distance } from '../util/Value';
import { RawAxisAngle, RawQuaternion, RawReferenceFrame, RawVector3 } from '../util/math/math';
import { Angle, Mass, Distance } from '../util/math/Value';

class ScriptManager {
private scene_: Scene;
Expand Down
6 changes: 3 additions & 3 deletions src/Sim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import HavokPhysics from "@babylonjs/havok";
import '@babylonjs/loaders/glTF';
import '@babylonjs/core/Physics/physicsEngineComponent';

import Dict from './util/Dict';
import { RawQuaternion, RawVector2, RawVector3 } from './util/math';
import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from './util/unit-math';
import Dict from './util/objectOps/Dict';
import { RawQuaternion, RawVector2, RawVector3 } from './util/math/math';
import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from './util/math/UnitMath';
import { Angle } from './util';

import store from './state';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Dict from "../util/Dict";
import { RawVector2 } from "../util/math";
import { Color } from "../state/State/Scene/Color";
import Geometry from "../state/State/Scene/Geometry";
import Node from "../state/State/Scene/Node";
import { Distance, Mass } from "../util";
import Dict from "../../util/objectOps/Dict";
import { RawVector2 } from "../../util/math/math";
import { Color } from "../../state/State/Scene/Color";
import Geometry from "../../state/State/Scene/Geometry";
import Node from "../../state/State/Scene/Node";
import { Distance, Mass } from "../../util";

// TODO: Consider deep-freezing all of these objects

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mass } from '../util';
import { Mass } from '../../util';

export const WOMBAT_BATTERY_MASS: Mass = Mass.grams(113);
export const MOTOR_MASS: Mass = Mass.grams(55);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Robot from "../state/State/Robot";
import Node from "../state/State/Robot/Node";
import Geometry from "../state/State/Robot/Geometry";
import { Angle, Distance, Mass } from '../util';
import { RawVector3 } from '../util/math';
import { RotationwUnits, Vector3wUnits } from '../util/unit-math';
import Robot from "../../state/State/Robot";
import Node from "../../state/State/Robot/Node";
import Geometry from "../../state/State/Robot/Geometry";
import { Angle, Distance, Mass } from '../../util';
import { RawVector3 } from '../../util/math/math';
import { RotationwUnits, Vector3wUnits } from '../../util/math/UnitMath';

import tr from '@i18n';

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Scene from '../state/State/Scene';
import LocalizedString from '../util/LocalizedString';
import Scene from '../../state/State/Scene';
import LocalizedString from '../../util/LocalizedString';

import { createCanNode, createBaseSceneSurfaceA } from './jbcBase';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Scene from "../state/State/Scene";
import { Distance } from "../util";
import LocalizedString from '../util/LocalizedString';
import Scene from "../../state/State/Scene";
import { Distance } from "../../util";
import LocalizedString from '../../util/LocalizedString';

import { createBaseSceneSurfaceB, createCanNode } from './jbcBase';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Scene from "../state/State/Scene";
import { Distance } from "../util";
import LocalizedString from '../util/LocalizedString';
import Scene from "../../state/State/Scene";
import { Distance } from "../../util";
import LocalizedString from '../../util/LocalizedString';

import { createBaseSceneSurfaceB, createCanNode } from './jbcBase';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Scene from "../state/State/Scene";
import { Distance } from "../util";
import LocalizedString from '../util/LocalizedString';
import Scene from "../../state/State/Scene";
import { Distance } from "../../util";
import LocalizedString from '../../util/LocalizedString';

import { createBaseSceneSurfaceA, createCanNode } from './jbcBase';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Scene from "../state/State/Scene";
import LocalizedString from '../util/LocalizedString';
import Scene from "../../state/State/Scene";
import LocalizedString from '../../util/LocalizedString';

import { createBaseSceneSurfaceA, createCanNode } from './jbcBase';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Scene from "../state/State/Scene";
import { ReferenceFramewUnits, RotationwUnits } from "../util/unit-math";
import { Distance, Mass } from "../util";
import LocalizedString from '../util/LocalizedString';
import Scene from "../../state/State/Scene";
import { ReferenceFramewUnits, RotationwUnits } from "../../util/math/UnitMath";
import { Distance, Mass } from "../../util";
import LocalizedString from '../../util/LocalizedString';

import { createBaseSceneSurfaceA } from './jbcBase';

Expand Down
Loading

0 comments on commit 4ea1f86

Please sign in to comment.