le717 / LDR-Importer

Import LDraw .dat and .ldr models into Blender 3D
GNU General Public License v2.0
61 stars 19 forks source link

don't repeat meshes - use Linked Duplicates instead #43

Open MinnieTheMoocher opened 10 years ago

MinnieTheMoocher commented 10 years ago

Improvement suggestion:

As far as I can see, currently each and every single LDRAW file gets imported into a Blender scene without creating references.

For example, if a primitive 1-4cyli.dat is used, it is repeated in each and every instance as a separate mesh.

I think that Blender supports re-use of objects. I cannot really imagine that it does not.

My suggestion is to search for that feature and modify the loading script to not repeat and repeat and repeat each mesh, but instead only load it once, and then in all places where it is used, make a reference to that one instance, just applying transformation matrix, i.e., rotation and translation and coloring.

This should dramatically reduce the resulting blender scene size, rendering time, importing time etc.

I cannot really imagine that Blender does not have such a feature...

Also: the already loaded files should be cached inside the importing script. Currently it seems to me that a file like 1-4cyli.dat gets repeatedly parsed each time it is used. That's not necessary. It should get read just once, and its parsed contents saved in some python object. When the next occurrence of it is met, and it is already parsed, then the parsed version will be used. This should save a LOT of loading time.

JoshTheDerf commented 10 years ago

Blender doesn't have such a feature, other than duplicating objects, afaik. Materials behave like this though, and should already be handled in such a fashion.

le717 commented 10 years ago

/cc @rioforce You know how this could work.

MinnieTheMoocher commented 10 years ago

I think the feature exists and is called "Linked Duplicate" http://wiki.blender.org/index.php/Doc:2.4/Manual/Modeling/Objects/Duplication

This script seems to use it: https://sites.google.com/site/impiaaa/blenderldrawimporter

JoshTheDerf commented 10 years ago

A linked duplicate is not necessarily a good option, supposing a user wants to directly modify or simulate parts of his/her model. It would be good for things like studs, but the linking would be restricted to per-part.

rioforce commented 10 years ago

It is definitely possible in code, you'd just have to change the LDraw file parser to detect if a brick was imported by the name of the model, duplicate it (either Ctrl+D, which doesn't link, or Alt+D, which does link) and move it the the proper location. The problem is, you'd have to read the LDraw file to determine the location of the brick without having it import it again. This would save loading times and also make the script expandable.

le717 commented 10 years ago

We actually have two issues here: an option to reuse mesh and an option to link alike mesh. The former should happen and would speed everything up, but the latter would come later. As Tribex accurately said, this would be a part-by-part bases. Only alike bricks would be linked. A 2x2 brick would not be linked to,say, a 4x6 plate.

Here's the Blender 2.6 (instead of 2.4) documentation. http://wiki.blender.org/index.php/Doc:2.6/Manual/Modeling/Objects/Duplication

Moved to milestone v1.3, as linked mesh has been requested before.

MinnieTheMoocher commented 10 years ago

i was just talking about not having multiple meshes of 2x4 bricks. instead, the 2x4 brick mesh should be present only once, and then the other instances of it in the model should refer to that mesh.

and i was not talking of the manual editing process later, but of the importing step.

there, each brick file should only be read once, and its mesh be established only once, and all other copies of it re-use that 1 mesh.

the implementation would be very simple as well: when importing a model, every part should be put in a dictionary. when you later encounter it again, you check if it is already in the dictionary. if yes, re-use that mesh. if no, load the mesh and put it into the dictionary. a simple, quite straightforward implementation, which will dramatically reduce scene complexity, importing time and memory usage.

rioforce commented 10 years ago

I wasn't saying afterwards, I was saying while it imports.

  1. Script imports 2x4
  2. Script sees another 2x4 needs importing
  3. Script finds name of original imported 2x4 and selects 2x4 model
  4. Script Duplicates (or duplicates linked, depending on what it is told to do) 2x4
  5. Script moves 2x4 to proper location.
MinnieTheMoocher commented 10 years ago

yep, exactly

rioforce commented 9 years ago

Just adding a method that may work:

  1. Read entire file
  2. Find how many 2x4s need importing
  3. Import x number of 2x4s in proper locations
MinnieTheMoocher commented 9 years ago

No, that's IMHO a weird workaround implementation, and its implementation is as expensive (if not: more expensive) than the really desired one.

The desired one is very, very, very, very simple, as described in my post above 14 months ago.

le717 commented 8 years ago

Linking #71 as it contains info that can be used here.