(
local ResetMax
local GetAllFilesWithPatternInDirectoryRecursively
local DoedFolderExist
local DoImportFile
local DoExportFile
local DoAutoSmooth
fn StartExecute =
(
--Fields
local rootFolderPath = "D:\Source"
local exportRootFolderPath = "D:\Dest"
local autosmoothThreshold = 50.0
local exportASCII = true
--Editable_Poly for some reason gives bad results. false for now
local useEditablePoly = false
ResetMax()
openLog(exportRootFolderPath+"\"+logFileName) mode:"w" outputonly:true
print("Start: "+(timestamp() as string))
print("SutismoothThreshold: "+ (autosmoothThreshold as string))
local filesInFolder = GetAllFilesWithPatternInDirectoryRecursively rootFolderPath "*.fbx"
print("Files to Process: " + (filesInFolder.count as string))
for filePath in filesInFolder do
(
--if filenameFromPath filePath != "__xxx.fbx" then
--continue
print "New Object"
print filePath
DoImportFile(filePath)
DoAutoSmooth autosmoothThreshold useEditablePoly
local exportPath = replace filePath 1 rootFolderPath.count exportRootFolderPath
print exportPath
DoesFolderExist(getFilenamePath exportPath) create:true
DoExportFile exportPath exportASCII
ResetMax()
--Exit()
)
)
--Returns an array
fn GetAllFilesWithPatternInDircetoryRecursively dir pattern =
(
local dirArr = GetDirectories(dir+"\\*")
for d in dirArr do
(
join dirArr (getDirectories(d+"\\*"))
)
append dirArr (dir+"\") -- Need to include the original top level directory
local patternMatchedFile = #()
for f in dirArr do
(
join patternMatchedFiles (getFiles(f+pattern))
)
return patternMatchedFiles
)
--Test whether folderPath exists and is a folder; create it if it doesn't and create==true
fn DoesFolderExist folderPath create:true =
(
local val = if(doesFileExist folderPath) and (getfileattribute folderPath #directory) then true else false
if not val and create then
(
val = makeDir folderPath
)
return val
)
fn DoImportFile fileName =
(
FBXImporterSetParam "ResetImport"
FBXImporterSetParam "SmoothingGroups" true
importFile fileName #noPrompt using:FXBIMP
)
fn DoExportFile fileName exportASCII =
(
FBXExporterSetParam "ResetExport"
FBXExporterSetParam "SmoothingGroups" true
FBXExporterSetParam "Animation" false
FBXExporterSetParam "Cameras" false
--Set to true if you want a Human-Readable file.
if exportAscii then
(
FBXExporterSetParam "ASCII" true
)
if units.SystemType == #Inches then
(
print "Converting Units to CM"
--This is completely broken.
--FBXExporterSetParam "COnvertUnit" "cm"
--Shitty replacement solution
selectedObject = selection[1]
print selectedObject.scale
selectedObject.scale=[1,1,1]
print selectedObject.scale
)
print "Exp Smooth?"
print ((FBXExporterGetParam "SmoothingGroups") as string)
exportFile (fileName) #noPrompt selectedOnly:false using:FBXEXP
)
fn ResetMax=
(
--Reset max file silently
resetMaxFile #noPrompt
)
fn ExitMan=
(
--Exit max
quitMax #noPrompt
)
fn DoAutoSmooth autosmoothThreshold useEditablePoly=
(
if selection.count == 1 then
(
print selection[1]
selectedObject = selection[1]
if useEditablePoly then
(
convertTo selectedObject Editable_Poly
)
select selectedObject
if useEditablePoly then
(
print "converting to Editable Poly"
polyOp.setFaceSelection selectedObject #{1..polyOp.getNumFaces selectedObject}
--Clear existing smoothing groups
selectObject.EditablePoly.setSmoothingGroups 0
selectedObject.autosmoothThreshold = autosmoothThreshold
print "[erforming AutoSmooth on Editable Poly"
selectedObject.EditablePoly.autosmooth()
)
else
(
print "Performing AutoSmooth on Editable Mesh"
meshop.autoSmooth selectedObject #{1..selectedObject.numfaces} autosmoothThreshold
)
)
else
(
print "Error:Multiple Objects Selected."
)
)
--Start at the end?
StartExecute()
ExitMax()
)
上帝为我关上了窗,我绝不洗洗睡!