unlimitedbacon / stl-thumb

Thumbnail generator for STL files
MIT License
1.09k stars 93 forks source link

Support for OBJ files #31

Closed csicar closed 1 year ago

csicar commented 3 years ago

This PR adds support for rendering .obj files in stl-thumb.

I think it would be nice to have the same aesthetic of the thumbnails for obj files as well.

unlimitedbacon commented 3 years ago

This looks like an excellent contribution, although I have not tested it yet. Is there no existing solution like this for thumbnailing OBJ files?

How is the performance compared to loading STL files? Have you investigated using the material data in OBJ files to render objects with different colors?

csicar commented 3 years ago

Here's the results I get on my machine:

$ cargo bench
....
cube stl                time:   [35.713 ms 36.381 ms 37.233 ms]
                        change: [-7.0127% -4.5887% -2.0766%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high severe

benchy stl              time:   [130.03 ms 131.95 ms 133.17 ms]
                        change: [-2.9838% -1.1484% +0.4709%] (p = 0.25 > 0.05)
                        No change in performance detected.

cube obj                time:   [78.457 ms 79.287 ms 80.003 ms]
                        change: [-2.0402% -0.9227% +0.2899%] (p = 0.16 > 0.05)
                        No change in performance detected.

benchy obj              time:   [399.68 ms 401.47 ms 405.12 ms]
                        change: [-1.8699% +0.2505% +2.6128%] (p = 0.84 > 0.05)
                        No change in performance detected.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high mild
$ lscpu | grep Modellname
Modellname:                      Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
$ ls -hl test_data
insgesamt 29M
-rw-r--r-- 1 csicar users  18M 22. Dez 00:21 3DBenchy.obj
-rw-r--r-- 1 csicar users  11M 17. Dez 01:50 3DBenchy.stl
-rw-r--r-- 1 csicar users  763 22. Dez 00:18 cube.obj
-rw-r--r-- 1 csicar users  684 22. Dez 00:18 cube.stl

not awesome, but I think it's fine. If you have any idea on how to improve the performance, let me know.

I haven't yet looked into using material files. Though it should be relatively easy, because tobj offers support for it

unlimitedbacon commented 3 years ago

Yah, I think that's acceptable. Are you going to handle the thumbnailer file as well?

csicar commented 3 years ago

Yes, i'll give it a try, though I'm don't know a lot about thumbnailer files

csicar commented 3 years ago

I found obj files here https://www.iana.org/assignments/media-types/model/obj , but I'm not sure, if I adapted the stl rules correctly..

unlimitedbacon commented 3 years ago

Sorry for taking so long to get around to this. This seems like a nice addition and I'd like to merge it. There are a few things I think need consideration first.

  1. We'll have to figure out what to do in stl-thumb-mime.xml. I looked into it and I was very surprised to learn that there is no standard mimetype for .obj files. Looks like you copied the definition for .stl files. The way you have it, it is still trying to match against the headers in an .stl, which is obviously not going to work. I think the best thing to do would be to copy Cura. They use the type application/prs.wavefront-obj. They have a definition in cura.sharedmimeinfo.
  2. It would be really nice to improve the speed and memory usage. I was playing around with very large (~300 mb) .obj files, and they take several seconds to render. I don't see anything obviously slow about your code, though. The only thing I can think to do would be to experiment with other .obj loading libraries. I found obj and obj-rs.
csicar commented 3 years ago

Hey, no worries :)

  1. Great idea! I adapted the mimetype rule from cura.
  2. Ok. I'll do further tests. Maybe I can find the bottleneck. I think I acutally initially started with obj-rs.
VerscheldeAlynne commented 2 years ago

has this been merged with main branch yet?

unlimitedbacon commented 2 years ago

Not yet. Was waiting on some investigation into the performance difference.

daadu commented 2 years ago

I am waiting for this PR? how can I get access to the binary (amd64) to get access to this experimental feature. I dont have Rust setup. Just a user of this wonderful proj.

daadu commented 2 years ago

I am waiting for this PR? how can I get access to the binary (amd64) to get access to this experimental feature. I dont have Rust setup. Just a user of this wonderful proj.

Went ahead and built it - if anyone wants basic OBJ support at least as CLI - can check - https://github.com/daadu/stl-thumb/releases/tag/v0.5.0%2Bobjsupport.0

This was my first time writing (mostly copying from this PR and adjusting) rust - so point me if there is any apparent mistake.

csicar commented 2 years ago

yeah, so I rebased & updated the PR now. Performance is still no better. I think this may also be because of also needing to load the normal data, but not sure..

unlimitedbacon commented 1 year ago

Sorry I've been so slow to get this in. I've had a lot going on lately. Will roll out OBJ support in v0.6.0.