Few questions...

I have some questions about few things…

from panda3d.core import WindowProperties

wp = WindowProperties.getDefault()
wp.setCursorHidden(True)
wp.setUndecorated(True)
wp.setTitle(“test”)
WindowProperties.setDefault(wp)

Why is this not working? it does not show ‘test’ on title box and the cursor is still visible.

self.dlight = DirectionalLight(‘dlight’)
self.dlight.setColor(VBase4(0.8, 0.8, 0.8, 3))
self.dlnp = render.attachNewNode(self.dlight)
self.dlnp.setHpr(7, -6, 0)
self.dlnp.setPos(0, 8, 4)
render.setLight(self.dlnp)

I would like to know what this whole codes does but you can partially answer.
(I really don’t like Panda3D doc. It makes me even more confusing…)

  1. last question…

What does CollisionTraverser() do?
and what does base.pusher = CollisionHandlerPusher() does?

why can’t I change base.cTrav to something like base.trav?

(again I read the doc but it didn’t explain clearly.)

EDIT

I have another question…

What’s the difference between using

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

def __init__(self):
    ShowBase.__init__(self)

app = MyApp()
app.run()

and just using

import direct.directbase.DirectStart

run()

is there are more benefits less benefits for each one?

Another edit sorry…

How do I import light attributes from panda3d.core?

I don’t want to just do this,
from panda3d.core import *

The window properties are set that way for any windows opened in the future. If you already have one (importing directStart or initing showBase opens a window for you)then the code will do nothing. Run it before any other imports or use base.openMainWindow(props=WindowProperties.getDefault(), gsg=base.win.getGsg())

self.dlight = DirectionalLight(‘dlight’)
creates a directional light node named ‘dlight’ and stores a reference to it as self.dlight

self.dlight.setColor(VBase4(0.8, 0.8, 0.8, 3))
sets the color of the light to:
red= 0.8
green=0.8
blue=0.8
alpha=3 (alpha for lights is ignored, but some shader could still use this data).
VBase4 could be replaced with Vec4 or just a tuple.

self.dlnp = render.attachNewNode(self.dlight)
creates and attaches a new node to render, in this case our light. In other words -wraps the light into a NodePath

self.dlnp.setHpr(7, -6, 0)
sets the orientation (heading, pitch, roll) of the node.

self.dlnp.setPos(0, 8, 4)
sets the position (x,y,z) of the node
(silly in this case -directional lights have no position)

render.setLight(self.dlnp)
tells render to use this light.

  1. Use base.win.requestProperties instead of WindowProperties.setDefault(wp) where “base” is your ShowBase object

self.dlight = DirectionalLight(‘dlight’) # Create Directional Light
self.dlight.setColor(VBase4(0.8, 0.8, 0.8, 3)) # Set light color
self.dlnp = render.attachNewNode(self.dlight) # Attach light to the scene graph. And create NodePath to manipulate it
self.dlnp.setHpr(7, -6, 0) # Set light orientation
self.dlnp.setPos(0, 8, 4) # For Directional light it not need because DL works independently of position
render.setLight(self.dlnp) # Set on what our light should affect. In this case it’s whole scene (render is a scene root), but you can set somethig like my_model.setLight(self.dlnp) and light should affect only on your model

  1. Collisions is quite complex question. In short: CollisionTraverser calculate yor collisions. base.cTrav - default traverser, which run every frame automatically. If you use another variable for traverser, then you can/should call traverse(NP) by hand when you need.
    Traverser provide information about collision (point, normal, e.t.c), but do nothing with collided models. Handlers (include CollisionHandlerPusher) work with collision information and do something with collided models. What they do is depends of handler type - push, generate event, e.t.c.

  2. direct.directbase.DirectStart just make ShowBase object for you, or you can create it by hand with class MyApp(ShowBase) in second case.

  3. from panda3d.core import LightAttrib

DirectStart works by magic (sort of).
You import it and puff you have a run() function, some global names like render and base, you have a window opened, a traverses ready, audio managers and all sorts of gizmos.

Some say it’s unpythonic, same say it’s convenient. Use what you like, python Zen says:
‘Explicit is better than implicit
(…)
Although practicality beats purity.’

For the record, this is the contents of DirectStart.py:

print 'DirectStart: Starting the game.'

from direct.showbase import ShowBase
base = ShowBase.ShowBase()

It will be deprecated in 1.9.0.

What exactly will be deprecated? You mean using DirectStart or using ShowBase without creating inherited class?

Just the DirectStart module. It causes issues for tools that inspect modules by importing them, and serves not much purpose other than confusing people while barely saving on the amount of code typed. People can just use those two lines in their code in place of the DirectStart import.

There is no requirement to inherit from anything, nor will there be for the foreseeable future. I will be discouraging the use of some unnecessary globals though, by suggesting people to use “base.run()” instead of “run()”, “base.camera” instead of “camera”, etc.

Thanks you guys for replaying!

It helped me a lot.