I’m new with Panda3D and try simple example - rotating box, looked and lighted by side. But the light spot must be always infront of the camera, why it is moves with the rotating box, as if the light is child to the box node (it’s NOT!):
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from panda3d.core import PointLight
from geomgen import MakeBox
class MyApp(ShowBase):
"""app"""
def __init__(self):
super().__init__()
light_node = PointLight("point_light")
light = self.cam.attach_new_node(light_node)
self.render.set_light(light)
self.holder = self.render.attach_new_node('holder')
self.box = self.holder.attach_new_node(MakeBox().generate())
self.box.setPos(-0.5, -0.5, -0.5)
self.box.set_render_mode_filled_wireframe((1., 0., 0., 1.))
self.cam.setPos(0, -5, 0)
self.taskMgr.add(self.rot_box_task, 'rot_box_task')
def rot_box_task(self, task):
'''rot'''
alfa = task.time * 50.0
self.holder.setHpr(alfa, alfa*2, alfa*3)
return Task.cont
app = MyApp()
app.run()
and the model is generated by this (geomgen.py file):
# -*- coding: utf-8 -*-
from panda3d.core import (GeomVertexData, GeomVertexFormat, GeomVertexWriter,
Geom, GeomTriangles, GeomNode)
class MakeBox:
'''box'''
def generate(self):
vdata = GeomVertexData('name', GeomVertexFormat.getV3(), Geom.UHStatic)
vdata.setNumRows(8)
vertex = GeomVertexWriter(vdata, 'vertex')
# 6 7
# 4 5
# 2 3
# 0 1
vertex.add_data3(0, 0, 0)
vertex.add_data3(1, 0, 0)
vertex.add_data3(0, 0, 1)
vertex.add_data3(1, 0, 1)
vertex.add_data3(0, 1, 0)
vertex.add_data3(1, 1, 0)
vertex.add_data3(0, 1, 1)
vertex.add_data3(1, 1, 1)
prim = GeomTriangles(Geom.UHStatic)
prim.add_vertices(0, 1, 3)
prim.add_vertices(0, 3, 2)
prim.add_vertices(1, 5, 7)
prim.add_vertices(1, 7, 3)
prim.add_vertices(5, 4, 6)
prim.add_vertices(5, 6, 7)
prim.add_vertices(4, 0, 2)
prim.add_vertices(4, 2, 6)
prim.add_vertices(2, 3, 7)
prim.add_vertices(2, 7, 6)
prim.add_vertices(1, 0, 4)
prim.add_vertices(1, 4, 5)
geom = Geom(vdata)
geom.addPrimitive(prim)
node = GeomNode('gnode')
node.addGeom(geom)
return node