--lua -- -------------------------- -- Object bake Extender v1.0 - -------------------------- -- AUTHOR: Zoltan Erdokovy (zoltan.erdokovy@gmail.com) -- -- -- CHANGELOG: -- -- v1.0 (2009-10-22): -- It's for Modo 401 SP2 and above! -- -- USAGE: -- -- This script is for storing a bake distance in a mesh item and using that distance automatically when -- baking from objects. -- There are three ways to run the script: -- -- @ObjectBakeExtender.lua SetDistance -- -- In this case am "Item Tag" dialog will pop up. Set the "Value" to the bake distance of your choice. -- Make sure not to modify the "Tag" field, it should be "BAKX". ---- -- -- @ObjectBakeExtender.lua ToOutputs -- -- This starts a "Bake from objects to render outputs" baking, using the stored distance, if it exists. ---- -- -- @CameraExtender.lua ToTexture -- -- This starts a "Bake from objects to selected texture" baking, using the stored distance, if it exists. ---- ------------------------------------------------ -- -- If you find a bug or have a feature requests don't hesitate to contact me. :) -- ------------------------------------------------ -- This software is licensed under the -- Creative Commons Attribution-Share Alike 3.0 Unported License. -- For more info please visit -- http://creativecommons.org/licenses/by-sa/3.0/ ------------------------------------------------ --------------- -- Changelog -- --------------- -- -- v1.0 (2009-10-22): -- First public release ------------------------------------------------ version = "v1.0" SelectedMesh = nil -- The selected mesh we are working with. SelectedTexture = nil -- The selected texture layer we are baking to. -- -- -- GET MESH TAG -- -- -- function GetMeshTag() local Tag Tag = "" lx("select.drop item") lx("select.item "..SelectedMesh) Tag = lxq("item.tag string BAKX ?")[1] if Tag == "" then -- Non existent tag gives back an empty string instead of nil. o_O lxout("WARNING: No bake distance tag was found.") Tag = nil else lxout("Bake distance tag: "..Tag) end return Tag end -- -- -- SET MESH TAG -- -- -- function SetMeshTag() lx("select.drop item") lx("select.item "..SelectedMesh) lx("item.tag string BAKX ") end -- -- -- GET MESH ITEM -- -- -- function GetMeshItem() ItemCount = 0 ItemType = "" ItemID = "" ItemCount = lxq( "query sceneservice item.N ?")[1] for i = 0, ItemCount-1 do ItemType = lxq( "query sceneservice item.type ? "..i )[1] if ItemType == "mesh" then ItemID = lxq( "query sceneservice item.id ? "..i )[1] end end --lxout(ItemID) return(ItemID) end -- -- -- GET BAKE DISTANCE -- -- -- function GetBakeDistance(Tag) local UnitSystem local MeterPerGameunit local BakeDistance BakeDistance = tonumber(Tag) UnitSystem = lxq("pref.value units.system ?")[1] -- Get units system. if UnitSystem == "game" then MeterPerGameunit = lxq("pref.value units.gameScale ?")[1] -- Get accurate game units. return(BakeDistance*MeterPerGameunit) else return(BakeDistance) end end -- -- -- BAKE -- -- -- function Bake(Type) local BakeDistance local Tag BakeDistance = 0 Tag = GetMeshTag() if Tag ~= nil then BakeDistance = GetBakeDistance(Tag) lxout("Final bake distance: "..BakeDistance) if Type == "ToOutputs" then lxout("Object baking to render outputs.") lx("bake.obj dist:"..BakeDistance) else lxout("Object baking to texture.") if SelectedTexture == nil then lxout("WARNING: No texture layer is selected.") else lx("select.subItem "..SelectedTexture.." set textureLayer;render;environment;light;camera") lx("bake.objToTexture "..BakeDistance) end end end end -- -- -- MAIN -- -- -- Arg1 = arg[1] -- First argument -- Initialization -- SelectedMesh = lxq("query sceneservice selection ? mesh") SelectedTexture = lxq("query sceneservice selection ? textureLayer") if SelectedTexture ~= nil then SelectedTexture = SelectedTexture[1] end if SelectedMesh ~= nil then SelectedMesh = SelectedMesh[1] if (Arg1 ~= nil) then Arg1 = string.upper(Arg1) if Arg1 == "SETDISTANCE" then SetMeshTag() elseif Arg1 == "TOOUTPUTS" then Bake("ToOutputs") elseif Arg1 == "TOTEXTURE" then Bake("ToTexture") end else lxout("WARNING: No argument was passed.") --lx("select.drop item") --lx("select.item "..SelectedMesh) -- Reselect the mesh before leaving the script. end else lxout("WARNING: No mesh is selected.") end