Check normals?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/06/2011 at 12:35, xxxxxxxx wrote:
No, GetPoint is a Method of the PointObject - class.
print op.GetPoint(polygon.a)
You see ? op is a PointObject, 'polygon' is a CPolygon. So, here is a better explanation: CPolygon-objects hold indicies of Points in their attributes a,b,c and d. Theese indieces represent the points of a PointObject (PolygonObject inherits from PointObject).
myPointIndexTakenFromCPolygon = myPolygonTakenFromPointOrPolygonObject.a myPointCoordinate = myPointOrPolygonObject.GetPoint(myPointIndexTakenFromCPolygon)
Ergo, a Polygon is defined by the indieces of points of an object. It would be absolutely redundant saving the Vectors of the Points twice.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/06/2011 at 12:47, xxxxxxxx wrote:
f**king brilliant. it works like a charm. i just needed to replace your "polygon" with the name of my polygon. i didn't understand why i would have to access "op" at first, but now i see that i HAVE to pass the GetPoint Function on my base object in order to use the fucntion and then use the CPolygon object to tell Python what points to get. awesome. thanks again man. the working code is:
def SelectWalls(op) :
polys = op.GetAllPolygons()#Get a list of all available polygons
for poly in polys:
return op.GetPoint(poly.a)and it returns:
Vector(-325, -331, -99)
when i print. brilliant.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/06/2011 at 13:18, xxxxxxxx wrote:
Np.
Just for final correction of your comment:Originally posted by xxxxxxxx
polys = op.GetAllPolygons()#How many polygons does the object have in total?
Does not (not only actually) return the number of polygons, it returns a list containing all polygons. And the length of the list ( len(polys) ) is the number of Polygons, logically.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/06/2011 at 13:34, xxxxxxxx wrote:
haha, yeah sorry forgot to change the comment to say #Get All Polygons., I totally understand and will fix it.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2011 at 02:55, xxxxxxxx wrote:
In case you do search for an algorithm of how to calculate the Normal of a Polygon, here is a very good and easy to reproduce in Python - Pseudocode:
http://www.opengl.org/wiki/Calculating_a_Surface_Normal
Cheers,
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2011 at 05:45, xxxxxxxx wrote:
Btw. the cross-product is already implemented. So just use:
normal = vec1.Cross(vec2)
Be aware that switching the vectors, will switch the direction of the normal.
Cheers,
maxx -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2011 at 06:06, xxxxxxxx wrote:
But the normal of 2 vectors is not what he searched for.
Anyway, very useful ! Didn't know about that Method. Thanks -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2011 at 08:08, xxxxxxxx wrote:
Well, actually, it is.
You just take the three points, create two vectors by substraction, calculate the normal by cross-product ... The result is the normal on the polygon-surface (defined by the three points).
Cheers,
maxx -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2011 at 10:29, xxxxxxxx wrote:
wow! thanks guys and gals! that openGL wiki is exactly what i was looking for. and the little snippet on how to get the cross product of two vectors is super helpful as well. thanks so much!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2011 at 11:38, xxxxxxxx wrote:
ok, so thanks to everybody's help i was successfully able to calculate the face normals and find out which way the polygon is facing. It seems to be working so I Thought this might help some people out!
def FindNormals(op) : #function to find direction of walls and assign to seperate selection tags
polys = op.GetAllPolygons() #get list of polygons in op
doc = c4d.documents.BaseDocument()
i=0
for poly in polys: #find normalspt_a = op.GetPoint(poly.a)
pt_b = op.GetPoint(poly.b)
pt_c = op.GetPoint(poly.c)
pt_d = op.GetPoint(poly.d)
vector1 = pt_a-pt_b
vector2 = pt_b-pt_c
normal = vector1.Cross(vector2)
normal.Normalize()
nx = normal.x
ny = normal.y
nz = normal.z
if(nx!=0) : #check x normal
print "poly",i,poly,"is facing x to a degree of:",nx
i+=1
elif(ny!=0) : #check y normal
print "poly",i,poly,"is facing y to a degree of:",ny
i+=1
elif(nz!=0) : #check z normal
print "poly",i,poly,"is facing z to a degree of:",nz
i+=1
else:
print "something went wrong"update: fixed some minor code output issues.