gpvigano/AsImpL

Load meshes containing multiple materials

X2Stone opened this issue · 4 comments

Hi,
First of all, thank you so much for your awesome work ! It rocks !
I would like to have some feedback concerning my problem using it :
I need to load an OBJ file containing a mesh that have multiple materials on it (assigned to different faces of the mesh). The OBJ is perfectly imported into Unity via the Editor (it keeps the mesh as is, 1 shape with 3 materials on it) but when I load my OBJ file with AsImpl, it splits the mesh into sub-meshes (childs) that have only 1 material each.
I really need to keep single meshes as single meshes with their several materials, is there a way to modify your plugin so that it keeps the OBJ as it is ?
Thanks a lot for your answer.

The implementation of this feature is not trivial, it requires important changes to the object building process. I'm working on it...

I just committed a new version supporting sub-meshes for each material.

I added an option to split meshes by materials (splitByMaterial, default = false) that can be changed both in inspector and in the AsImpL asset import dialog.

Important: now sub-meshes are enabled by default, if you need to keep the old loading mode (e.g. you need to access object parts like in the previous version) you need to enable the Split By Material option.
For older Unity versions without the support for 32 bit indices the building process falls back to the old mode (split by material).

I made a massive refactoring of the object building process.

This is a summary of the call hierarchy in ObjectBuilder:

  • BuildObjectAsync
    • BuildNextObject
      • SetUpNewObject
      • BuildCurrentPart/BuildCurrentMesh
        (according to split by material option)

split by material option (old implementation):

  • BuildCurrentPart
    • ImportSubObject
      • BuildMesh
        • CreateMesh
        • GetLibraryMaterial
        • UpdateRendererMaterials
        • BuildSubMesh
        • FinalizeMesh
      • FinalizeObject

default (new implementation):

  • BuildCurrentMesh
    • CreateMesh
    • GetLibraryMaterial
    • BuildSubMesh
    • UpdateRendererMaterials
    • FinalizeMesh
    • FinalizeObject

Wahouuu thank you so much for this update, i’m conscious that it hasn’t been easy to modify your plugin to take into account my request, really appreciate it !
Can’t wait to test it !
You rock man !

You're welcome. If you find some problem we can reopen this issue.