OBJ mesh split issue with some applications

Sipe
2013-02-15
2013-06-03
  • Sipe
    Sipe
    2013-02-15

    I'm having difficulty with OBJ file format. Seems that some of the DCC applications generates massive list of different meshes with same material index. 3DSMax is really bad example of this, It creates new mesh every time you define material ID set for selection.

    Example of scattered faces:

    g Building
    usemtl Wall
    s 4
    f 3838/4116/2302 3839/4117/2302 3840/4118/2302 3841/4119/2303
    usemtl Windows
    s 2
    f 3842/4120/2304 3843/4121/2305 3844/4122/2305 3845/4123/2306
    usemtl Wall
    s 1
    f 3846/4124/2307 3847/4125/2307 3848/4126/2308 3849/4127/2308
    s 4
    f 3850/4128/2309 3851/4129/2309 3852/4130/2309 3853/4131/2309
    s 1
    f 3854/4132/2310 3855/4133/2310 3856/4134/2308 3857/4135/2308
    s 2
    f 3858/4136/2307 3859/4137/2307 3860/4138/2308 3861/4139/2308
    f 3862/4140/2308 3863/4141/2308 3864/4142/2307 3865/4143/2307
    s 1
    f 3866/4144/2311 3867/4145/2311 3868/4146/2312 3869/4147/2312
    f 3870/4148/2313 3871/4149/2313 3872/4150/2314 3873/4151/2314
    f 3874/4152/2311 3875/4153/2311 3876/4154/2312 3877/4155/2312
    f 3878/4156/2313 3879/4157/2313 3880/4158/2314 3881/4159/2314
    s 2
    f 3879/4157/2311 3878/4156/2311 3882/4160/2312 3883/4161/2312
    f 3867/4145/2313 3866/4144/2313 3884/4162/2314 3885/4163/2314
    f 3886/4164/2313 3887/4165/2313 3888/4166/2314 3889/4167/2314
    f 3871/4149/2311 3870/4148/2311 3890/4168/2312 3891/4169/2312
    s 1
    f 3846/4124/2307 3869/4147/2312 3868/4146/2312 3847/4125/2307
    f 3848/4126/2308 3873/4151/2314 3872/4150/2314 3849/4127/2308
    f 3854/4132/2310 3877/4155/2312 3876/4154/2312 3855/4133/2310
    f 3856/4134/2308 3881/4159/2314 3880/4158/2314 3857/4135/2308
    s 2
    f 3858/4136/2307 3883/4161/2312 3882/4160/2312 3859/4137/2307
    f 3860/4138/2308 3885/4163/2314 3884/4162/2314 3861/4139/2308
    f 3862/4140/2308 3889/4167/2314 3888/4166/2314 3863/4141/2308
    f 3864/4142/2307 3891/4169/2312 3890/4168/2312 3865/4143/2307
    usemtl Windows
    f 3843/4170/2305 3892/4171/2315 3893/4172/2316 3844/4173/2305
    s 1
    f 3894/4174/2317 3895/4175/2318 3896/4176/2317 3897/4177/2317
    f 3896/4176/2317 3898/4178/2318 3897/4177/2317
    f 3899/4179/2318 3894/4174/2317 3897/4177/2317

    I'm using these flags during import. (I don't use remove redudant materials because otherwise asset importer will create joint materials) and it doesn't matter if its on or off, asset importer create separate meshes.

    aiProcess_FlipWindingOrder |  \
    aiProcess_MakeLeftHanded |  \
    aiProcess_CalcTangentSpace |  \
    aiProcess_GenSmoothNormals |  \
    aiProcess_JoinIdenticalVertices |  \
    aiProcess_ImproveCacheLocality |  \
    aiProcess_LimitBoneWeights |  \
    aiProcess_SplitLargeMeshes |  \
    aiProcess_Triangulate |  \
    aiProcess_GenUVCoords                   |  \
    aiProcess_SortByPType                   |  \
    aiProcess_FindDegenerates               |  \
    aiProcess_FindInvalidData               |  \
    aiProcess_FindInstances                 |  \
    aiProcess_ValidateDataStructure         |  \
    aiProcess_OptimizeMeshes                |  \
    aiProcess_FlipUVs |  \

    I have created workaround for these which will merge separate meshes but I was wondering if this is how OBJ and asset importer should work or is it DCC related issue?

    Thanks

     
  • Kim Kulling
    Kim Kulling
    2013-02-15

    Taking a first look onto the file and it seems that DCC is using the s-statement to define smooth-shading groups. That shuld be the reason for this.

    Kimmi

     
  • Sipe
    Sipe
    2013-02-16

    Yeah this seems that it's DCC issue. It produces like hundreds of different usemtl statements and the AI will pick those up as separate meshes. I have big building with 8 different materials and AI will import it as ~380 different small mesh parts.

    3DSmax OBJ exporter doesn't provide that much control how mesh will be exported I don't want to start writing own exporter for it :)
    http://docs.autodesk.com/3DSMAX/15/ENU/3ds-Max-Help/index.html?url=files/GUID-437051A1-983B-4B6A-80C4-D2FA43B7393D.htm,topicNumber=d30e521090,hash=GUID-0BC2E07F-706B-46E0-A455-81D96B8D86EC

    The only workaround is to loop all of the meshes and gather geometry by material index and merge manually them during importing. I haven't yet check that will it produce extra vertices because of the massive mesh count. If it does, I need to manually remove redundant vertices also. I was hoping that there would be automatic workaround for this.

     
  • To my knowledge aiProcess_OptimizeGraph und _OptimizeMeshes do just that. It might be that they stop at meshes that have a unique name, though.