Panda3D 初学者教程(一)

Panda3D 初学者教程(一)

原文链接

原文

Lesson 1

Hello World

In which we learn how to make and run a Panda3D instance, and how to load and manipulate models.

At it’s most basic, running a Panda3D program is quite simple: create a “ShowBase” object, and tell it to run.

Specifically, it can be convenient to make our main “game-class” a sub-class of ShowBase: this unifies our game-class with the ShowBase that we’ll run, and even gives us a globally-accessible variable, named “base”, that points to our game.

from direct.showbase.ShowBase import ShowBase

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

game = Game()
game.run()

If you run the code above, a window should open titled “Panda”, and showing an empty grey view:
Panda3D 初学者教程(一)_第1张图片

By default, Panda3D opens an 800x600 window, which can be somewhat small. So, let’s make it a little bigger.

There are a few ways of doing this, but one simple method is to “request window properties”. In short, we create a “WindowProperties” object, set the properties that we want in that object, and then pass it back to Panda, requesting that it apply them.

I’ve chosen a window-size of 1000x750; modify this to suit your screen and preference.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties

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

        properties = WindowProperties()
        properties.setSize(1000, 750)
        self.win.requestProperties(properties)

game = Game()
game.run()

Panda3D by default uses a particular mouse-based camera-control. We probably don’t want to use that, so we disable that control, allowing us to (later) control the camera ourselves:

self.disableMouse()

Next, let’s consider adding some models to the scene…

翻译:

在其中,我们学习如何创建和运行Panda3D实例,以及如何加载和操作模型。
最基本的是,运行Panda3D程序非常简单:创建一个“ShowBase”对象,并告诉它运行。
具体来说,可以方便地将我们的主“游戏类”设置为ShowBase的子类:这将我们的游戏类与我们要运行的ShowBase统一起来,甚至为我们提供了一个全局可访问的变量,名为“base”,它指向我们的游戏。

from direct.showbase.ShowBase import ShowBase

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

game = Game()
game.run()

如果运行上述代码,将打开一个标题为“Panda”的窗口,并显示一个空的灰色视图:
Panda3D 初学者教程(一)_第2张图片

默认情况下,Panda3D会打开一个800x600窗口,该窗口可能有些小。所以,让我们把它放大一点。
有几种方法可以做到这一点,但一种简单的方法是“请求窗口属性”。简而言之,我们创建一个“WindowProperties”对象,设置该对象中需要的属性,然后将其传递回Panda,请求它应用这些属性。
我选择了尺寸为1000x750的窗口;修改此选项以适合您的屏幕和偏好。

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties

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

        properties = WindowProperties()
        properties.setSize(1000, 750)
        self.win.requestProperties(properties)

game = Game()
game.run()

默认情况下,Panda3D使用特定的基于鼠标的摄影机控件。我们可能不想使用它,所以我们禁用该控件,允许我们(稍后)自己控制相机:

self.disableMouse()

接下来,让我们考虑在场景中添加一些模型…

你可能感兴趣的:(python,计算机视觉)