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