PDA

View Full Version : objects visible in camera


manditri
06-29-2007, 04:01 PM
Hi,
I am trying to get the names of objects that are currently visible(partially or complete) through the ative camera. Is there any direct MEL command/option to do this? Or if there is some logic that can be applied in a script and get the obj names shed some light on it.

Would really appreciate the help. Thanks

trancor
06-29-2007, 04:51 PM
Well, I began writing a script a little while ago, never got around to finishing it (damn work) that does kind of what you need. The script would find the dotProduct of locators I connected to faces with a locator on the inside of an object to return a value of 1 or -1 for if the object was inside or outside of the object placed. BASICLY, using some highschool geometry to figure out if something was above or below a point.


If you make a few locators, one for the top of the render view, left of the view, right, and bottom, and then place one locator inbetween them all, you can figure out if something is within the 4 locators due to the inside locator.

I don't have the time to write up a full script and give you a mb with the set up, but I can tell you how to go about setting up what you'd need.

Dot Product - The difference between two points devided by the distance between the points times the edge points you set up minus the position of the objects in your scene, this will return a positive value or negative value, this basicly looks like -


$a = `pointPosition A`;
$b = `pointPosition B`;
$p1 = `pointPosition $currentObject`;
$c = ($b - $a)/mag($b - $a);
float $dotPlane = $c*($b-$p1);


Point A is your locator in the center of your view (parent this to your camera aim)
Point B is one of your locators on the outside of your view to look for the pos/neg value
Point p1 is your current object that is being looked at.
C is just some math
$dotPlane is your infinate plane that determines the positive negative relationship in math. This number is the number you call up to check if it's + or - 0 to check for the name of the objects.

You'd need to apply this script for each of the 4 points determining the outside of your view. Basicly imaging a line being drawn from point A to point B and that line is kind of like a normal on a polygon, determining what is the outside face of the poly.

if you put these scripts into an if statement like this -

if (($dotPlane1>=0) && ($dotPlane2>=0) && ($dotPlane3>=0) && ($dotPlane4>=0)){
print $currentObject;
}


It should print out the objects within your view. Obviously you'd need to make a script to select all of the objects and add them to an array and do a for loop to run through the array checking if the object is within the 4 points or not.

If I didn't explain myself well enough or you want me to make a basic set up of the scene for you I will, but it will need to be later.

trancor
06-29-2007, 04:57 PM
oh, I forgot there is actually a command in mel to find dot products, this should be fast and easy for you, it's just dot, but look it up, find out how to use it. I'm more of a math guy and programmer, this mel stuff is too easy now, hehe.

CGTalk Moderation
06-29-2007, 04:57 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.