feredynamics.blogg.se

Maya python setattr of list
Maya python setattr of list




maya python setattr of list

cubeId = "%s%s%s" % (cubePosX, cubePosY, cubePosZ ) if cubeId in voxelIdList : We then multiply the rounded value (5) by the size of a cube (2) to obtain a new position: The position of the cube, not wedged on the vertex but keyed to the voxel grid. So now we know that if we create a cube of size 2.0, you should move it 5 times its size to make it emcompass the vertex. In the case of round(5.1), we have 5 (5.7 would give 6). How do I know what is the 10.2 distance in cube size 2.0? By simply: 10.2/2.0 = 5.1.Īs we cann't have 5.1 cubes, we round using the round() function. We would not get the desired effect at all. Of course, we will not put our cube in the center of the vertex (10.2). It comes across a vertex set with a X value of 10.2. Let's suppose the desired size cubes is 2.0. x/voxelStep ) *voxelStepĪnd here are the small lines that does everything. We create a list which will be used to store identifiers (or keys) of areas where cubes have already been generated. It is just more convenient to delete a group with everything in it than select all the cubes manually. Here we only create an empty group that will store cubes we will create later. The first line creates a MPointArray to store our mesh vertices positions.Īnd the second line fills the array with vertices coordinates world space (position relative to the center of the scene, not the center of the object itself).

maya python setattr of list

So we have a _inMesh_ that we will use to retrieve mesh's vertices. I invite you to read the documentation to understand the how and why of function sets. The MFnMesh class allow you to deal with a "true" programming object from which we will be able to get informations. In general, we check the MObject type using MObject.apiType() or MObject.hasFn().īut here we assume the user provide a mesh. MFnMesh ( dagPath )īy default, all what you get from the API are MObjects. So we've "converted" "pSphere1" (that doesn't mean anything in Maya API) in true MObject. We add the Maya object "pSphere1" in the MSelectionList and we retrieve its DAG path (zero is the index in the list). Two instances have only one shape node but it is indeed two different DAG path and world space coordinates of one vertex can have two possible values depending "from where we go". Many Maya API functions require DAG path to work.įor example, you can't retrieve world space coordinates of shape node's vertices if you don't know the path by which you get there.

  • DAG path: This is the "path" of a node through the hierarchy (and thus, having all these transformations).
  • DAG: This is the Maya "hierarchy" (parent/child).
  • It is always difficult to explain to begginers what is a DAG and a DAG path. The particularity of a MSelectionList is to retrieve the MObject of a Maya node from its name, what we will do later. I never really understood what the term "selection" meant in this context as it actually does not "select" anything. MSelectionList ( )īasically, a MSelectionList is a list of MObject. setAttr (m圜ube+ ".translate", cubePosX, cubePosY, cubePosZ ) Explainations sel = OpenMaya. pol圜ube (width=voxelStep, height=voxelStep, depth=voxelStep ) cmds. z/voxelStep ) *voxelStepĬubeId = "%s%s%s" % (cubePosX, cubePosY, cubePosZ ) if cubeId in voxelIdList : y/voxelStep ) *voxelStepĬubePosZ = round (pointArray. x/voxelStep ) *voxelStepĬubePosY = round (pointArray. length ( ) ) :ĬubePosX = round (pointArray.

    maya python setattr of list

    VoxelIdList = list ( ) for i in xrange (pointArray. The only dificulty with this implementation is, once the vertex position recovered, to know where must be the center of the cube. The method chosen here is simple: For each vertex of the geometry, we find the position "in cube unit" and generates a cube.

    Maya python setattr of list pro#

    There are a thousands of ways to solve it and each method has these pro and con. Before we begin, know that this problem is a textbook case.






    Maya python setattr of list