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

Fix loading of .obj mesh files #3772

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion crates/re_types/src/archetypes/asset3d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions crates/re_types/src/components/media_type_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ impl MediaType {
/// Tries to guess the media type of the file at `path` based on its extension.
#[inline]
pub fn guess_from_path(path: impl AsRef<std::path::Path>) -> Option<Self> {
let path = path.as_ref();

// `mime_guess` considers `.obj` to be a a tgif… but really it's way more likely to be an obj.
if path
.extension()
.and_then(|ext| ext.to_str().map(|s| s.to_lowercase()))
.as_deref()
== Some("obj")
{
return Some(Self::obj());
}

mime_guess::from_path(path)
.first_raw()
.map(ToOwned::to_owned)
Expand Down
2 changes: 1 addition & 1 deletion docs/code-examples/asset3d_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main(int argc, char* argv[]) {
std::vector<std::string> args(argv, argv + argc);

if (args.size() < 2) {
std::cerr << "Usage: " << args[0] << " <path_to_asset.[gltf|glb]>" << std::endl;
std::cerr << "Usage: " << args[0] << " <path_to_asset.[gltf|glb|obj]>" << std::endl;
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/code-examples/asset3d_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import rerun as rr

if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <path_to_asset.[gltf|glb]>")
print(f"Usage: {sys.argv[0]} <path_to_asset.[gltf|glb|obj]>")
sys.exit(1)

rr.init("rerun_example_asset3d_simple", spawn=True)
Expand Down
2 changes: 1 addition & 1 deletion docs/code-examples/asset3d_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rerun::external::anyhow;
fn main() -> anyhow::Result<()> {
let args = std::env::args().collect::<Vec<_>>();
let Some(path) = args.get(1) else {
anyhow::bail!("Usage: {} <path_to_asset.[gltf|glb]>", args[0]);
anyhow::bail!("Usage: {} <path_to_asset.[gltf|glb|obj]>", args[0]);
};

let (rec, storage) =
Expand Down
4 changes: 3 additions & 1 deletion rerun_cpp/src/rerun/archetypes/asset3d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rerun_cpp/src/rerun/archetypes/asset3d_ext.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <string>
Expand All @@ -17,6 +18,7 @@ namespace rerun {
) {
std::filesystem::path file_path(path);
std::string ext = file_path.extension().string();
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);

if (ext == ".glb") {
return rerun::components::MediaType::glb();
Expand Down
2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/asset3d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/asset3d_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def guess_media_type(path: str) -> MediaType | None:

from ..components import MediaType

ext = Path(path).suffix
ext = Path(path).suffix.lower()
if ext == ".glb":
return MediaType.GLB
elif ext == ".gltf":
Expand Down
Loading