1. #1
    New Member Follow User Gallery
    Join Date
    Mar 2019
    Posts
    11

    Default how to load multiple mdd files to layers for different subtools

    for example, I have a subtools contain three meshes, and a folder have obj or mdd for each of them, how can I load them as a layer to matched mesh? I found a similar tool - ImportLayers, but it will show error msg if you select the incompatible file.

    thanks,

  2. #2
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    The straightforward way would be to match the file names to the subtools. If you can't do that then you would need to compare the number of vertices, though note that if there are subtools with the same number of vertices then there's no way to be sure the right file is loaded.

    With OBJ, if it is from ZBrush then the number of vertices is given in a comment at the beginning of the file but this isn't standard and OBJs from elsewhere would need to be parsed or imported separately to get the vertex count.

    MDD files are simpler and the vertex count could be read from the start of the file.

  3. #3
    New Member Follow User Gallery
    Join Date
    Mar 2019
    Posts
    11

    Default

    got it, so where I can find the api for compare the vertex count ?

  4. #4
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    The zscript command reference is here:
    http://docs.pixologic.com/user-guide...and-reference/

    Here's a way to do both types of file. But note that the OBJ example will only work with OBJs exported from ZBrush. To cope with other files you would need to either load them into ZBrush separately so you could check the vertex count that way or parse them using a dynamic library which you called from your zscript code.

    [IButton,CompareVertCountMDD,"Check if the MDD file verts count is the same as selected mesh",
    [VarSet,fileVerts,0]
    [VarSet,meshVerts,0]
    //load the file 5th - 8th bytes into memory
    [MemCreateFromFile,MC_VertTestMem,"boxing.mdd",4,4]
    [MemCreate,MC_VertsLEMem,4,0]
    //convert big endian to little endian:
    [MemCopy,MC_VertTestMem,3,MC_VertsLEMem,0]
    [MemCopy,MC_VertTestMem,2,MC_VertsLEMem,1]
    [MemCopy,MC_VertTestMem,1,MC_VertsLEMem,2]
    [MemCopy,MC_VertTestMem,0,MC_VertsLEMem,3]
    //get the file verts number - unsigned long
    [MemRead,MC_VertsLEMem,fileVerts,6,0]
    //done with memblocks - delete
    [MemDelete,MC_VertTestMem]
    [MemDelete,MC_VertsLEMem]
    //get the mesh verts number:
    [Mesh3DGet,0,,,meshVerts]
    [If,(fileVerts == meshVerts),
    //OK they match
    [Note,"OK, the verts number is the same"]
    ,//else they are different
    [Note,"WARNING! the verts number is different"]
    ]
    ]

    [IButton,CompareVertCountOBJ,"Check if the OBJ file verts count is the same as selected mesh",
    [VarSet,fileVerts,0]
    [VarSet,meshVerts,0]
    [VarSet,vertsStr,""]
    [VarSet,offset,0]
    [VarSet,bytes,0]
    //load first part of OBJ file into memory
    [MemCreateFromFile,MC_VertTestMem,"boxing.obj",0,512]
    //check the comment lines for ZBrush vertex count entry
    [Loop,5,
    [VarSet,bytes,[MemReadString,MC_VertTestMem,vertsStr,offset,1]]
    [VarAdd,offset,bytes]
    [If,([StrFind,"#Vertex Count ",vertsStr]==0),//if entry is there
    [VarSet,vertsStr,[StrExtract,vertsStr,14,256]]
    [VarSet,fileVerts,vertsStr]
    [LoopExit]
    ]
    ]
    //get the mesh verts number:
    [Mesh3DGet,0,,,meshVerts]
    [If,(fileVerts == meshVerts),
    //OK they match
    [Note,"OK, the verts number is the same"]
    ,//else they are different
    [Note,"WARNING! the verts number is different"]
    ]
    ]

  5. #5
    New Member Follow User Gallery
    Join Date
    Mar 2019
    Posts
    11

    Default

    thanks marcus, you are my hero again.
    I uploaded the code and video here, hope you will be interested.

  6. #6
    Moderator Follow User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    11,462

    Default

    Looks great! Thanks for sharing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •