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

Write directly to GLB from TGeometries #6404

Merged
merged 23 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion 3rdparty/assimp/assimp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ ExternalProject_Add(
-DCMAKE_CXX_FLAGS:STRING=${assimp_cmake_cxx_flags}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DASSIMP_NO_EXPORT=ON
-DASSIMP_BUILD_ASSIMP_TOOLS=OFF
-DASSIMP_BUILD_TESTS=OFF
-DASSIMP_INSTALL_PDB=OFF
Expand Down
16 changes: 10 additions & 6 deletions cpp/open3d/io/file_format/FileASSIMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void LoadTextures(const std::string& filename,
if (mat->GetTextureCount(type) > 0) {
aiString path;
mat->GetTexture(type, 0, &path);

// If the texture is an embedded texture, use `GetEmbeddedTexture`.
if (auto texture = scene->GetEmbeddedTexture(path.C_Str())) {
if (texture->CheckFormat("png")) {
Expand All @@ -91,13 +92,10 @@ void LoadTextures(const std::string& filename,
if (image->HasData()) {
img = image;
}
}

else {
} else {
utility::LogWarning(
"This format of image is not supported.");
}

}
// Else, build the path to it.
else {
Expand All @@ -122,7 +120,12 @@ void LoadTextures(const std::string& filename,
}
};

texture_loader(aiTextureType_DIFFUSE, maps.albedo);
// Prefer BASE_COLOR texture as assimp now uses it for PBR workflows
if (mat->GetTextureCount(aiTextureType_BASE_COLOR) > 0) {
texture_loader(aiTextureType_BASE_COLOR, maps.albedo);
} else {
texture_loader(aiTextureType_DIFFUSE, maps.albedo);
}
texture_loader(aiTextureType_NORMALS, maps.normal);
// Assimp may place ambient occlusion texture in AMBIENT_OCCLUSION if
// format has AO support. Prefer that texture if it is preset. Otherwise,
Expand Down Expand Up @@ -414,7 +417,8 @@ bool ReadModelUsingAssimp(const std::string& filename,
mat->Get(AI_MATKEY_SHEEN, o3d_mat.base_reflectance);

mat->Get(AI_MATKEY_CLEARCOAT_THICKNESS, o3d_mat.base_clearcoat);
mat->Get(AI_MATKEY_CLEARCOAT_ROUGHNESS,
mat->Get(AI_MATKEY_CLEARCOAT_FACTOR, o3d_mat.base_clearcoat);
mat->Get(AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR,
o3d_mat.base_clearcoat_roughness);
mat->Get(AI_MATKEY_ANISOTROPY, o3d_mat.base_anisotropy);
aiString alpha_mode;
Expand Down
4 changes: 4 additions & 0 deletions cpp/open3d/t/io/ImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ bool WriteImageToPNG(const std::string &filename,
const geometry::Image &image,
int quality = kOpen3DImageIODefaultQuality);

bool WriteImageToPNGInMemory(std::vector<uint8_t> &output_buffer,
const geometry::Image &image,
int quality = kOpen3DImageIODefaultQuality);

bool ReadImageFromJPG(const std::string &filename, geometry::Image &image);

bool WriteImageToJPG(const std::string &filename,
Expand Down
1 change: 1 addition & 0 deletions cpp/open3d/t/io/TriangleMeshIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static const std::unordered_map<
const bool)>>
file_extension_to_trianglemesh_write_function{
{"npz", WriteTriangleMeshToNPZ},
{"glb", WriteTriangleMeshUsingASSIMP},
};

std::shared_ptr<geometry::TriangleMesh> CreateMeshFromFile(
Expand Down
9 changes: 9 additions & 0 deletions cpp/open3d/t/io/TriangleMeshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ bool ReadTriangleMeshFromNPZ(const std::string &filename,
geometry::TriangleMesh &mesh,
const open3d::io::ReadTriangleMeshOptions &params);

bool WriteTriangleMeshUsingASSIMP(const std::string &filename,
const geometry::TriangleMesh &mesh,
const bool write_ascii,
const bool compressed,
const bool write_vertex_normals,
const bool write_vertex_colors,
const bool write_triangle_uvs,
const bool print_progress);

bool WriteTriangleMeshToNPZ(const std::string &filename,
const geometry::TriangleMesh &mesh,
const bool write_ascii,
Expand Down
Loading
Loading