Jump to content

[SOLVED] remove points behind obstacle


Entropy

Recommended Posts

Hello to all,

this is my first post
I am starting to learn houndini 

i try to convert some of my projects done with grasshopper
i want to do a line mesh intersection test to cull points that are behind a mesh obstacle
for each point i need to create a line to the camera origin  
and then check if the lines intersect with the mesh
if true then i need to remove those points 

Any suggestions ?

Thanks in advance.
Ioannis

 

 

Edited by Entropy
Link to comment
Share on other sites

Hi Henry,

Thanks a lot for the file
it is working fine as long as the points are based on different geometry 

when i use the same object to construct the points there are a lot of inaccuracies 
normally all the points that are facing the camera should be visible

please have a look at the file 

Thanks in advance.
Ioannis

ray_project_cull_self.hip

Edited by Entropy
Link to comment
Share on other sites

You just need to introduce a little ray bias into your Ray SOP. A value of 0.1 got me pretty close. 

If all you're trying to do is remove points that are backfacing the camera, there's a simpler way. Unique the points on your mesh using a Facet SOP or however you like, create point normals via a Normal SOP, scatter, then just use a Delete SOP in Normals mode. There's an attribute there that accepts a camera input to determine backfaces. As long as the scattered points inherit your mesh's point normals, this will work.

  • Like 1
Link to comment
Share on other sites

dunno for your exact situation...but i tested on 'lines' and it works even not needing any blocking mesh (coz it works on N forward or backfacing)...you must initialize N first tho...

test.jpg

Edited by Noobini
Link to comment
Share on other sites

You can avoid the need to resample with some Clip SOP magic.

Compute dot(I, N) where I is the normalized vector between your camera and point position, set a rest position, then use a wrangle to move your points into a world position based on that dot product:

vector camP = point(1, "P", 0);
vector I = normalize(camP - @P);
@dot = dot(@N, I);

v@rest = @P;
@P = set(0,@dot,0);

Then use a Clip SOP to cut off any primitives where dot product is less than 0. The defaults work fine here. Afterwards, just move your points back to their original rest positions.

 

smooth_line_clip.hip

  • Like 2
Link to comment
Share on other sites

I would render the underlying mesh as a matte object. The surface will naturally cull geometry behind it. Nice way to render wireframes. If you want to do it in SOPs, I would stick to the Ray node method. Delete-by-normal method doesn't really cull things. It works properly in the file you posted.

Here is VEX version of initial idea (identical to just using the Ray, though):

// Point wrangle.

vector camP = point(1, "P", 0);
vector dir = normalize(camP - @P);
float bias = 0.01; // Error margin to avoid self-occlusions.

// Get all intersections along the ray.
vector hit_ps[];
int hits = intersect_all(2, @P, dir * 100, hit_ps, {}, {});

if (hits && distance(@P, hit_ps[-1]) > bias)
{
    // Occluded by some surface.
    removepoint(0, @ptnum);
}

vex_cull_curves.png.6e6d2bd1a7e56c92bddeab34ecf4a3c7.png

vex_cull_curves.hipnc

  • Like 5
  • Thanks 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...