Notifications
Clear all

[Closed] Normal Tex Baking – via Scanline

Hey guys/and girls,

I try to create a fast normal baking script in which the user only has to select two geometries and set a cage- Then the Script will bake the last selected on the first. WEverything seems to work allright except the outcome is always complete flat. I’m completly sure that I forgot some on liner or something similar. So if anyone has allready worked with the bake elments in maxscript I would really appreciate any help. Greeting ELi

–in method objList[1] –select two objects first is target other is source gets Projected
function setRefCage obj obj2 stdm=
(
obj.iNodeBakeProperties.removeAllBakeElements()
cagedistance = stdm.value
print cagedistance
converttopoly obj
theProj = ProjectionMod()
addModifier obj theProj
select obj
theProj.addObjectNode obj2
theProj.autowrapCage()
theProj.resetCage()
theProj.pushCage cagedistance
theProj.addRegisteredProjectionType 1
theProj.projectProjectionType 1
theProj.ignoreBackfacing = true
theProj.pushValue = cagedistance
theProj.displayCage = true
)

global objList = getcurrentSelection()

–try killing the old dialog, if there is one
try(closeRolloutFloater rof)catch()

rollout a “Set the Cage for the Bake” width:250 height:400
(
spinner stdnum_mtl “Cage Distance:” pos:[35,26] width:164 height:16 range:[2,100,10] type:#integer fieldwidth:40
button btn_2″Set Cage for Bake” pos:[20,47] width:200 height:20
button btn_1 “Start” pos:[20,90] width:200 height:40

on btn_2 pressed do
(
    setRefCage objList[1] objList[2] stdnum_mtl
)

on btn_1 pressed do
(       
    select objList
    renderers.current =  RendererClass.classes[1]() --scanline

    if superclassof objList[1] == geometryclass and classof objList[1] != bonegeometry and  superclassof objList[2] == geometryclass and classof objList[2] != bonegeometry then 
    (
        print "everything fine"
    )
    else 
    (
        messagebox "Select a mesh" title: "Wrong Selection"  beep:true
    )
    size = 4096
    --Clear all render elements 

    --Preparing theobjectfor baking:
    objList[1].INodeBakeProperties.bakeEnabled = true --enabling baking
    objList[1].INodeBakeProperties.bakeChannel = 1 --channel to bake
    objList[1].INodeBakeProperties.nDilations = 1 --expand the texturea bit

    --Preparing the Bake Elements:
    be1 = normalsmap() --instance of the bake element class
    be1.outputSzX = be1.outputSzY = size --set the size of the baked map
    be1.useNormalBump = true
    --specifythe full file path, name and type:
    be1.fileType = (getDir #image+"\\"+objList[1].name+"_normalMap.png")
    be1.fileName = filenameFromPath be1.fileType
    be1.filterOn = true --enable filtering
    --be1.lightingOn = false --disable lighting
    be1.enabled = true --enable baking
    --be1.samples = 128


    objList[1].INodeBakeProperties.addBakeElement be1 --add first element

    select objList[1] 
    --we are baking the selection, so we select the object
    --Call the renderer to bake both elements:
    render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[size,size]
)--end on

)–end ro

rof=newrolloutfloater “RenderToTex with Projection v0.1” 500 500

addRollout a rof rolledUp:false

Seems lika a lot of code but without the rollout its not that much.

Hope someone knows what up