emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 7, 2011 9:42:12 GMT -5
Loading and Posing an Object:
# HINT - A basic program showing a scene with one object from a fixed camera # NOTE - Numeric values are arbitrary in this example (you need to change them for your program) import direct.directbase.DirectStart # Disabling user controlled camera base.disableMouse() # Placing the camera in world space base.camera.setPos(-0.5,-3.5,0.5) # Location (x, y, z) base.camera.setHpr(-45,0,0) # Orientation in degrees (Heading, Pitch, Roll) # Loading a new ready-made model model = loader.loadModel("television.egg") # Model filename model.setScale(0.15) # Uniform scaling of the model model.setPos(2,-2,0) # Location (x, y, z) model.setHpr(-45,0,0) # Orientation in degrees (Heading, Pitch, Roll) # Adding the model to the Scene Graph under the root model.reparentTo(render) # Start main loop run()
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 7, 2011 9:47:33 GMT -5
Finding a Node and Applying Texture:
# HINT - A basic program showing a scene with one object from a fixed camera # NOTE - Numeric values are arbitrary in this example (you need to change them for your program) import direct.directbase.DirectStart # Disabling user controlled camera base.disableMouse() # Placing the camera in world space base.camera.setPos(-0.5,-3.5,0.5) # Location (x, y, z) base.camera.setHpr(-45,0,0) # Orientation in degrees (Heading, Pitch, Roll) # Loading a new ready-made model model = loader.loadModel("television.egg") # Model filename model.setScale(0.15) # Uniform scaling of the model model.setPos(2,-2,0) # Location (x, y, z) model.setHpr(-45,0,0) # Orientation in degrees (Heading, Pitch, Roll) # Adding the model to the Scene Graph under the root model.reparentTo(render) # HINT - Finding a nodepath to a named sub-node nodepath = model.find("**/screen") # HINT - Loading a new texture mytexture = loader.loadTexture("Textures/shuttle.avi") # HINT - Setting a texture property nodepath.setTexture(mytexture, 1) # Start main loop run()
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 7, 2011 9:49:39 GMT -5
Creating a World Class and Simple Navigation:
import direct.directbase.DirectStart from direct.showbase.DirectObject import DirectObject
class World(DirectObject): def __init__(self): """ The constructor, which builds the scene and sets up user control """ # Code for building the scene could go here... base.camera.setPos(-0.5,-3.5,0.5) # Location (x, y, z) base.camera.setHpr(-45,0,0) # Orientation in degrees (Heading, Pitch, Roll) """ An interactive scene """ model = loader.loadModel("television.egg") # Model filename model.setScale(0.15) # Uniform scaling of the model model.setPos(2, -2, 0) # Location (x, y, z) model.setHpr(-45, 0, 0) # Orientation in degrees (Heading, Pitch, Roll) # Adding the model to the Scene Graph under the root model.reparentTo(render) # HINT - Finding a nodepath to a named sub-node nodepath = model.find("**/screen") # HINT - Loading a new texture mytexture = loader.loadTexture("Textures/shuttle.avi") # HINT - Setting a texture property nodepath.setTexture(mytexture, 1) # Set up movement keys self.keystate = {'back':0} # Just a member variable to store the state of each key self.accept('s', self.set_keystate, ['back', 1]) # Handler for 's' press self.accept('s-up', self.set_keystate, ['back', 0]) # Handler for 's' release self.lasttime = 0 taskMgr.add(self.update_camera, "camerathread") # Start a new thread which then will loop run() # forever to update the camera position def set_keystate(self, key, state): """ Set a stored state (either 0 or 1) for a specified key ('back',...)""" self.keystate[key] = state # Updates the member variable holding the states of the keys def update_camera(self, task): """ Update camera position and/or rotation for all active key states. """ elapsed = task.time - self.lasttime if self.keystate['back'] is 1: # Checks the member variable for the current state of a given key base.camera.setPos(camera, 0, -0.7 * elapsed, 0) # "setPos" with 4 parameters makes the translation # relative to the first parameter self.lasttime = task.time return task.con
This doesn't work, any help?
|
|
|
Post by David Sorrentino on May 7, 2011 12:46:05 GMT -5
Please, could you be more clear? Could you post the error(s) in question? Anyway, off the top of my head, I think that the problem should be that, after creating the class World, you should instantiate it. To do it, you could let two empty lines at the end of the file and then insert:
World() Cheers, David
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 7, 2011 12:50:52 GMT -5
I have no error messages, but the screen of panda 3d appears and rapidly disappears soon after... The following is the output....as you see I think it's pretty normal DirectStart: Starting the game. Known pipe types: wglGraphicsPipe (all display modules loaded.)
|
|
|
Post by David Sorrentino on May 7, 2011 12:58:34 GMT -5
Sorry, we posted at the same time! Anyway, maybe in my previous post I got the point about your problem. Let us know if it works! David
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 7, 2011 13:15:54 GMT -5
unfortunately it doesn't
DirectStart: Starting the game. Known pipe types: wglGraphicsPipe (all display modules loaded.) Traceback (most recent call last): File "C:\Users\emiliano\Desktop\workspace\lab2\src\test\world.py", line 46, in update_camera return task.con AttributeError: 'libpanda.PythonTask' object has no attribute 'con' :task(error): Exception occurred in PythonTask camerathread Traceback (most recent call last): File "C:\Users\emiliano\Desktop\workspace\lab2\src\test\world.py", line 49, in <module> run() File "C:\Panda3D-1.7.2\direct\showbase\ShowBase.py", line 2630, in run self.taskMgr.run() File "C:\Panda3D-1.7.2\direct\task\Task.py", line 502, in run self.step() File "C:\Panda3D-1.7.2\direct\task\Task.py", line 460, in step self.mgr.poll() File "C:\Users\emiliano\Desktop\workspace\lab2\src\test\world.py", line 46, in update_camera return task.con AttributeError: 'libpanda.PythonTask' object has no attribute 'con'
|
|
|
Post by David Sorrentino on May 7, 2011 13:19:19 GMT -5
The last line (before the instantiation of World) is:
return task.cont and NOT:
return task.con
David
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 7, 2011 13:33:03 GMT -5
from direct.showbase.DirectObject import DirectObject import direct.directbase.DirectStart
class World(DirectObject):
def __init__(self): """ The constructor, which builds the scene and sets up user control """ base.camera.setPos(-0.5,-3.5,0.5) # Location (x, y, z) base.camera.setHpr(-45,0,0) # Orientation in degrees (Heading, Pitch, Roll) # Code for building the scene could go here... # Loading a new ready-made model model = loader.loadModel("television.egg") # Model filename model.setScale(0.15) # Uniform scaling of the model model.setPos(2,-2,0) # Location (x, y, z) model.setHpr(-45,0,0) # Orientation in degrees (Heading, Pitch, Roll) # Adding the model to the Scene Graph under the root model.reparentTo(render) # HINT - Finding a nodepath to a named sub-node nodepath = model.find("**/screen") # HINT - Loading a new texture mytexture = loader.loadTexture("Textures/shuttle.avi") # HINT - Setting a texture property nodepath.setTexture(mytexture, 1) # Set up movement keys self.keystate = {'back':0} # Just a member variable to store the state of each key self.accept('s', self.set_keystate, ['back',1]) # Handler for 's' press self.accept('s-up', self.set_keystate, ['back',0]) # Handler for 's' release self.lasttime = 0 taskMgr.add(self.update_camera, "camerathread") # Start a new thread which then will loop # forever to update the camera position def set_keystate(self, key, state): """ Set a stored state (either 0 or 1) for a specified key ('back',...)""" self.keystate[key] = state # Updates the member variable holding the states of the keys def update_camera(self, task): """ Update camera position and/or rotation for all active key states. """ elapsed = task.time - self.lasttime if self.keystate['back'] is 1: # Checks the member variable for the current state of a given key base.camera.setPos(camera,0,-0.7*elapsed,0) # "setPos" with 4 parameters makes the translation # relative to the first parameter self.lasttime = task.time return task.cont
World() run()
I have a grey screen, no model is shown
P.s: I find very annoying that the indentation is not preserved copying my code...I even use the code tags
|
|
|
Post by David Sorrentino on May 7, 2011 13:35:20 GMT -5
One moment, I try it on my pc. In the meantime try to insert another line before the instantiation of World.
David
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 7, 2011 13:42:51 GMT -5
it's just the same...isn't the indentation of World() correct? this way the indentation should be preserved! Attachments:
|
|
|
Post by David Sorrentino on May 7, 2011 13:52:25 GMT -5
The problem was that the command base.disableMouse() was missing. Try to insert it at the beginning of the constructor(__init__). However I have attached the corrected code to this post. Cheers Emiliano , David Attachments:
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 8, 2011 4:32:08 GMT -5
problem solved, this is the solution of "Creating a World Class and Simple Navigation": anyway I'm wondering what's the meaning of "elapsed time" in the calculus of the camera relocation... Attachments:
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 8, 2011 5:20:34 GMT -5
Now I'm stuck at point 4: I've created a new file, named Room.py. Now I've these 2 files, but I have an error message saying " global name 'Room' is not defined". Attachments:
|
|
emiliano
New Member
Get rich or die trading.
Posts: 21
|
Post by emiliano on May 8, 2011 5:21:11 GMT -5
And here it is the Room.py Attachments:
|
|