Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Maxunderground news unavailable

Methods of detecting occluded faces
show user profile  9krausec
Hey guys! So.. I've been banging my head against my desk for the past week figuring out the proper way to detect if a face is occluded or unoccluded and I'm looking for general theory input from anyone willing to take a swing at it.

So the mission here is to script a solution to optimize a mesh by deleting all faces that wouldn't be visible externally from imported CAD. Since CAD comes in as a shell (solid parts), there is a huge number of wasted polygons that aren't seen externally. So far I've been playing around with 2 methods-

Method 1-

Create a low poly sphere at the center of selected objects, encompassing those objects. Have a camera be positioned in an iterative manner at each vert point having it's target at the center of the mass. Select all polygons visible to the camera, store in an array, move on to the next vert and repeat.

By the end of it all you have an array with all visible polygons so you can work with that to get all the ones not visible to the camera.. Works with simple objects perfectly, but completely fails when it comes to a complex 1 million poly assembly composed of many different parts. I'm thinking to attempt different shapes at a closer distance (instead of sphere, use a helix and rotate down the object to get close up accurate selections)

Method 2-

Bake light data into the vert colors and then write a face detection script looking at the vert color channel to figure out if the face is occluded or not. So far this sort of works, but it's been a struggle to control the light (I'm getting objects with vert data that should be occluded as unoccluded, and vise-versa...) This method seems a lot more unstable as far as control and baking the light takes some major time.

I'm open to any ideas that you guys can think of. Those are the two straight forward methods that I could think up, but I'm sure you guys have some good ideas. I'm using Maya/Python so that's why I'm looking for theory, not asking for maxscript! :D

Thanks again guys. I'll let you know if I find a viable solution.

- Portfolio-

read 482 times
5/27/2015 1:49:15 AM (last edit: 5/27/2015 1:50:01 AM)
show user profile  Garp
I would try something like raycasting, shooting a ray from each triangle along its normal, checking for self-hits (same object) and whether it hit a backface or a frontface.

edit: Actually you don't need to know if it's a backface or not. If the number of hits is even, the ray was shot from an outer face. Otherwise, it was shot from inside.
Of course you need a method to cast a ray and collect hits on both frontfaces and backfaces. If the method stops after the first hit, you have to reshoot from the hit position along the same normal.

edit2: I think my previous edit might just be plain wrong...

read 477 times
5/27/2015 2:03:32 AM (last edit: 5/27/2015 3:54:18 AM)
show user profile  9krausec
Thanks Garp. I originally was attempting that but couldn't really figure out how to detect front facing/back facing..

I think I need to revisit this though as it would be the most optimal way to go about it.. There has to be the ability to detect that sort of thing within the mfn mesh class... It seems complicated enough!


- Portfolio-

read 471 times
5/27/2015 2:16:05 AM (last edit: 5/27/2015 2:16:05 AM)
show user profile  Garp
Typing at the same time again :)
See my edit in the previous post.

read 469 times
5/27/2015 2:17:43 AM (last edit: 5/27/2015 2:17:43 AM)
show user profile  ScotlandDave
Doing a scipting a raycast was my first thought, iteratively around the model as per your method 1..

It's a tough problem.. I'm sure it's came up on here before..

Had a quick google and found this thread, the guy says in the end he takes the geometry into Maya, and uses it's camera based selection tool..

Not sure how the api's are in max, but if there's functionality for selecting visible ( as per your first method but within a script ) it might be worth playing with. C4D has a VPS ( viewport select ) method in C++ and Python api so assuming most apps have similar. Might encounter the same issue with very large scenes taking a very long time - using a script rather than doing it in the viewport might help with this though, for example a simple recursive function that takes every single object one at a time, and does select-visible, then invert selection and deletes, rather than all objects at once.. Might take a while to run through but possibly worth the payoff.

Final word of caution would be regards selecting occluded polies or doing simple raycasts, that from a front facing angle a polygon might not be 'hit', but from a sheer angle it might be.. Hence probably the necessity of iterating a camera around your scene as per your first method..

Getting a bulk of the unnecessary geometry as opposed to every last poly might be the best you can hope for without going deeply into it..

Website | Blog | Contact | Vimeo

read 465 times
5/27/2015 2:23:25 AM (last edit: 5/27/2015 2:23:25 AM)
show user profile  9krausec
That was my though too Garp, but I found that I cannot do that because all objects have a shell as described below-

So if I could pick apart back facing and front facing I'd be able to do this I think. Right? Or am I missing something (a good possibility here)

- Portfolio-

read 463 times
5/27/2015 2:28:44 AM (last edit: 5/27/2015 2:28:44 AM)
show user profile  9krausec
@ScotlandDave-Thanks for the reply. Yeah, the method that I have a working solution for now (at a simple level.. it falls apart with complexity) is that camera based selection method of moving a camera around the object and generating an array.

I think that for whatever reason, Maya is having a hard time discerning what should be selected and not since the polys are so small and the camera is further away to encompass the entire object. That theory doesn't sound right though because it should be all math based (if in the viewport and visible, select the shit out of that polygon, should not be size dependent at all).

edit: I take that back.. seems to be distance dependent at some level-

Unable to display content. Adobe Flash is required.

- Portfolio-

read 460 times
5/27/2015 2:37:14 AM (last edit: 5/27/2015 2:42:56 AM)
show user profile  Garp
I understand better, now that I've seen your picture.
Stictly speaking, if the object is shelled, there is no 'inside'.

Perhaps an approach based on ambient occlusion? Then again, AO would also catch surface details on the outside. Tough one. I can't think of a simple way that wouldn't require human intervention.

read 448 times
5/27/2015 3:10:13 AM (last edit: 5/27/2015 3:11:50 AM)
show user profile  9krausec
Yeah, it is a tough one! As it stands now, I'm going with the camera based selection approach. The damn thing would work out without a hitch if the camera based selection maintained accuracy not dependent by distance...

Instead of generating a sphere around the object, I'm going to play around with driving the camera position off of a helix. Get all nice and tight on the object (so the whole thing won't be in frame at one time.. but through the revolutions all faces of all objects should be visible at one time or another).

So alas, camera based selection driven by script, but change the way how I'm collecting the data.

- Portfolio-

read 442 times
5/27/2015 3:14:19 AM (last edit: 5/27/2015 3:14:19 AM)
show user profile  herfst1
How about manual? You can use that select-by-angle option with ignore-backface ticked as well and grab the outer shell pretty quickly as in, less than an ten minutes... but, yeah, if there's an automated solution, fuck manual.
read 429 times
5/27/2015 5:35:56 AM (last edit: 5/27/2015 5:35:56 AM)
show user profile  9krausec
Woooo! I think it's working now! I went with a helix approach as opposed to a sphere with the camera based selection model, then I increased the focal length to a telephoto, cropping out a lot of the object, but getting up close to sections.

Wrapping the camera around a helix path allows for everything to be in camera at one time or another.

Data processing is FASTER and it seems far most stable without quality degradation of the mesh after the operation is performed. I need to run more tests and do some refinement on the script, but for now it looks like it is working.

Stuck a lot of hours into this bastard and I'm feeling good about this. Thanks guys!!!!

- Portfolio-

read 410 times
5/28/2015 2:22:47 AM (last edit: 5/28/2015 2:22:47 AM)
show user profile  Garp

read 410 times
5/28/2015 2:43:05 AM (last edit: 5/28/2015 2:43:05 AM)
#Maxforums IRC
Open chat window