Pergunta

correct me if I am wrong but when you use call getArea() from a meshFace node it doesn't return the area relative to the current scene units but rather relative to its own scale.

For example:

If I create a box with the scene units set to Meters, then the box is created with a scale of 1,1,1.

With this box I call:

#Assuming you selected only faces from the scene.
import pymel.core as pm

selected = pm.ls(selection = True, flatten = True)
totalFaceArea = 0

for face in selected:
    totalFaceArea = totalFaceArea + face.getArea(space = "world")

print selected
print totalFaceArea

However, if I change the scene units to Centimeters then the scale doesn't change (which makes sense). The problem is that the area seems to be coming from the scale not the amount of space its taking up in the scene so the area doesn't change when you change the scene units.

Do you guys know of a way to compensate for the change in scene units or a way to get the area of a face in the scene units?

Thanks!

Foi útil?

Solução

Maya uses cm internally, and it's shamefully inconsistent about applying unit settings. Most systems and commands work in you work unit, but not all. Off the top of my head a few of the holdouts are camera settings, polySelectConstraints, and (as in your case) all API based geometry calculations.

for cases like this usually have a corrective function to translate the values into my expected units. The function is trivial:

def scene_unit_linear(val):
     _IN_CM = {'m':100, 'in':2.54, 'cm':1, 'ft':30.48}
     _scale = _IN_CM[cmds.currentUnit(q=True, l=True)]
     return _scale * val

Unfortunately the hard part is knowing when to use it :( Also (and this is important!) you need to use the appropriate power if you're getting a two or three dimensional value. In your case, you'd need to square it since you're getting an area value: 1 square meter is 10,000 square cm, not 100!

   def scene_unit_area(val):
     _IN_CM = {'m':100, 'in':2.54, 'cm':1, 'ft':30.48}
     _scale = _IN_CM[cmds.currentUnit(q=True, l=True)]
     return _scale * _scale * val


world_area = scene_unit_area(face.getArea(space = "world"))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top