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

)


效果图:


  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值