创建灯光脚本最重要的就是 找到了面中心
-- 创建面灯 的脚本 这个ui 很好
(
(
(
rollout AlightSetup "Mondo Area Lights"
(
local Flatness = 0.2
spinner MyFlatnessSp "Surround" range:[0,1.0,Flatness] type:#float scale:0.01
on MyFlatnessSp changed val do
(
Flatness = val
)
local AreaSize = 100
spinner AreaSizeSp "Area Size" range:[1,10000,AreaSize] type:#integer scale:10
on AreaSizeSp changed val do
(
AreaSize = val
)
local Shad = true
local MyMult = 4
spinner MultiplierSp "Multiplier" Range:[0.001,10.0,MyMult] type:#float scale: 0.01
on MultiplierSp changed val do
(
MyMult = val
)
local Myhotspot = 20
spinner MyhotspotSp "Hotspot" Range:[0,90,Myhotspot] type:#float
on MyhotspotSp changed val do
(
Myhotspot = val
)
local Myfalloff = 60
spinner MyfalloffSp "Falloff" Range:[10,170,Myfalloff] type:#float
on MyfalloffSp changed val do
(
Myfalloff = val
)
local MyUseNearAttCBv = false
checkbox MyUseNearAttCB "Use Near Attenuation" checked:false
on MyUseNearAttCB state changed do
(
MyUseNearAttCBv = MyUseNearAttCB.state
)
local MynearAttenStart = 0
spinner MynearAttenStartSp "Start" Range:[0,100000,MynearAttenStart] scale:1 fieldwidth: 40 across:2
on MynearAttenStartSp changed val do
(
MynearAttenStart = val
)
local MynearAttenEnd = 0
spinner MynearAttenEndSp "End" Range:[0,100000,MynearAttenEnd] scale:1 fieldwidth: 40
on MynearAttenEndSp changed val do
(
MynearAttenEnd = val
)
local MyUseFarAttCBv = false
checkbox MyUseFarAttCB "Use Far Attenuation" checked:false
on MyUseFarAttCB state changed do
(
MyUseFarAttCBv = MyUseFarAttCB.checked
)
local MyfarAttenStart = 0
spinner MyfarAttenStartSp "Start" Range:[0,100000,MyfarAttenStart] scale:1 fieldwidth: 40 across:2
on MyfarAttenStartSp changed val do
(
MyfarAttenStart = val
)
local MyfarAttenEnd = 800
spinner MyfarAttenEndSp "End" Range:[0,100000,MyfarAttenEnd] scale:1 fieldwidth: 40
on MyfarAttenEndSp changed val do
(
MyfarAttenEnd = val
)
local MyinOut = 1
local NumLight = 120
spinner NumLightSp "Light Count" range:[1,200,NumLight] type:#integer
on NumLightSp changed val do
(
NumLight = val
)
local JitterSPv = 0.0
spinner JitterSP "Scatter Jitter" range:[0.0,1.0,JitterSPv] type:#Float scale:0.1
on JitterSP changed val do
(
JitterSPv = val
)
local MyHavePicked = 0
local MySphere = 1
checkbox UseSphereCB "Use Sphere" checked:true
---上面这种写法叫我有点不能接受。 我觉得这样是方便了。
on UseSphereCB changed state do
(
if UseSphereCB.state == false then
(
if MyHavePicked == 0 then
(
UseSphereCB.state = true
MySphere = 1
)
)
else (MyShphere = 0)
)
local MyHavePicked = 0
pickButton MyGetObj "Pick Object"
on MyGetObj picked obj do
(
AreaObj = obj
MyGetObj.text = obj.name
MySphere = 0
MyHavePicked = 1
UseSphereCB.state = false
)
button MakeItB "Make Area Light"
on MakeItB pressed do -------------向这样的脚本没有多少函数, 只要从头读到尾就好了
(
if MySphere == 1 then
(
AreaObj = GeoSphere pos: [0,0,0] radius: AreaSize segments: 4
AreaObj.name = "AreaObj"
convertToMesh AreaObj
AreaObj.renderable = false --关掉了可渲染的功能。
select $AreaObj ---选择创建 的节点
max modify mode
addModifier AreaObj (volumeselect()) --添加体积选择。
areaobj[4][1].level = 1
--改成点的形式
areaobj[4][1][1].pos = [0,0,(AreaSize * -.88)] --移动他的 Gizmo
addModifier AreaObj (deletemesh()) ---删除选择, 这里面的这用删除好用 是按距离不安面数
convertToMesh AreaObj
select $AreaObj ------- 改变了起属性
max modify mode
subobjectLevel = 0
addModifier AreaObj (volumeselect())
areaobj[4][1].level = 0
addModifier AreaObj (XForm())
AreaObj.XForm[2][3].value = [1,1,Flatness]
convertToMesh AreaObj
)
--上面的代码就是对图像的修改 这个效果很好,
if MySphere == 0 then
(
print "Use picked Object"
newAreaObj = snapshot AreaObj ---快照的处理方式。
AreaObj = newAreaObj
)
FCount = getnumfaces AreaObj ---读取三角面数。 这个效果很好。
i = 1
NumLight = NumLight * 1.0
if Fcount <= NumLight then
(
NumLight = Fcount
)
----不知道具体什么意思但是知道是数的交换
for i = 1 to FCount by (FCount / NumLight) do
(
if MyinOut == 1 then ( MyMult = ( MyMult / (NumLight * 1.0)) * 2.0)
if MyMult <= 0.01 then MyMult = 0.011
MyLDir = (getfacenormal AreaObj i) ---法线的坐标
MyLVerts = getFace AreaObj i ----面的坐标
MyLpos = ((getvert AreaObj MyLVerts.x)+(getvert AreaObj MyLVerts.y)+(getvert AreaObj MyLVerts.z))/3
----上面的两句就是把物体放到面上。 get 一个面返回的是一个面的顶点序号。 然后再分别对顶点序号 球坐标 在/3 球的中间值。
---我在学习这个脚本中觉得这个最重要。
MyD1 = distance MyLpos (getvert AreaObj MyLVerts.x)
MyD2 = distance MyLpos (getvert AreaObj MyLVerts.y)
MyD3 = distance MyLpos (getvert AreaObj MyLVerts.z)
MyJitterMax = (MyD1 + MyD1 + MyD1)/3
print "MyJitterMax"
print MyJitterMax
MyJitterMax *= JitterSPv
MyLpos += [(random (MyJitterMax * -1)MyJitterMax),(random (MyJitterMax * -1)MyJitterMax),(random (MyJitterMax * -1)MyJitterMax)]
if i == 1 then
(
AL1 = freespot pos: MyLpos multiplier: MyMult hotspot:Myhotspot falloff: Myfalloff softenDiffuseEdge: 100 \
value: 255 farAttenStart: MyfarAttenStart farAttenEnd: MyfarAttenEnd nearAttenStart: MynearAttenStart \
nearAttenEnd: MynearAttenEnd useNearAtten:(MyUseNearAttCB.checked) useFarAtten:(MyUseFarAttCB.checked) castShadows: Shad
AL1.dir = MyinOut * MyLDir
AL1.parent = AreaObj
AL1.name = "AreaSpot"
)
else
(
if i >= 2 then
(
AL2 = instance $AreaSpot
AL2.pos = MyLpos
AL2.dir = MyinOut * MyLDir
AL2.parent = AreaObj
)
)
)
---在上面最重要的是,找到物体 每个面的中心 这样才好。 定位
$AreaSpot.mapsize = 300 --分别是阴影的 处理值 因为是关联 改你一就好
$AreaSpot.mapbias = 0.1
$AreaSpot.samplerange = 6.0
select $area*
max group group -- I group these new lights
)
)
AL = newRolloutFloater "Area Lights" 198 370
addRollout AlightSetup AL
)
)
)