Skip to content

Commit

Permalink
Merge branch 'develop' into iss1435
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamenot authored Nov 17, 2022
2 parents 8bd8d1f + c4f76d8 commit 7129e8e
Show file tree
Hide file tree
Showing 25 changed files with 251 additions and 83 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Copy and pasting the git commit messages is __NOT__ enough.
- Added ego's mission details into the `FormatObs` wrapper.
- Added `SmartsLaneChangingModel` and `SmartsJunctionModel` to types available for use with the new smarts traffic engine within Scenario Studio.
- Added option to `AgentInterface` to include traffic signals (lights) in `EgoVehicleObservation` objects.
- Added the ability to hover over vehicles and roadmap elements in Envision to see debug info.

### Deprecated
- Deprecated a few things related to traffic in the `Scenario` class, including the `route` argument to the `Scenario` initializer, the `route`, `route_filepath` and `route_files_enabled` properties, and the `discover_routes()` static method. In general, the notion of "route" (singular) here is being replaced with "`traffic_specs`" (plural) that allow for specifying traffic controlled by the SMARTS engine as well as Sumo.
Expand Down Expand Up @@ -59,6 +60,7 @@ Copy and pasting the git commit messages is __NOT__ enough.
- Fixed issues with Envision. The playback bar and realtime mode now work as expected.
- Fixed a bug where traffic history vehicles would not get traffic signal observations
- Fixed a bug where envision would not work in some versions of python due to nuances of `importlib.resource.path()`.
- Fixed an issue with incorrect vehicle sizes in Envision.

## [0.6.1]
### Added
Expand Down
4 changes: 2 additions & 2 deletions 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.

41 changes: 41 additions & 0 deletions envision/web/src/components/DebugInfoDisplay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2022. 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.
import React from "react";

export default function DebugInfoDisplay({ data, attrName }) {
return (
<table style={{ margin: "15px", tableLayout: "auto" }}>
<thead>
<tr key={`data-body-${attrName}`}>
<th style={{ paddingRight: "15px" }}>{attrName}</th>
</tr>
</thead>
<tbody>
{Object.entries(data).map(([key, val]) => {
return (
<tr key={`data-body-${key}`}>
<td style={{ paddingRight: "15px" }}>{`${key}: ${val}`}</td>
</tr>
);
})}
</tbody>
</table>
);
}
4 changes: 3 additions & 1 deletion envision/web/src/components/ScenarioNameDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default function ScenarioNameDisplay({
</tr>
</thead>
<tbody>
<td style={{ paddingRight: "15px" }}>{data_formattter(data)}</td>
<tr key="data-body">
<td style={{ paddingRight: "15px" }}>{data_formattter(data)}</td>
</tr>
</tbody>
</table>
);
Expand Down
45 changes: 44 additions & 1 deletion envision/web/src/components/simulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import {
HemisphericLight,
MeshBuilder,
Color4,
ActionManager,
ExecuteCodeAction,
} from "@babylonjs/core";

import "@babylonjs/loaders/glTF/2.0/Extensions/ExtrasAsMetadata.js";
import { GLTFLoader } from "@babylonjs/loaders/glTF/2.0/glTFLoader";
import SceneComponent from "babylonjs-hook";

Expand All @@ -46,6 +49,7 @@ import { attrs, agentModes } from "./control_panel";

import InfoDisplay from "./InfoDisplay";
import ScenarioNameDisplay from "./ScenarioNameDisplay";
import DebugInfoDisplay from "./DebugInfoDisplay.js";
import earcut from "earcut";
import { SceneColors } from "../helpers/scene_colors.js";
import unpack_worldstate from "../helpers/state_unpacker.js";
Expand Down Expand Up @@ -88,6 +92,11 @@ export default function Simulation({
lane_ids: [],
});

// Mouse selection and debug info
const [vehicleSelected, setVehicleSelected] = useState(false);
const [mapElementSelected, setMapElementSelected] = useState(false);
const [debugInfo, setDebugInfo] = useState({});

const mapMeshesRef = useRef([]);

// Parse extra data attached in glb file
Expand Down Expand Up @@ -226,12 +235,38 @@ export default function Simulation({

// Update material for all child meshes
// Currently only use flat shading, replace imported pbr material with standard material
let roadColor = new Color4(...SceneColors.Road);
let roadColorSelected = new Color4(...SceneColors.Selection);
for (const child of meshes[0].getChildMeshes()) {
let material = new StandardMaterial("material-map", scene);
material.backFaceCulling = false;
material.diffuseColor = new Color4(...SceneColors.Road);
material.diffuseColor = roadColor;
material.specularColor = new Color3(0, 0, 0);
child.material = material;

child.actionManager = new ActionManager(scene);
child.actionManager.registerAction(
new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, function (
evt
) {
material.diffuseColor = roadColorSelected;
setMapElementSelected(true);
setDebugInfo({
road_id: child.metadata.gltf.extras.road_id,
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
) {
material.diffuseColor = roadColor;
setMapElementSelected(false);
setDebugInfo({});
})
);
}

mapMeshesRef.current = meshes;
Expand Down Expand Up @@ -270,6 +305,8 @@ export default function Simulation({
worldState={worldState}
vehicleRootUrl={`${client.endpoint.origin}/assets/models/`}
egoView={egoView}
setVehicleSelected={setVehicleSelected}
setDebugInfo={setDebugInfo}
/>
<Bubbles scene={scene} worldState={worldState} />
<DrivenPaths
Expand Down Expand Up @@ -354,6 +391,12 @@ export default function Simulation({
ego_only={!controlModes[agentModes.socialObs]}
/>
) : null}
{vehicleSelected ? (
<DebugInfoDisplay data={debugInfo} attrName="Selected Vehicle" />
) : null}
{mapElementSelected ? (
<DebugInfoDisplay data={debugInfo} attrName="Selected Map Element" />
) : null}
</div>
</div>
);
Expand Down
88 changes: 62 additions & 26 deletions envision/web/src/components/vehicles.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,37 @@
import {
Vector3,
Color3,
Color4,
SceneLoader,
StandardMaterial,
Quaternion,
MeshBuilder,
Mesh,
Color4,
BoundingInfo,
ActionManager,
ExecuteCodeAction,
} from "@babylonjs/core";

import { useRef, useEffect } from "react";

import { ActorTypes } from "../enums.js";
import { SceneColors } from "../helpers/scene_colors.js";
import { intersection, difference } from "../math.js";
import {
vehicleMeshFilename,
vehicleMeshColor,
buildLabel,
} from "../render_helpers.js";

const DEBUG_PROPS = [
"actor_id",
"position",
"speed",
"heading",
"actor_type",
"vehicle_type",
];

let meshesLoaded = (vehicleMeshTemplates) => {
for (const [_, mesh] of Object.entries(vehicleMeshTemplates)) {
if (mesh == null) {
Expand All @@ -54,6 +66,8 @@ export default function Vehicles({
worldState,
vehicleRootUrl,
egoView,
setVehicleSelected,
setDebugInfo,
}) {
if (scene == null) {
return null;
Expand Down Expand Up @@ -164,6 +178,7 @@ export default function Vehicles({
// Create new meshes
for (const meshId of vehicleMeshIdsToAdd) {
let state = worldState.traffic[meshId];

// Vehicle mesh
let filename = vehicleMeshFilename(state.actor_type, state.vehicle_type);
if (!vehicleMeshTemplates[filename]) {
Expand All @@ -187,31 +202,52 @@ export default function Vehicles({
rootMesh.addChild(instancedSubMesh);
}

// Render bounding box for social vehicle
if (state.actor_type == ActorTypes.SOCIAL_VEHICLE) {
let boundingInfo = vehicleMeshTemplates[filename].getBoundingInfo();
let boxSize = boundingInfo.boundingBox.extendSize.scale(2);
let box = MeshBuilder.CreateBox(
`boundingbox-${meshId}`,
{
height: boxSize.y + 0.1,
width: boxSize.x + 0.1,
depth: boxSize.z + 0.1,
},
scene
);
box.position = boundingInfo.boundingBox.center;

let boxMaterial = new StandardMaterial(
`boundingbox-${meshId}-material`,
scene
);
boxMaterial.diffuseColor = new Color4(...color);
boxMaterial.specularColor = new Color3(0, 0, 0);
boxMaterial.alpha = 0.75;
box.material = boxMaterial;
rootMesh.addChild(box);
}
let boundingInfo = vehicleMeshTemplates[filename].getBoundingInfo();
let boxSize = boundingInfo.boundingBox.extendSize.scale(2);
let box = MeshBuilder.CreateBox(
`boundingbox-${meshId}`,
{
height: boxSize.y + 0.1,
width: boxSize.x + 0.1,
depth: boxSize.z + 0.1,
},
scene
);

let boxMaterial = new StandardMaterial(
`boundingbox-${meshId}-material`,
scene
);
boxMaterial.diffuseColor = new Color4(...SceneColors.Selection);
boxMaterial.specularColor = new Color3(0, 0, 0);
boxMaterial.alpha = 0.0;

box.material = boxMaterial;
box.position = boundingInfo.boundingBox.center;
box.actionManager = new ActionManager(scene);
box.actionManager.registerAction(
new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, function (
evt
) {
boxMaterial.alpha = 0.5;
setVehicleSelected(true);
let debugInfo = {};
for (const prop of DEBUG_PROPS) {
debugInfo[prop] = state[prop];
}
setDebugInfo(debugInfo);
})
);
box.actionManager.registerAction(
new ExecuteCodeAction(ActionManager.OnPointerOutTrigger, function (
evt
) {
boxMaterial.alpha = 0.0;
setVehicleSelected(false);
setDebugInfo({});
})
);
rootMesh.addChild(box);

rootMesh.metadata = {};
rootMesh.metadata.actorType = state.actor_type;
Expand Down
1 change: 1 addition & 0 deletions envision/web/src/helpers/scene_colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const SceneColors = Object.freeze({
SocialAgent: Silver,
SocialVehicle: Silver,
Road: DarkGrey,
Selection: LightBlue,
EgoWaypoint: CyanTransparent,
EgoDrivenPath: CyanTransparent,
BubbleLine: LightGreyTransparent,
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ coverage==6.5.0
cycler==0.11.0
dm-tree==0.1.7
eclipse-sumo==1.10.0
exceptiongroup==1.0.3
exceptiongroup==1.0.4
execnet==1.9.0
filelock==3.8.0
flatbuffers==22.10.26
Expand All @@ -38,7 +38,7 @@ google-api-core==2.10.2
google-auth==2.14.1
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
googleapis-common-protos==1.56.4
googleapis-common-protos==1.57.0
gpustat==1.0.0
grpcio==1.50.0
gym==0.19.0
Expand Down Expand Up @@ -118,7 +118,7 @@ tensorboard==2.10.1
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorboardX==2.5.1
tensorflow==2.10.0
tensorflow==2.10.1
tensorflow-estimator==2.10.0
tensorflow-io-gcs-filesystem==0.27.0
termcolor==2.1.0
Expand All @@ -138,4 +138,4 @@ wrapt==1.14.1
yarl==1.8.1
yattag==1.14.0
zipp==3.10.0
zope.interface==5.5.1
zope.interface==5.5.2
Binary file modified smarts/core/models/bus.blend
Binary file not shown.
Binary file modified smarts/core/models/bus.glb
Binary file not shown.
Binary file modified smarts/core/models/coach.blend
Binary file not shown.
Binary file modified smarts/core/models/coach.glb
Binary file not shown.
Binary file modified smarts/core/models/muscle_car.blend
Binary file not shown.
Binary file modified smarts/core/models/muscle_car.glb
Binary file not shown.
Binary file modified smarts/core/models/simple_car.blend
Binary file not shown.
Binary file modified smarts/core/models/simple_car.glb
Binary file not shown.
Binary file modified smarts/core/models/trailer.blend
Binary file not shown.
Binary file modified smarts/core/models/trailer.glb
Binary file not shown.
Binary file modified smarts/core/models/truck.blend
Binary file not shown.
Binary file modified smarts/core/models/truck.glb
Binary file not shown.
25 changes: 18 additions & 7 deletions smarts/core/opendrive_road_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

from smarts.core.road_map import RoadMap, RoadMapWithCaches, Waypoint
from smarts.core.route_cache import RouteWithCache
from smarts.core.utils.geometry import generate_mesh_from_polygons
from smarts.core.utils.geometry import generate_meshes_from_polygons
from smarts.core.utils.key_wrapper import KeyWrapper
from smarts.core.utils.math import (
CubicPolynomial,
Expand Down Expand Up @@ -770,9 +770,14 @@ def _make_glb_from_polys(self):
polygons = []
for lane_id in self._lanes:
lane = self._lanes[lane_id]
polygons.append(lane.shape())
metadata = {
"road_id": lane.road.road_id,
"lane_id": lane_id,
"lane_index": lane.index,
}
polygons.append((lane.shape(), metadata))

mesh = generate_mesh_from_polygons(polygons)
meshes = generate_meshes_from_polygons(polygons)

# Attach additional information for rendering as metadata in the map glb
# <2D-BOUNDING_BOX>: four floats separated by ',' (<FLOAT>,<FLOAT>,<FLOAT>,<FLOAT>),
Expand All @@ -791,11 +796,17 @@ def _make_glb_from_polys(self):
metadata["lane_dividers"] = lane_dividers
metadata["edge_dividers"] = road_dividers

mesh.visual = trimesh.visual.TextureVisuals(
material=trimesh.visual.material.PBRMaterial()
)
for mesh in meshes:
mesh.visual = trimesh.visual.TextureVisuals(
material=trimesh.visual.material.PBRMaterial()
)

scene.add_geometry(mesh)
road_id = mesh.metadata["road_id"]
lane_id = mesh.metadata.get("lane_id")
name = f"{road_id}"
if lane_id is not None:
name += f"-{lane_id}"
scene.add_geometry(mesh, name, extras=mesh.metadata)
return _GLBData(gltf.export_glb(scene, extras=metadata, include_normals=True))

def _compute_traffic_dividers(self):
Expand Down
Loading

0 comments on commit 7129e8e

Please sign in to comment.