Lightmapping Tutorial Part 2 : Lightmaps in Panda

Moderator: BenChang

Lightmapping Tutorial Part 2 : Lightmaps in Panda

Postby BenChang » Sun Oct 13, 2013 6:18 am

The lightmaps we created in Part 1 are stored as PNG files in the lightmaps folder. They aren't included in the .egg file when you export from Maya, but it's not hard to load them and reattach them to the geometry in your Panda code.

All the files have names like "baked_tpIllumination_groundShape.png" or "baked_tpIllumination_hengepieceShape7.png". These filenames are generated by a pattern you set in the Render Settings for Turtle in Maya. By default, it's
Code: Select all

where $p is the Pass (Diffuse, Specular, Ambient, Albedo, SSS, etc) and $s is the shape name. We're using the "Illumination" pass which is the sum of all the lighting components. If you check "Full Shading" it also includes the material and texture properties, or what is known optimistically as the "Beauty" pass.

In Panda, we're going to load the PNG file, find the appropriate NodePath to attach it to, create a new texture stage and apply the texture.

Exporting from Maya

The default Panda export settings should work. Make sure that "Keep all UV's" is checked - otherwise it will trim out UV sets that it doesn't think you're using.

Panda Code

Code: Select all
import direct.directbase.DirectStart #starts Panda
from pandac.PandaModules import *    #basic Panda modules
from direct.showbase.DirectObject import DirectObject  #for event handling
from import Actor #for animated models
from direct.interval.IntervalGlobal import *  #for compound intervals
from direct.task import Task         #for update fuctions
import sys, math, os

class World(DirectObject):
    def __init__(self):
        self.level = loader.loadModel("henge")
    def applyLightMaps(self):
        lightmapFiles = os.listdir("lightmaps")
        for f in lightmapFiles:
            f2=os.path.splitext(f)[0]   #remove the extension
            shapename=f2.split("_")[-1]  #split on _ and take the last one
            transformName=shapename.replace("Shape","",1) #remove the word "Shape" to get the name of the transform node
            print f
            print transformName
            obj = self.level.find("**/"+transformName)
            print obj
            if not obj.isEmpty():
                tex=loader.loadTexture("lightmaps/" + f)


The only trickery to this is figuring out the name of the NodePath based on the filename. In Maya, all objects have two nodes - a Transform node and a Shape node. The Transform only holds transform data (position, rotation, etc) while the Shape node holds the actual geometry data, for example "hengepiece1" and "hengepieceShape1" or "pCube1" and "pCubeShape1". In Panda, the NodePath is equivalent to Maya's Transform, while a Node contains the Shape data. The setTexture() function is applied at the NodePath level, but the lightmap filenames all are based on the names of the Shape nodes in Maya, so we just have to do some string manipulation to get the name of the transform to feed into find() and setTexture().

For more on those functions, see the sections in the Panda Manual:
[url] ... cene_Graph[/url]
[url] ... troduction[/url]

Scene without lightmaps, and then with lightmaps


User avatar
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Return to Art and Animation

Who is online

Users browsing this forum: No registered users and 2 guests