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?
guess you just need this line:
put it before the run() command
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.
Is it possible?
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.
# "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() ):
else: return True
Or simply call isInView for every object.
Ahh… Gonna give it a try then, all your suggestions.
Thanks alot everyone!
Thanks alot! mavasher, I used your method, works like a charm. Thanks once again for the code?
But out of curiousity, how do I do isInView? Could you provide me an example? Because it sounds really interesting…
base.camNode.isInView(point) is a more reliable way of doing what mavasher does with project().
I tried but with no luck: no object detected in view
*see 2 post down
The point has to be in the coordinate space of the camera, of course.
ok, now we got it:
# -*- coding: utf-8 -*-
from direct.showbase.DirectObject import DirectObject
import random, sys
from direct.directbase.DirectStart import *
for i in range(20):
ball = loader.loadModel("smiley")
ball.setPos(random.randint(-3,3)*2, random.randint(-3,3)*2, random.randint(-3,3)*2)
for o in objs:
print "%r IN view"%o.getPos()
print "%r NOT IN view"%o.getPos()
w = World()
To be short I tested just the object center anyhow with a little more code using the getTightBounds method should be perfect.
Ahh… I see.
Just applied it, works perfectly as well.
Thanks alot everyone!