⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtoolsutility.ms

📁 3dmax导出3d模型二次开发插件
💻 MS
📖 第 1 页 / 共 2 页
字号:
-------------------------------------------------------------------------------
-- AttachScriptOnThis( ScriptName )
-- AttachScriptOnCharacter( ScriptName )
-- SetParamOnThis( ParamName, ParamVal
-- SetParam( MaxObjName, ParamName, ParamValue )
-- SetAttributeOnThis( AttName, AttValue, AttType, AttCatego )
-- SetAttributeOnCharacter( AttName, AttValue, AttType, AttCatego )
-- Load( fileName )
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
-- Global Variables
-------------------------------------------------------------------------------
global exportFct, previewFct, quickPreviewFct, updateInstructionsList, registerInstruction
global AddCKChunk, RemoveCKChunk, WriteConfig, ReadConfig, GetLevelObject
global Virtools_Preview, VirtoolsExportOpt, VirtoolsExportProcess, VirtoolsInstructionsManager

global posAsVirtools, boolAsVirtools, matrixInParentAsVirtools
global ReadCKBufValue, ReadCKBufValueAsFloat, ReadCKBufValueAsInt, ReadCKBufValueAsVector
global ReadCKBufValueAsAngle, ReadCKBufValueAsTime

global maxPath = getdir #maxroot
global virtoolsAddonsPath = maxPath + "plugins\\Virtools AddOns\\"
global CKInstPath = maxPath + "scripts\\CKInstScripts\\"
global previewFileName = virtoolsAddonsPath + "preview.vmo"
global configFileName = (getdir #plugcfg) + "\\Max2Nmo.CFG"
global configSettingSection = "Settings"

if VirtoolsWindow!=undefined do (
	closerolloutfloater VirtoolsWindow
)
global VirtoolsWindow
global currentRollout = unsupplied

global CKCHUNKBEGINSTR = "CKCHUNK_BEGIN"
global CKCHUNKENDSTR = "CKCHUNK_END"

global CKAttacheScriptOnThisStr = "CK_AttachScriptOnThis"
global CKAttachScriptOnCharacterStr = "CK_AttachScriptOnCharacter"
global CKSetParamOnThisStr = "CK_SetParamOnThis"
global CKSetParamStr = "CK_SetParam"
global CKSetAttributeOnThisStr = "CK_SetAttributeOnThis"
global CKSetAttributeOnCharacterStr= "CK_SetAttributeOnCharacter"
global CKLoadStr = "CK_Load"

global instNameSet = #()
global instFctSet = #()
global instRolloutSet = #()

global objWithInst = #()

global currentSelectedInst = 1

global objectAsLevel = undefined

global currentChunkBuf = undefined


-------------------------------------------------------------------------------
-- Reading CK Buffer Functions
-------------------------------------------------------------------------------
fn GetCKChunk obj chunkKey = (

	local buf = getUserPropBuffer obj
	if (buf==undefined) do return undefined

	local startIndex = findString buf (CKCHUNKBEGINSTR + " \"" + chunkKey + "\"")
	if (startIndex==undefined) do return undefined

	local endIndex = findstring buf CKCHUNKENDSTR
	if (endIndex==undefined) do return undefined
	endIndex += CKCHUNKENDSTR.count
	
	return (substring buf startIndex (endIndex-startIndex))
)


fn ReadCKBufValue paramString paramIsInst:false = (
	if (currentChunkBuf==undefined) do return undefined
	if (paramString==undefined) do return undefined
	local strToFind = if paramIsInst then (paramString+"(\"") else ("\""+paramString+"\", \"")
	local tmp = findstring currentChunkBuf strToFind
	if (tmp==undefined) do return undefined
	
	tmp += strToFind.count
	local buf = substring currentChunkBuf tmp -1
	tmp = findstring buf "\""
	if (tmp==undefined) do return undefined
	return substring buf 1 (tmp-1)
)

fn ReadCKBufValueAsNumber paramString = (
	local str = ReadCKBufValue paramString
	if (str==undefined) do return undefined
	return (execute str)
)

fn ReadCKBufValueAsVector paramString = (
	local str = ReadCKBufValue paramString
	if (str==undefined) do return undefined
	return (execute ("["+str+"]"))
)

fn ReadCKBufValueAsAngle paramString = (
	local str = ReadCKBufValue paramString
	if (str==undefined) do return undefined
	-- Angles are always written "0:angle"
	return (execute (substring str 3 -1))
)

fn ReadCKBufValueAsTime paramString = (
	local str = ReadCKBufValue paramString
	if (str==undefined) do return undefined
	-- Times are always written "0m times 0ms"
	local tmp = findstring str "s 0ms"
	return (execute (substring str 4 (tmp-4)))
)

fn ReadCKBufValueAsBool paramString = (
	local str = ReadCKBufValue paramString
	if (str==undefined) do return undefined
  if (str=="TRUE") then (return true) else (return false)
)


-------------------------------------------------------------------------------
-- Convenient Conversion Functions
-------------------------------------------------------------------------------
fn posAsVirtools v = 
(
	(v.x as string) + "," + (v.z as string) + "," + (v.y as string)
)

fn boolAsVirtools b = 
(
	if b then (return "TRUE") else (return "FALSE")
)

fn matrixInParentAsVirtools obj = 
(
	m = if (obj.parent==undefined) then (obj.transform) else (obj.transform * inverse (obj.parent.transform) )
	local row1 = m.row1
	local row2 = m.row2
	local row3 = m.row3
	local row4 = m.row4
	local str = "[" + (row1.x as string) + "," + (row1.z as string) + "," + (row1.y as string) + ",0]"
	str += "[" + (row3.x as string) + "," + (row3.z as string) + "," + (row3.y as string) + ",0]"
	str += "[" + (row2.x as string) + "," + (row2.z as string) + "," + (row2.y as string) + ",0]"
	str += "[" + (row4.x as string) + "," + (row4.z as string) + "," + (row4.y as string) + ",1]"
	return str
)

-------------------------------------------------------------------------------
-- Export Options Rollout
-------------------------------------------------------------------------------
rollout VirtoolsExportOpt "Export Options" width:408 height:500 category:0 rolledup:true
(
	radiobuttons exportas_Radio "" pos:[8,8] width:126 height:48 enabled:true labels:#("Export as Objects", "Export as a Character", "Export Animation Only") default:1 columns:1
	edittext charname_Edit "Character Name: " text:"Character" pos:[200,16] width:191 height:16 enabled:false fieldwidth:200
	edittext animname_Edit "Animation Name: " text:"Animation" pos:[200,40] width:191 height:16 enabled:true fieldwidth:150
	GroupBox generaloptions_Group "General Options" pos:[8,72] width:208 height:96
	checkbox onlytexturefilenames_Check "Store only texture filenames" pos:[22,90] width:154 height:16
	checkbox rescale_Check "Rescale scene to 1 unit = 1 meter" pos:[22,109] width:184 height:16
	checkbox placeasroup_Check "Convert group to places" pos:[22,128] width:152 height:16
	checkbox selectiontogroup_Check "Named selections to groups" pos:[22,147] width:152 height:16 default:true
	GroupBox physique_Group "Physique conversion" pos:[224,72] width:168 height:56
	radiobuttons convert_Radio "" pos:[232,88] width:154 height:32 enabled:true labels:#("Convert to Skin", "Convert to Morph Animation") default:1 columns:1
	GroupBox biped_Group "Biped options" pos:[224,128] width:168 height:40
	checkbox savebiped_Check "Save biped geometry" pos:[232,146] width:152 height:16
	GroupBox line1_Group "" pos:[-4,58] width:410 height:8
	GroupBox line2_Group "" pos:[-4,170] width:410 height:8
	GroupBox grp22 "Controllers Output" pos:[8,184] width:384 height:96
	label only_Label "Only Linear,TCB and Bezier controllers are supported; other controllers will be converted to Linear animation or morph Animation (Mesh modifiers) using the given sampling step:" pos:[16,202] width:196 height:70
	label sampling_Label "Sampling Step for..." pos:[279,203] width:98 height:18
	spinner sampstepforcontrollers_Spin "Controllers:" pos:[280,227] width:100 height:16 range:[0,10000,3] type:#integer fieldwidth:40
	spinner sampstepfordeformables_Spin "Deformable Objects:" pos:[280,249] width:100 height:16 range:[0,10000,3] type:#integer fieldwidth:40

	on exportas_Radio changed stat do (
		if stat==2 then charname_Edit.enabled=true
		else charname_Edit.enabled=false
	)
	
)


-------------------------------------------------------------------------------
-- Export Process Rollout
-------------------------------------------------------------------------------
rollout VirtoolsExportProcess "Export Process" width:408 height:86 category:0 
(
	spinner report_Spin "" pos:[104,34] width:48 height:16 range:[0,3,0] type:#integer
	spinner compression_Spin "" text:"3" pos:[104,8] width:48 height:16 range:[0,9,6] type:#integer
	label report_Label "Report log detail level: (0 for no log)" pos:[9,26] width:95 height:26
	label compression_Label "Compression level:" pos:[9,8] width:95 height:16
	button export_Button "Export" pos:[309,6] width:88 height:20
	checkbox onlySelected_Check "Only Selected" pos:[215,10] width:88 height:16
	button exactPreview_Button "Exact Preview" pos:[309,32] width:88 height:20
	button quickPreview_Button "Quick Preview" pos:[212,32] width:88 height:20
	Timer closePreview_Timer "" pos:[360,58] width:24 height:24 interval:50 active:true


	on export_Button pressed do
	(
		local fileName
		if( alreadyGivenFileName==undefined ) then (
			fileName = getsavefilename caption:"Virtools Export" \
							types:"Virtools Export (*.NMO)|*.nmo|Virtools Viewer Export (*.VMO)|*.vmo"\
		) else (
			fileName = alreadyGivenFileName
			alreadyGivenFileName = undefined
		)
		if fileName != undefined do (
			filetype = getfilenametype filename
			if filetype == "" do filename += ".nmo"
			setwaitcursor()
			exportFct fileName
			setarrowcursor()
		)
	)

	on exactPreview_Button pressed do
	(
		previewFct()
	)

	on quickPreview_Button pressed do
	(
		quickPreviewFct()
	)

	on closePreview_Timer tick do
	(
		if not Virtools_Preview.open do (
			removerollout Virtools_Preview VirtoolsWindow
		)
	) 
)



-------------------------------------------------------------------------------
-- Write Settings in the Configuration file
-------------------------------------------------------------------------------
fn WriteConfig = (
	local version = getINIsetting configFileName configSettingSection "Version"
	if (version!="2") do (createfile configFileName)
	
	setINIsetting configFileName configSettingSection "Version" "2"
	setINIsetting configFileName configSettingSection "Export As" (VirtoolsExportOpt.exportas_Radio.state as string)
	setINIsetting configFileName configSettingSection "Character Name" (VirtoolsExportOpt.charname_Edit.text as string)
	setINIsetting configFileName configSettingSection "Animation Name" (VirtoolsExportOpt.animname_Edit.text as string)
	setINIsetting configFileName configSettingSection "Only Texture Filenames" (VirtoolsExportOpt.onlytexturefilenames_Check.state as string)
	setINIsetting configFileName configSettingSection "Rescale" (VirtoolsExportOpt.rescale_Check.state as string)
	setINIsetting configFileName configSettingSection "Group To Place" (VirtoolsExportOpt.placeasroup_Check.state as string)
	setINIsetting configFileName configSettingSection "Selection To Group" (VirtoolsExportOpt.selectiontogroup_Check.state as string)
	setINIsetting configFileName configSettingSection "Physique Conversion" (VirtoolsExportOpt.convert_Radio.state as string)
	setINIsetting configFileName configSettingSection "Sampling Controllers" (VirtoolsExportOpt.sampstepforcontrollers_Spin.value as string)
	setINIsetting configFileName configSettingSection "Sampling Deformables" (VirtoolsExportOpt.sampstepfordeformables_Spin.value as string)

	setINIsetting configFileName configSettingSection "Compression level" (VirtoolsExportProcess.compression_Spin.value as string)
	setINIsetting configFileName configSettingSection "Report level" (VirtoolsExportProcess.report_Spin.value as string)
	setINIsetting configFileName configSettingSection "Only Selected" (VirtoolsExportProcess.onlySelected_Check.state as string)
)


-------------------------------------------------------------------------------
-- Read Settings in the Configuration file
-------------------------------------------------------------------------------
fn ReadConfig = (
	local version = getINIsetting configFileName configSettingSection "Version"
	if (version!="2") do (return false)
	
	VirtoolsExportOpt.exportas_Radio.state = (getINIsetting configFileName configSettingSection "Export As") as integer
	VirtoolsExportOpt.charname_Edit.text = (getINIsetting configFileName configSettingSection "Character Name")
	VirtoolsExportOpt.animname_Edit.text = (getINIsetting configFileName configSettingSection "Animation Name")
	VirtoolsExportOpt.onlytexturefilenames_Check.state = (getINIsetting configFileName configSettingSection "Only Texture Filenames")=="true"
	VirtoolsExportOpt.rescale_Check.state = (getINIsetting configFileName configSettingSection "Rescale")=="true"
	VirtoolsExportOpt.placeasroup_Check.state= (getINIsetting configFileName configSettingSection "Group To Place")=="true"
	VirtoolsExportOpt.selectiontogroup_Check.state = (getINIsetting configFileName configSettingSection "Selection To Group")=="true"
	VirtoolsExportOpt.convert_Radio.state = (getINIsetting configFileName configSettingSection "Physique Conversion") as integer
	VirtoolsExportOpt.sampstepforcontrollers_Spin.value = (getINIsetting configFileName configSettingSection "Sampling Controllers") as integer
	VirtoolsExportOpt.sampstepfordeformables_Spin.value = (getINIsetting configFileName configSettingSection "Sampling Deformables") as integer

	VirtoolsExportProcess.compression_Spin.value = (getINIsetting configFileName configSettingSection "Compression level") as integer
	VirtoolsExportProcess.report_Spin.value = (getINIsetting configFileName configSettingSection "Report level") as integer
	VirtoolsExportProcess.onlySelected_Check.state = (getINIsetting configFileName configSettingSection "Only Selected")=="true"
)


-------------------------------------------------------------------------------
-- Export function
-- it can be called when hiting Export button, Quick Preview button or Exact
-- Preview buttton.
-------------------------------------------------------------------------------
fn exportFct fileName = 
(
	-- Really Do Export
	WriteConfig()
	export2nmo fileName \
			VirtoolsExportProcess.onlySelected_Check.checked \
			VirtoolsExportOpt.exportas_Radio.state \
			VirtoolsExportOpt.onlytexturefilenames_Check.checked \
			VirtoolsExportOpt.rescale_Check.checked \
			VirtoolsExportOpt.placeasroup_Check.checked \
			VirtoolsExportOpt.selectiontogroup_Check.checked \
			(VirtoolsExportOpt.convert_Radio.state == 1) \
			VirtoolsExportOpt.savebiped_Check.checked \
			VirtoolsExportOpt.sampstepforcontrollers_Spin.value \
			VirtoolsExportOpt.sampstepfordeformables_Spin.value \
			VirtoolsExportProcess.compression_Spin.value\
			VirtoolsExportProcess.report_Spin.value\
			VirtoolsExportOpt.charname_Edit.text\
			VirtoolsExportOpt.animname_Edit.text

)


-------------------------------------------------------------------------------
-- Preview Function
-------------------------------------------------------------------------------
fn previewFct = (
	setwaitcursor()
	exportFct previewFileName
	if Virtools_Preview.open then (
		Virtools_Preview.ax.load previewFileName
	) else (
		addrollout Virtools_Preview VirtoolsWindow
	)
	setarrowcursor()
)

-------------------------------------------------------------------------------
-- Get Level Object
-------------------------------------------------------------------------------
fn GetLevelObject = (
  local virtoolsGlobalHelper = $VirtoolsGlobalHelper
  if (virtoolsGlobalHelper!=undefined) do return (objectAsLevel=virtoolsGlobalHelper)

	if (geometry==undefined) do return (objectAsLevel=undefined)

	if (geometry!=undefined and geometry.count!=0) then ( objectAsLevel=geometry[1] )
	else if (ligths!=undefined and ligths.count!=0) then ( objectAsLevel=lights[1] )
	else if (cameras!=undefined and cameras.count!=0) then ( objectAsLevel=cameras[1] )
	else if (helpers!=undefined and helpers.count!=0) then ( objectAsLevel=helpers[1] )
	else if (shapes!=undefined and shapes.count!=0) then ( objectAsLevel=shapes[1] )
	else undefined
	
	objectAslevel
)

-------------------------------------------------------------------------------
-- Quick Preview Function
-------------------------------------------------------------------------------
fn quickPreviewFct = (

	--------------------
	-- Add Instructions

	if (GetLevelObject()==undefined) do return
	
	-- set camera
	activeCamera = undefined
	orbitCamera = undefined
	createdCamera = undefined

	local centerToLookAt = geometry.center
	if (selection.count!=0) do centerToLookAt = selection.center

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -