neverhood311 / Stop-motion-OBJ

A Blender add-on for importing a sequence of OBJ meshes as frames
GNU General Public License v3.0
681 stars 52 forks source link

Request: multi-object obj import #182

Open hamoid opened 11 months ago

hamoid commented 11 months ago

Is your feature request related to a problem? Please describe. The issue is described at https://blenderartists.org/t/stop-motion-obj-obj-stl-ply-sequence-importer-v2-1-1/670105/144

Basically, I would like to be able to apply transformations separately to the objects imported in an obj file. Currently they are grouped together and applying something like extrusion affects all o elements in the file.

Describe the solution you'd like I would like that imported objects are not grouped (as an option).

Describe alternatives you've considered The suggested alternative is for me to export one sequence per object, then import all the sequences. My only concern is that it is going to be a lot of files on disk, but I guess it should work.

Additional context Here the test files I have been using. obj-anim-frames.zip

It's an animation of two objects rotating, each with a different material (and different colors).

screen01 screen02

When I Edit -> Extrude, fill (press F) and bevel, both shapes are rendered with the same color. I do not know enough Blender to know where this issue comes from.

screen03

neverhood311 commented 11 months ago

There are two parts to your post:

  1. Multi-object sequences

and

  1. Issues with multiple materials

Regarding 1, it's been requested before, but I've not had the bandwidth to work on it. Regarding 2, I inspected some of your meshes in a text editor and noticed that you're defining the material before you define the object, like this:

usemtl Foo1
o obj1
# lists of vertices and lines

usemtl Foo2
o obj2
# more lists of vertices and lines

If you import a single .obj file using the built-in importer, it assigns both materials to obj1 and no material to obj2

If possible, switch the order of the usemtl and o commands, like this:

o obj1
usemtl Foo1
# lists of vertices and lines

o obj2
usemtl Foo2
# more lists of vertices and lines

As far as I can tell, Blender's obj importer expects to have an object defined before you can set its material. I tested this out and it works (the square and the circle have different materials) when you import a single .obj file. This still doesn't help you with multi-object sequences, unfortunately, since the obj importer seems to be applying the material to all objects in the .obj file. This might also have to do with the fact that you're using 2D lines instead of 3D faces; I've tested multi-material .obj files in the past and they've worked fine.

hamoid commented 11 months ago

Thank you very much for your help! :-)

I noticed I was also calling mtllib in the .mtl file instead of the .obj file.

I fixed that and thanks to your tips now loading multiple shapes from disk is working :tada:

Now to do some Python scripting in Blender :-)