Announcement

Collapse
No announcement yet.

SDK: Intersecting GenericPrimitive

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SDK: Intersecting GenericPrimitive

    I was thinking of writing curvature shader. The idea is to check normal direction in nearby points of the intersectiong and comparing them. Here is the code:

    Code:
    	float backstep = 0.001f;
    	float delta = 0.001f;
    		
    	VR::Vector normal = rc.rayresult.normal;
    	normal.makeNormalized();
    	VR::GenericPrimitive *prim = rc.rayresult.primitive;
    
    	// These form the surface plane
    	VR::Vector surfX;
    	VR::Vector surfY;
    
    	//surfX = VR::Vector(-normal.z / normal.x, 0.f, 1.f);
    	//surfY = (normal ^ surfY);
    	
    	if (normal.x == 0 && normal.y == 0) {
    		surfX = VR::Vector(1,0,0);
    		surfY = VR::Vector(0,1,0);
    	} else {		
    		surfX = normal ^ VR::Vector(0,0,1);
    		surfY = normal ^ surfX;
    	}
    
    	surfX.makeNormalized();
    	surfY.makeNormalized();
    	
    	VR::Vector pos = rc.rayresult.origPoint + normal * backstep;		
    	  
    	VR::RSRay xRay = VR::RSRay(VR::Ray(pos + surfX * delta, -normal));
    	VR::RSRay yRay = VR::RSRay(VR::Ray(pos + surfY * delta, -normal));
    	xRay.clearIntersection();
    	yRay.clearIntersection();
    
    	if (!prim->intersect(xRay))
    		return AColor(1,0,0,1);
    	VR::Vector xNormal = prim->getNormal(xRay);	
    	if (!prim->intersect(yRay))
    		return AColor(0,1,0,1);
    	VR::Vector yNormal = prim->getNormal(yRay);
    Unfortunately it never finds any intersections (just returns red color from the first if clause).

    So what am I doing wrong here? Intersecting the whole scene would probably be inneficient since I just want to measure the curvature (difference in normals around the intersection point) of the single object.

    - Jerry
    http://www.ylilammi.com/

  • #2
    Does it work if you set the default geometry type to "Dynamic" in the System rollout of V-Ray?

    Best regards,
    Vlado
    I only act like I know everything, Rogers.

    Comment


    • #3
      Just realized this is probably not going to work at all, even if the intersection method worked - the actual intersected primitives will typically not be able to give you a smooth normal. For example, the triangles stored in the ray server do not store any information beyond what is directly necessary for intersecting them (which is the three vertices). The geometry generator that created those triangles keeps that information.

      Best regards,
      Vlado
      I only act like I know everything, Rogers.

      Comment


      • #4
        Hello Jerry,

        I thought that you can do at least
        rsray.is.primitive->getGNormal(rsray);

        But perhaps you can use

        F = rsray.is.primitive->ownerIndex; FaceID of the intesected face
        VR::Vector B = rsray.is.bary; Barycentric coords

        then get the vertexnormals from the original 3dsmax object and interpolate yourself

        Best regards,
        Dieter
        Last edited by dimo; 29-04-2009, 09:56 AM.
        --------
        visit my developer blog

        Comment

        Working...
        X