[Closed] RTT Issuse
Global really does mean global, within Max at least. Even other scripts can use variables globally declared in other scripts (in fact, this is one of the reasons why declaring global variables should be kept to an absolute minimum – especially if it has a fairly simple name that could easily be used in other scripts, like “count” or “theMesh” or something. This is, as you correctly diagnosed, the reason why it was working, then ceased to work after you closed Max).
I was wondering about that thanks for the clarification. What is the best way to have variables multiple scripts need access to?
To avoid that kind of problems i use this stencil to write scripts:
stencil.ms:
-- General comments about script, name, creation date, last modification date, author, source of inspiration authors or pages, changes log....
( --start script
--write all inside
--includes
-- local and globals variables
global mainRoll -- rollout name may be global but sure not with that name
local SourceDirectoryName_STR = undefined --your variable is local and you can initialize
--local functions
fn addProjMod lowResObj highResObjs cageOffset =
(
--blablabla
) --end fn addProjMod lowResObj highResObjs cageOffset =
--rollouts
rollout mainRoll "Unreal Multi Tool"
(
-- blabla
) --end rollout mainRoll "Unreal Multi Tool"
createDialog mainRoll 175 450
) --end script
Sure there are better ways but at least it works for simple scripts
I will make sure to use the for the future and thanks for the heads up on the use of undefined. I had tried that before but it was not working, probably because I had it set up incorrectly, but everything is coming along nicely now and I am starting to get a better and better grip on how all of this works. Here is what I have working so far in case anyone is interested.
-- Store the selected path so that we can use it / change it later on.
-- This needs to be up here or it will not allow the saving of the path. This will conflict with the other sctipt as I do n
Global SourceDirectoryName_STR = undefined
-- Makes sure that we have only one window open at a time.
if (( mainRoll != undefined) and ( mainRoll.isdisplayed)) do
(destroyDialog mainRoll ) -- test if dialog exist
rollout mainRoll "Unreal Multi Tool"
(
group "RTT"
(
button hp "High Poly" align:#left width:85 height:20
button lp "Low Poly" align:#left width:85 height:20
button browse "Texture Location" align:#left width:85 height:20
edittext SourcePath "Export File Location :" text: "<Select Valid source path>" fieldWidth:150 align:#left readOnly:true labelOnTop:true
button butRTT "RTT"align:#left width:70 height:20
spinner cage "Cage Offset" align:#left width:70 height:20
colorpicker csRayMissColor "Ray Miss Color" align:#Left fieldwidth:15 height:15 color:black
)
On hp pressed do
(
fn geometryHP = isKindOf obj Geometry
(
theGeo1 = selectByName title:"Select High Poly" buttonText:"Select Mesh" showHidden:false single:true
global theProjObj = theGeo1
print(theGeo1)
)
)
On lp pressed do
(
fn geometryLP = isKindOf obj Geometry
(
theGeo2 = selectByName title:"Select Low Poly" buttonText:"Select Mesh" showHidden:false single:true
global theObj = theGeo2
print(theGeo2)
)
)
on butRTT pressed do
(
if (ClassOf theObj.modifiers[1]) != projection do
(
-- add project modifier and projection objects
fn addProjMod lowResObj highResObjs cageOffset =
(
modMode = getCommandPanelTaskMode()
setCommandPanelTaskMode #modify
projMod = projection()
addModifier lowResObj projMod
for obj in highResObjs do
(
projMod.addObjectNode obj
)
projMod.resetCage()
projMod.pushCage cage.value
projMod.displayCage = true
projMod.name = "ProjMod"
setCommandPanelTaskMode modMode
-- This is our retun for later.
projMod
)
)
if (ClassOf theObj.modifiers[1]) == projection do
(
fn addProjMod lowResObj highResObjs cageOffset =
(
--projMod = projection()
projMod
)
)
-- define variables
renderSize = 512
fileName = theObj.name + ".tga"
print(fileName)
filePath = SourceDirectoryName_STR
print(filePath)
-- the bake object needs to be selected
select theObj
-- set up the bake interfaces
bakeProps = theObj.INodeBakeProperties
bakeProps.removeAllBakeElements()
bakeProjProps = theObj.INodeBakeProjProperties
-- add type of map to render
--map = NormalsMap()
map = LightingMap()
-- file name
map.filename = fileName
map.fileType = filePath + filename
-- map size
map.outputSzX = renderSize
map.outputSzY = renderSize
map.enabled = true
--New options that I need to look up what they do.
map.shadowsOn =true --enable shadows
map.filterOn = true --enable filtering
bakeProps.addBakeElement map --add first element
bakeProps.bakeEnabled = true --enabling baking
bakeProps.bakeChannel = 1 --channel to bake
bakeProps.nDilations = 1 --expand the texture a bit
bakeProjProps.rayMissColor = csRayMissColor.color
-- projection
bakeProjProps.enabled = true
bakeProjProps.projectionMod = (addProjMod theObj #(theProjObj) 1)
-- open and close RTT
macros.run "Render" "BakeDialog"
destroyDialog gTextureBakeDialog
-- do the render
-- curBM = bitmap renderSize renderSize
--render rendertype:#bakeSelected frame:0 to:curBM vfb:true cancelled:&wasCanceled
-- close curBM
-- the bake object needs to be selected
select theObj
-- do the render
render rendertype:#bakeSelected frame:0 vfb:off progressBar:true outputSize:[renderSize, renderSize] cancelled:&wasCanceled
)
on browse pressed do
(
--Get the location of where we want to export the file to.
SourcePath_Var = getSavePath caption:"Please select a Folder to export";
--If there is no path selected promt the user to select a path.
if SourcePath_Var == undefined then
(
messagebox "Please select an Export location";
)
-- This stores the soruce path as a string.
else
(
SourcePath.text = SourcePath_Var + "\\"
SourceDirectoryName_STR = SourcePath.text
)
)
)
createDialog mainRoll 175 450