Skip to content

Instantly share code, notes, and snippets.

@aobond2
Last active October 14, 2022 15:05
Show Gist options
  • Save aobond2/6e1129eda6b792692039cee84d540038 to your computer and use it in GitHub Desktop.
Save aobond2/6e1129eda6b792692039cee84d540038 to your computer and use it in GitHub Desktop.
try (closeRolloutFloater MainFloater) catch()
rollout LODCheck "LOD Checker"
(
spinner lodNumberSpinner "Max LOD number" type:#integer range:[0,5,3] align:#left
spinner reductionSpinner "Reduction percentage" type:#integer range:[0,100,50] align:#left
global nodeArray = #()
global reductionPercentage = 50
global maxLOD = 3
label menuLabel "Select an object/layer from layer explorer" align:#left
button checkLODButton "Check LODs Tris Count And Naming" height:40
on reductionSpinner changed val do
(
reductionPercentage = reductionSpinner.value
)
on lodNumberSpinner changed val do
(
maxLOD = lodNumberSpinner.value
)
--function to select child nodes
fn selectNodesInLayer layer_name =
(
local nodes(LayerManager.getLayerFromName layer_name).nodes &nodes
select nodes
nodeArray = selection as array
-- custom function for sorting
fn compareNames str1 str2 = stricmp str1.name str2.name
qsort nodeArray compareNames
)
-- Check nodes name against pattern
fn nameCheck nodeArrayInput =
(
trimLength = 4
namePattern = "LOD"
wrongNameArray = #()
for i in nodeArrayInput do
(
correct = findString i.name namePattern
if correct == undefined then
append wrongNameArray i.name
)
if wrongNameArray.count > 0 then
messageBox (wrongNameArray[1] + " have wrong name and need to be corrected")
)
-- Check triangle reduction on each lods
fn checkTriangleReduction nodeArrayInput =
(
lowReductionArray = #()
for i = 1 to nodeArrayinput.count - 1 do
(
idealReduction = nodeArrayInput[i].mesh.numfaces * (100 - reductionPercentage) / 100
if nodeArrayInput[i + 1].mesh.numfaces > idealReduction then
append lowReductionArray nodeArrayInput[i + 1].name
)
if lowReductionArray.count > 0 then
for i = 1 to lowReductionArray.count do (
messageBox (lowReductionArray[i] + " need to be reduced more")
)
)
fn checkLODNumber arrayinput =
(
if arrayinput.count > maxLOD then
messageBox ("Max number of LOD allowed is " + maxLOD as string)
)
on checkLODButton pressed do
(
-- This condition doesnt work, because I don't know how to differentiate whether we're
-- selecting an object or a layer. But selecting an object is enough to run this script
if layername != undefined then
(
--Get selected layer name
tmp = SceneExplorerManager.GetActiveExplorer()
layer = tmp.SelectedItems()
layername = layer[1].name
-- select children of selected layer
selectNodesInLayer layername
)
--This is for selecting an object then select all other object that in the same child hierarchy level
if selection != undefined then
(
for obj in selection do obj.layer.select true
nodeArray = selection as array
-- custom function for sorting
fn compareNames str1 str2 = stricmp str1.name str2.name
qsort nodeArray compareNames
)
--Do name check
nameCheck nodeArray
-- Check number of lods
checkLODNumber nodeArray
-- Do Triangle reduction check
checkTriangleReduction nodeArray
nodeArray = #()
layername = undefined
)
)
rollout materialCheck "Material Checker"
(
spinner checkMaterialSpinner "Max Texture number" type:#integer range:[0,5,4] align:#left
button checkMaterialButton "Check LODs Material Number" height:40
global selectionArray = #()
global maxMaterialNumber = 4
on checkMaterialSpinner changed val do
(
maxMaterialNumber = checkMaterialSpinner.value
)
fn checkMaterialNumber arrayInput =
(
exceedMeshIDArray = #()
-- go thorugh all face and get id
for i in selectionArray do
(
ids = #{}
for node in geometry as array do
(
m = snapshotAsMesh node
for f = 1 to m.numfaces do ids[getFaceMatID m f] = on
delete m
)
ids
if ids.count > maxMaterialNumber then append exceedMeshIDArray i
)
for i in exceedMeshIDArray do
(
messageBox (i.name + " have too many materials, max is " + maxMaterialNumber as string)
)
)
on checkMaterialButton pressed do
(
for obj in selection do obj.layer.select true
selectionArray = selection as array
checkMaterialNumber selectionArray
)
)
MainFloater = newRolloutFloater "This is a menu" 250 300
addRollout LODCheck MainFloater
addRollout materialCheck MainFloater
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment