Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix envision gltf metadata hierarchy. #2113

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Copy and pasting the git commit messages is __NOT__ enough.
- Fixed an issue where the `EnvisionDataFormatterArgs` default would use a locally defined lambda and cause a serialization failure.
- Fixed an issue where user configuration was being overridden.
- Fixed a `pkg_resources` deprecation warning in `python3.10` and up.
- Fixed the envision camera to center on the map which was broken due to a change in the `gltf` metadata hierarchy.
- Fixed an issue where you would need to install `waymo` in order to use any kind of dataset histories.
### Removed
### Security

Expand Down
2 changes: 1 addition & 1 deletion envision/web/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion envision/web/dist/main.js.map

Large diffs are not rendered by default.

43 changes: 24 additions & 19 deletions envision/web/src/components/simulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,20 @@ export default function Simulation({
this.name = `load_gltf_extras_${scenario_id}`;
this.enabled = true;

if (loader.gltf["extras"]) {
if (loader.gltf.extras["lane_dividers"]) {
setLaneDividerPos(loader.gltf.extras["lane_dividers"]);
let extras = loader.gltf["extras"]
? loader.gltf.extras
: loader.gltf["scenes"]
? loader.gltf.scenes[0].extras
: null;
if (extras) {
if (extras["lane_dividers"]) {
setLaneDividerPos(extras["lane_dividers"]);
}
if (loader.gltf.extras["edge_dividers"]) {
setEdgeDividerPos(loader.gltf.extras["edge_dividers"]);
if (extras["edge_dividers"]) {
setEdgeDividerPos(extras["edge_dividers"]);
}
if (loader.gltf.extras["bounding_box"]) {
setRoadNetworkBbox(loader.gltf.extras["bounding_box"]);
if (extras["bounding_box"]) {
setRoadNetworkBbox(extras["bounding_box"]);
}
}
}
Expand All @@ -129,28 +134,28 @@ export default function Simulation({
let cylinder_ = MeshBuilder.CreateCylinder(
"waypoint",
{ diameterTop: 0.5, diameterBottom: 0.5, height: 0.01 },
scene_,
scene_
);
cylinder_.isVisible = false;

setEgoWaypointModel(cylinder_.clone("ego-waypoint").makeGeometryUnique());
setSocialWaypointModel(
cylinder_.clone("social-waypoint").makeGeometryUnique(),
cylinder_.clone("social-waypoint").makeGeometryUnique()
);

// Driven path cuboid
let cuboid_ = MeshBuilder.CreateBox(
"drivenPath",
{ height: 0.3, width: 1, depth: 0.01 },
scene_,
scene_
);
cuboid_.isVisible = false;

setEgoDrivenPathModel(
cuboid_.clone("ego-driven-path").makeGeometryUnique(),
cuboid_.clone("ego-driven-path").makeGeometryUnique()
);
setSocialDrivenPathModel(
cuboid_.clone("social-driven-path").makeGeometryUnique(),
cuboid_.clone("social-driven-path").makeGeometryUnique()
);

// Light
Expand Down Expand Up @@ -226,7 +231,7 @@ export default function Simulation({
`load_gltf_extras_${worldState.scenario_id}`,
function (loader) {
return new LoadGLTFExtras(loader, worldState.scenario_id);
},
}
);

SceneLoader.ImportMesh("", mapRootUrl, mapFilename, scene, (meshes) => {
Expand All @@ -250,7 +255,7 @@ export default function Simulation({
child.actionManager = new ActionManager(scene);
child.actionManager.registerAction(
new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, function (
evt,
evt
) {
material.diffuseColor = roadColorSelected;
setMapElementSelected(true);
Expand All @@ -259,23 +264,23 @@ export default function Simulation({
lane_id: child.metadata.gltf.extras.lane_id,
lane_index: child.metadata.gltf.extras.lane_index,
});
}),
})
);
child.actionManager.registerAction(
new ExecuteCodeAction(ActionManager.OnPointerOutTrigger, function (
evt,
evt
) {
material.diffuseColor = roadColor;
setMapElementSelected(false);
setDebugInfo({});
}),
})
);
}

mapMeshesRef.current = meshes;

GLTFLoader.UnregisterExtension(
`load_gltf_extras_${worldState.scenario_id}`,
`load_gltf_extras_${worldState.scenario_id}`
);
});
}, [scene, worldState.scenario_id]);
Expand Down Expand Up @@ -370,7 +375,7 @@ export default function Simulation({
attrName="Position"
data_formattter={(position) =>
`x: ${parseFloat(position[0]).toFixed(2)} y: ${parseFloat(
position[1],
position[1]
).toFixed(2)}`
}
ego_agent_ids={worldState.ego_agent_ids}
Expand Down
2 changes: 1 addition & 1 deletion smarts/core/waymo_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
vec_2d,
)
from smarts.sstudio.types import MapSpec
from smarts.waymo.exceptions import WaymoDatasetError
from smarts.waymo.waymo_open_dataset.protos import scenario_pb2
from smarts.waymo.waymo_open_dataset.protos.map_pb2 import (
Crosswalk,
Expand All @@ -57,7 +58,6 @@
SpeedBump,
StopSign,
)
from smarts.waymo.waymo_utils import WaymoDatasetError

try:
import rtree
Expand Down
11 changes: 8 additions & 3 deletions smarts/sstudio/genhistories.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
vec_to_radians,
)
from smarts.sstudio import types
from smarts.waymo.waymo_open_dataset.protos import scenario_pb2
from smarts.waymo.waymo_open_dataset.protos.map_pb2 import TrafficSignalLaneState
from smarts.waymo.waymo_utils import WaymoDatasetError
from smarts.waymo.exceptions import WaymoDatasetError

METERS_PER_FOOT = 0.3048
DEFAULT_LANE_WIDTH = 3.7 # a typical US highway lane is 12ft ~= 3.7m wide
Expand Down Expand Up @@ -800,6 +798,9 @@ def _get_scenario(self):
# Loop over the scenarios in the TFRecord and check its ID for a match
scenario = None
dataset = read_tfrecord_file(self._dataset_spec["input_path"])

from smarts.waymo.waymo_open_dataset.protos import scenario_pb2

for record in dataset:
parsed_scenario = scenario_pb2.Scenario()
parsed_scenario.ParseFromString(bytes(record))
Expand Down Expand Up @@ -931,6 +932,10 @@ def lerp(a: float, b: float, t: float) -> float:
yield rows[j]

def _encode_tl_state(self, waymo_state) -> SignalLightState:
from smarts.waymo.waymo_open_dataset.protos.map_pb2 import (
TrafficSignalLaneState,
)

if waymo_state == TrafficSignalLaneState.LANE_STATE_STOP:
return SignalLightState.STOP
if waymo_state == TrafficSignalLaneState.LANE_STATE_CAUTION:
Expand Down
27 changes: 27 additions & 0 deletions smarts/waymo/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# MIT License
#
# Copyright (C) 2023. Huawei Technologies Co., Ltd. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.


class WaymoDatasetError(Exception):
"""Represents an error related to the data in a Waymo dataset scenario."""

pass
7 changes: 0 additions & 7 deletions smarts/waymo/waymo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
from smarts.core.utils.file import read_tfrecord_file
from smarts.waymo.waymo_open_dataset.protos import scenario_pb2


class WaymoDatasetError(Exception):
"""Represents an error related to the data in a Waymo dataset scenario."""

pass


MAP_HANDLES = [
Line2D([0], [0], linestyle=":", color="gray", label="Lane Polyline"),
Line2D([0], [0], linestyle="-", color="yellow", label="Single Road Line"),
Expand Down
Loading