This tutorial explains how to do Texture Baking using Lua scripts.
The scene dice.sceng has two objects, DiceHP, a high resolution version of the dice, and DiceLP, a low resolution version of the dice for which the textures will be created.
Load the SceneEngine libraries:
require("gmt_lua") require("sceng_lua")
Load the dice scene:
sceng.OpenScene( "scenes/dice.sceng" )
Set DiceHP and DiceLP as Lua variables:
dice_hp = sceng.GetNode( "DiceHP" ) dice_lp = sceng.GetNode( "DiceLP" )
Call the RenderParameters table to get a default set of rendering parameters.
rp = sceng.RenderParameters()
Turn on texture baking mode, and set the offset and prefilter values.
rp.do_texture_baking = true rp.ray_offset = 5.0 rp.prefilter_size = 5.0
Set the filenames of the texture elements that the raytracer will save.
rp.output_file = "scenes/dice_complete.tga" rp.diffuse_file = "scenes/dice_diffuse.tga" rp.normals_file = "scenes/dice_normals.tga" rp.wire_file = "scenes/dice_wire.tga"
Texture size and antialiasing:
rp.width = 512 rp.height = 512 rp.samples = 2
Set the target node as DiceLP and the uvw mesh id as 0.
rp.target_nodes = {} rp.target_nodes[1] = dice_lp rp.target_uvw_ids = { 0 }
Set the source node as DiceHP.
rp.source_nodes = {} rp.source_nodes[1] = dice_hp
And render the scene:
sceng.Render( rp )
These are the resulting images: