On 18/03/2015 at 10:15, xxxxxxxx wrote:
Hello Whithers,
you´re right, GeRayCollider needs a polygonal object, but the steps to calculate collisions could be done easier.
With utils.SendModellingCommand(c4d.MCOMMAND_CURRENTSTATETOOBJECT) you can convert the particle geometry to polygon objects.
You´ll have a null object with all the particle geometryclones as children than, which can be converted to a single object with utils.SendModellingCommand(c4d.MCOMMAND_JOIN)
The first member of the result is your merged polygonal object which can be checked against rays.
Hope this helps?
Best wishes
Martin
A snippet
import c4d
from c4d import gui, utils
def Intersect_Rc(op,p0,p1) :
ray = utils.GeRayCollider()
ray.Init(op, True)
matr = op.GetMg()
pos = p0 * matr
ldir = p1-p0
direction = ldir.GetNormalized()
raylength = ldir.GetLength()
CollisionState = ray.Intersect(pos, direction, raylength)
erg = []
count= ray.GetIntersectionCount()
print count
if count >0:
for i in xrange(count) :
result = ray.GetIntersection(i)["hitpos"]
erg.append(result)
return erg
else: return
def main() :
#_____________________________________
#particle geometry must be the active object
if not op: return
if not op.IsInstanceOf(1001414) : return
#_____________________________________
#prepare test line/ray to check
LINE=doc.SearchObject("LINE")
if not LINE: return
p0l = LINE.GetPoint(0)
p1l = LINE.GetPoint(1)
Lmatr = LINE.GetMg()
##line points in rayobject local space
matr = op.GetMg()
p0 = p0l*Lmatr*~matr
p1 = p1l*Lmatr*~matr
#_____________________________________
#validate particle geometry
virtualop = utils.SendModelingCommand(command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
list = [op.GetClone()],
doc = doc)
if not virtualop: return
merge = utils.SendModelingCommand(command = c4d.MCOMMAND_JOIN,
list = virtualop,
doc = doc)
if not merge: return
print merge
geometry = merge[0]
#_____________________________________
#test insertion
#doc.InsertObject(merge[0])
#c4d.EventAdd()
#_____________________________________
#ray collision
print Intersect_Rc(geometry, p0, p1)
if __name__=='__main__':
main()