Sorry to bother, but is there a way to get all the stuff being rendered on the scene via the camera?
As in, a Panda3D method of sorts.
‘cuz I want to find a way to be able to detect all the nodepaths that are being shown, so that I can highlight a particular few of interest… And if theres no built-in method, I gonna have to do a check between the objects’ positions and the camera’s position, and the angle of the camera to the object… That… should work as well, right?
Thanks for replying, but that… wasn’t exactly what I was aiming for…
I was talking about stuff which is being seen on the camera, not those that are on the scene, ehehe…
Basically, what you are looking at. So for example, I look at an apple in front of me, and I look at the wall behind me, and the results which come out will be different, one having the apple and one without.
ah sorry not getting what you said - a possible solution is with collision solids: you provide a collision solid shooting off the camera lens and then test whos inside - as much as fishing with a net - here you’ll find all you need
PS: of course is not what you need ready to go - you gotta take off the parts you need and set the polygon boundaries for the entire frustum
Here’s one way to do it. In this one, you have to query each node/object- that should not be hard just set up a for loop using this function and it will return True if it’s on screen and False if it’s not.
def _onscreen(object):
# "object" is the nodepath you are asking about.
# Convert the point to the 3-d space of the camera
p3 = base.cam.getRelativePoint(render, object.getPos())
# Convert it through the lens to render2d coordinates
if not base.camLens.project(p3, Point2() ):
return False
else: return True
# -*- coding: utf-8 -*-
from direct.showbase.DirectObject import DirectObject
import random, sys
from direct.directbase.DirectStart import *
base.cam.setPos(0,-20,0)
class World(DirectObject):
def __init__(self):
for i in range(20):
ball = loader.loadModel("smiley")
ball.reparentTo(render)
ball.setPos(random.randint(-3,3)*2, random.randint(-3,3)*2, random.randint(-3,3)*2)
self.accept("escape", sys.exit)
self.accept("mouse1", self.click)
def click(self):
objs=base.render.findAllMatches("**/+ModelNode")
for o in objs:
if base.camNode.isInView(o.getPos(base.cam)):
print "%r IN view"%o.getPos()
o.setColor((1,0,0,1))
else:
print "%r NOT IN view"%o.getPos()
o.setColor((1,1,1,1))
w = World()
run()
To be short I tested just the object center anyhow with a little more code using the getTightBounds method should be perfect.