Inspired by GML(Game Maker Language) from Game Maker. [size=59]I know it’s a piece of **** and *** and s***s so much that ***** * *** *******.[/size]
-POST WAS LOST-
So I will just quickly write down the class. Put it in your game(to the top) or pu it in a separate file and import it after that:
class Light:
count = 0
def amb_lght(cla, clb, clc, cld):
counta = 0
name = "ambient_light %d" % counta
counta += 1
alight = AmbientLight(name)
alight.setColor(VBase4(cla, clb, clc, cld))
alnp = render.attachNewNode(alight)
render.setLight(alnp)
return alnp
def pnt_lght(x, y, z, cla, clb, clc, cld):
countp = 0
name = "point_light %d" % countp
countp += 1
plight = PointLight(name)
plight.setColor(VBase4(cla, clb, clc, cld))
plnp = render.attachNewNode(plight)
plnp.setPos(x, y, z)
render.setLight(plnp)
return plnp
def dir_lght(h, p, r, cla, clb, clc, cld):
countd = 0
name = "directional_light %d" % countd
countd += 1
dlight = DirectionalLight(name)
dlight.setColor(VBase4(cla, clb, clc, cld))
dlnp = render.attachNewNode(dlight)
dlnp.setHpr(h, p, r)
render.setLight(dlnp)
return dlnp
def spot_lght_lookat(x, y, z, cla, clb, clc, cld, lens, obj):
counts = 0
name = "directional_light %d" % counts
counts += 1
slight = Spotlight(name)
slight.setColor(VBase4(cla, clb, clc, cld))
slight.setLens(lens)
slnp = render.attachNewNode(slight)
slnp.setPos(x, y, z)
slnp.lookAt(obj)
render.setLight(slnp)
return slnp
It’s really easy to use:
tpt = loader.loadModel("teapot")
tpt.reparentTo(render)
ambientlight1 = amb_lght(0.7, 0.7, 0.81, 1)
ambientlight2 = amb_lght(1, 1, 1, 1)
pointlight = pnt_lght(0, 0, 100, 0.9, 0.9, 10, 0.1000)
directionallight = dir_lght(0, 0, 1, 1, 1, 1, 1)
spotlight = spot_lght_lookat(0, 10, 4, 1, 1, 1, 1, PerspectiveLens(), tpt)
Rate&report bugs.
EDIT:
Only spotlight has been not reported to be working. If you want to help, then try it, please!