def buildWiperMesh(self, p1, p2): """ Build the wiper mesh Parameters ---------- p1 : Point3 the world position of the first dummy placed on the exterior part of the wiper p2 : Point3 the world position of the second dummy placed on the exterior part of the wiper """ animationLength = self.animInEndFrame - self.animInStartFrame + 1 projectMeshVertices = [] projectMeshFaces = [] vColors = [rt.Point3(0, 0, 0) for i in range(animationLength * 2)] vert_count = 0 if rt.DEBUG_MODE: print( "------------------------------------------------------------------" ) #fill projectMeshVertices with the exterior points of the wiper for each frame f = self.animInStartFrame while f <= self.animInEndFrame: with at(f): projectMeshVertices.append(p1.transform.position) projectMeshVertices.append(p2.transform.position) f += 1 # fill the vertexColors array during animation IN vIndex = 0 f = self.animInStartFrame while f <= self.animInEndFrame: with at(f): self.setColorByFrame(f, vColors[vIndex]) self.setColorByFrame(f, vColors[vIndex + 1]) f += 1 vIndex += 2 # fill the vertexColors array during animation OUT vIndex = 0 f = self.animOutEndFrame while f >= self.animOutStartFrame: with at(f): self.setColorByFrame(f, vColors[vIndex]) self.setColorByFrame(f, vColors[vIndex + 1]) f -= 1 vIndex += 2 axis = rt.Point3(1, 0, 0) result = rt.dot(p2.transform.position, axis) for i in range(1, len(projectMeshVertices) - 1): #build the triangle with the righ orientation if i % 2 != 0: projectMeshFaces.append( rt.Point3(vert_count + 3, vert_count + 2, vert_count + 1)) else: projectMeshFaces.append( rt.Point3(vert_count + 2, vert_count + 3, vert_count + 1)) vert_count += 1 #build the mesh with an array of vertex and triangles projectionMesh = rt.mesh(vertices=rt.Array(*(projectMeshVertices)), faces=rt.Array(*(projectMeshFaces))) rt.defaultVCFaces(projectionMesh) #set the vertex color for each vertex for i in range(len(projectMeshVertices)): rt.setVertColor(projectionMesh, i + 1, vColors[i]) if result > 0: rt.select(projectionMesh) rt.execute("max modify mode") normalModifier = rt.NormalModifier() rt.addModifier(projectionMesh, rt.NormalModifier()) normal = rt.Name("Normal") projectionMesh.modifiers[normal].flip = True rt.maxOps.CollapseNode(projectionMesh, False) #quadrify rt.select(projectionMesh) rt.convertToPoly(projectionMesh) rt.execute("max modify mode") rt.PolyToolsModeling.Quadrify(True, False) edge = rt.Name("EDGE") edgeNumber = projectionMesh.EditablePoly.getNumEdges() edgeList = [1] if result < 0 else [2] edgeSelection = rt.BitArray(*(edgeList)) rt.subObjectLevel = 2 projectionMesh.EditablePoly.SetSelection(edge, edgeSelection) projectionMesh.EditablePoly.SelectEdgeRing() projectionMesh.connectEdgeSegments = 3 rt.execute('macros.run "Ribbon - Modeling" "ConnectEdges"') return projectionMesh
def TupleToArray(tuple_obj): arr = rt.Array(*tuple_obj) _ShowMXSObject(arr) print return arr
def ListToArray(list_obj): arr = rt.Array(*list_obj) _ShowMXSObject(arr) print return arr
def CreateArray(): arr = rt.Array(*range(3)) _ShowMXSObject(arr) print return arr
def old_recreate(self): with pymxs.undo(True): if len(self.result) > 0: self.newNodes = [] self.dict = {} temp = mxs.Array() lastNode = None index = 0 rootNode = mxs.point() rootNode.size = 2 rootNode.showlinks = True rootNode.Box = True rootNode.cross = False rootNode.axistripod = False rootNode.centermarker = False mxs.join(temp, rootNode) def create_constraints(node, nNode): # Position sub = mxs.getSubAnim(nNode, 3) secsub = mxs.getSubAnim(sub, 1) secsub.controller = mxs.Position_List() posCtrl = mxs.Position_Constraint() thirdsub = mxs.getSubAnim(secsub, 2) thirdsub.controller = posCtrl posConstraintInterface = posCtrl.constraints posConstraintInterface.appendTarget(node, 100) # Rotation sub = mxs.getSubAnim(nNode, 3) secsub = mxs.getSubAnim(sub, 2) secsub.controller = mxs.rotation_list() posCtrl = mxs.Orientation_Constraint() thirdsub = mxs.getSubAnim(secsub, 2) thirdsub.controller = posCtrl posConstraintInterface = posCtrl.constraints posConstraintInterface.appendTarget(node, 100) for i in self.result: # Create new nodes and add them to list and dict nNode = mxs.point() nNode.showlinks = True nNode.size = 2 nNode.transform = i.transform nNode.name = i.name nNode.wireColor = i.wireColor self.dict[i] = nNode self.newNodes.append(i) # Create parent connections if mxs.isValidNode(i.parent): nNode.parent = self.dict[i.parent] else: nNode.parent = rootNode # Create Constraints create_constraints(i, nNode) # final part mxs.join(temp, nNode) lastNode = nNode index += 1 mxs.select(temp) mxs.redrawViews()
def recreate(self): defaultSize = 2 bones = mxs.Array() if len(self.result) > 0: self.newNodes = [] self.dict = {} temp = mxs.Array() lastNode = None index = 0 rootNode = mxs.BoneSys.createBone(mxs.point3(0, 0, 0), mxs.point3(0, 1, 0), mxs.point3(0, 1, 0)) rootNode.transform = mxs.Matrix3(1) rootNode.size = 2 rootNode.name = "rootBone" mxs.join(temp, rootNode) def new_create_constraints(node, nNode): posList = mxs.position_list() # Create Pos_List const = mxs.Position_Constraint() # Create Pos_Constraint const.appendTarget(nNode, 100) # Add target to Constraint secsub = mxs.setPropertyController(node.controller, "Position", posList) # Add PosList to node mxs.setPropertyController(secsub, 'Available', const) posList = mxs.rotation_list() # Create Pos_List const = mxs.Orientation_Constraint() # Create Pos_Constraint const.appendTarget(nNode, 100) # Add target to Constraint secsub = mxs.setPropertyController(node.controller, "Rotation", posList) # Add PosList to node mxs.setPropertyController(secsub, 'Available', const) def create_constraints(nNode, node): # Position posList = mxs.position_list() # Create Pos_List const = mxs.Position_Constraint() # Create Pos_Constraint const.appendTarget(nNode, 100) # Add target to Constraint secsub = mxs.setPropertyController(node.controller, "Position", posList) # Add PosList to node mxs.setPropertyController(secsub, 'Available', const) # Rotation posList = mxs.rotation_list() # Create Pos_List const = mxs.Orientation_Constraint() # Create Pos_Constraint const.appendTarget(nNode, 100) # Add target to Constraint secsub = mxs.setPropertyController(node.controller, "Rotation", posList) # Add PosList to node mxs.setPropertyController(secsub, 'Available', const) for obj in self.result: endPos = mxs.point3(0, 0, 0) if obj.children.count > 0: endPos = obj.children[0].transform.pos else: endPos = (mxs.transmatrix(mxs.point3(defaultSize, 0, 0)) * obj.transform).pos zPos = (mxs.transmatrix(mxs.point3(0, 0, 1)) * obj.transform).pos d = mxs.BoneSys.createBone(obj.transform.pos, endPos, zPos) d.transform = obj.transform d.name = obj.name d.wirecolor = obj.wirecolor mxs.join(bones, d) self.dict[obj] = d self.newNodes.append(obj) # Create parent connections if mxs.isValidNode(obj.parent): d.parent = self.dict[obj.parent] else: d.parent = rootNode create_constraints(obj, d) mxs.select(bones) mxs.selectmore(rootNode) mxs.redrawViews()