[SOLVED]

ok so thought id start learning panda3d. Starting with the Hello World tutorial but adjusted a bit to load my own models and such to get the feel for it.

here is my first attempt to load a plain ol sphere into the scene graph:


from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor

#quick and dirty start
#import direct.directbase.DirectStart

class MyApp(ShowBase):

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

#load models and stuff here
self.pandaActor = Actor("models/Antris V")
self.pandaActor.setScale(0.25, 0.25, 0.25)
self.pandaActor.reparentTo(self.render)

#loop animation here since its a planet that spins
#self.pandaActor.loop("rotate")

# Main Loop
app = MyApp()
app.run()

and here is the result:

Traceback (most recent call last):
  File "C:\Panda3D-1.7.1\DarkRift MMO\DarkRift MMO\src\darkriftmmo.py", line 22, in <module>
    self.pandaActor = Actor("models/Antris V")
  File "C:\Panda3D-1.7.1\direct\actor\Actor.py", line 176, in __init__
    self.mergeLODBundles = base.config.GetBool('merge-lod-bundles', True)
NameError: global name 'base' is not defined

I have tried this using loadModel as well with pretty much the same result. any ideas? this is Panda 1.7.1 on windows 7 x64 ultimate in the case that makes a difference.

Proper indentation is important in Python. Might want to properly indent the code.

thats how netbeans indented the codeblock when I typed it, is the def__init__(self): block misindented? also the code runs fine when the model code is comented out as is. AND its not raising an indentation error usualy python does if its not properly indented.

I assure you it is an indentation problem. The difference between this:

class MyApp(ShowBase):

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

#load models and stuff here
self.pandaActor = Actor("models/Antris V") 

And this:

class MyApp(ShowBase):

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

        #load models and stuff here
        self.pandaActor = Actor("models/Antris V") 

is the difference between an incorrect program and a correct one. Just because the Python interpreter didn’t yell about it doesn’t mean it is correct.

David

ok , fixed that but now nothing happens at all when I run it lol, not even any errors nor the grey panda window.

here is the revised code with a camera and stuff added:


from math import pi, sin, cos

from direct.task import Task
from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor

#quick and dirty start
#import direct.directbase.DirectStart

class DarkRift(ShowBase):

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

#load models and stuff here
    self.pandaActor = Actor("DarkRift/models/Antris V")
    self.pandaActor.setScale(1.25, 1.25, 1.25)
    self.pandaActor.reparentTo(self.render)
    self.pandaActor.setPos(-8, 42, 0)
    
 # Add the spinCameraTask procedure to the task manager.
    self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
#loop animation here since its a planet that spins
#self.pandaActor.loop("rotate")
# Define a procedure to move the camera.
  def spinCameraTask(self, task):
    angleDegrees = task.time * 6.0
    angleRadians = angleDegrees * (pi / 180.0)
    self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
    self.camera.setHpr(angleDegrees, 0, 0)
    return Task.cont
# Main Loop
    app = DarkRift()
    app.run()

i dont know if it cant find my model or what but

Please pay very, very careful attention to indentation. Now you have gone too far the other way.

Replace:

# Main Loop
    app = DarkRift()
    app.run() 

With:

# Main Loop
app = DarkRift()
app.run() 

You should understand that indentation is how Python assigns the scope of commands. When you indent a command inside a function, it means that command is intended to be part of that function and will run when that function is called. When you don’t indent a command, it means that command is outside of any functions and will run when the file is imported.

David

DOH , Thanks for pointing that out, Im kinda still getting used to python from php and c++. now it tries to run but im not pointing it to the right model folder, but thats an io problem i can maybe figure out .

I will try to slow down and pay closer attention to my indentation.

lol DANG IT heres what happens now, something related to verts in the model:



Error in /c/Panda3D-1.7.1/DarkRift/src/Models/Antris V.egg at line 8218, column 28:
      <Ref> { Antris V.verts }
                           ^
parse error

:egg2pg(error): Error reading /c/Panda3D-1.7.1/DarkRift/src/Models/Antris V.egg
:loader(error): Couldn't load file Models/Antris V.egg: all matching files on model path invalid (the model path is currently: "/c/Panda3D-1.7.1/DarkRift/src;/c/Panda3D-1.7.1/etc/..;/c/Panda3D-1.7.1/etc/../models")
Traceback (most recent call last):
  File "C:\Panda3D-1.7.1\DarkRift\src\darkriftmmo.py", line 42, in <module>
    app = DarkRift()
  File "C:\Panda3D-1.7.1\DarkRift\src\darkriftmmo.py", line 25, in __init__
    self.environ = self.loader.loadModel("Models/Antris V")
  File "C:\Panda3D-1.7.1\direct\showbase\Loader.py", line 169, in loadModel


    raise IOError, message
IOError: Could not load model file(s): ['Models/Antris V']
:TaskManager: TaskManager.destroy()

no idea what this one means either lol

Nevermind, I had the model scaled way to high in max so essensialy the camera was “spawning” for lack of a better term inside it.

Actually, that problem was due to the space within the name “Antris V”. The Max to egg converter should have been responsible for removing these spaces, but it didn’t, so I guess that means you can’t have an object with a space in the name in Max.

David

upon more investigation, now that I scaled the model down it loads fine with the space in the name.

before , the model was so big the camera ended up inside the sphere which in this case is a solid object. even though collision isnt set up, it didnt like it. now even with the space in it, it loads as expected. unless the name is being truncated when it acculy loads the model. so, probably just one of those odd quirks about the engine but scaling the model back up reproduces the issue.

so, could be that i just happened to get lucky in my scale and the camera was exactly at the same place as one of the verts in the mesh or something.

Would you mind naming your threads more context oriented? Thanks

A Tip on a sidenote:
using minus or underscore or possibly not using any word dividers at all (how about ThisKindOfNames?) will make your life way easier.