-
Notifications
You must be signed in to change notification settings - Fork 3
/
NDP_NOESIS_CMD.ms
467 lines (422 loc) · 16.4 KB
/
NDP_NOESIS_CMD.ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
--Naughty Dog PAK Noesis CMD tool
--Version: v0.27
--Last Release: February 26 2023
--Created by: alphaZomega
global noesis_path = "C:\\Program Files\\Noesis\\Noesis.exe"
global python_plugin = "fmt_nd_pak.py"
global reimport_path = "F:\\"
global formNPDNoesisCMD
fn collectSkinBones node = (
fn findNodesByName list name = (
for node in list where stricmp node.name name == 0 collect node
)
max modify mode
local bones = #()
for sk in node.modifiers where iskindof sk Skin do (
modpanel.setcurrentobject sk
nodes = for n in (refs.dependson sk) where isvalidnode n collect n
for k=1 to skinops.getnumberbones sk do (
name = skinops.getbonename sk k 0
join bones (findNodesByName nodes name)
)
)
bones
)
fn selectSkeleton node = (
local originalSelection = selection as array
local bones = collectSkinBones node
while bones[1].parent != undefined do
bones[1] = bones[1].parent
bones = #(bones[1])
for p in bones where p.children != undefined do join bones p.children
join originalSelection bones
select originalSelection
)
try(destroydialog formNPDNoesisCMD; clearlistener())catch()
rollout formNPDNoesisCMD "Noesis PAK v0.26" (
group "Import" (
button btn_import "Import To Scene" align:#center
checkbox chk_legacyFBX "Use Legacy FBX" checked:false align:#left tooltip:"Import as FBX 2014"
checkbox chk_rpgOptimize "Optimize" checked:true align:#left tooltip:"Have Noesis automatically remove duplicate vertices on import"
checkbox chk_folder "Import Folder" checked:false align:#left
checkbox chk_populateBones "Populate Bones Lists" checked:false align:#left tooltip:"Populate the bones list of every Skin modifier to have all bones"
)
group "Export" (
button btn_export "Export To Game" align:#center
checkbox chk_writeBones "Write Bone Positions" checked:false align:#left
checkbox chk_texOnly "Inject Textures Only" checked:false align:#left
checkbox chk_useTexFolder "Use this texture folder:" checked:false align:#left
edittext edt_folder "" align:#left
button btn_browseTexFolder "Browse" align:#center
checkbox chk_injectThisMesh "Inject this mesh:" checked:false align:#left
edittext edt_injectMeshName "" align:#left
button btn_browseInjectMesh "Browse" align:#center
)
group "Utilities" (
--button BtnSkinOnTop "Move Skin to Top of Stack" align:#center
button BtnSetScale "Set Scale" offset:[-30,0] toolTip:"Multiply mesh scale by this value.\nRight click to change preset scales"
edittext FldScale "" text:"1.0" fieldWidth:60 labelOnTop:false offset:[70,-25]
button btn_reimport "Reimport Noesis FBX" align:#center
button btn_removeZeroWeights "Set Bone Limits" align:#center toolTip:"Set the Bone Affect Limit for the selected meshes to 8, and Remove Zero Weights"
)
group "Config" (
checkbox chk_showPlugOpt "Show FBX Options" checked:false align:#left
checkbox chk_delFBX "Delete FBX Files" checked:true align:#left
checkbox chk_showCMD "Show Console" checked:false align:#left
checkbox chk_noDialog "No Dialog" checked:false align:#left
checkbox chk_doLODs "Import/Export all LODs" checked:false align:#left
label lbl_noesis "Noesis Path:" align:#left
edittext edt_noesis "" align:#left
button btn_noesis "Browse" align:#center tooltip:"Edit NDP_Noesis_CMD.ms (this script) in a text editor to save your Noesis path"
)
label lbl_author "By alphaZomega" align:#right
local ScaleValue = 1.0
local vFactory = 0
local cmd = ""
local fbx_path = ""
fn checkDialog = (
local hwnd = dialogMonitorOps.getWindowHandle()
if (uiAccessor.getWindowText hwnd == "Import Name Conflict") then (
uiAccessor.PressButtonByName hwnd "OK"
)
true
)
fn waitForFileUnlock file file_open_limit:30 = (
local i = 0
local startTime = timeStamp()
while i < file_open_limit and timeStamp()-startTime < file_open_limit do (
if (try(renameFile file (file + ".tmp"))catch(false)) do (
renameFile (file + ".tmp") file
return true
)
sleep 1
i += 1
)
return false
)
fn noesisComponentsFound = (
local state = false
if doesFileExist noesis_path and doesFileExist ((getFilenamePath noesis_path) + "plugins\\python\\" + python_plugin) do (
state = true
)
state
)
on formNPDNoesisCMD open do (
if doesFileExist (try(noesis_path)catch("")) do (
edt_noesis.text = noesis_path
)
)
on btn_noesis pressed do (
local cmd = getOpenFileName types:"Noesis.exe|noesis.exe|All|*.*|"
if cmd != undefined and cmd != "" do (
edt_noesis.text = noesis_path = cmd
)
)
on btn_browseInjectMesh pressed do (
local cmd = getOpenFileName types:"Naughty Dog PAK Model|*.pak|All|*.*|"
if cmd != undefined and doesFileExist cmd then (
edt_injectMeshName.text = cmd
chk_injectThisMesh.checked = true
)
)
on btn_browseTexFolder pressed do (
local cmd = getOpenFileName types:"DDS Image|*.dds|All|*.*|"
if cmd != undefined and doesFileExist (getFilenamePath cmd) then (
edt_folder.text = getFilenamePath cmd
chk_useTexFolder.checked = true
)
)
on edt_noesis changed cmd do (
edt_noesis.text = noesis_path = cmd
)
on edt_folder changed cmd do (
edt_folder.text = cmd
)
on edt_injectMeshName changed cmd do (
edt_injectMeshName.text = cmd
)
on btn_removeZeroWeights pressed do (
local oldSelection = $
for mesh in $ where superclassof mesh == GeometryClass and mesh.modifiers[#Skin] != undefined and mesh.modifiers[#Skin].bone_Limit > 8 do (
select mesh
max modify mode
mesh.modifiers[#Skin].bone_Limit = 8
skinOps.RemoveZeroWeights mesh.modifiers[#Skin]
)
select oldSelection
)
on btn_import pressed do (
if noesisComponentsFound() then (
local cmd = getOpenFileName types:"Naughty Dog PAK Model|*.pak|All|*.*|"
if cmd != undefined and doesFileExist cmd do (
local showFbxOptions = chk_showPlugOpt.checked
local files = #(cmd)
if chk_folder.checked then
files = getFiles (getFilenamePath cmd + "\\*.mesh")
for f = 1 to files.count do (
cmd = files[f]
local fbx_path = (getFilenamePath cmd) + (getFilenameFile (getFilenameFile cmd)) + ".fbx"
local outtxt_path = fbx_path + ".txt"
cmd = (
"\"" + noesis_path + "\" ?cmode \"" + cmd + "\" \"" + fbx_path + "\"" \
+ (if chk_legacyFBX.checked then " -fbxoldexport -fbxexportver FBX201400" else "") \
+ (if not chk_rpgOptimize.checked then " -fbxnooptimize" else "") \
+ (if chk_noDialog.checked then " -nodialog" else "") \
+ (if chk_doLODs.checked then " -lods" else "") \
+ (" -notex -fbxmeshmerge") --always
) -- -
if chk_showCMD.checked then (
DOSCommand ("\"" + cmd + " -logfile \"" + outtxt_path + "\"")
)
else (
HiddenDOSCommand ("\"" + cmd + " -logfile \"" + outtxt_path + "\"") startpath:(getFilenamePath noesis_path) donotwait:false
)
print outtxt_path
waitForFileUnlock(fbx_path)
if showFbxOptions then (--chk_impPrompt
success = importFile fbx_path using:FBXIMP
)
else (
success = importFile fbx_path #noPrompt using:FBXIMP
)
actionMan.executeAction 0 "40472" --open listener
format "Import Command:\n%\n" cmd
print "Something"
if doesFileExist outtxt_path then (
local fs = openFile outtxt_path
if fs != undefined then (
local noesisOutput = "\n"
while not eof fs do
noesisOutput = noesisOutput + (readline fs) + "\n"
print noesisOutput
close fs
deletefile outtxt_path
) else format "Could not open %\n" outtxt_path
) else print "No Noesis log was found"
if chk_delFBX.checked do (
deleteFile fbx_path
format "Deleted FBX file %\n" fbx_path
)
format "\nImport Command: %\n" cmd --print the command for reference
if success then (
with redraw off (
local objSelected = selection as array
local meshes = for obj in objSelected where (classof obj == Editable_mesh) collect obj
local bones = for obj in objSelected where (superclassof obj == Helper or classof obj == BoneGeometry) collect obj
for bone in bones do hide bone
container = Point size:1.0
local uniqueNames = #(); local mainmeshes = #()
container.name = getFilenameFile (getFilenameFile cmd)
for mesh in meshes do (
mesh.parent = container
mesh.material = undefined
mesh.wirecolor = color (random 0 255) (random 0 255) (random 0 255)
if getNumVerts mesh == 3 or mesh.modifiers[#Skin] == undefined then continue
select mesh
max modify mode
sk = mesh.modifiers[#Skin]
sk.bone_Limit = 8
skinOps.RemoveZeroWeights sk
--local boneNames = for i=1 to (skinOps.GetNumberBones mesh.modifiers[#Skin]) collect (skinOps.GetBoneName mesh.modifiers[#Skin] i 0)
for bone in bones do (
bone.showLinks = true
bone.showLinksOnly = true
bone.wirecolor = orange
if chk_populateBones.checked do (
skinOps.selectBoneByNode sk bone
local bnName = skinOps.GetBoneName sk (skinOps.GetSelectedBone sk) 0
if bnName != bone.name then
skinops.addBone sk bone 0
)
)
)
)
)
if chk_folder.checked then
showFbxOptions = false
)
)
) else (messagebox "Failed to Locate Noesis!")
)
on btn_export pressed do (
if noesisComponentsFound() then (
local doUseGivenMesh = (chk_injectThisMesh.checked and doesFileExist edt_injectMeshName.text)
if doUseGivenMesh then
local cmd = getSaveFileName types:"Naughty Dog PAK Model|*.pak|All|*.*|"
else
local cmd = getOpenFileName types:"Naughty Dog PAK Model|*.pak|All|*.*|"
if cmd != undefined and cmd != "" do (
local fbx_path = (getFilenamePath cmd) + ((getFilenameFile cmd)) + ".fbx"
local out_path = (getFilenamePath cmd) + ((getFilenameFile cmd)) + ".NEW" + (getFilenameType cmd)
local outtxt_path = fbx_path + ".txt"
if not doUseGivenMesh and findString (toLower fbx_path) ".orig.fbx" != undefined then (
meshPath = (replace fbx_path (findString (toLower fbx_path) ".orig.fbx") 9 (".pak"))
format "Changing file output from %.pak to %.pak\n" (getFilenameFile out_path) (getFilenameFile meshPath)
out_path = meshPath
)
local originalSelection = selection as array
--select originalSelection
for obj in originalSelection where superclassof obj == GeometryClass and obj.modifiers[#Skin] != undefined do (
selectSkeleton obj
exit
)
local copyNodes = #()
if chk_writeBones.checked then
for obj in originalSelection where obj.modifiers[#Skin] != undefined do (
selectSkeleton obj
--Create dummy mesh with all bones in skin modifier so that FBX will save all bones
maxOps.cloneNodes obj cloneType:#copy newNodes:©Nodes #nodialog
local lastSelection = (selection as array); select copyNodes[1]; copyNodes[1].name = "FBXBoneStorage"
for bn in lastSelection do
if superclassof bn == Helper or classof bn == BoneGeometry then
skinops.addBone copyNodes[1].modifiers[#Skin] bn 0
selectmore lastSelection
exit
)
if chk_showPlugOpt.checked then (--chk_expPrompt
exportFile fbx_path selectedOnly:true using:FBXEXP
)
else (
exportFile fbx_path #noPrompt selectedOnly:true using:FBXEXP
)
if doesFileExist fbx_path do (
waitForFileUnlock(fbx_path)
cmd = (
"\"" + noesis_path + "\" ?cmode \"" + fbx_path + "\" \"" + out_path + "\"" \
+ (if chk_writeBones.checked then " -bones" else "") \
+ (if chk_texOnly.checked then " -t" else "") \
+ (if chk_doLODs.checked then " -lods" else "") \
+ (" -meshfile \"" + (if doUseGivenMesh then edt_injectMeshName.text else cmd) + "\"") \
+ (if chk_useTexFolder.checked then (" -texfolder \"" + edt_folder.text + "\"") else "") \
)
if chk_showCMD.checked then (
DOSCommand ("\"" + cmd + " -logfile \"" + outtxt_path + "\"")
)
else (
HiddenDOSCommand ("\"" + cmd + " -logfile \"" + outtxt_path + "\"") startpath:(getFilenamePath noesis_path) donotwait:false
)
waitForFileUnlock(fbx_path)
if chk_delFBX.checked do (
deleteFile fbx_path
format "Deleted FBX file %" fbx_path
)
)
--if copyNodes[1] != undefined then delete copyNodes[1]
actionMan.executeAction 0 "40472" --open listener
format "Export Command:\n%\n" cmd
if doesFileExist outtxt_path then (
local fs = openFile outtxt_path
if fs != undefined then (
local noesisOutput = "\n"
while not eof fs do
noesisOutput = noesisOutput + (readline fs) + "\n"
print noesisOutput
close fs
deletefile outtxt_path
)
)
select originalSelection
)
) else (messagebox "Failed to Locate Noesis!")
)
on btn_reimport pressed do (
if true then ( --with redraw off (
if noesisComponentsFound() then (
if superclassof $ != GeometryClass then return false
cmd = reimport_path + "ReImportedMeshout.fbx"
newFile = cmd; origNode = $
fbx_path = reimport_path + "ReImportedMesh.fbx"
copyNodes = #(); maxOps.cloneNodes selection cloneType:#copy newNodes:©Nodes #nodialog
select copyNodes[1]; collapsestack $; $.name = origNode.name
if chk_showPlugOpt.checked then (--chk_expPrompt
if not (exportFile fbx_path selectedOnly:true using:FBXEXP) then format ("Failed to write to %\n" fbx_path)
)
else (
if not (exportFile fbx_path #noPrompt selectedOnly:true using:FBXEXP) then format ("Failed to write to %\n" fbx_path)
)
if doesFileExist fbx_path do (
if not waitForFileUnlock(fbx_path) then (
messagebox "Failed to read fbx (timeout)"
return false
)
cmd = (
"\"" + noesis_path + "\" ?cmode \"" + fbx_path + "\" \"" + cmd + "\"" + " -fbxmeshmerge -noanims -notex" -- + (if chk_noesisOpt.checked then " -RPGOptimize" else "")
)
if chk_showCMD.checked then (
DOSCommand ("\"" + cmd + "\"")
)
else (
HiddenDOSCommand ("\"" + cmd + "\"") startpath:(getFilenamePath noesis_path) donotwait:false
)
format "%\n" cmd
if not waitForFileUnlock(fbx_path) then (
messagebox "Failed to read fbx (timeout)"
return false
)
if not waitForFileUnlock(newFile) then (
messagebox "Failed to read new pak file (timeout)"
return false
)
oldObj = objects as array
if chk_showPlugOpt.checked then (
if not (importFile newFile using:FBXIMP) then ( format "Failed to read %\n" newFile)
) else ( if not (importFile newFile #noPrompt using:FBXIMP) then ( format "Failed to read %\n" newFile) )
if chk_delFBX.checked do (
deleteFile fbx_path
deleteFile newFile
)
newObj = for o in objects where findItem oldObj o == 0 collect o
for obj in newObj do (
if superclassof obj == GeometryClass then
selectmore obj
else delete obj
)
if $ != undefined then (
collapsestack $
addModifier $ (Skin_Wrap())
skinWrap = $.modifiers["Skin_Wrap"]
skinWrap.weightAllVerts = true
skinWrap.falloff = 1.0
skinWrap.Distance = 0.05
skinWrap.meshList = #(origNode)
skinWrap.convertToSkin false
$.modifiers[#Skin].bone_Limit = 8
deleteModifier $ $.modifiers["Skin_Wrap"]
)
)
delete copyNodes[1]
) else (messagebox "Failed to Locate Noesis!")
)
)
on FldScale entered num do (
ScaleValue = try (num as float) catch (1.0)
FldScale.text = ScaleValue as string
)
on BtnSetScale pressed do (
local object = $
if superclassof object == GeometryClass and object.modifiers[#skin] != undefined then (
local bones = collectSkinBones object
while bones[1].parent != undefined do
bones[1] = bones[1].parent
object = bones[1]
)
if (superclassof object == Helper or classof object == BoneGeometry) then (
with undo on (
local bone = object
while bone.parent != undefined do bone = bone.parent
local delta = (matrix3 [1,0,0][0,0,-1][0,1,0][0,0,0])--inverse bone.transform
if ScaleValue == 1 then (
bone.transform = (matrix3 [1,0,0] [0,0,1] [0,-1,0] bone.pos)
) else bone.transform *= delta * (matrix3 [ScaleValue,0,0] [0,0,ScaleValue] [0,-ScaleValue,0] [0,0,0]) --
)
) else
messagebox "Select the root bone"
)
on BtnSetScale rightclick do (
if ScaleValue == 1.0 then ScaleValue = 0.393701
else if ScaleValue == 0.393701 then ScaleValue = 2.54
else if ScaleValue == 2.54 then ScaleValue = 1.0
FldScale.text = ScaleValue as string
)
)
createdialog formNPDNoesisCMD