using the ball from the normal mapping tutorial, and a geom wall, I was able to enable an ambient light, and a point light. but the point light does not shine on the geometry.
Any help?
#from pandac.PandaModules import loadPrcFileData
#loadPrcFileData("", "want-directtools #t")
#loadPrcFileData("", "want-tk #t")
from direct.directbase import DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.gui.DirectGui import *
from direct.interval.IntervalGlobal import *
from pandac.PandaModules import *
from random import randint, random
from direct.task.Task import Task
import sys, os
import math
import random
def makeSquare(x1,y1,z1, x2,y2,z2,flip):
format=GeomVertexFormat.getV3n3cpt2()
vdata=GeomVertexData('square', format, Geom.UHDynamic)
vertex=GeomVertexWriter(vdata, 'vertex')
texcoord=GeomVertexWriter(vdata, 'texcoord')
color=GeomVertexWriter(vdata, 'color')
if x1!=x2:
vertex.addData3f(x1, y1, z1)
vertex.addData3f(x2, y1, z1)
vertex.addData3f(x2, y2, z2)
vertex.addData3f(x1, y2, z2)
else:
vertex.addData3f(x1, y1, z1)
vertex.addData3f(x2, y2, z1)
vertex.addData3f(x2, y2, z2)
vertex.addData3f(x1, y1, z2)
color.addData4f(1.0,1.0,1.0,1.0)
color.addData4f(1.0,1.0,1.0,1.0)
color.addData4f(1.0,1.0,1.0,1.0)
color.addData4f(1.0,1.0,1.0,1.0)
tri1=GeomTriangles(Geom.UHDynamic)
tri2=GeomTriangles(Geom.UHDynamic)
tri1.addVertex(0)
tri1.addVertex(1)
tri1.addVertex(3)
tri2.addConsecutiveVertices(1,3)
tri1.closePrimitive()
tri2.closePrimitive()
square=Geom(vdata)
square.addPrimitive(tri1)
square.addPrimitive(tri2)
return square
def renderwall(snode, texttype):
cube=mazenode.attachNewNode(snode)
cube.setTwoSided(True)
def drawbox(boxx,boxy):
rl=1
ll=0
nt=2
square0=makeSquare(boxx-2,boxy-2,-1, boxx,boxy-2, 1.5,ll)
square1=makeSquare(boxx-2, boxy,-1, boxx, boxy, 1.5,rl)
square2=makeSquare(boxx-2, boxy, 1.5, boxx,boxy-2, 1.5,nt)
square3=makeSquare(boxx-2, boxy,-1, boxx,boxy-2,-1,ll)
square4=makeSquare(boxx-2,boxy-2,-1, boxx-2, boxy, 1.5,rl)
square5=makeSquare(boxx,boxy-2,-1, boxx, boxy, 1.5,ll)
snode=GeomNode('square')
snode.addGeom(square0)
snode.addGeom(square1)
snode.addGeom(square2)
snode.addGeom(square3)
snode.addGeom(square4)
snode.addGeom(square5)
renderwall(snode, 0)
def lighting():
areacolour=VBase4(0.4,0.4,0.4,0.4)
ambient = AmbientLight('ambient')
ambient.setColor(VBase4(areacolour))
ambientNP = mazenode.attachNewNode(ambient.upcastToPandaNode())
mazenode.setLight(ambientNP)
def lighting1():
sphere = loader.loadModel("models/sphere")
sphere.reparentTo(mazenode)
sphere.setScale(0.5,0.5,0.5)
plight = PointLight('plight')
plight.setColor(VBase4(1, 0, 0, 1))
plnp = mazenode.attachNewNode(plight)
plnp.setPos(-5, -5, 0)
mazenode.setLight(plnp)
mazenode=render.attachNewNode("mazeNode")
mazenode.reparentTo(render)
def main():
drawbox(2,2)
lighting()
lighting1()
base.useDrive()
base.setBackgroundColor(0.3, 0.3, 0.3)
# base.camera.setPos(0,-4.5,0)
# base.camera.lookAt(0,0,0)
#base.camera.setHpr(-38,0,0)
main()
run()