How to query which way a face is pointing?

How to query which way a face is pointing?

malcolm_341
Collaborator Collaborator
1,332 Views
9 Replies
Message 1 of 10

How to query which way a face is pointing?

malcolm_341
Collaborator
Collaborator

I'm trying to make an if statement based on if the selected face is pointing positive or negative Y, does anyone know if there's a way to query the face and get some kind of usable number if facing Y type of data. I looked online and everything seemed very complex about getting the average normal, but vectors and normals are far out of my skill level at the moment. Anything more rudimentary or simple?

0 Likes
1,333 Views
9 Replies
Replies (9)
Message 2 of 10

stuzzz
Collaborator
Collaborator

Hello Malcom

 

this should help

- get the normal of the selected face (polyInfo -fn) might do the trick (there might be other solution like MItMeshPolygon::getNormal() or a cross product)

- do a dot product of this normal and vector Yup vector (0,1,0).

- if the result is positive, then the vectors are pointing in the same direction

- if not, they are not pointing in the same direction

0 Likes
Message 3 of 10

malcolm_341
Collaborator
Collaborator

Thanks I'll look into that, I have no idea what a dot product is so I'll research that as well. I had previously looked into polyInfo -fn, but that command for no apparent reason returns an annotated string array which isn't casted easily there's a whole procedure you need to write just to get the polyInfo to be usable floats. Wish they just had a built in command to query the normal direction.

0 Likes
Message 4 of 10

stuzzz
Collaborator
Collaborator

I know, that's pretty suprising to have an output result of the polyInfo command. I created my own module

please look at this url

Message 5 of 10

malcolm_341
Collaborator
Collaborator

Oh ha ha, that's the site I was reading to learn about how to do this. Great site I've learned a lot of stuff there, thanks.

0 Likes
Message 6 of 10

stuzzz
Collaborator
Collaborator

If you work with python you may have a look at the regex to extract token from a string.

Getting the face normal with the Api is quite easy also

0 Likes
Message 7 of 10

stuzzz
Collaborator
Collaborator

here's a quick example if you need to extract the vectors from a string with regex. I believe that you can achieve the same result with the tokenize command with melscript

 

import re
faces = cmds.polyInfo(fn=True)
for face in faces:
	x,y,z = re.findall(r'(\d+\.+\d+)+', face)
	print "myVector x:{} y:{} z:{}".format(x, y, z)
        #feel free to append a list here if needed

 

0 Likes
Message 8 of 10

malcolm_341
Collaborator
Collaborator

Haven't made it to Python yet, I'm 3D artist learning to code for the first time, shelf teaching my way through mel so Python's still a ways off.

0 Likes
Message 9 of 10

stuzzz
Collaborator
Collaborator

I used melscript before but will never get back to it since python offers way more advantages.

Learning with melScript is the hardway imo.

0 Likes
Message 10 of 10

malcolm_341
Collaborator
Collaborator

Yeah I've been told that by a couple programmers, but it's too late for me I've already developed a bunch of tools in mel and I'm enjoying it except for frustrations like this.

0 Likes