Home Technical Talk

Maxscript - Delete all polys that the camera can't see?

Novian
polycounter lvl 5
Offline / Send Message
Novian polycounter lvl 5
Gents / Ladies,

Is the subject possible? As part of my internship I am creating a great number of scenes that are camera static so I am directed to delete all hidden geometry. It would be great if there were a script I could write to do this. Would anyone happen to know how I should structure the logic for if a poly can be seen by the camera? I'd imagine I would like it to be in a percentage coverage so that I don't accidentally delete something that could be mostly seen. Just brainstorming.

As always any help would be most appreciated (and save me some work :))

Cheers~

Replies

  • Adam L. Gray
    Options
    Offline / Send Message
    Well, if there really are a lot of objects and scenes, then I have no idea, as I don't script myself. But otherwise;

    You could probably select all the faces of the meshes in edit poly, viewing from the camera angle, while having (ignore backfaces?) enabled. And then just to be on the safe side, expand your selection once, then inverse your selection and delete.

    Still though, are you sure this is a good idea? Could get some pretty iffy shadow casting if there's going to be any lighting in there.
  • Novian
    Options
    Offline / Send Message
    Novian polycounter lvl 5
    @Adam L. Gray: Thanks for the suggestion. All lighting in the game is baked, save for the characters which are dynamic lit. And their shadows only fall mostly on solid ground so I am told there is no fear of missing polys for shadow's sake. I had that same question when I first started. What about the polys needed for curves and such? Nope. All baked. :)

    Thanks again.

    Cheers~
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    I have seen scripts that do exactly this on scriptspot and elsewhere on the web

    related results (using google)
    http://www.scriptspot.com/bobo/mxs2/cfc/
    http://www.scriptspot.com/3ds-max/scripts/camera-based-face-selection
    http://72.27.230.245/3ds-max/scripts/camerafacecounter

    The way pretty much all of them work is by creating a cone mesh of the field of view, then looping through all objects to see if they hit, if they do: loop through the faces see if they intersect or are within the cone and if they face the camera (backface culling) if all that applies keep the faces, the others delete.

    I remember a thread on Cgtalk or here where someone created a script that actually adds faces over time as the camera would be animated. So imagine a a complex scenery and you only keep the faces of the environment that is actually visible to the camera. So if you aim for that you need an bitArray per object where you mark all the faces being kept - or to delete over the range of time-range.
    Anyway I have seen more stuff like this on the internet so search more aggressive as I did and you will find them.
  • Novian
    Options
    Offline / Send Message
    Novian polycounter lvl 5
    @renderhjs: Thanks very much! I thought the problem would be more complex so I admit my searching was a bit lax and for that I apologise. I'm not one of those "here let me google that for you" types. I'm very new still to scripting so to me the issue seemed pretty difficult. However I forgot that there are people like you and mcLichy out there who are much smarter than I! :) hehe. Thanks again!

    Cheers~
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    I spend sometimes an entire week researching particular problems on the net, collecting everything I can get my hands on and eventually understand a little bit more to get a picture of whats out there. I am sometimes a bit obsessed but in the end I always manage somehow to get results.

    If you are stuck with even starting to script this, just ask here. I or many of the other members will help you with the bits you are stuck with - if you should. I remember myself creating once a script like this, at least with the camera facing part. If i'd had to do it again and I'd be kinda lost right I'd just open those sample scripts I linked copy bits of them and try to get as far as possible with that.
  • Titus
  • marks
    Options
    Offline / Send Message
    marks greentooth
    This is probably a really great excercise for learning about doing raytracing in maxscript :)
Sign In or Register to comment.