Ever wondered what “Orient Polygons” does? It tells me that it winds all the polygons in the same ‘direction’. What direction is that?
And how does it know (determine) what polygons to reverse or flip. I find that desription utterly useless and needed more control over my prim normals in Houdini (defining direction using a set of shared points and their surface orientaiton) for a project i’m working on.
Based on those requirementrs I made a simple orient prim normal operator that uses a vector point attribute to test the primitive orientation. If the op determines the prim normal needs to be flipped, it’s added to a primitive normal group that can be reversed using the reverse SOP.
import math
# This code is called when instances of this SOP cook.
node = hou.pwd()
geo = node.geometry()
# Evaluate the parameters
prim_group = hou.pwd().evalParm("primitive_group") #primitive group to sample from
normal_name = hou.pwd().evalParm("sample_attribute") #vector attribute used for averaging and comparison
export_group = hou.pwd().evalParm("export_group") #primitive group wrong faced normals get exported to
angle_threshold = hou.pwd().evalParm("angle_offset") #maximum allowed angle
# Finds the primitive group
def findPrimGroup(inName):
for group in geo.primGroups():
if group.name() == inName:
return group.prims()
break
return None
'''
Sample Information------------------------------------------------------------------------------------------
'''
# Fetch the primitives and sample input information
if len(prim_group) is not 0:
prims = findPrimGroup(prim_group)
if prims is None:
raise hou.NodeError("Can't find primitive group: %s" % prim_group)
else:
prims = geo.prims()
if len(prims) < 1:
raise hou.NodeError("Not enough primitives provided! Need at least one..")
if len(export_group) < 1:
raise hou.NodeError("No export group found")
if export_group in geo.primGroups():
raise hou.NodeError("Primitive group '%s' already exists" % export_group)
export_group = geo.createPrimGroup(export_group)
normal_attrib = geo.findPointAttrib(normal_name)
if normal_attrib is None:
raise hou.NodeError("Lookup attribute '%s' does not exist" % normal_name)
'''
Compute---------------------------------------------------------------------------------------------------
'''
# Now sample the normals
for prim in prims:
# get the prim verts
verts = prim.vertices()
# from every vert get the associated point normals
# note that every point normal is normalized
prim_point_normals = []
for v in verts:
vector = hou.Vector3(v.point().attribValue(normal_attrib))
vector.normalized()
prim_point_normals.append(vector)
# accumulate point normals
accum = hou.Vector3(0,0,0)
for n in prim_point_normals:
for i in range(3):
accum[i]+=n[i]
# get the average
count = len(prim_point_normals)
for i in xrange(len(accum)):
accum[i] /= count
# get primitive normal
prim_normal = hou.Vector3(prim.normal())
inv_prim_normal = -1*prim_normal
# get the angle
current = accum.angleTo(prim_normal)
inversed = accum.angleTo(inv_prim_normal)
if inversed < (current+angle_threshold):
export_group.add(prim)
# This code is called when instances of this SOP cook.
node = hou.pwd()
geo = node.geometry()
# Evaluate the parameters
prim_group = hou.pwd().evalParm("primitive_group") #primitive group to sample from
normal_name = hou.pwd().evalParm("sample_attribute") #vector attribute used for averaging and comparison
export_group = hou.pwd().evalParm("export_group") #primitive group wrong faced normals get exported to
angle_threshold = hou.pwd().evalParm("angle_offset") #maximum allowed angle
# Finds the primitive group
def findPrimGroup(inName):
for group in geo.primGroups():
if group.name() == inName:
return group.prims()
break
return None
'''
Sample Information------------------------------------------------------------------------------------------
'''
# Fetch the primitives and sample input information
if len(prim_group) is not 0:
prims = findPrimGroup(prim_group)
if prims is None:
raise hou.NodeError("Can't find primitive group: %s" % prim_group)
else:
prims = geo.prims()
if len(prims) < 1:
raise hou.NodeError("Not enough primitives provided! Need at least one..")
if len(export_group) < 1:
raise hou.NodeError("No export group found")
if export_group in geo.primGroups():
raise hou.NodeError("Primitive group '%s' already exists" % export_group)
export_group = geo.createPrimGroup(export_group)
normal_attrib = geo.findPointAttrib(normal_name)
if normal_attrib is None:
raise hou.NodeError("Lookup attribute '%s' does not exist" % normal_name)
'''
Compute---------------------------------------------------------------------------------------------------
'''
# Now sample the normals
for prim in prims:
# get the prim verts
verts = prim.vertices()
# from every vert get the associated point normals
# note that every point normal is normalized
prim_point_normals = []
for v in verts:
vector = hou.Vector3(v.point().attribValue(normal_attrib))
vector.normalized()
prim_point_normals.append(vector)
# accumulate point normals
accum = hou.Vector3(0,0,0)
for n in prim_point_normals:
for i in range(3):
accum[i]+=n[i]
# get the average
count = len(prim_point_normals)
for i in xrange(len(accum)):
accum[i] /= count
# get primitive normal
prim_normal = hou.Vector3(prim.normal())
inv_prim_normal = -1*prim_normal
# get the angle
current = accum.angleTo(prim_normal)
inversed = accum.angleTo(inv_prim_normal)
if inversed < (current+angle_threshold):
export_group.add(prim)
Hello my friend! I want to say that this article is awesome, great written and include approximately all significant infos. I would like to look more posts like this .
Hello my loved one! I wish to say that this article is awesome, nice written and include approximately all significant infos. I¡¦d like to see more posts like this .
I simply could not go away your website prior to suggesting that I extremely enjoyed the usual info an individual supply on your guests? Is going to be back regularly to investigate cross-check new posts
Simply desire to say your article is as amazing. The clearness in your post is simply excellent and i could assume you are an expert on this subject. Well with your permission allow me to grab your feed to keep updated with forthcoming post. Thanks a million and please continue the rewarding work.
I’m just commenting to make you know of the impressive discovery my wife’s girl developed going through your site. She learned too many issues, including what it’s like to have an ideal coaching nature to get folks very easily comprehend specific very confusing issues. You undoubtedly exceeded her desires. Thanks for supplying the warm and helpful, trusted, revealing and fun thoughts on the topic to Evelyn.
Hello There. I found your blog using msn. This is an extremely well written article. I will be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I will certainly comeback.
Very efficiently written story. It will be beneficial to anybody who employess it, as well as me. Keep doing what you are doing – can’r wait to read more posts.
I’ve been surfing online more than 3 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my view, if all website owners and bloggers made good content as you did, the web will be much more useful than ever before.
I truly appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thx again
Lovely blog! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also
I¡¦ll right away clutch your rss as I can not in finding your email subscription hyperlink or newsletter service. Do you have any? Please permit me recognize in order that I may subscribe. Thanks.
I intended to put you this tiny note so as to say thanks a lot once again relating to the stunning tricks you’ve discussed on this site. It was really extremely open-handed of you to convey freely all that a few people could have distributed as an electronic book to end up making some dough for themselves, even more so considering that you could possibly have done it if you ever desired. The ideas additionally served to become a easy way to fully grasp the rest have a similar interest much like mine to learn good deal more regarding this condition. I believe there are thousands of more fun sessions up front for individuals that find out your blog.
Unquestionably believe that which you stated. Your favorite justification appeared to be on the internet the simplest thing to be aware of. I say to you, I certainly get irked while people consider worries that they plainly don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will probably be back to get more. Thanks
Thanks for sharing superb informations. Your site is so cool. I’m impressed by the details that you¡¦ve on this web site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found just the info I already searched everywhere and just couldn’t come across. What a great site.
Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and return to read more of your useful info. Thanks for the post. I will certainly return.
You made some decent points there. I looked on the internet for the subject and found most individuals will approve with your blog.
Wow! This can be one particular of the most useful blogs We have ever arrive across on this subject. Basically Fantastic. I’m also a specialist in this topic therefore I can understand your effort.
Nice blog post, I truly wait for posts from you.
Where exactly is the facebook like link ?
Cool tips! I have been hunting for things similar to this for a while today. Thanks!
Outstanding insights! I have already been searching for something like this for quite a while now. Thanks for your insight!
good blog post, good website design and style, maintain the great work
Fine related information! I have been searching for things such as this for a while now. With thanks!
Beneficial facts! I have been previously seeking something like this for a time now. With thanks!
Bookmarked, I love your blog! 🙂
Huge lover on this blog, a great deal of your posts have definitely helped me out. Looking forward to improvements!
Terrific facts! I have been seeking something like this for quite a while now. With thanks!
I would like to give thanks a lot for the job you have made in writing this blog post. I am hoping the same effective job from you later on also.
This can be an issue I need to find more information about, thank you for the posting.
Saved as a favorite, I enjoy your site! 🙂
Greetings I located your blog by mistake when i was searching Bing for this subject, I have to tell you your webpage is truly helpful I also seriously like the theme, it is good!
Added, I enjoy your site! 🙂