Dev:2.4/Source/Extensions/BLU/Documentation/Testlua

提供: wiki
移動先: 案内検索
local lampmembers= { "name", "r", "g", "b" }
local obmembers= { "name", "x", "y", "z" }

function lampdump(ud)
  print(ud)
  for k,v in pairs(lampmembers) do print("\t", v, ud[v]) end
end

function obdump(ud)
  print(ud)
  for k,v in pairs(obmembers) do print("\t", v, ud[v]) end
end

io.write("\n\nBegin the Lua test script\n\n")

io.write("\n************\nObject functions:\n") for n,v in pairs(Object) do print("\t",n,v) end
io.write("\n************\nLamp functions:\n") for n,v in pairs(Lamp) do print("\t",n,v) end
io.write("\n************\nScene functions:\n") for n,v in pairs(Scene) do print("\t",n,v) end
io.write("\n************\nCamera functions:\n") for n,v in pairs(Camera) do print("\t",n,v) end

io.write("\n")

lampob = Object.new(Object.Lamp, "LuaLamp")
lampob2 = Object.get("Lamp")

lampob.x, lampob.y, lampob.z = 66, 67, 68

lampob.name = "LampObSetter"
print(lampob.name)

lampdat = Lamp.new(Lamp.Spot, "MyLuaLampDat")
lampdump(lampdat)

lampdat2 = Lamp.get("Spot")
io.write(lampdat2:get_name(), "\n")
lampdat2:set_name("LuaRenamedSpot")
io.write("Lamp data name: ", lampdat2:get_name()," bias: ", lampdat2:get_bias(), ". buffer size: ", lampdat2:get_buffer_size(), "\n")

obdump(lampob)
obdump(lampob2)

lampob:set_location(2,2,2)
lampob:link(lampdat)
lampob.data = lampdat2
lampob.data = lampdat

lampob2:set_location(-1, -1, -1)

obs = Object.get()

print(lampob2)
print(lampob)

print(lampdat)
print(lampdat2)

lampob:link(lampdat2)

col = vector3(0.2, 0.73, 0.11)
io.write("set color... ")
lampdat:set_color(col)
print(lampdat)
lampdat:set_color(0.5, 0.5, 0.6)
print(lampdat)
getcol = lampdat:get_color()
print("r=", getcol.r, " g=", getcol.g, " b=", getcol.b)

lampdat.bias = 2.4
print("bias=",lampdat.bias)

print("clipstart", lampdat:get_clip_start())
print("clipend", lampdat:get_clip_end())
print("clipdist", lampdat:get_clip_dist())
lampdat:set_clip_start(0.7)
lampdat:set_clip_end(50)
lampdat:set_clip_dist(30)
print("clipstart", lampdat:get_clip_start())
print("clipend", lampdat:get_clip_end())
print("clipdist", lampdat:get_clip_dist())

lampdat:set_halo_intensity(3.2)
print("halo_intensity", lampdat:get_halo_intensity())

-- Lets try some scene functionality

sce = Scene.new("MyLuaScene")
sce2 = Scene.get("Scene")
sce3 = Scene.get_current()
print(sce)
print(sce2)
print(sce3)

sce:link(lampob)

tst = sce:unlink(lampob)
tst2 = sce2:unlink(lampob2)

print(tst)
print(tst2)

sce:link(lampob2)
sce2:link(lampob2)
sce3:link(lampob)

ca = Camera.get("Camera")
ca2 = Camera.new(Camera.Ortho,"LuaCreatCam")
print(ca)
print(ca2)
ca.name = "LuaRenamedCam"
print(ca)
camob = Object.new(Object.Camera, "LuaCamOb")
camob:set_location(-1, 0, -3)
sce:link(camob)
print(camob)
camob:link(ca2)

--[[ io.write("\nvector tests\n\n")
  -- 
  -- a=vector3(10.5,20,30)
  -- print(a)
  -- print(a.r,a.g,a.b)
  -- 
  -- io.write("\nbitop tests\n")
  -- 
  -- bittest = 8
  -- print(bittest)
  -- bittest = bit.lshift(bittest, 2)
  -- print(bittest)
  -- bittest = bit.rshift(bittest, 1)
  -- print(bittest)
  -- bittest = bit.bnot(bittest)
  -- print(bittest)
  -- bittest = bit.mod(bittest, 3)
  -- print(bittest)
  -- 
  -- io.write("\nrandom tests\n")
  -- 
  -- r=random.new(1234)
  -- 
  -- print("new",r:value(),r:value(),r:value())
  -- s=r:clone()
  -- print("more",r:value(),r:value(),r:value())
  -- r:seed(5678)
  -- print("seed",r:value(),r:value(),r:value())
  -- r:seed(1234)
  -- print("seed",r:value(),r:value(),r:value())
  -- print("more",r:value(),r:value(),r:value())
  -- print("clone",s:value(),s:value(),s:value())
  -- 
  -- r:seed(os.time())
  -- N=100000
  -- 
  -- S={0,0,0,0,0,0,0,0,0,0,0}
  -- for i=1,N do
  --  local i=r:valuei(8)
  --  S[i]=S[i]+1
  -- end
  -- for i=1,9 do
  --  S[i]=math.floor(100*S[i]/N+0.5)
  -- end
  -- print("1..8",S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[8])
  -- 
  -- S={0,0,0,0,0,0,0,0,0,0,0}
  -- for i=1,N do
  --  local i=r:valuei(2,4)
  --  S[i]=S[i]+1
  -- end
  -- for i=1,9 do
  --  S[i]=math.floor(100*S[i]/N+0.5)
  -- end
  -- print("2..4",S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[8])
  -- 
  -- print""
  -- print(random.version)
--]]

io.write("\n\nEnd of script reached\n\n")

to documentation