Do not render flexes/skins with no geometry.
PiperOrigin-RevId: 933604372 Change-Id: I80169ff09ec6908d101b5f10bbf8aa1a6e8b8249
This commit is contained in:
committed by
Copybara-Service
parent
e1711529f2
commit
6294e77907
@@ -126,8 +126,10 @@ void SceneBridge::Update(const mjrRect& viewport, const mjvScene* scene) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (geom->type == mjGEOM_FLEX || geom->type == mjGEOM_SKIN) {
|
if (geom->type == mjGEOM_FLEX || geom->type == mjGEOM_SKIN) {
|
||||||
scene_objects_->CreateSkinFlexMesh(scene, model_objects_->GetModel(),
|
if (!scene_objects_->CreateSkinFlexMesh(scene, model_objects_->GetModel(),
|
||||||
*geom);
|
*geom)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UniquePtr<mjrfRenderable> renderable = CreateGeomRenderable(
|
UniquePtr<mjrfRenderable> renderable = CreateGeomRenderable(
|
||||||
|
|||||||
@@ -103,9 +103,13 @@ static std::span<const int> GetIndices(const mjModel* model,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdateSkinFlexMeshData(mjrfMeshData* data, const mjModel* model,
|
static bool UpdateSkinFlexMeshData(mjrfMeshData* data, const mjModel* model,
|
||||||
const mjvScene* scene, const mjvGeom& geom) {
|
const mjvScene* scene, const mjvGeom& geom) {
|
||||||
auto positions = GetPositions(model, scene, geom);
|
auto positions = GetPositions(model, scene, geom);
|
||||||
|
if (positions.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto normals = GetNormals(model, scene, geom);
|
auto normals = GetNormals(model, scene, geom);
|
||||||
auto uvs = GetUvs(model, scene, geom);
|
auto uvs = GetUvs(model, scene, geom);
|
||||||
auto indices = GetIndices(model, scene, geom);
|
auto indices = GetIndices(model, scene, geom);
|
||||||
@@ -133,16 +137,19 @@ static void UpdateSkinFlexMeshData(mjrfMeshData* data, const mjModel* model,
|
|||||||
data->compute_bounds = true;
|
data->compute_bounds = true;
|
||||||
data->release = nullptr;
|
data->release = nullptr;
|
||||||
data->user_data = nullptr;
|
data->user_data = nullptr;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneObjects::SceneObjects(mjrfContext* ctx) : ctx_(ctx) {}
|
SceneObjects::SceneObjects(mjrfContext* ctx) : ctx_(ctx) {}
|
||||||
|
|
||||||
void SceneObjects::CreateSkinFlexMesh(const mjvScene* scene,
|
bool SceneObjects::CreateSkinFlexMesh(const mjvScene* scene,
|
||||||
const mjModel* model,
|
const mjModel* model,
|
||||||
const mjvGeom& geom) {
|
const mjvGeom& geom) {
|
||||||
mjrfMeshData data;
|
mjrfMeshData data;
|
||||||
mjrf_defaultMeshData(&data);
|
mjrf_defaultMeshData(&data);
|
||||||
UpdateSkinFlexMeshData(&data, model, scene, geom);
|
if (!UpdateSkinFlexMeshData(&data, model, scene, geom)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (geom.type == mjGEOM_FLEX) {
|
if (geom.type == mjGEOM_FLEX) {
|
||||||
flexes_.insert_or_assign(geom.objid, CreateMesh(ctx_, data));
|
flexes_.insert_or_assign(geom.objid, CreateMesh(ctx_, data));
|
||||||
} else if (geom.type == mjGEOM_SKIN) {
|
} else if (geom.type == mjGEOM_SKIN) {
|
||||||
@@ -150,6 +157,7 @@ void SceneObjects::CreateSkinFlexMesh(const mjvScene* scene,
|
|||||||
} else {
|
} else {
|
||||||
mju_error("Unsupported dynamic mesh type: %d", geom.type);
|
mju_error("Unsupported dynamic mesh type: %d", geom.type);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mjrfMesh* SceneObjects::GetFlexMesh(int geom_id) const {
|
const mjrfMesh* SceneObjects::GetFlexMesh(int geom_id) const {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class SceneObjects {
|
|||||||
explicit SceneObjects(mjrfContext* ctx);
|
explicit SceneObjects(mjrfContext* ctx);
|
||||||
|
|
||||||
// Creates a skin or flex mesh from the given geom in the mjvScene.
|
// Creates a skin or flex mesh from the given geom in the mjvScene.
|
||||||
void CreateSkinFlexMesh(const mjvScene* scene, const mjModel* model,
|
bool CreateSkinFlexMesh(const mjvScene* scene, const mjModel* model,
|
||||||
const mjvGeom& geom);
|
const mjvGeom& geom);
|
||||||
|
|
||||||
// Returns the mesh for the given geom id, as created by CreateSkinFlexMesh.
|
// Returns the mesh for the given geom id, as created by CreateSkinFlexMesh.
|
||||||
|
|||||||
Reference in New Issue
Block a user