Spline projection
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/09/2007 at 06:30, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 10.111
Platform: Windows ;
Language(s) :---------
Hi,I want to project a spline on geometry.
May approach was: To sample a number of points from the spline, then send collision rays from these points to see if there's any geometry. Then move the point's position to the position of ray collision.
But this would only let me project the spline on *one* object with geometry, right? I want it to be projected on more than just one geometry.
Like the "Project" function in the Functions->Spline Menu, I want any object (or at least more than just one) to be used for projection.
How could I do that? Is there any basic concept I need to know, or example code? My only idea would be to iterate through all objects in the scene, always doing the ray collision check (sounds slow). I also got the tip to connect all objects in the scene to one big object (internally in my plugin) but I think that would cost lots of memory, wouldn't it?
Greetings,
Jack -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/09/2007 at 02:48, xxxxxxxx wrote:
OK, in the meantime I wrote the function myself. For now it works with only one geometry object for collision.
1. I resample the spline. User defines number of samples, and I take several samples of SplinePoint positions. From these positions a new spline is created.
2. Using GeRayCollider, I shoot a ray from a certain -Y distance of each point's position, looking for geometry to project on.
This works pretty well and doesn't run as slow as I had imagined
But there's a problem: It only works when Spline Generator Object and Geometry Object are located at global position (0.0.0).
The GeRayCollider returns local positions of the collision geometry (at least I suppose so, the SDK doc doesn't go into detail there). How do I transform those positions into local positions of my Spline Generator Object?
Regards,
Jack -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/09/2007 at 06:57, xxxxxxxx wrote:
OK, my projection function looks like this:
SplineObject *ProjectSpline(BaseObject *op, BaseObject *cg, BaseObject *pl, Real Range, LONG Axis) { // pl : Spline Generator Plugin Object // cg : Collision Geometry Object // op : Spline Object (contains generated spline, which will later be output in the GetContour() fc**tion of the Generator Plugin). SplineObject *sp = static_cast<SplineObject*>(op); AutoAlloc<GeRayCollider> rc; if (!rc) return FALSE; GeRayColResult res; if (!op || !cg || !pl) return sp; LONG i; LONG Points = sp->GetPointCount(); Vector *padr = ToPoint(sp)->GetPointW(); Vector PointPos; Vector FromPos; Vector ToDir; Matrix invMatrix = !pl->GetMg(); rc->Init(cg,FALSE); for (i=0; i<Points; i++) { PointPos = ((padr _* invMatrix) * cg- >GetMg()); switch (Axis) { case PATHCREATOROBJ_PROJECT_AXIS_X: FromPos = PointPos-Vector(Range/2, 0.0, 0.0); ToDir = Vector(1.0, 0.0, 0.0); break; case PATHCREATOROBJ_PROJECT_AXIS_Y: FromPos = PointPos-Vector(0.0, Range/2, 0.0); ToDir = Vector(0.0, 1.0, 0.0); break; case PATHCREATOROBJ_PROJECT_AXIS_Z: FromPos = PointPos-Vector(0.0, 0.0, Range/2); ToDir = Vector(0.0, 0.0, 1.0); break; } if (rc->Intersect(FromPos, ToDir, Range)) { if (rc->GetNearestIntersection(&res;)) { invMatrix = !cg->GetMg(); padr _= ((res.hitpos * invMatrix) * pl- >GetMg()); } } } return sp; }
I do something wrong with those Matrix operations. But i can't figure out, what's wrong. Been trying for some time now, and still no solution
Regards,
Jack -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/09/2007 at 05:39, xxxxxxxx wrote:
You have first to convert the spline points into global space. Do this by multiplying the points with the splines's global matrix. The bring the now global points into the collider object's local space. Multiply with the inverted matrix of the collider object. It should work then.
btw. currently there is bug in the forum software. so don't use "i" as array index, it will turn your code into italic and parts of the code will be missing.
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/09/2007 at 05:50, xxxxxxxx wrote:
Aha! OK, so generally:
Local Coordinate * GlobalMatrix = Global Koordinate
Global Coordinate * !GlobalMatrix = Local KoordinateI think maybe I finally understood
Thank you so much, Matthias!And about the "i" forum problem:
That's not the only bug. Just edit a posting that contains the "CODE" BBtag and see what happens to the Code after editingGreetings,
Jack -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/09/2007 at 10:27, xxxxxxxx wrote:
Hm, unfortunately this didn't work at all
The spline still moves around, when I move geometry object or spline generator object.
This is how it looks now:
//SplineObject sp = My Spline Object //BaseObject cg = Some Polygon Object used as collision geometry Matrix invMatrix = !(cg->GetMg()); for (x=0; x<Points; x++) { PointPos = padr[x] * sp->GetMg(); // From local Space of Spline Obj -> Global Space PointPos = PointPos * invMatrix; // From Glboal Space -> Local Space of Collision object switch (Axis) { case PATHCREATOROBJ_PROJECT_AXIS_X: FromPos = PointPos+Vector(Range/2, 0.0, 0.0); ToDir = Vector(-1.0, 0.0, 0.0); break; case PATHCREATOROBJ_PROJECT_AXIS_Y: FromPos = PointPos+Vector(0.0, Range/2, 0.0); ToDir = Vector(0.0, -1.0, 0.0); break; case PATHCREATOROBJ_PROJECT_AXIS_Z: FromPos = PointPos+Vector(0.0, 0.0, Range/2); ToDir = Vector(0.0, 0.0, -1.0); break; } if (rc->Intersect(FromPos, ToDir, Range)) { if (rc->GetNearestIntersection(&res;)) { padr[x] = res.hitpos; } } }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 25/09/2007 at 01:12, xxxxxxxx wrote:
Ha! I fixed it!
Problem was:
> Matrix invMatrix = !(cg- >GetMg());
This should be done *in* the loop, not before it. The result was, that only the first point could be calculated correctly.
So there wasn't even a matrix problem, just one of those stupid mistakes that take days to find out about
Greetings,
Jack