demoCombineMeshes.py

demoCombineMeshes.py
1 '''
2 Demonstrates combining the mesh of two scene nodes
3 '''
4 from PySide2 import QtWidgets
5 import MaxPlus
6 
7 def GetObjectMesh(node):
8  node.Convert(MaxPlus.ClassIds.TriMeshGeometry)
9  object_state = node.EvalWorldState()
10  obj_original = object_state.Getobj()
11  tri_obj = MaxPlus.TriObject._CastFrom(obj_original)
12  tri_mesh = tri_obj.GetMesh()
13  return tri_mesh
14 
15 def CombineNodes():
17  msg = "Please select 2 nodes to combine."
18  print msg
19  show_alert(msg)
20  else:
23  a = GetObjectMesh(node1)
24  b = GetObjectMesh(node2)
25  # create a new, empty mesh for the combined meshes:
27  new_node = MaxPlus.Factory.CreateNode(new_obj)
28  new_mesh=new_obj.GetMesh()
29  # combine a and b into the new mesh:
30  MaxPlus.Mesh.CombineMeshes(new_mesh,a,b)
31 
32 def show_alert(message):
33  msgBox = QtWidgets.QMessageBox()
34  msgBox.setText(message)
35  msgBox.exec_()
36 
37 def main():
38  w = QtWidgets.QDialog(MaxPlus.GetQMaxMainWindow())
39  w.resize(250, 100)
40  w.setWindowTitle('Combine 2 Nodes')
41 
42  main_layout = QtWidgets.QVBoxLayout()
43  label = QtWidgets.QLabel("Combine 2 Nodes")
44  main_layout.addWidget(label)
45 
46  combine_btn = QtWidgets.QPushButton("Combine")
47  combine_btn.clicked.connect(CombineNodes)
48  main_layout.addWidget(combine_btn)
49 
50  w.setLayout(main_layout)
51  w.show()
52 
53 
54 if __name__ == '__main__':
55  main()