kvark / obj

Basic Wavefront OBJ loader
Apache License 2.0
29 stars 12 forks source link

Question: how to avoid duplicating material data if multiple objects/groups link to the same material? #14

Closed azymohliad closed 4 years ago

azymohliad commented 4 years ago

Greetings! So as I understand, the workflow to load materials data is: you go through the list of objects, then through the list of groups in the object, and if the group has the material - you load its data (textures, colours, etc). So if multiple groups link to the same material you end up duplicating all its data including textures, is it correct?

Is it possible to avoid this duplication?

For example tobj stores materials in a separate Vec and each mesh (group) than just contains material index as Option<usize>, so you can go through this flat list of materials, load all their textures etc, and then if multiple meshes link to the same material you can reuse their loaded data. tobj doesn't look as complete as this crate though.

kvark commented 4 years ago

Looks like this is addressed by #15

elrnv commented 4 years ago

In #15, the material libraries are loaded into a separate vector material_libs and these materials are then referenced through Arcs in each group.

kvark commented 4 years ago

Fixed by #15

azymohliad commented 4 years ago

Great! Thanks!