Panda3D is:

Panda3D is:

0 0


Reveal.js presentation describing a basic start-to-finish Panda3D project

On Github collectivecognition / hello.panda

Panda3D is:

  • A cross-platform 3D engine
  • Both python and c++ runtimes
  • Cross platform, including web and soon mobile

Install Panda3D & Dependencies:

Create a model:

Export Model

Save to models/sphere.obj

Problem! Panda3D expects sphere.egg


ppython models/sphere.obj

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

class Hello(ShowBase):
	def __init__(self):
		base.setBackgroundColor(0.0, 0.0, 0.0)
		# Load a model and parent it to the renderer
		sphere = loader.loadModel("models/sphere.egg")
		sphere.setPos(0.0, 0.0, 0.0)
hello = Hello()

Let's give it a try:

Not very exciting!

Point the camera at the model:

# Position and aim the camera
base.camLens.setNearFar(1.0, 50.0)
base.camLens.setFov(45.0), 5.0, 15.0), 0.0, 0.0)


Add some ambient light:

Panda3D is 100% lit by default.

# Set up an ambient light
ambientLight = AmbientLight("ambientLight")
ambientLight.setColor(Vec4(0.3, 0.3, 0.3, 1))
ambientLightNP = render.attachNewNode(ambientLight)

Not quite right...

Add a point light:

# Add a point light
pointLight = PointLight("pointLight")
pointLight.setColor(VBase4(0.5, 0.5, 0.5, 1))
pointLightNode = render.attachNewNode(pointLight)
pointLightNode.setPos(5.0, 0.0, 5.0)


And some texture:

# Apply a texture to the sphere
textureStage = TextureStage("ts")
texture = loader.loadTexture("textures/grid.png")
sphere.setTexture(textureStage, texture)
sphere.setTexScale(textureStage, 2.0, 2.0)

Now we're getting somewhere...

Add some movement:

import math
from direct.task import Task 
from direct.interval.IntervalGlobal import *

. . .

# Spin the object
def SpinTask(task): 
	x, y, z = sphere.getHpr()
	sphere.setHpr(x + 1.0, y + 1.0, z + 1.0)
	return Task.cont 
self.taskMgr.add(SpinTask, "SpinTask")

Sign and bundle:

openssl genrsa 1024 > ~/.ssh/panda3d.pem
openssl req -new -x509 -nodes -sha1 -days 365 
  -key ~/.ssh/panda3d.pem >> ~/.ssh/panda3d.pem
packp3d -c auto_start=1 -S ~/.ssh/panda3d.pem -o ../hello.p3d -d ./

Embed in a web page:

<object width="640" height="480"
type="application/x-panda3d" data="hello.p3d">
	<object width="640" height="480"
		<param name="data" value="hello.p3d">