Modding, Mission Design, and Coding > The Modding Workshop
Useful scripts for 3ds Max
Scooby_Doo:
LODDING
This script let's you hide/show lod levels quickly and easily. You have 4 lod levels to use, simply select the object(s) you want on a specific level and hit the "+" next to the LOD level. "-" will remove it from that level. You can then use the show/hide buttons for those objects. Hint: Objects can be on more than one lod level.
--- Code: ---macroScript LodDisplay category:"Fast Utils"
(
rollout renameObjs_rollout "LODS" width:344 height:240
(
button btnShow0 "Show" pos:[48,66] width:107 height:34
button btnHide0 "Hide" pos:[160,66] width:104 height:32
label lbl4 "LOD 0" pos:[8,80] width:32 height:16
button btnAdd0 "+" pos:[272,66] width:32 height:32
button btnRemove0 "-" pos:[304,66] width:32 height:32
button btnShow1 "Show" pos:[48,104] width:107 height:34
button btnHide1 "Hide" pos:[160,104] width:104 height:32
label lbl7 "LOD 1" pos:[8,118] width:32 height:16
button btnAdd1 "+" pos:[272,104] width:32 height:32
button btnRemove1 "-" pos:[304,104] width:32 height:32
button btnShow2 "Show" pos:[48,144] width:107 height:34
button btnHide2 "Hide" pos:[160,144] width:104 height:32
label lbl8 "LOD 2" pos:[8,158] width:32 height:16
button btnAdd2 "+" pos:[272,144] width:32 height:32
button btnRemove2 "-" pos:[304,144] width:32 height:32
button btnShow3 "Show" pos:[48,184] width:107 height:34
button btnHide3 "Hide" pos:[160,184] width:104 height:32
label lbl9 "LOD 3" pos:[8,198] width:32 height:16
button btnAdd3 "+" pos:[272,184] width:32 height:32
button btnRemove3 "-" pos:[304,184] width:32 height:32
fn ShowChildren parent levelText =
(
for obj in parent do
(
test = getUserPropBuffer obj
if matchpattern test pattern:levelText then
unhide obj
)
for children in parent.children do
(
ShowChildren children levelText
)
)
fn HideChildren parent levelText =
(
for obj in parent do
(
test = getUserPropBuffer obj
if matchpattern test pattern:levelText then
hide obj
)
for children in parent.children do
(
HideChildren children levelText
)
)
on btnShow0 pressed do
(
for obj in rootscene.world.children do
(
ShowChildren obj "*lod=0*"
)
)
on btnHide0 pressed do
(
for obj in rootscene.world.children do
(
HideChildren obj "*lod=0*"
)
)
on btnAdd0 pressed do
(
for loop = 1 to selection.Count do
(
test = getUserPropBuffer selection[loop]
if not(matchpattern test pattern:"*lod=0*") then
(
test = test + "lod=0\r\n"
setUserPropBuffer selection[loop] test
)
)
)
on btnRemove0 pressed do
(
for loop = 1 to selection.Count do
(
buff = (getUserPropBuffer selection[loop]) as stringStream
newb = stringStream ""
while not eof buff do
(
str = readLine buff
if str != "" and not matchpattern str pattern:"*lod=0*" do format "%\r\n" str to:newb
)
setUserPropBuffer selection[loop] (replace_LF_with_CRLF (newb as string))
)
)
on btnShow1 pressed do
(
for obj in rootscene.world.children do
(
ShowChildren obj "*lod=1*"
)
)
on btnHide1 pressed do
(
for obj in rootscene.world.children do
(
HideChildren obj "*lod=1*"
)
)
on btnAdd1 pressed do
(
for loop = 1 to selection.Count do
(
test = getUserPropBuffer selection[loop]
if not(matchpattern test pattern:"*lod=1*") then
(
test = test + "lod=1\r\n"
setUserPropBuffer selection[loop] test
)
)
)
on btnRemove1 pressed do
(
for loop = 1 to selection.Count do
(
buff = (getUserPropBuffer selection[loop]) as stringStream
newb = stringStream ""
while not eof buff do
(
str = readLine buff
if str != "" and not matchpattern str pattern:"*lod=1*" do format "%\r\n" str to:newb
)
setUserPropBuffer selection[loop] (replace_LF_with_CRLF (newb as string))
)
)
on btnShow2 pressed do
(
for obj in rootscene.world.children do
(
ShowChildren obj "*lod=2*"
)
)
on btnHide2 pressed do
(
for obj in rootscene.world.children do
(
HideChildren obj "*lod=2*"
)
)
on btnAdd2 pressed do
(
for loop = 1 to selection.Count do
(
test = getUserPropBuffer selection[loop]
if not(matchpattern test pattern:"*lod=2*") then
(
test = test + "lod=2\r\n"
setUserPropBuffer selection[loop] test
)
)
)
on btnRemove2 pressed do
(
for loop = 1 to selection.Count do
(
buff = (getUserPropBuffer selection[loop]) as stringStream
newb = stringStream ""
while not eof buff do
(
str = readLine buff
if str != "" and not matchpattern str pattern:"*lod=2*" do format "%\r\n" str to:newb
)
setUserPropBuffer selection[loop] (replace_LF_with_CRLF (newb as string))
)
)
on btnShow3 pressed do
(
for obj in rootscene.world.children do
(
ShowChildren obj "*lod=3*"
)
)
on btnHide3 pressed do
(
for obj in rootscene.world.children do
(
HideChildren obj "*lod=3*"
)
)
on btnAdd3 pressed do
(
for loop = 1 to selection.Count do
(
test = getUserPropBuffer selection[loop]
if not(matchpattern test pattern:"*lod=3*") then
(
test = test + "lod=3\r\n"
setUserPropBuffer selection[loop] test
)
)
)
on btnRemove3 pressed do
(
for loop = 1 to selection.Count do
(
buff = (getUserPropBuffer selection[loop]) as stringStream
newb = stringStream ""
while not eof buff do
(
str = readLine buff
if str != "" and not matchpattern str pattern:"*lod=3*" do format "%\r\n" str to:newb
)
setUserPropBuffer selection[loop] (replace_LF_with_CRLF (newb as string))
)
)
)
createDialog renameObjs_rollout
)
--- End code ---
How it works: It simply adds a property "lod" to the objects properties.
Scooby_Doo:
Collapse Clones
Ever get the message in PCS2 that something couldn't be imported because it wasn't xform resetted? But you don't want to do an xform reset because you'll lose inheritance data. This comes to the rescue... Simply select the object(s) and run script. The original object will be cloned, that clone will be xform reset and the original object(s) will be hidden. If you make changes to the original object latter, just rerun the script, it'll delete the original clone and make a new one.
--- Code: ---macroScript CollapseClones category:"Fast Utils"
(
fn AddKey theObject key=
(
buff = getUserPropBuffer theObject
buff = buff + key
setUserPropBuffer theObject buff
)
fn RetrieveID theObj theKey =
(
buff = (getUserPropBuffer theObj) as stringStream
newb = stringStream ""
scankey = "*" + theKey + "*"
while not eof buff do
(
str = readLine buff
if str != "" and matchpattern str pattern:scankey do
(
filtered = filterString str "="
return filtered[2]
)
)
return ""
)
fn RemoveKey object key =
(
buff = (getUserPropBuffer object) as stringStream
newb = stringStream ""
while not eof buff do
(
str = readLine buff
if str != "" and not matchpattern str pattern:("*" + key + "*") do format "%\r\n" str to:newb
)
setUserPropBuffer object (replace_LF_with_CRLF (newb as string))
)
fn DeleteChildren obj =
(
for loop = 1 to obj.Children.count do
(
DeleteChildren obj.Children[loop]
)
delete obj
)
fn RemoveExistingClones parentID =
(
for child in rootscene.world.children do
(
id = RetrieveID child "slave"
if matchpattern id pattern:parentID then
(
DeleteChildren child
)
)
)
fn CreateClone object uniqueID =
(
--Get the node and all it's children
maxOps.CloneNodes
-- Now create the clone
maxOps.CloneNodes object clonetype:#copy newnodes:&cloneNodes expandHierarchy:true
for loop = 1 to cloneNodes.count do
(
AddKey cloneNodes[loop] ("slave=" + uniqueID + "\r\n")
--cloneNodes[loop].Name = cloneNodes[loop].Name + "-Cloned"
cloneNodes[loop].Name = (uniquename "cloned")
--First unlink children
tempChildren = #()
for child in cloneNodes[loop].Children do
(
append tempChildren child
child.parent = undefine
)
--Then collapse
collapseStack cloneNodes[loop]
ResetXForm cloneNodes[loop]
collapseStack cloneNodes[loop]
--Then relink
for child in tempChildren do
append cloneNodes[loop].Children child
)
)
fn HideOriginal obj =
(
for loop = 1 to obj.Children.Count do
(
HideOriginal obj.Children[loop]
)
hide obj
)
fn ResetXFormClone object =
(
for obj in object do
objectChildren = #()
for child in obj.children do
append objectChildren child
for child in objectChildren do
child.parent = undefined
--print ("Reseting XForm on " + node.name)
collapseStack obj
ResetXForm obj
collapseStack obj
if objectChildren.count >= 1 then
(
for child in objectChildren do
child.parent = obj
)
)
for loop = 1 to selection.count do
(
checkForSlave = RetrieveId selection[loop] "*slave=*"
if (checkForSlave != "") then
continue
-- Retrieve the existing unique ID, if any
uniqueID = RetrieveID selection[loop] "master"
if (uniqueID != "") then
(
RemoveExistingClones uniqueID
RemoveKey selection[loop] "master"
)
--Create a random parent ID value
randomValue = random 1000 9999
uniqueID = uniquename selection[loop].Name + randomValue as string
CreateClone selection[loop] uniqueID
--Now add that name to the parents properties
AddKey selection[loop] ("master=" + uniqueID + "\r\n")
HideOriginal selection[loop]
)
)
--- End code ---
How it works: it simply creates a random number name that it attaches to the master/slave.
Navigation
[0] Message Index
[*] Previous page
Go to full version