On 29/10/2013 at 07:39, xxxxxxxx wrote:
Hello,
I used the function GeRayCollider() in a plugin. But I have a few problems.
First I created a cube.
Then I tried to initialize the ray collider with this cube.
But I got an error message, that the argument must be a polygon object.
So I tried to convert the cube to a polygonobject.
I used a call command for this and it works (I can see the polygon object in cinema 4d), but the error message is the same.
Here ist the code:
import c4d
import os, sys
import time
import math
from c4d import plugins
from c4d import utils
from config import PLUGIN_ID
class CommandDataExecute(plugins.CommandData) :
dialog = None
#plugin started by user
def Execute(self, doc) :
cube = c4d.BaseObject(c4d.Ocube)
doc.InsertObject(cube)
c4d.EventAdd()
cube.SetBit(c4d.BIT_ACTIVE)
print "Typ: ", cube.GetType()
c4d.CallCommand(12236)
c4d.EventAdd()
print "Typ: ", cube.GetType()
ray=c4d.utils.GeRayCollider()
if not ray.Init(cube) :
print "Initialisierung nicht erfolgreich"
else:
start = c4d.Vector(400,0,0)
end = c4d.Vector(-400,0,0)
direction = c4d.Vector(-1,0,0)
length = 800
print "globale matrix cube: ", cube.GetMg()
print "radius of the bounding box: ", cube.GetRad()
does_intersect = ray.Intersect(start, direction, length)
print "Intersection? ", does_intersect
return True
Now I have four questions:
1. Is it necessary to convert the cube to a polygon object?
2. Is there a better way to convert the cube than using call commands?
3. Why doesnt the function "ray.Init(cube)" work?
4. "does_intersect = ray.Intersect(start, direction, length)" should return true. Did I use the function correctly?
Thanks for your comments.
Conny