check if defined Objects are behind other Objects

Hello together,

i wonder if there is a way to check if some objects (lets call them Hotspots) floating around a fixed object are visible to the camera or behind the main object and therefore not visible?

So far i have written (and copypasted some parts) a script (max design 2013) which outputs the Position of the Hotspots relative to the Camerascreen (XY-Coordinates). Now what i need is a Boolean which says if the object is visible at the moment or not.

Is that even possible using only maxscript?

Sincerly Jerod

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jerodjay's picture

Hello again, so far im

Hello again,

so far im experimenting with the intersectRayScene feature.
From what i see it is possible to shoot a Ray from the Cameraposition to the position of the Hotspots.
Now i have to detect which objects are hit first.
So if the Ray hits a Hotspot first then the Boolean should turn to 1 (=visible)
if the Static object is hit first, then the Boolean should turn to 0 (=not visible) right?

im not sure how to setup this script...

barigazy's picture

...

I don't know is this what you looking for but anyway this is a example how to
collect separately:
"front objects" ei. objects between Hotspot (Yellow sphere "Sphere004") and camera and "behind objects" ei. objects behind hotspot but in front of camera.

This is the fn

fn objectsInFrontOf cam hotspot =
(
	if (zPosHotSpot = in coordsys cam hotspot.pos.z) < 0 do
	(
		local dist = distance cam hotspot
		local objs = dataPair front:#() behind:#()
		for o in geometry where not isKindOf o TargetObject and o.name != hotspot.name do
		(
			if (zPos = in coordsys cam o.pos.z) <= 0 do
				if distance cam o <= dist then append objs.v1 o else append objs.v2 o
		) ; objs
	)
)

barigazy

barigazy's picture

...

In previous example camera object name is "Camera001" and hotspot object "Sphere004". Now to use this fn run the next line

objs = objectsInFrontOf $Camera001 $Sphere004

If you want to select "in front" objects or do some operation on these
U can do this :

select objs.front

Or to select "behind objects" :

select objs.behind

barigazy

barigazy's picture

...

Edit:
change the line

if (zPosHotSpot = in coordsys cam hotspot.pos.z) < 0 do ...

to this

if (in coordsys cam hotspot.pos.z) < 0 do ...

I forgot to remove variable :)

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.