added std.loadModelBounds()
git-svn-id: svn://anubis/anaglym/trunk@202 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
ca6aa317ce
commit
873e12e3cf
28
lib/std.lua
28
lib/std.lua
@ -63,3 +63,31 @@ std.pcty = function(percent)
|
||||
local width, height = ag.getScreenSize()
|
||||
return height * percent
|
||||
end
|
||||
|
||||
-- Load an object from a model file and figure out what scale
|
||||
-- to use based on a maximum specified bounding box the model must fit in.
|
||||
-- Input:
|
||||
-- model_name: the string containing the name of the model to load
|
||||
-- max_x, max_y, max_z:
|
||||
std.loadModelBounds = function(model_name, max_x, max_y, max_z)
|
||||
local tmp_model = ag.loadModel(model_name)
|
||||
local sx, sy, sz = tmp_model:getSize()
|
||||
tmp_model:destroy()
|
||||
local scale = 1.0
|
||||
if (max_x > 0 and sx > 0) then
|
||||
scale = max_x / sx
|
||||
end
|
||||
if (max_y > 0 and sy > 0) then
|
||||
local s = max_y / sy
|
||||
if (s < scale) then
|
||||
scale = s
|
||||
end
|
||||
end
|
||||
if (max_z > 0 and sz > 0) then
|
||||
local s = max_z / sz
|
||||
if (s < scale) then
|
||||
scale = s
|
||||
end
|
||||
end
|
||||
return ag.loadModel(model_name, scale)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user