Results 1 to 5 of 5

Thread: [Python] MaxPlus: how to combine two meshes

  1. #1

    Default [Python] MaxPlus: how to combine two meshes



    I'm making a tool for the optimization for scenes with large numbers of objects - I'm using Python in 3ds Max 2016, and MaxPlus specifically. Now there's a problem i've run into that has me running into a wall: I would like to avoid going between Python and MaxScript all the time to execute a mesh combine operation ( never mind the difficulty in passing object references between the two ), and so I am trying to perform the merge operation in Python.
    Now, for this purpose, the only available method I've found whose name seems to describe it doing what I need, is Mesh.CombineMeshes, as documented here: http://docs.autodesk.com/3DSMAX/16/E...Number=d30e920

    Based on the _extremely_ limited documentation, I think this method needs at minimum three arguments, all three of the Mesh Class. My approach so far is the following:

    Make an empty geometry object: ( code lifted directly from the API documentation )

    Code:
    geom = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.TriMeshGeometry)
    tri = MaxPlus.TriObject._CastFrom(geom)
    mesh = tri.GetMesh()
    get meshes from the objects I want to merge: ( note: the two lines with mesh1 and mesh2 are being executed in a for loop that loops over the array "self.objects[1:]" - meaning all objects should be merged with the first object in that array.

    Code:
    def getObjectMesh(self,obj):
        geom = obj.GetObject().AsTriObject()
        mesh = geom.GetMesh()
        return mesh
    
    mesh1 = self.getObjectMesh(self.objects[0])
    mesh2 = self.getObjectMesh(obj)
    And lastly, perform the merge: ( or try to )

    Code:
    mesh.CombineMeshes(mesh,mesh1,mesh2)
    When executing this code, max gives me the following error:

    Code:
    File "C:\Program Files\Autodesk\3ds Max 2016\MaxPlus.py", line 15115, in CombineMeshes
        return _MaxPlus.Mesh_CombineMeshes(*args)
    RuntimeError: Unknown MaxPlus Exception
    Sadly, when you go look in the given file at that line, the line is just: ( this is literally the entire function )

    Code:
    return _MaxPlus.Mesh_CombineMeshes(*args)
    Does anyone know what I'm doing wrong / how to use the method? Would be much appreciated :)

  2. #2

    Default

    I got the same problem with MaxPlus. But pymxs works fine, try this:


    Code:
    import pymxs
    
    mesh_01 = pymxs.runtime.getNodeByName('box_01')
    mesh_02 = pymxs.runtime.getNodeByName('box_02')
    mesh_01.attach(mesh_02, mesh_01)

  3. #3

    Default .

    Ow, I also need this in MaxPlus. :(
    Last edited by vonBerg; 08-17-2016 at 12:45 AM.

  4. #4

    Default fixed

    Never mind! :)

    After 6 hours of research I finally found it.! yeaah.
    I found the function hidden in the dark and scary Autodesk SDK docs: http://help.autodesk.com/view/3DSMAX...f_mesh_8h_html

    Code:
    Parameters
    mesh	The result of the combine operation is stored here. mesh = mesh1+mesh2.
    mesh1	The first operand.
    mesh2	The second operand.
    tm1	If non-NULL then the points of mesh1 will transformed by this matrix before the boolean operation.
    tm2	If non-NULL then the points of mesh2 will transformed by this matrix before the boolean operation.
    whichInv	If 0, the resulting mesh will be transformed by Inverse(tm1). If 1, the resulting mesh will be transformed by Inverse(tm2). If -1, the mesh will not be transformed back.

    Code:
    EDITMESH_CLASS_ID = MaxPlus.Class_ID(3830386867L, 0L)
    
    def createResultMesh(self):
        geom = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.TriMeshGeometry)
        tri = MaxPlus.TriObject._CastFrom(geom)
        node = MaxPlus.Factory.CreateNode(tri)
        return node
    
    def getMesh(iNode):
        meshObj = iNode.GetObject().AsTriObject().GetMesh()
        return meshObj
    
    def main():
        sel = MaxPlus.SelectionManager
    
        # get the source iNodes, make sure they are editable meshes!
        sourceNode1 = sel.GetNode(0)
        sourceNode2 = sel.GetNode(1)
    
        # get the mesh from the source node
        mesh1 = getMesh(sourceNode1)
        mesh2 = getMesh(sourceNode2)
    
        # create the resultMesh
        meshResult = getMesh(createResultMesh())
    
        # get the transform matrix.
        mesh1TM = sel.GetNode(0).GetLocalTM()
        mesh2TM = sel.GetNode(1).GetLocalTM()
    
        #CombineMeshes ( meshResult, mesh1, mesh2, mesh1TM, mesh2TM, whichInv)
        MaxPlus.Mesh.CombineMeshes( meshResult, mesh1, mesh2, mesh1TM, mesh2TM, 0 )
    
    
    main()
    Last edited by vonBerg; 08-17-2016 at 01:12 PM.

  5. #5
    integer
    Join Date
    Mar 2009
    Location
    Japan, Tokyo
    Posts
    49

    Default

    oh man, awesome thread... that help me a lot >___<!!! .....

Bookmarks

Posting Permissions

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