TraceGeometry() - RayHitID::GetSecond() always 0
-
On 12/01/2016 at 08:57, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform:
Language(s) :---------
Hi!I'm using VolumeData::TraceGeometry(). There seems to be a problem with the RayHitID data that
is written into the SurfaceIntersection structure. Although the geometry that is traced does have
quadrangles (actually, only quadrangles and no triangles), RayHitID::GetSecond() always returns false.I'm either missing something very important to make that flag being set by TraceGeometry(), or
is it a bug in the SDK? If it is a bug, any chance to work around it?Let me know if anything is unclear and if I should provide a snippet.
Thanks,
Niklas -
On 12/01/2016 at 09:10, xxxxxxxx wrote:
The workaround I use is not really nice as it's very computation heavy. I compute the
barycentric coordinates of p in the triangle of the first half of the polygon, then check
if the point was actually inside that triangle. If it was not, assume the traced point was
from the other half of the polygon.I need to compute these barycentric coordinates anyway, but having to compute them
twice for the other side of the quadrangle sounds "insane". Anyone got a better idea?inline void compute_uvw(Vector const& p, Vector const& a, Vector const& b, Vector const& c, Vector* out) { Vector f1 = (a - p); Vector f2 = (b - p); Vector f3 = (c - p); Vector va = Cross(a - b, a - c); Vector va1 = Cross(f2, f3); Vector va2 = Cross(f3, f1); Vector va3 = Cross(f1, f2); Real x = 1.0 / va.GetLength(); out->x = va1.GetLength() * x * sgn(Dot(va, va1)); out->y = va2.GetLength() * x * sgn(Dot(va, va2)); out->z = va3.GetLength() * x * sgn(Dot(va, va3)); }
-
On 13/01/2016 at 01:40, xxxxxxxx wrote:
Hello,
can you share some code of what you are actually doing? Are you using this function in a VideoPost, a material or shader?
Best wishes,
Sebastian -
On 13/01/2016 at 03:59, xxxxxxxx wrote:
Hey Sebastian, thanks for the reply. It's a bit related to this other question of me.
If you need a more complete example than what I already posted in that question (also
below for reference), let me know!I'm using this code from VideoPostData::Execute() on VIDEOPOSTCALL_RENDER with vps- >open == false.
// Render the color and object buffer data. if (vps->vd && vps->render && vps->vp == VIDEOPOSTCALL_RENDER && !vps->open && colorBuffer\_ != 0) { VPBuffer\* colorBuf = vps->render->GetBuffer(VPBUFFER_POSTEFFECT, colorBuffer\_); LONG const xres = colorBuf->GetInfo(VPGETINFO_XRESOLUTION); LONG const yres = colorBuf->GetInfo(VPGETINFO_YRESOLUTION); LONG const cpp = colorBuf->GetInfo(VPGETINFO_CPP); Bool hit; Ray ray; SurfaceIntersection si; for (LONG y = 0; y < yres; ++y) { for (LONG x = 0; x < xres; ++x) { // Find the first polygon that hits the ray for the current pixel. vps->vd->GetRay(x, y, &ray); hit = vps->vd->TraceGeometry(&ray, MAXREALr, vps->vd->lhit, &si); if (!hit || !si.op || !si.op->link) { continue; } // SReal pixel[3] = {1.0, 1.0, 1.0}; // colorBuf->SetLine(x, y, 1, &pixel, 32, false); CriticalAssert(!si.id.GetSecond()); // never throws if (si.id.GetSecond()) GePrint("GetSecond() set!"); // never prints } } }
-
On 15/01/2016 at 08:55, xxxxxxxx wrote:
Hello,
the "second" part is only set when the hit quadrangle is non-coplanar. In case of a planar quadrangle "second" is never set.
Best wishes,
Sebastian -
On 15/01/2016 at 10:44, xxxxxxxx wrote:
Thanks Sebastian. I can reproduce that. I should use something other than a cube for initial tests.
I don't exactly understand why that is, I might be lacking some background knowledge in that area,
but my rendering algorithm works nevertheless.Cheers,
Niklas