-
Notifications
You must be signed in to change notification settings - Fork 21
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
Export render and depth tensors #78
Changes from 16 commits
7bb1945
2d4ad38
88ccb10
09ed737
60db2c3
7f3ab55
b225ae8
25171ae
a3bbae0
ba6ac85
06ad38c
61f42fb
27cfb56
145794d
cde55c4
2388548
9296cd8
af4ebcd
7689d24
70dbc0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ static inline Entity createAgent(Engine &ctx, const MapObject &agentInit) { | |
{ | ||
trajectory.positions[i] = Vector2{.x = agentInit.position[i].x - ctx.data().mean.x + length, .y = agentInit.position[i].y - ctx.data().mean.y + width}; | ||
trajectory.velocities[i] = Vector2{.x = agentInit.velocity[i].x, .y = agentInit.velocity[i].y}; | ||
trajectory.headings[i] = toRadians(agentInit.heading[i]); | ||
trajectory.headings[i] = toRadians(agentInit.heading[i]) - M_PI_2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a big thing. Why do we think this is right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change crept in :) Will remove that. |
||
trajectory.valids[i] = agentInit.valid[i]; | ||
} | ||
|
||
|
@@ -272,6 +272,13 @@ static inline Entity createAgentPadding(Engine &ctx) { | |
ctx.get<StepsRemaining>(agent).t = consts::episodeLen; | ||
ctx.get<ControlledState>(agent) = ControlledState{.controlledState = ControlMode::EXPERT}; | ||
|
||
if (ctx.data().enableRender) { | ||
render::RenderingSystem::attachEntityToView(ctx, | ||
agent, | ||
90.f, 0.001f, | ||
1.5f * math::up); | ||
} | ||
|
||
return agent; | ||
} | ||
|
||
|
@@ -306,10 +313,10 @@ void createPaddingEntities(Engine &ctx) { | |
} | ||
|
||
void createPersistentEntities(Engine &ctx, Map *map) { | ||
|
||
createFloorPlane(ctx); | ||
ctx.data().mean = {0, 0}; | ||
ctx.data().mean.x = map->mean.x; | ||
ctx.data().mean.y = map->mean.y; | ||
// ctx.data().mean.x = map->mean.x; | ||
// ctx.data().mean.y = map->mean.y; | ||
ctx.data().numControlledVehicles = 0; | ||
|
||
CountT agentIdx = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,48 @@ | |
#include <fstream> | ||
#include <optional> | ||
|
||
#include <iostream> | ||
// #include "json_serialization.hpp" | ||
#include <nlohmann/json.hpp> | ||
|
||
using namespace madrona; | ||
using namespace madrona::viz; | ||
|
||
std::pair<float, float> calc_mean(const nlohmann::json &j) | ||
{ | ||
std::pair<float, float> mean = {0, 0}; | ||
int64_t numEntities = 0; | ||
for (const auto &obj : j["objects"]) | ||
{ | ||
int i = 0; | ||
for (const auto &pos : obj["position"]) | ||
{ | ||
if (obj["valid"][i++] == false) | ||
continue; | ||
numEntities++; | ||
float newX = pos["x"]; | ||
float newY = pos["y"]; | ||
// Update mean incrementally | ||
mean.first += (newX - mean.first) / numEntities; | ||
mean.second += (newY - mean.second) / numEntities; | ||
} | ||
} | ||
for (const auto &obj : j["roads"]) | ||
{ | ||
for (const auto &point : obj["geometry"]) | ||
{ | ||
numEntities++; | ||
float newX = point["x"]; | ||
float newY = point["y"]; | ||
|
||
// Update mean incrementally | ||
mean.first += (newX - mean.first) / numEntities; | ||
mean.second += (newY - mean.second) / numEntities; | ||
} | ||
} | ||
return mean; | ||
} | ||
|
||
static HeapArray<float> readReplayLog(const char *path) { | ||
std::ifstream replay_log(path, std::ios::binary); | ||
replay_log.seekg(0, std::ios::end); | ||
|
@@ -65,18 +104,19 @@ int main(int argc, char *argv[]) | |
#endif | ||
|
||
WindowManager wm {}; | ||
WindowHandle window = wm.makeWindow("Escape Room", 2730, 1536); | ||
WindowHandle window = wm.makeWindow("Escape Room", 640, 480); | ||
render::GPUHandle render_gpu = wm.initGPU(0, { window.get() }); | ||
|
||
Manager mgr({ | ||
.execMode = exec_mode, | ||
.gpuID = 0, | ||
.numWorlds = num_worlds, | ||
.autoReset = replay_log.has_value(), | ||
.jsonPath = "../maps", | ||
.jsonPath = "/home/aarav/gpudrive/nocturne_data", | ||
.params = { | ||
.polylineReductionThreshold = 1.0, | ||
.observationRadius = 100.0, | ||
.maxNumControlledVehicles = 0 | ||
}, | ||
.enableBatchRenderer = enable_batch_renderer, | ||
.extRenderAPI = wm.gpuAPIManager().backend(), | ||
|
@@ -88,11 +128,27 @@ int main(int argc, char *argv[]) | |
(math::Quat::angleAxis(0, math::up) * | ||
math::Quat::angleAxis(-math::pi / 2.f, math::right)).normalize(); | ||
|
||
std::string path = "/home/aarav/gpudrive/nocturne_data"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid hardcoding if possible. Maybe we can assume a relative path? |
||
std::string mapPath; | ||
for (auto const &mapFile : std::filesystem::directory_iterator(path)) | ||
{ | ||
if (mapFile.path().extension() == ".json") | ||
{ | ||
mapPath = mapFile.path().string(); | ||
break; | ||
} | ||
} | ||
std::cout<<mapPath<<std::endl; | ||
std::ifstream in(mapPath); | ||
nlohmann::json rawJson; | ||
in >> rawJson; | ||
auto mean = calc_mean(rawJson); | ||
|
||
Viewer viewer(mgr.getRenderManager(), window.get(), { | ||
.numWorlds = num_worlds, | ||
.simTickRate = 20, | ||
.cameraMoveSpeed = 20.f, | ||
.cameraPosition = 20.f * math::up, | ||
.cameraPosition = mean.first * math::right + mean.second*math::fwd + 100.f * math::up, | ||
.cameraRotation = initial_camera_rotation, | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SamanKazemkhani I vaguely remember a comment about this elsewhere too?