diff --git a/src/simulator/babylonBindings/RobotBinding.ts b/src/simulator/babylonBindings/RobotBinding.ts index bbb9d0c9..e312a002 100644 --- a/src/simulator/babylonBindings/RobotBinding.ts +++ b/src/simulator/babylonBindings/RobotBinding.ts @@ -535,9 +535,9 @@ class RobotBinding { const default_offset = LocalizedString.getOriginal(this.robot_.name) === 'Demobot' ? -1 * Math.PI / 2 : Math.PI / 2; const UpdatedEulerOrigin = RawEuler.create( - newOriginE.x + Robot_OriginE.x, - newOriginE.y + Robot_OriginE.y + default_offset, - newOriginE.z + Robot_OriginE.z, + newOriginE.x, + newOriginE.y + default_offset, + newOriginE.z, "xyz" ); @@ -561,8 +561,7 @@ class RobotBinding { weight.physicsBody.setLinearVelocity(Vector3.Zero()); } - rootTransformNode.position = RawVector3.toBabylon(rawOrigin.position || RawVector3.ZERO) - .add(RawVector3.toBabylon(rawInternalOrigin.position || RawVector3.ZERO)); + rootTransformNode.position = RawVector3.toBabylon(rawOrigin.position || RawVector3.ZERO); rootTransformNode.rotationQuaternion = RawQuaternion.toBabylon(RawEuler.toQuaternion(UpdatedEulerOrigin)); diff --git a/src/simulator/babylonBindings/SceneBinding.ts b/src/simulator/babylonBindings/SceneBinding.ts index ef426354..f7b6122d 100644 --- a/src/simulator/babylonBindings/SceneBinding.ts +++ b/src/simulator/babylonBindings/SceneBinding.ts @@ -123,7 +123,7 @@ class SceneBinding { this.gizmoManager_.rotationGizmoEnabled = true; this.gizmoManager_.scaleGizmoEnabled = false; this.gizmoManager_.usePointerToAttachGizmos = false; - // Un comment for boudning boxes in scene + // Uncomment for bounding boxes in scene // this.gizmoManager_.boundingBoxGizmoEnabled = true; // this.gizmoManager_.gizmos.boundingBoxGizmo.setColor(new Color3(0, 0, 1)); @@ -960,6 +960,9 @@ class SceneBinding { // Update intersections for (const nodeId in this.intersectionFilters_) { + const nodeMeshes = this.nodeMeshes_(nodeId); + if (nodeMeshes.length === 0) continue; + try { const nodeBoundingBoxes = this.nodeBoundingBoxes_(nodeId); const filterIds = this.intersectionFilters_[nodeId]; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 570bb654..878e2ada 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -20,6 +20,7 @@ export * from './jbc18-Stackerz-New'; export * from './jbc19-Bump-New'; export * from './jbc20-Amazing-New'; export * from './jbc21-Proximity-New'; +export * from './jbc23-Find-the-Black-Line-New'; export * from './jbc24-Walk-the-Line-New'; export * from './moonSandbox'; // export * from './jbc2b-Ring-Around-the-Cans-Sr'; diff --git a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts index bdba086e..e8ded99f 100644 --- a/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts +++ b/src/simulator/definitions/scenes/jbc15-Go-Fetch-New.ts @@ -36,7 +36,7 @@ const uprightCan = ` // When a can is standing upright, the upright condition is met. const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); -const yAngle = (nodeId) => 180 / Math.PI * Math.acos(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.Y, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.Y)); +const yAngle = (nodeId) => 180 / Math.PI * -1 * Math.asin(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.Y, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.Y)); scene.addOnRenderListener(() => { diff --git a/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts new file mode 100644 index 00000000..ead91e73 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc23-Find-the-Black-Line-New.ts @@ -0,0 +1,92 @@ +import Scene from '../../../state/State/Scene'; +import { ReferenceFramewUnits, RotationwUnits, Vector3wUnits } from '../../../util/math/unitMath'; +import { Distance } from '../../../util'; +import LocalizedString from '../../../util/LocalizedString'; +import Script from '../../../state/State/Scene/Script'; +import { createBaseSceneSurfaceA, canPositions } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; + +const baseScene = createBaseSceneSurfaceA(); + +const foundBlack = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible + }); + + console.log('Robot crossing black line', type, otherNodeId); + if(scene.programStatus === 'running'){ + if(scene.nodes['robot'].state.getAnalogValue(1) > 2000) { + scene.setChallengeEventValue('stopAtBlackLine', type === 'start'); + setNodeVisible('otherNodeId', true); + } + } +}, 'blackLine'); +`; + +function randomCircle(): Vector3wUnits { + const circles = [2, 4, 6, 9, 11]; + const randomCircle = circles[Math.floor(Math.random() * circles.length)]; + console.log('randomCircle: ', randomCircle); + const circle: Vector3wUnits = { + ...canPositions[randomCircle - 1], + }; + console.log('circle: ', circle); + return circle; +} + +const ROBOT_ORIGIN: ReferenceFramewUnits = { + position: { ...randomCircle() }, + orientation: RotationwUnits.eulerDegrees(0, 180, 0) +}; + +export const JBC_23: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: 'JBC 23' }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 23: Find the Black Line`, + }, + scripts: { + foundBlack: Script.ecmaScript('Found Black Line', foundBlack), + }, + geometry: { + ...baseScene.geometry, + blackLine_geom: { + type: "box", + size: { + x: Distance.inches(24), + y: Distance.centimeters(10), + z: Distance.inches(0.65), + }, + }, + }, + nodes: { + ...baseScene.nodes, + robot: { + ...baseScene.nodes['robot'], + origin: ROBOT_ORIGIN, + startingOrigin: ROBOT_ORIGIN, + }, + blackLine: { + type: "object", + geometryId: "blackLine_geom", + name: { [LocalizedString.EN_US]: "Black Line" }, + visible: true, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.inches(5.95), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 255, 255), + }, + }, + }, + }, +}; diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index dbb8d975..cbd5312a 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -327,7 +327,7 @@ const DEFAULT_SCENES: Scenes = { jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), // jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), - // jbc23: Async.loaded({ value: JBC_SCENES.JBC_23 }), + jbc23: Async.loaded({ value: JBC_SCENES.JBC_23 }), jbc24: Async.loaded({ value: JBC_SCENES.JBC_24 }), // scriptPlayground: Async.loaded({ value: JBC_SCENES.scriptPlayground }), // lightSensorTest: Async.loaded({ value: JBC_SCENES.lightSensorTest }),