1-- NW4C Menu Script(2010/12/07)
2-- Version 0.5.0d
3-- (c)2010 Nintendo
4
5fileIn  "NW4C_utils.ms.inc"
6
7nw4cExportRollout = undefined
8
9rollout nw4cSR_Output "Output Options"
10(
11	label lbl4 "Export Target"  /*width:96 height:20*/ align:#left across: 3
12	radioButtons rdoSelection ""  /*width:80*/ height:16 labels:#("All", "Selection") columns:2 align:#left offset:[-30,0]
13	label lblDummyOut1 ""
14
15	label lbl2 "File name:"  /*width:72*/ height:20 align:#left across: 4 --offset:[0,-10]
16	editText editFilename ""  width:256 align:#left  offset:[-30,0]
17	button btnNameNode "Node"  width:45 height:16 align:#right  offset:[60,0]
18	button btnNameScene "Scene"  width:45 height:16 align:#right
19
20	radiobuttons rdoFileSel "" labels:#("Output 3D Intermediate Files") align:#left
21	label lbl1 "    File path:"  width:72 height:20 align:#left across:4
22	editText editFilepath ""  width:332 offset:[-30,0]
23	label lblDummy1 ""
24	button btnSelectPath "..."  width:20 height:16 toolTip:"Select folder" align:#right
25	radiobuttons rdoUseCS "" labels:#("Use Creative Studio") align:#left  offset:[0,-5]
26
27	label lblDummy3 "" height:4
28
29	checkbox chkMergeCmdl "Merge cmdl"  width:80 height:16 align:#left across:4
30	editText editMergeFile ""  width:332 offset:[-30,0]
31	label lblDummy2 ""
32	button btnSelectMerge "..."  width:20 height:16 toolTip:"Select Merge File" align:#right
33
34	on btnSelectPath pressed do
35	(
36		local filepath = getSavePath initialDir:editFilepath.text
37		if(filepath != undefined) do editFilepath.text = filepath
38	)
39	on btnNameNode pressed do
40	(
41		sel = getCurrentSelection()
42		if sel.count > 0 do
43		(
44			editFilename.text = sel[1].name
45		)
46	)
47	on btnNameScene pressed do
48	(
49		if(maxFilePath != "") do
50		(
51			editFilename.text = (getFilenameFile maxFileName)
52		)
53	)
54	on btnSelectMerge pressed do
55	(
56		local filepath = getOpenFileName initialDir:editMergeFile.text types:"NW4C Model(*.cmdl)|*.cmdl|All|*.*|"
57		if(filepath != undefined) do editMergeFile.text = filepath
58	)
59	on chkMergeCmdl changed val do nw4cExportRollout.redrawItems()
60	--on chkUseCS changed val do nw4cExportRollout.redrawItems()
61	on nw4cSR_Output rolledUp  val  do  nw4cExportRollout.resizeAll()
62	on rdoUseCS changed val do
63	(
64		if val == 1 do rdoFileSel.state = 0
65		editFilepath.enabled = btnSelectPath.enabled = (val != 1)
66	)
67	on rdoFileSel changed val do
68	(
69		if val == 1 do rdoUseCS.state = 0
70		editFilepath.enabled = btnSelectPath.enabled = (val == 1)
71	)
72)
73
74rollout nw4cSR_General "General Options"
75(
76	spinner spnMagnify "Magnify: "  width:120 height:16 range:[0.0001,10000,1] type:#float scale:0.1 across:2 align:#left
77	checkbox chkUseFigureMode "Use FigureMode and SkinPose"  height:16 align:#left
78
79	label lbl8 "Start/End Frame:"  width:112 height:20 across:4 align:#left
80	radioButtons rdoTimeRange ""  width:104 height:16 labels:#("All", "Range") columns:2  align:#left
81	spinner spnTimeStart ""  width:64 height:16 range:[0,100000,0] type:#integer scale:1  align:#left
82	spinner spnTimeEnd ""  width:64 height:16 range:[0,100000,100] type:#integer scale:1  align:#left offset:[-40,0]
83
84	on rdoTimeRange changed val do nw4cExportRollout.redrawItems()
85	on nw4cSR_General rolledUp  val  do nw4cExportRollout.resizeAll()
86)
87rollout nw4cSR_FileSelection "Output File Selection"
88(
89	label lblExportModel "Model Data " align:#right offset:[20,0] across:4
90	checkbox chkExportModel "[.cmdl]" align:#left offset:[20,0]
91	label lblExportMtlAnim "Material Animation Data " align:#right offset:[20,0]
92	checkbox chkExportMtlAnim "[.cmata]" align:#left offset:[20,0]
93
94	label lblExportTex "Texture Data " align:#right offset:[20,0] across:4
95	checkbox chkExportTex "[.ctex]" align:#left offset:[20,0]
96	label lblExportCamera "Camera Data " align:#right offset:[20,0]
97	checkbox chkExportCamera "[.ccam]" align:#left offset:[20,0]
98
99	label lblExportMdlAnim "Model Animation Data " align:#right offset:[20,0] across:4
100	checkbox chkExportMdlAnim "[.cmdla]" align:#left offset:[20,0]
101	label lblExportLight "Light Data " align:#right offset:[20,0]
102	checkbox chkExportLight "[.clgt]" align:#left offset:[20,0]
103
104	label lblExportSkelAnim "Skeletal Animation Data " align:#right offset:[20,0] across:4
105	checkbox chkExportSkelAnim "[.cskla]" align:#left offset:[20,0]
106	label lblExportEnv "Environment Data " align:#right offset:[20,0]
107	checkbox chkExportEnv "[.cenv]" align:#left offset:[20,0]
108
109	on nw4cSR_FileSelection rolledUp  val  do nw4cExportRollout.resizeAll()
110)
111rollout nw4cSR_Optimization "Optimization Options"
112(
113	dropDownList ddlCompressNode "Compress Node"  width:140 height:41 \
114		items:#("None", "Cull Useless Node", "Cull Uninfluential Node", "Unite Compressible Node", "Unite All Node") across:3
115	dropDownList ddlOptimizeMtl "Compress Material"  width:140 height:41 \
116		items:#("None", "Compress Same Material") --offset:[32,0]
117	label lblDummy ""
118
119	--checkbox chkDisableSimplification "Disable SkeletalModel- Simplification"  width:166 height:28 pos:[320,30]
120	checkbox chkOptimizePrim "Optimize Primitive"  width:166 height:16 pos:[320,8]
121	checkbox chkConvertToModel "Convert To Model"  width:166 height:16 pos:[320,30]
122
123	on chkConvertToModel changed val do nw4cExportRollout.redrawItems()
124	on nw4cSR_Optimization rolledUp  val  do nw4cExportRollout.resizeAll()
125)
126rollout nw4cSR_Quantization "Quantization Options"
127(
128	dropDownList ddlQuantPosition "Position"  width:64 height:41  items:#("Float", "Short", "Byte")  across:6
129	dropDownList ddlQuantNormal "Normal"  width:64 height:41  items:#("Float", "Short", "Byte")
130	dropDownList ddlQuantTex "Tex Coord"  width:64 height:41  items:#("Float", "Short", "Byte")
131	label lblDummyQO1 ""; label lblDummyQO2 ""; label lblDummyQO3 ""
132	on nw4cSR_Quantization rolledUp  val  do nw4cExportRollout.resizeAll()
133)
134rollout nw4cSR_Model "Model Options"
135(
136	dropDownList ddlSkinningMode "Adjust Skinning"  width:120
137		items:#("None If Possible", "Rigid Skinning") across:3
138	dropDownList ddlModelBindBy "Mesh Visibility Mode"  width:120
139		items:#("Bind By Index", "Bind By Name")
140	label lblDummyMDL2 ""
141
142
143	checkbox chkNonUniformScale "Non-Uniform Scale"  width:140 height:16 across:3
144	spinner spnReserveUniform "Max Reserved Uniform Registers:"  width:160 range:[0,60,0] type:#integer scale:1\
145		align:#left
146	label lblDummyMDL1 ""
147
148	/*
149	dropDownList ddlModelBindBy "Mesh Visibility Mode"  width:120 items:#("Bind By Index", "Bind By Name") offset:[8,0]
150	spinner spnReserveUniform "Max Reserved Uniform Registers:"  width:80 range:[0,60,0] type:#integer scale:1\
151		align:#left offset:[0,-24]
152*/
153	on nw4cSR_Model rolledUp  val  do nw4cExportRollout.resizeAll()
154)
155
156rollout nw4cSR_Animation "Animation Options"
157(
158	dropDownList ddlAnimationPrecision "Frame Precision"  width:104 height:41 items:#("1.0", "0.5", "0.2", "0.1") --across:4
159	checkbox chkAnimationLoop "Loop"  --width:80 height:16
160	checkbox chkFrameFormat "Frame Format"  --width:80 height:16
161
162	label lblAO3 "Translate Quantize Quality:" align:#right pos:[155,12] width:140
163	editText editTransQuality ""  width:32 pos:[295,10]
164	slider sldTransQuality "" range:[0,9,9] type:#integer width:135 pos:[336,0]
165
166	label lblAO2 "   Rotate Quantize Quality:"  align:#right pos:[155,44] width:140
167	editText editRotateQuality ""  width:32 pos:[295,42]
168	slider sldRotateQuality "" range:[0,9,9] type:#integer width:135 pos:[336,32]
169
170	label lblAO1 "    Scale Quantize Quality:"  align:#right pos:[155,76] width:140
171	editText editScaleQuality ""  width:32 pos:[295,74]
172	slider sldScaleQuality "" range:[0,9,9] type:#integer width:135 ticks:10 pos:[336,64]
173
174
175
176	fn validateSliderVal it =
177	(
178		local val = it.text as integer
179		if val == undefined do return undefined
180		if (0 <= val and val <= 9) do return val
181		return undefined
182	)
183
184	fn updateQuality isEdit =
185	(
186		if isEdit do
187		(
188			local val
189			val = validateSliderVal editScaleQuality
190			if val != undefined do sldScaleQuality.value = val
191			val = validateSliderVal editRotateQuality
192			if val != undefined do sldRotateQuality.value = val
193			val = validateSliderVal editTransQuality
194			if val != undefined do sldTransQuality.value = val
195		)
196		editScaleQuality.text = sldScaleQuality.value as string
197		editRotateQuality.text = sldRotateQuality.value as string
198		editTransQuality.text = sldTransQuality.value as string
199	)
200
201	on editScaleQuality entered val do (updateQuality true)
202	on editRotateQuality entered val do (updateQuality true)
203	on editTransQuality entered val do (updateQuality true)
204
205	on sldScaleQuality changed val do (updateQuality false)
206	on sldRotateQuality changed val do (updateQuality false)
207	on sldTransQuality changed val do (updateQuality false)
208	on nw4cSR_Animation rolledUp  val  do nw4cExportRollout.resizeAll()
209)
210rollout nw4cSR_Toletance "Tolerance Options"
211(
212	spinner spnToleranceNodeT "Node Translate:"  width:80 height:16  range:[0.0001,100,0.01] type:#float scale:0.01 align:#right across:3
213	spinner spnToleranceTexT "Tex Translate:"  width:80 height:16   range:[0.0001,100,0.01] type:#float scale:0.01 align:#right
214	spinner spnToleranceColor "Color:"  width:80 height:16 range:[0.0001,100,0.001] type:#float scale:0.01 align:#right
215
216	spinner spnToleranceNodeR "   Node Rotate:"  width:80 height:16  range:[0.0001,100,0.1] type:#float scale:0.01 align:#right across:3
217	spinner spnToleranceTexR "   Tex Rotate:"  width:80 height:16 range:[0.0001,100,0.1] type:#float scale:0.01  align:#right
218	label lblDummyTO1 ""
219
220	spinner spnToleranceNodeS "    Node Scale:"  width:80 height:16  range:[0.0001,100,0.1] type:#float scale:0.01 align:#right across:3
221	spinner spnToleranceTexS "    Tex Scale:"  width:80 height:16 range:[0.0001,100,0.1] type:#float scale:0.01 align:#right
222	label lblDummyTO2 ""
223	on nw4cSR_Toletance rolledUp  val  do nw4cExportRollout.resizeAll()
224)
225
226-- Main rollout
227nw4cExportRollout_subOpen = #()
228nw4cExportRollout_height = 600
229rollout nw4cExportRollout "NW4C Export Setting" width:500 height:600
230(
231	local utils = nw4c_utils()
232	-- sub rollouts
233	local srOutput, srGeneral, srFileSelection, srOptimization, srQuantization, srModel, srAnimation, srToletance
234
235	SubRollout ro "" width:480 height:860 align:#center --offset:[-5,0]
236	button btnExport "Export" width:144 height:24 across:3
237	button btnApply "Apply" width:144 height:24
238	button btnClose "Close" width:144 height:24
239
240	fn redrawItems =
241	(
242		srGeneral.spnTimeStart.enabled = srGeneral.spnTimeEnd.enabled = (srGeneral.rdoTimeRange.state == 2)
243		srOutput.editMergeFile.enabled = srOutput.btnSelectMerge.enabled = srOutput.chkMergeCmdl.state
244		--srOutput.editFilepath.enabled = srOutput.btnSelectPath.enabled = not srOutput.chkUseCS.state
245		srOutput.editFilepath.enabled = srOutput.btnSelectPath.enabled = (srOutput.rdoUseCS.state != 1)
246		nw4cSR_Optimization.ddlCompressNode.enabled = (not nw4cSR_Optimization.chkConvertToModel.state)
247
248		srAnimation.updateQuality false
249	)
250
251	fn loadConfig loadFromScene:true =
252	(
253		--print "load config"
254		local nw4c = nw4cmax
255		if loadFromScene do nw4c.LoadSetting()
256		srOutput.editFilepath.text = nw4c.outFolder
257		srOutput.editFilename.text = nw4c.filename
258		--srOutput.chkUseCS.state = nw4c.UseCreativeStudio
259		srOutput.rdoUseCS.state = if nw4c.UseCreativeStudio then 1 else 0
260		srOutput.rdoFileSel.state = 1 - srOutput.rdoUseCS.state
261
262		srFileSelection.chkExportModel.state = nw4c.doesExportModel
263		srFileSelection.chkExportTex.state = nw4c.doesExportTexture
264		srFileSelection.chkExportSkelAnim.state = nw4c.doesExportAnimation
265		srFileSelection.chkExportCamera.state = nw4c.doesExportCamera
266		srFileSelection.chkExportLight.state = nw4c.doesExportLight
267		srFileSelection.chkExportMtlAnim.state = nw4c.doesExportMtlAnim
268		srFileSelection.chkExportMdlAnim.state = nw4c.doesExportModelAnim
269		srFileSelection.chkExportEnv.state = nw4c.doesExportEnv
270
271		--
272		srOutput.rdoSelection.state = (if nw4c.doesExportSelected then 2 else 1)
273		--
274		srGeneral.spnMagnify.value = nw4c.Magnify
275		--
276		srGeneral.rdoTimeRange.state = (if nw4c.doesExportAllFrames then 1 else 2)
277		srGeneral.spnTimeStart.value = nw4c.StartFrame
278		srGeneral.spnTimeEnd.value = nw4c.EndFrame
279		srAnimation.chkAnimationLoop.state = nw4c.IsLoop
280		srAnimation.ddlAnimationPrecision.selection = case of
281		(
282				(1 >= nw4c.AnimPrecision) : 1
283				(2 >= nw4c.AnimPrecision) : 2
284				(5 >= nw4c.AnimPrecision) : 3
285				(10 >= nw4c.AnimPrecision) : 4
286				default: 1
287		)
288		--
289		srOptimization.ddlCompressNode.selection = if nw4c.CompressNode == 6 then 1 else nw4c.CompressNode -- Unite Bleow Node��p�~
290		srOptimization.chkOptimizePrim.state = nw4c.OptimizePrimitive
291		--chkOptimizeMtl.state = nw4c.OptimizeMaterial
292		srOptimization.ddlOptimizeMtl.selection = if nw4c.OptimizeMaterial then 2 else 1
293		srOptimization.chkConvertToModel.state = (not nw4c.DisableModelSimplification)
294		srModel.chkNonUniformScale.state = nw4c.NonUniformScale
295		srModel.spnReserveUniform.value = nw4c.ReservedUniformRegister
296		srModel.ddlModelBindBy.selection = (if nw4c.VisibilityBindByName then 2 else 1)
297		--srModel.ddlSkinningMode.selection = (if nw4c.SkinningMode <=1 then 1 else nw4c.SkinningMode)
298		srModel.ddlSkinningMode.selection = nw4c.SkinningMode
299		--
300		srToletance.spnToleranceNodeT.value = nw4c.ToleranceTrans
301		srToletance.spnToleranceNodeR.value = nw4c.ToleranceRotate
302		srToletance.spnToleranceNodeS.value = nw4c.ToleranceScale
303		--
304		srToletance.spnToleranceTexT.value = nw4c.ToleranceUVTrans
305		srToletance.spnToleranceTexR.value = nw4c.ToleranceUVRotate
306		srToletance.spnToleranceTexS.value = nw4c.ToleranceUVScale
307		srToletance.spnToleranceColor.value = nw4c.ToleranceColor
308		--
309		--spnPrecisionTrans.value = nw4c.PrecisionTrans
310		--spnPrecisionRotate.value = nw4c.PrecisionRotate
311		--spnPrecisionScale.value = nw4c.PrecisionScale
312		--
313		/*spnScaleQuality.value = nw4c.ScaleQuality
314		--spnRotateQuality.value = nw4c.RotateQuality
315		--spnTransQuality.value = nw4c.TransQuality
316		*/
317		srAnimation.sldScaleQuality.value = nw4c.ScaleQuality
318		srAnimation.sldRotateQuality.value = nw4c.RotateQuality
319		srAnimation.sldTransQuality.value = nw4c.TransQuality
320		--
321		srQuantization.ddlQuantPosition.selection = nw4c.QuantPos
322		srQuantization.ddlQuantNormal.selection = nw4c.QuantNormal
323		srQuantization.ddlQuantTex.selection = nw4c.QuantTex
324		--
325		srGeneral.chkUseFigureMode.state = nw4c.UseFiguremode
326		--rdoFrameFormat.state = (if nw4c.IsFrameFormat then 2 else 1)
327		srAnimation.chkFrameFormat.state = nw4c.IsFrameFormat
328		--
329		srOutput.chkMergeCmdl.state = nw4c.UseMerge
330		srOutput.editMergeFile.text = nw4c.MergeFilename
331
332		-- �t�@�C�����A�p�X�����̏ꍇ�ɓK���Ȓl������
333		if(srOutput.editFilepath.text == "") do
334		(
335			-- max�t�@�C�����ǂݍ��݁E�ۑ�����Ă��Ȃ��ꍇ
336			if(maxFilePath == "") then srOutput.editFilepath.text = (pathConfig.getDir #export)
337			else srOutput.editFilepath.text = maxFilePath
338		)
339		if(srOutput.editFilename.text == "") do
340		(
341			-- max�t�@�C�����ǂݍ��݁E�ۑ�����Ă��Ȃ��ꍇ
342			if(maxFilePath == "") then srOutput.editFilename.text = "nw4c"
343			else srOutput.editFilename.text = (getFilenameFile maxFileName)
344		)
345		redrawItems()
346	)
347
348	fn saveConfig  saveToScene:true =
349	(
350		--print "save config"
351		local nw4c = nw4cmax
352		nw4c.doesExportSelected = (srOutput.rdoSelection.state == 2)
353		nw4c.outFolder = srOutput.editFilepath.text
354		nw4c.filename = srOutput.editFilename.text
355		nw4c.UseCreativeStudio = (srOutput.rdoUseCS.state == 1)
356
357		nw4c.doesExportModel = srFileSelection.chkExportModel.state
358		nw4c.doesExportTexture = srFileSelection.chkExportTex.state
359		nw4c.doesExportAnimation = srFileSelection.chkExportSkelAnim.state
360		nw4c.doesExportCamera = srFileSelection.chkExportCamera.state
361		nw4c.doesExportLight = srFileSelection.chkExportLight.state
362		nw4c.doesExportMtlAnim = srFileSelection.chkExportMtlAnim.state
363		nw4c.doesExportModelAnim = srFileSelection.chkExportMdlAnim.state
364		nw4c.doesExportEnv = srFileSelection.chkExportEnv.state
365		--
366		nw4c.Magnify = srGeneral.spnMagnify.value
367		--
368		nw4c.doesExportAllFrames = (srGeneral.rdoTimeRange.state == 1)
369		nw4c.StartFrame = srGeneral.spnTimeStart.value
370		nw4c.EndFrame = srGeneral.spnTimeEnd.value
371		nw4c.IsLoop = srAnimation.chkAnimationLoop.state
372		nw4c.AnimPrecision = case srAnimation.ddlAnimationPrecision.selection of
373			(
374				1: 1
375				2: 2
376				3: 5
377				4: 10
378				default: 1
379			)
380		--
381		nw4c.CompressNode = srOptimization.ddlCompressNode.selection
382		nw4c.OptimizePrimitive = srOptimization.chkOptimizePrim.state
383		-- nw4c.OptimizeMaterial = chkOptimizeMtl.state
384		nw4c.OptimizeMaterial = (srOptimization.ddlOptimizeMtl.selection	== 2)
385		nw4c.DisableModelSimplification = (not srOptimization.chkConvertToModel.state)
386		nw4c.NonUniformScale = srModel.chkNonUniformScale.state
387		nw4c.ReservedUniformRegister = srModel.spnReserveUniform.value
388		nw4c.VisibilityBindByName = (srModel.ddlModelBindBy.selection == 2)
389		nw4c.SkinningMode = srModel.ddlSkinningMode.selection
390		--
391		nw4c.ToleranceTrans = srToletance.spnToleranceNodeT.value
392		nw4c.ToleranceRotate = srToletance.spnToleranceNodeR.value
393		nw4c.ToleranceScale = srToletance.spnToleranceNodeS.value
394		--
395		nw4c.ToleranceUVTrans = srToletance.spnToleranceTexT.value
396		nw4c.ToleranceUVRotate = srToletance.spnToleranceTexR.value
397		nw4c.ToleranceUVScale = srToletance.spnToleranceTexS.value
398		nw4c.ToleranceColor = srToletance.spnToleranceColor.value
399		--
400		--nw4c.PrecisionTrans = spnPrecisionTrans.value
401		--nw4c.PrecisionRotate = spnPrecisionRotate.value
402		--nw4c.PrecisionScale = spnPrecisionScale.value
403		--
404		nw4c.QuantPos = srQuantization.ddlQuantPosition.selection
405		nw4c.QuantNormal = srQuantization.ddlQuantNormal.selection
406		nw4c.QuantTex = srQuantization.ddlQuantTex.selection
407		--
408		--nw4c.ScaleQuality = spnScaleQuality.value
409		--nw4c.RotateQuality = spnRotateQuality.value
410		--nw4c.TransQuality = spnTransQuality.value
411		nw4c.ScaleQuality = srAnimation.sldScaleQuality.value
412		nw4c.RotateQuality = srAnimation.sldRotateQuality.value
413		nw4c.TransQuality = srAnimation.sldTransQuality.value
414		--
415		nw4c.useFiguremode = srGeneral.chkUseFigureMode.state
416		--nw4c.IsFrameFormat = (rdoFrameFormat.state == 2)
417		nw4c.IsFrameFormat = srAnimation.chkFrameFormat.state
418		--
419		nw4c.UseMerge = srOutput.chkMergeCmdl.state
420		nw4c.MergeFilename = srOutput.editMergeFile.text
421
422		if saveToScene do nw4c.SaveSetting()
423	)
424
425	fn checkOverwriteFiles fName =
426	(
427		local nw4c = nw4cmax
428		local owflag = false
429		if nw4c.doesExportModel and  doesFileExist(fName + ".cmdl") do ( owflag = true)
430		if nw4c.doesExportAnimation and  doesFileExist(fName + ".cskla") do ( owflag = true)
431		if nw4c.doesExportCamera and  doesFileExist(fName + ".ccam") do ( owflag = true)
432		if nw4c.doesExportLight and  doesFileExist(fName + ".clgt") do ( owflag = true)
433		if nw4c.doesExportModelAnim and  doesFileExist(fName + ".cmdla") do ( owflag = true)
434		if nw4c.doesExportMtlAnim and  doesFileExist(fName + ".cmata") do ( owflag = true)
435		if nw4c.doesExportEnv and  doesFileExist(fName + ".cenv") do ( owflag = true)
436
437		if owflag == false do
438		(
439			return true
440		)
441
442		mes = fName + ".*\n" + " already exists.\nOverwrite ?"
443		local ret = queryBox mes title:"confirm overwrite"
444		return ret
445	)
446
447	fn doExport =
448	(
449		local fname = srOutput.editFilepath.text
450		local nw4c = nw4cMax
451		if(fname[fname.count] != "\\") do append fname "\\"
452		if (srOutput.rdoUseCS.state != 1) do
453		(
454			if  (fname.count) <= 1 or not (doesFileExist fname) do
455			(
456				messageBox "Output Folder is wrong"
457				return undefined
458			)
459		)
460		if (srOutput.editFilename.text.count <= 0)do
461		(
462			messageBox "Output File Name is wrong"
463			return undefined
464		)
465		-- time
466		if (srGeneral.rdoTimeRange.state == 2) do
467		(
468			if(srGeneral.spnTimeStart.value > srGeneral.spnTimeEnd.value) do
469			(
470				messageBox "Time Range is wrong"
471				return undefined
472			)
473		)
474
475		if (srModel.spnReserveUniform.value + (if srModel.chkNonUniformScale.state then 6 else 3) ) > 60 do
476		(
477			messageBox "Max Reserved Uniform Registers is wrong"
478			return undefined
479		)
480
481		saveConfig saveToScene:utils.enableSaveToScene
482		utils.saveSettingDefault()
483
484		if (srOutput.rdoUseCS.state != 1) do
485		(
486			ret = checkOverwriteFiles (fname + srOutput.editFilename.text)
487			if not ret do
488			(
489				return undefined
490			)
491		)
492
493		displayTempPrompt "Exporting..." 99999999
494		setWaitCursor()
495		local ret = nw4cMax.doExport(srOutput.rdoSelection.state == 2)
496		setArrowCursor()
497		removeTempPrompt()
498		return ret
499	)
500
501	fn resizeAll =
502	(
503		local sHeight = 0
504		for i = 1 to nw4cExportRollout.ro.rollouts.count do
505		(
506			local sro = nw4cExportRollout.ro.rollouts[i]
507			sHeight += 25
508			sHeight += if sro.open then sro.height else -4
509		)
510		--sHeight = if sHeight < 700 then sHeight else 700
511		nw4cExportRollout.ro.height = sHeight
512
513
514		btnExport.pos.y = sHeight + 10
515		btnApply.pos.y = sHeight + 10
516		btnClose.pos.y = sHeight + 10
517		nw4cExportRollout.height = sHeight + 40
518	)
519
520	on nw4cExportRollout open  do
521	(
522		nw4cExportRollout.ro.visible = false
523		AddSubRollout ro nw4cSR_Output
524		AddSubRollout ro nw4cSR_General
525		AddSubRollout ro nw4cSR_FileSelection
526		AddSubRollout ro nw4cSR_Optimization
527		AddSubRollout ro nw4cSR_Quantization
528		AddSubRollout ro nw4cSR_Model
529		AddSubRollout ro nw4cSR_Animation
530		AddSubRollout ro nw4cSR_Toletance
531
532		srOutput = ro.nw4cSR_Output
533		srGeneral = ro.nw4cSR_General
534		srFileSelection = ro.nw4cSR_FileSelection
535		srOptimization = ro.nw4cSR_Optimization
536		srQuantization = ro.nw4cSR_Quantization
537		srModel = ro.nw4cSR_Model
538		srAnimation = ro.nw4cSR_Animation
539		srToletance = ro.nw4cSR_Toletance
540
541		if 	nw4cExportRollout_subOpen.count == nw4cExportRollout.ro.rollouts.count do
542		(
543			for i = 1 to nw4cExportRollout_subOpen.count do
544			(
545				nw4cExportRollout.ro.rollouts[i].open = nw4cExportRollout_subOpen[i] as booleanClass
546			)
547		)
548
549		resizeAll()
550
551		nw4cExportRollout.utils.loadSettingDefault()
552		loadConfig loadFromScene:utils.enableSaveToScene
553		nw4cExportRollout.ro.visible = true
554	)
555
556	on nw4cExportRollout close  do
557	(
558		--nw4cExportRollout.utils.saveSettingDefault()
559		--nw4cExportRollout.utils.saveSettingConfig()
560		nw4cExportRollout_subOpen.count = nw4cExportRollout.ro.rollouts.count
561		for i = 1 to nw4cExportRollout_subOpen.count do
562		(
563			nw4cExportRollout_subOpen[i] = nw4cExportRollout.ro.rollouts[i].open
564		)
565		nw4cExportRollout_height = nw4cExportRollout.height
566	)
567
568	on btnExport pressed  do
569	(
570		local ret = doExport()
571		if ret == true then
572		(
573			DestroyDialog nw4cExportRollout
574		)
575		else if ret == false then
576		(
577			messageBox "Export Error!"
578		)
579		else if ret == undefined then
580		(
581			-- donothing
582		)
583	)
584	on btnApply pressed  do
585	(
586		local ret = doExport()
587		if ret == false then
588		(
589			messageBox "Export Error!"
590		)
591		else if ret == undefined then
592		(
593			-- donothing
594		)
595	)
596	on btnClose pressed  do DestroyDialog nw4cExportRollout
597) -- rollout
598
599-----------------------------------------------------
600-- main menu
601rcMenu NW4CSettingMenu
602(
603	subMenu "NW4C Settings"
604	(
605		menuItem mi_scene "Save / Load Scene Settings" checked:false
606		menuItem mi_resetScene "Reset Scene Settings"
607		menuItem mi_deleteScene "Delete Scene Settings"
608		separator sep1
609		menuItem mi_loadFile "Load Settings from c3es File"
610		menuItem mi_saveFile "Save Settings to c3es File"
611	)
612	fn updateMenu =
613	(
614		mi_scene.checked = nw4cExportRollout.utils.enableSaveToScene
615	)
616	on mi_scene picked do
617	(
618		local val = nw4cExportRollout.utils.enableSaveToScene
619		nw4cExportRollout.utils.enableSaveToScene = not val
620		nw4cExportRollout.utils.saveSettingConfig()
621		updateMenu()
622	)
623	on mi_resetScene picked do
624	(
625		if (queryBox "Reset NW4C Settings?") do
626		(
627			nw4cmax.ResetSetting()
628			nw4cExportRollout.loadConfig loadFromScene:false
629			updateMenu()
630		)
631	)
632	on mi_deleteScene picked do
633	(
634		if (queryBox "Delete NW4C Settings?") do
635		(
636			deleteItem rootnode.custattributes "NW4C Custom Attribute"
637			nw4cExportRollout.loadConfig loadFromScene:false
638			updateMenu()
639		)
640	)
641	on mi_saveFile picked do
642	(
643		--print "mi_saveFile"
644		nw4cExportRollout.saveConfig saveToScene:false
645		local fname = getSaveFileName caption:"Save NW4C Setting File" types:"NW4C Settings(*.c3es)|*.c3es|All|*.*|" historyCategory:"NW4C_Setting_File"
646		if not (nw4cExportRollout.utils.saveSettingToFile fname) do
647		(
648			messageBox "c3es save error"
649		)
650	)
651	on mi_loadFile picked do
652	(
653		--print "mi_loadFile"
654		local fname = getOpenFileName caption:"Load NW4C Setting File" types:"NW4C Settings(*.c3es)|*.c3es|All|*.*|" historyCategory:"NW4C_Setting_File"
655		if not (nw4cExportRollout.utils.loadSettingFromFile fname) do
656		(
657			messageBox "c3es load error"
658		)
659		nw4cExportRollout.loadConfig loadFromScene:false
660	)
661	on NW4CSettingMenu open do updateMenu()
662	on NW4CSettingMenu update do updateMenu()
663)
664
665macroScript nw4cMS_ExportWithSetting category:"NW4C"
666(
667	on execute do
668	(
669		CreateDialog  nw4cExportRollout menu:NW4CSettingMenu height:nw4cExportRollout_height --modal:true
670	)
671)
672
673macroScript ResetExportSetting category:"NW4C"
674(
675	on execute do
676	(
677		local ret = queryBox "Reset Export Setting?" title:"confirm reset"
678		if ret do
679		(
680			nw4cmax.ResetSetting()
681			nw4cmax.SaveSetting()
682		)
683	)
684)
685
686macroScript nw4cMS_ExportNow category:"NW4C"
687(
688	on execute do
689	(
690		local nw4c = nw4cmax
691		local fromScene = nw4cExportRollout.utils.loadSettingDefault()
692		if fromScene do nw4c.LoadSetting()
693
694		local fname = nw4c.outFolder
695		local nw4c = nw4cMax
696		if(fname[fname.count] != "\\") do append fname "\\"
697
698		if (nw4c.UseCreativeStudio == false) do
699		(
700			if  not (doesFileExist fname) do
701			(
702				messageBox "Output Folder is wrong"
703				return false
704			)
705			ret = nw4cExportRollout.checkOverwriteFiles (fname + nw4c.filename)
706			if not ret do
707			(
708				return false
709			)
710		)
711
712		if (nw4c.filename.count <= 0)do
713		(
714			messageBox "Output File Name is wrong"
715			return false
716		)
717
718		fname = fname + nw4c.filename + ".cmdl"
719
720		displayTempPrompt "Exporting..." 99999999
721		setWaitCursor()
722		local ret = nw4c.doExport nw4c.doesExportSelected
723		setArrowCursor()
724		removeTempPrompt()
725
726		if not ret do
727		(
728			messageBox "Export error!"
729		)
730	)
731)
732
733macroScript nw4cMS_SetNoCompressNode category:"NW4C"
734(
735	on execute do
736	(
737		CreateDialog  nw4cNodeRollout
738	)
739)
740macroScript nw4cMS_SetBillboard category:"NW4C"
741(
742	on execute do
743	(
744		CreateDialog  nw4cBillboardRollout
745	)
746)
747
748macroScript nw4cMS_SetMaterial category:"NW4C"
749(
750	on execute do
751	(
752		CreateDialog  nw4cMaterialRollout
753	)
754)
755
756macroScript nw4cMS_SetRenderPriority category:"NW4C"
757(
758	on execute do
759	(
760		CreateDialog  nw4cRenderPriorityRollout
761	)
762)
763
764macroScript nw4cMS_SetCombineGroup category:"NW4C"
765(
766	on execute do
767	(
768		CreateDialog  nw4cCombineRollout
769	)
770)
771
772macroScript nw4cMS_SetForceExportKey category:"NW4C"
773(
774	on execute do
775	(
776		CreateDialog  nw4cForceKeyRollout
777	)
778)
779
780macroScript nw4cMS_SetNodeUserData category:"NW4C"
781(
782	on execute do
783	(
784		CreateDialog  nw4cNodeUserDataRollout
785	)
786)
787
788
789macroScript nw4cMS_PluginVersion category:"NW4C"
790(
791	on execute do
792	(
793		local nw4c = nw4cmax
794		if nw4c == undefined do return()
795		mes = "NintendoWare for CTR\n"
796		mes += "3ds Max Plugin Ver " + nw4c.GetVersionString()
797		mes += "\n"
798		mes += "(C)2010 Nintendo.,Ltd.\n"
799		mes += "All rights reserved"
800
801		messageBox mes title:"NW4C 3ds Max Plugin Version"
802	)
803)
804
805
806fn getNw4cMenu =
807(
808	local mainMenuBar = menuman.getMainMenuBar()
809	for i = 1 to mainMenuBar.numitems() do
810	(
811		local mi = mainMenuBar.getItem i
812		if ( (mi.getTitle()) == "NW4C" ) do
813		(
814			return mi
815		)
816	)
817	-- NW4C���j���[�����o�^
818	local subMenu = menuMan.createMenu "NW4C"
819	local subMenuItem = menuMan.createSubMenuItem "Test Menu" subMenu
820	-- ���C�� ���j���[ �o�[�̍Ōォ�� 2 �Ԗڂ̃��j���[���ڂ̃C���f�b�N�X���v�Z���܂��B
821	local subMenuIndex = mainMenuBar.numItems() - 1
822	-- �T�u���j���[���Ōォ�� 2 �Ԗڂ̃X���b�g�ɒlj����܂��B
823	mainMenuBar.addItem subMenuItem subMenuIndex
824	return subMenuItem
825)
826
827fn resetMenuActions mi =
828(
829	local menu = mi.getSubMenu()
830	-- �܂��o�^�ς݂̃T�u���j���[�A�C�e�����폜
831	while (menu.numItems() > 0) do
832	(
833		menu.removeItemByPosition 1
834	)
835
836	local dialogItem
837
838	dialogItem = menuMan.createActionItem "nw4cMS_ExportNow" "NW4C"
839	dialogItem.setTitle "NW4C Export"
840	dialogItem.setUseCustomTitle true
841	menu.addItem dialogItem -1
842
843	dialogItem = menuMan.createActionItem "nw4cMS_ExportWithSetting" "NW4C"
844	dialogItem.setTitle "NW4C Export With Setting"
845	dialogItem.setUseCustomTitle true
846	menu.addItem dialogItem -1
847
848	dialogItem = menuMan.createSeparatorItem()
849	menu.addItem dialogItem -1
850
851	dialogItem = menuMan.createActionItem "nw4cMS_SetMaterial" "NW4C"
852	dialogItem.setTitle "NW4C Set Material Attribute"
853	dialogItem.setUseCustomTitle true
854	menu.addItem dialogItem -1
855
856	dialogItem = menuMan.createActionItem "nw4cMS_SetRenderPriority" "NW4C"
857	dialogItem.setTitle "NW4C Set Render Priority"
858	dialogItem.setUseCustomTitle true
859	menu.addItem dialogItem -1
860
861	dialogItem = menuMan.createSeparatorItem()
862	menu.addItem dialogItem -1
863
864	dialogItem = menuMan.createActionItem "nw4cMS_SetNoCompressNode" "NW4C"
865	dialogItem.setTitle "NW4C Set No Compress Node"
866	dialogItem.setUseCustomTitle true
867	menu.addItem dialogItem -1
868
869	dialogItem = menuMan.createActionItem "nw4cMS_SetBillboard" "NW4C"
870	dialogItem.setTitle "NW4C Set Billboard"
871	dialogItem.setUseCustomTitle true
872	menu.addItem dialogItem -1
873
874	dialogItem = menuMan.createActionItem "nw4cMS_SetCombineGroup" "NW4C"
875	dialogItem.setTitle "NW4C Set Combine Group"
876	dialogItem.setUseCustomTitle true
877	menu.addItem dialogItem -1
878
879	dialogItem = menuMan.createActionItem "nw4cMS_SetForceExportKey" "NW4C"
880	dialogItem.setTitle "NW4C Set Force Export Key"
881	dialogItem.setUseCustomTitle true
882	menu.addItem dialogItem -1
883
884	dialogItem = menuMan.createActionItem "nw4cMS_SetNodeUserData" "NW4C"
885	dialogItem.setTitle "NW4C Set User Data"
886	dialogItem.setUseCustomTitle true
887	menu.addItem dialogItem -1
888
889	dialogItem = menuMan.createSeparatorItem()
890	menu.addItem dialogItem -1
891
892	dialogItem = menuMan.createActionItem "nw4cMS_PluginVersion" "NW4C"
893	dialogItem.setTitle "Plugin Version"
894	dialogItem.setUseCustomTitle true
895	menu.addItem dialogItem -1
896
897)
898
899fileIn  "NW4C_node.ms.inc"
900fileIn  "NW4C_mtl.ms.inc"
901
902
903----------------------------------------------
904-- NW4C Main
905
906fn nw4cmain =
907(
908	-- ���C�����j���[��NW4C���j���[��lj�
909	local nw4cMenu = getNw4cMenu()
910	resetMenuActions nw4cMenu
911	-- �}�e���A���G�f�B�^��NW4C���j���[��lj�
912	local nw4cMtlMenu = getNw4cMtlMenu()
913	resetMtlMenuActions nw4cMtlMenu
914
915	nw4cExportRollout.utils.loadSettingDefault()
916
917	menuMan.updateMenuBar()
918
919	--DestroyDialog nw4cExportRollout
920	--CreateDialog  nw4cExportRollout  menu:NW4CSettingMenu --modal:true
921
922)
923
924-- nw4c�v���O�C�����ǂݍ��܂�Ă��Ȃ��ꍇ�͉������Ȃ��B
925if nw4cmax != undefined do
926(
927	--print "NW4C menu loaded"
928	nw4cMain()
929)
930