Elegant way to turn a collection instance to a mesh?

Hello,
I’m currently about to create some Add-on that is supposed to use collections to turn them in some single meshes.
I’m currently at a stage where I would have to traverse through all the objects that are part of the collection (and sub collections / instances recursively), apply all modifiers and scales, keep track of materials, UVs and so on then use the join operator and such to join them together.

To me it feels like having to manage all this manually in python is overkill (and could also become potentially slow for larger scenes) but since collection instance to some extent behave like single meshes I’m wondering if I overlooked some method to exploit that fact and extract a single new mesh just from the information a collection instance got or if there is any other more elegant route than the one I’m just about to follow.

Greetings,
Daniel

1 Like

I have nothing to offer in the way of help, all I can say is that as a user, I’d appreciate this addon.

Collection instances are powerful but annoying to use and unfinished in my opinion. You should be able to use them parametrically in modeling.

Is the plan to update the meshes in real time? For level design I’d appreciate an addon that could take a collection instance and make a mesh I can use on a curve or something and any changes made to the collection propagate to the mesh.

Since I’m currently experimenting and discovering what the API offers me I cannot predict what I will add for sure but you might want to check out the smart join addon for blender 2.7, I want to kind of rebuild the functionality but instead of relying on parented object’s I want to make full use of the collection system for 2.8.

I made some progress and I figured out that using the operators seems to save me from dealing with manually traversing objects and such but with the drawback that it is no understatement that it is quite a mystery how to setup the context correctly for that as the warning shows in the documentation. I hope Epic’s money for example can also be used to for example provide better interfaces to functions that are actually already implemented as user operators.

First quick and dirty test script by no means feature complete:

One click is not the worst workflow, but obviously the ideal is no further input from the artist once he has made a bunch of instances.

I assume that you are already already using the make_duplicates_real operator, but are you using the ‘use_base_parent’ property? If so, you know what the instance’s name was- so you also know the name of the empty that serves as a parent once you complete this operation. From there it’s just a matter of getting all of the mesh objects linked to it and doing the rest.

Also, you might not be aware that it’s not necessary to traversing the modifier stack if all you want to do is apply everything. The convert operator already does this (yes, it converts a mesh into a mesh- i found it odd when I found out as well).

I agree, it would be super handy if they had a “flatten instance to single mesh” operator (in Modo we called this “freeze mesh”, add that to the python python papercuts thread, or make a feature request at RCS and you’ll have my upvote.

1 Like

Thanks, that’s more or less what I ended up with, just felt a bit messy at the first place having to deal with selections / using context overrides for this. But for now it turned out to work quite good.

I sketched similar, complementary proposals in a new tread, but “at a more radical level”

I came up with some quite elaborated addon for this now which just needs some final tweaks to make to make it more useful (especially in my workflows at least), which is mainly UI / usability stuff until I release it.

In the meanwhile I still have the impression that I’m not aware of some more elegant way that might be hidden in the depths of blender’s data structures to get the evaluated mesh that a collection instance represents at the current frame.

I got this impression since it is just a few lines for to convert a single object using the depsgraph evaluation routines to get the evaluated mesh.

Therefore I would appreciate any pointer if something like this exists already or some feedback that this indeed does not exist and must be manually done in python while I continue working on the improvisations until I release it.

I found operator “Make instances real”.

1 Like

Unfortunately, CTRL+A/Make Instances Real doesn’t apply all non-destructive transformations to the resulting meshes.

When the original mesh has dependencies on its original transformation— E.G. when it has modifiers that depend on global space or on external objects in the global space— then the result fails as the object instances will have moved.

It also requires manual recursion via alternation between CTRL+A/Make Instances Real and CTRL+U/Make Single User, which is messy.

Ideally, someone should submit a patch to developer.blender.org that lets Visual Geometry to Mesh/Convert to Mesh work with Empty objects.

For now, the bundled .obj exporter seems to do a good job of applying all collection data congruously. You might also try reading its code to extract an independent workaround or figure out a fix for CTRL+A/ALT+C.

1 Like

Did you ever complete this addon?

I’ve spent months dreaming about something like this assuming I would be able to put modifiers on the final merged mesh it would be a dream come true!

in 2.92 and up, you can do this with the geometry nodes modifier without the need for an add-on

1 Like

I use it internally already and actually also just some bureaucracy on finding ways how to optionally monetarize it stopped me from releasing it for now. Maybe I will reconsider my choice and just upload it to my github if there’s enough interest.

On the other hand I also expected that the blender team will come up with some better internal ways to do what it does. Therefore I’m currently planning to redesign it for example to just automate the process using the geometry nodes that was described already but with some more comfort options for setting it up.

I will check this out as soon as possible but this might not be within the next very busy weeks.

the geometry node solution however losses all Vertex color, vertex group, weight, and UV data in the process which makes it hard to use in production. It is a known issue however as of yet it still has no one who has taken it up to solve =/

1 Like

i started working on a script to solve this today, and for the most part it works great but it does has one major problem left to solve- it puts Blender’s depsgraph into a state where a crash is all but inevitable. I posted a thread over on blenderartists if somebody wants to take a look and help figure out what’s causing the crash so I can get it cleaned up for everybody to use:

edit: actually I figured it out. feel free to use the code in the blenderartists thread for all your instance-to-mesh needs :slight_smile:

2 Likes

Isn’t a simple:
Object - Apply - Make Instances Real (on selected collections, can choose keep parent and hierarchy) and then
Object - Relations - Make Single User - Object & Data & Materials (or any wanted option) to make them real real independent objects
do the job?

No, otherwise we wouldn’t still be talking about this after 3 years :slight_smile: