Skip to content

Commit

Permalink
Preserve normals and mark the materials as non-flat where applicable.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Dec 20, 2022
1 parent aeda0f0 commit c8506b1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/utils/compositor/CompositorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ CompositorDataState::CompositorDataState(const Mn::Vector2i& textureAtlasSize):
Mn::PixelFormat::RGB8Unorm, {1, 1},
Mn::Trade::DataFlags{}, WhitePixel});

arrayAppend(inputMaterials, Mn::Trade::MaterialData{Mn::Trade::MaterialType::Flat, {
arrayAppend(inputMaterials, Mn::Trade::MaterialData{Mn::Trade::MaterialType::PbrMetallicRoughness, {
{Mn::Trade::MaterialAttribute::BaseColorTexture, 0u},
/* The layer ID and matrix translation get updated based on where the 1x1
image ends up being in the atlas */
Expand All @@ -136,12 +136,14 @@ CompositorDataState::CompositorDataState(const Mn::Vector2i& textureAtlasSize):
}

Mn::Trade::MeshData CompositorDataState::finalizeMesh() const {
/* Target layout for the mesh. So far just for flat rendering, no normals
etc */
/* Target layout for the mesh. So far just normals, no tangents for normal
mapping. */
Mn::Trade::MeshData mesh{Mn::MeshPrimitive::Triangles, nullptr, {
Mn::Trade::MeshAttributeData{Mn::Trade::MeshAttribute::Position, Mn::VertexFormat::Vector3, nullptr},
Mn::Trade::MeshAttributeData{Mn::Trade::MeshAttribute::Normal, Mn::VertexFormat::Vector3, nullptr},
Mn::Trade::MeshAttributeData{Mn::Trade::MeshAttribute::TextureCoordinates, Mn::VertexFormat::Vector2, nullptr},
}};
// TODO generate normals for meshes that don't have them if there are any
Mn::MeshTools::concatenateInto(mesh, inputMeshes);

return mesh;
Expand Down
5 changes: 2 additions & 3 deletions src/utils/compositor/compositor-fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int main(int argc, char** argv) {
arrayAppend(ds.inputMeshes, *std::move(mesh));

/* Add an empty colored material */
arrayAppend(ds.inputMaterials, Mn::Trade::MaterialData{Mn::Trade::MaterialType::Flat, {
arrayAppend(ds.inputMaterials, Mn::Trade::MaterialData{Mn::Trade::MaterialType::PbrMetallicRoughness, {
{Mn::Trade::MaterialAttribute::BaseColor, color},
{Mn::Trade::MaterialAttribute::BaseColorTexture, 0u},
{Mn::Trade::MaterialAttribute::BaseColorTextureLayer, 0u},
Expand Down Expand Up @@ -234,8 +234,7 @@ int main(int argc, char** argv) {
CORRADE_INTERNAL_ASSERT(material->layerCount() == 1);
arrayAppend(attributes, material->attributeData());

/* Make it just Flat */
material = Mn::Trade::MaterialData{Mn::Trade::MaterialType::Flat, std::move(attributes)};
material = Mn::Trade::MaterialData{material->types(), std::move(attributes)};

importedMaterialIds[transformationMeshMaterial.second()] = m.meshMaterial = ds.inputMaterials.size();
arrayAppend(ds.inputMaterials, *std::move(material));
Expand Down
18 changes: 12 additions & 6 deletions src/utils/compositor/compositor-replicacad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ int main(int argc, char** argv) {

const auto import = [&](
Cr::Containers::StringView filename,
Cr::Containers::StringView name) {
Cr::Containers::StringView name,
Mn::Trade::MaterialType materialType)
{
CORRADE_INTERNAL_ASSERT_OUTPUT(importer->openFile(filename));
CORRADE_INTERNAL_ASSERT(importer->sceneCount() == 1);

Expand Down Expand Up @@ -212,8 +214,8 @@ int main(int argc, char** argv) {
CORRADE_INTERNAL_ASSERT(material->layerCount() == 1);
arrayAppend(attributes, material->attributeData());

/* Make it just Flat */
material = Mn::Trade::MaterialData{Mn::Trade::MaterialType::Flat, std::move(attributes)};
/* The material type is overriden to Flat for some */
material = Mn::Trade::MaterialData{materialType, std::move(attributes)};

importedMaterialIds[transformationMeshMaterial.second()] = m.meshMaterial = ds.inputMaterials.size();
arrayAppend(ds.inputMaterials, *std::move(material));
Expand All @@ -224,13 +226,17 @@ int main(int argc, char** argv) {
};

Cr::Containers::String replicaPath = Cr::Utility::Path::join(args.value("input"), "ReplicaCAD_dataset_v1.5");

/* Stage_v3_sc*_staging are already pre-baked so Flat, frl_apartment_stage
is not */
import(Cr::Utility::Path::join({replicaPath, "stages/frl_apartment_stage.glb"}), "data/replica_cad/configs/stages/../../stages/frl_apartment_stage.glb", Mn::Trade::MaterialType::PbrMetallicRoughness);
for(const char* name: {
"Stage_v3_sc0_staging.glb",
"Stage_v3_sc1_staging.glb",
"Stage_v3_sc2_staging.glb",
"Stage_v3_sc3_staging.glb"
})
import(Cr::Utility::Path::join({replicaPath, "stages", name}), "data/replica_cad/configs/stages/../../stages/"_s + name);
import(Cr::Utility::Path::join({replicaPath, "stages", name}), "data/replica_cad/configs/stages/../../stages/"_s + name, Mn::Trade::MaterialType::Flat);

for(const char* name: {
"frl_apartment_basket.glb",
Expand Down Expand Up @@ -326,7 +332,7 @@ int main(int argc, char** argv) {
"frl_apartment_wall_cabinet_02.glb",
"frl_apartment_wall_cabinet_03.glb"
})
import(Cr::Utility::Path::join({replicaPath, "objects", name}), "data/replica_cad/configs/objects/../../objects/"_s + name);
import(Cr::Utility::Path::join({replicaPath, "objects", name}), "data/replica_cad/configs/objects/../../objects/"_s + name, Mn::Trade::MaterialType::PbrMetallicRoughness);

for(const char* name: {
"doors/double_door_R.glb",
Expand Down Expand Up @@ -354,7 +360,7 @@ int main(int argc, char** argv) {
"kitchen_cupboards/kitchencupboard_doorWhole_L.glb",
"kitchen_cupboards/kitchencupboard_doorWindow_L.glb"
})
import(Cr::Utility::Path::join({replicaPath, "urdf", name}), "data/replica_cad/urdf/"_s + name);
import(Cr::Utility::Path::join({replicaPath, "urdf", name}), "data/replica_cad/urdf/"_s + name, Mn::Trade::MaterialType::PbrMetallicRoughness);

// TODO some mesh optimization first?
CORRADE_INTERNAL_ASSERT(s.converter->add(ds.finalizeMesh()));
Expand Down
3 changes: 1 addition & 2 deletions src/utils/compositor/compositor-ycb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ int main(int argc, char** argv) {
CORRADE_INTERNAL_ASSERT(material->layerCount() == 1);
arrayAppend(attributes, material->attributeData());

/* Make it just Flat */
material = Mn::Trade::MaterialData{Mn::Trade::MaterialType::Flat, std::move(attributes)};
material = Mn::Trade::MaterialData{material->types(), std::move(attributes)};

importedMaterialIds[transformationMeshMaterial.second()] = m.meshMaterial = ds.inputMaterials.size();
arrayAppend(ds.inputMaterials, *std::move(material));
Expand Down

0 comments on commit c8506b1

Please sign in to comment.