Skip to content

Instantly share code, notes, and snippets.

@secemp9
Created September 5, 2024 06:01
Show Gist options
  • Save secemp9/5dcd2e5b5369a80bcf97375c64526f1a to your computer and use it in GitHub Desktop.
Save secemp9/5dcd2e5b5369a80bcf97375c64526f1a to your computer and use it in GitHub Desktop.
example scene in panda3D using local assets
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
import math
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Load the environment model.
self.scene = self.loader.loadModel("models/environment")
self.scene.reparentTo(self.render)
self.scene.setScale(0.25, 0.25, 0.25)
self.scene.setPos(-8, 42, 0)
# Add some lighting.
self.dir_light = DirectionalLight("dir_light")
self.dir_light.setColor((1, 1, 1, 1))
self.dir_light_nodepath = self.render.attachNewNode(self.dir_light)
self.dir_light_nodepath.setHpr(0, -60, 0)
self.render.setLight(self.dir_light_nodepath)
# Add ambient light.
self.ambient_light = AmbientLight("ambient_light")
self.ambient_light.setColor((0.2, 0.2, 0.2, 1))
self.ambient_light_nodepath = self.render.attachNewNode(self.ambient_light)
self.render.setLight(self.ambient_light_nodepath)
# Rotate the camera.
self.taskMgr.add(self.spin_camera_task, "spin_camera_task")
def spin_camera_task(self, task):
angle_degrees = task.time * 6.0
angle_radians = angle_degrees * (3.14159 / 180.0)
self.camera.setPos(20 * math.sin(angle_radians), -20.0 * math.cos(angle_radians), 3)
self.camera.lookAt(0, 0, 0)
return task.cont
app = MyApp()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment