Panda3D is:



Panda3D is:

0 0


hello.panda

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:

nevercenter.com/silo/

Export Model

Save to models/sphere.obj

Problem! Panda3D expects sphere.egg

Solution?

http://andyp.pfastergames.com/2008/12/15/updated-obj2eggpy-convert-obj-to-egg/

ppython obj2egg.py models/sphere.obj
					

hellopanda.py

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

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

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)
self.camera.setPos(0.0, 5.0, 15.0)
self.camera.lookAt(0.0, 0.0, 0.0)
					

Progress!

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)
render.setLight(ambientLightNP)
					

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)
render.setLight(pointLightNode)
					

Better!

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"
	classid="CLSID:924B4927-D3BA-41EA-9F7E-8A89194AB3AC">
		<param name="data" value="hello.p3d">
	</object>
</object>