MaxScript 例子 渲染

MaxScript 渲染的例子



macroScript NewTextureRender category:"WJL"
(
    --烘焙函數
    fn BakeDiffuseAndLighting obj size =
    (

    --清空所有渲染元素
    obj.iNodeBakeProperties.removeAllBakeElements()  

    --準備烘焙元素
    be1 = diffusemap()
    be1.outputSzX = be1.outputSzY = size --set the size of the baked map

    be1.fileType = (getDir #image+"\\"+obj.name+"_diffuse.tga")
    be1.fileName = filenameFromPath be1.fileType
    be1.filterOn = true --enable filtering
    be1.shadowsOn = false --disable shadows
    be1.lightingOn = false --disable lighting
    be1.enabled = true --enable baking
    

    be2 = LightingMap() -- 實例燈光烘焙元素
    be2.outputSzX = be2.outputSzY = size --set the size of the baked map

    be2.fileType = (getDir #image+"\\"+obj.name+"_lighting.tga")
    be2.fileName = filenameFromPath be2.fileType
    be2.filterOn = true --enable filtering
    be2.shadowsOn =true --enable shadows
    be2.enabled = true --enable baking

    --準備烘焙
    obj.INodeBakeProperties.addBakeElement be1 --add first element
    obj.INodeBakeProperties.addBakeElement be2 --add second element
    obj.INodeBakeProperties.bakeEnabled = true --enabling baking
    obj.INodeBakeProperties.bakeChannel = 1 --channel to bake
    obj.INodeBakeProperties.nDilations = 1 --expand the texture a bit
    
    --烘焙選中項,所以選中obj
    select obj

    --調用渲染烘焙
    render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[size,size]

    --創建一個複合紋理
    theComp = CompositeTextureMap()
    theComp.add() --添加第二個層
    theComp.blendMode = #(0,5) --設置層位模式 5:Multiply
    
    --創建兩個紋理,一個擁有diffuse,另一個用於lighting 紋理
    theMap1 = bitmaptexture filename:be1.fileType
    theMap2 = bitmaptexture filename:be2.fileType
    
    --複合兩個紋理
    theComp.mapList = #(theMap1, theMap2)
    --設置燈光紋理爲70%的透明度
    theComp.opacity = #(100,70)

    --創建一個標準的紋理,並設置diffuseMap爲 theComp,紋理光照強度爲100
    bakedMat = standard diffusemap:theComp selfIllumAmount:100

    --創建一個Shell_Material紋理並賦值給obj
    obj.material = Shell_Material originalMaterial:obj.material \
    bakedMaterial:bakedMat viewportMtlIndex:1 renderMtlIndex:1

    --顯示烘焙紋理到視口中
    showTextureMap obj.material obj.material.bakedMaterial true

    )--end fn

    
    --重置場景
    resetMaxFile #noprompt

    --創建燈光
    theLight = omniLight pos:[0,-60,100] rgb:white
    theLight.baseobject.castshadows = true
    
    --創建一個紋理球
    theObject = Sphere segs:32 mapcoords:true pos:[0,0,25]
    
    --創建一個網格紋理
    theMap = cellular cellColor:blue divColor1:red divColor2:yellow size:15

    theObject.material = standard diffusemap:theMap

    --調用烘焙函數
    BakeDiffuseAndLighting theObject 256

    --創建一個帶有紋理的平面對象
    theObject = Plane width:200 length:200 mapcoords:true

    --創建一個 checker map ,設置 tiling 爲 4x4
    theMap = checker Color1:green Color2:orange
    theMap.coordinates.uTiling = theMap.coordinates.vTiling = 4

    theObject.material = standard diffusemap:theMap

    --調用烘焙函數
    BakeDiffuseAndLighting theObject 256
   
    delete theLight
    max select none

)


效果圖:


發佈了50 篇原創文章 · 獲贊 19 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章