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

📄 virtoolsutility.ms

📁 3dmax导出3d模型二次开发插件
💻 MS
📖 第 1 页 / 共 2 页
字号:
		
	if (cameras.count!=0) then (
		activeCamera = cameras[1]
		
		orbitCamera = activeCamera
		if (activeCamera.parent!=undefined) do (
			if activeCamera.parent.isAnimated do (orbitCamera=undefined)
		)
		if ( (findstring (getUserPropBuffer orbitCamera) CKCHUNKBEGINSTR)!=undefined ) do (orbitCamera=undefined)
	) else (
		if not gw.isperspview() do (
			for a=1 to viewport.numviews do (
				viewport.activeViewport = a
				if gw.isperspview() do exit
			)
		)
		
		orbitCamera = freecamera name:"Camera01"
		if gw.isperspview() then (
			orbitCamera.fov = getviewfov()
			orbitCamera.transform = Inverse(getviewTM())
			orbitCamera.pos = (Inverse(getViewTM())).row4
		) else (
			orbitCamera.pos = geometry.max
			orbitCamera.dir = centerToLookAt
			orbitCamera.fov = 45.0
		)
		createdCamera = orbitCamera
		activeCamera = orbitCamera
		selectMore createdCamera
	)

	if (orbitCamera!=undefined) do (
		chunkData = "  " + CKAttacheScriptOnThisStr + "(\"Camera Orbit\")\x0d\x0a"
		chunkData += "  " + CKSetParamOnThisStr + "(\"Center To Look At\", \"" + (posAsVirtools centerToLookAt) + "\" )\x0d\x0a"
		AddCKChunk activeCamera "Quick Preview Camera Orbit" chunkData
	)

	if (activeCamera!=undefined) do (
		chunkData = "  " + CKAttacheScriptOnThisStr + "(\"set_as_active_camera\")\x0d\x0a"
		AddCKChunk activeCamera "Quick Preview Active Camera" chunkData
	)
	
	-- set light
	createdLight = undefined
	if (lights.count==0) do (
		createdLight = omnilight name:"Omni01" color:[255,255,255]
		createdLight.pos = activeCamera.pos
		createdLight.parent = activeCamera
		selectMore createdLight
	)
	
	-- set animation
	if (objectAsLevel!=undefined) do (
		chunkData = "  " + CKAttacheScriptOnThisStr + "(\"Play Global Animation\")\x0d\x0a"
		chunkData += "  " + CKSetParamOnThisStr + "(\"Global Animation Name\", \"CK_EXPORTEDANIMATION\" )\x0d\x0a"
		duration = (animationrange.end.frame-animationrange.start.frame)/(framerate * 0.125 * pow 2 timeconfiguration.playbackspeed)
		chunkData += "  " + CKSetParamOnThisStr + "(\"Global Animation Duration\", \"0m " + (duration as string) + "s 0ms\" )\x0d\x0a"
		AddCKChunk objectAsLevel "Quick Preview Play Global Animation" chunkData
	)
	
	-----------
	-- Preview
	previewFct ()
	
	------------------------------
	-- Remove Added Intstructions
	if (activeCamera!=undefined) do (RemoveCKChunk activeCamera "Quick Preview Active Camera"; activeCamera=undefined)
	if (orbitCamera!=undefined) do (RemoveCKChunk orbitCamera "Quick Preview Camera Orbit"; orbitCamera=undefined)
	if (createdCamera!=undefined) do (delete createdCamera; createdCamera=undefined)
	if (createdLight!=undefined) do (delete createdLight; createdLight=undefined)
	if (objectAsLevel!=undefined) do (RemoveCKChunk objectAsLevel "Quick Preview Play Global Animation"; objectAsLevel=undefined)

	updateInstructionsList()
)



-------------------------------------------------------------------------------
-- Preview Rollout
-------------------------------------------------------------------------------
rollout Virtools_Preview "Preview" width:408 height:300 category:0
(
	ActiveXControl ax "{C4925E65-7A1E-11D2-8BB4-00A0C9CC72C3}" pos:[4,4] width:394 height:298 align:#left setupEvents:false

	on Virtools_Preview open do
	(
		ax.allowpause = 1
		ax.src = previewFileName
		ax.keepkeyboard = 0
		ax.AllowFullScreen = 0
		
		enableAccelerators = false
	)
)



-------------------------------------------------------------------------------
-- Instructions Manager
-------------------------------------------------------------------------------
rollout VirtoolsInstructionsManager "Instructions Manager" width:408 height:178 category:1
(
	listbox instructionsApplied_List "Applied Instructions:" pos:[232,8] width:162 height:6
	button removeInst_Button "Remove" pos:[232,114] width:78 height:24 enabled:false
	button removeAllInst_Button "Remove All" pos:[314,114] width:80 height:24 enabled:false
	GroupBox sepInstList_Group "" pos:[204,0] width:1 height:140
	listbox instructions_List " " pos:[12,8] width:162 height:8
	checkbutton instset_Check "Instruction Set:" pos:[12,8] width:80 height:16 checked:true
	checkbutton objlist_Check "Object List:" pos:[94,8] width:80 height:16

	--------------------------------------
	-- Update Instruction Set List
	--------------------------------------
	fn updateInstSetList = (
		instructions_List.selection = 0
		if instset_Check.checked then (
		
			instructions_List.items = instNameSet
		
		) else (
			
			objWithInst = #()
			for obj in objects do (
				buf = getUserPropBuffer obj
				tmpStart = findstring buf CKCHUNKBEGINSTR
				if (tmpStart!=undefined) do (
					objWithInst += #(obj)
				)
			)
		
			instructions_List.items = #()
			n=1
			for obj in objWithInst do (
				if obj!=undefined do (
					instructions_List.items += #(obj.name)
					n += 1
				)
			)
		
		)
		updateInstructionsList()
	)	

	on instset_Check changed state do (
		objlist_Check.checked = not state
		updateInstSetList()
	)
	
	on objlist_Check changed state do (
		instset_Check.checked = not state
		updateInstSetList()
	)

	on instructionsApplied_List selected index do (
		if instset_Check.checked do (instructions_List.selection=0)
		removeInst_Button.enabled = true
		removeAllInst_Button.enabled = true
		currentSelectedInst = finditem instNameSet (instructionsApplied_List.selected)
		if( currentSelectedInst!=0 ) do (
			instRollout = instRolloutSet[currentSelectedInst]
			if (currentRollout!=instRollout) then (
				if( currentRollout!=unsupplied ) do (
					removerollout currentRollout VirtoolsWindow
				)
			)
			if (instRollout!=unsupplied) do (
				addrollout instRollout VirtoolsWindow
				currentRollout = instRollout
				instRollout.UpdateFromChunk()
			)
		)
		
	)
	
	on instructions_List selected index do (
		
		if instset_Check.checked then (
			-- Instruction List case
			currentSelectedInst = index
			instRollout = instRolloutSet[index]
			if (currentRollout!=instRollout) then (
				if (currentRollout!=unsupplied) do (
					removerollout currentRollout VirtoolsWindow
				)
			) else (
			)
			
			if (instRollout!=unsupplied) do (
				addrollout instRollout VirtoolsWindow
				currentRollout = instRollout
			)
	
		) else (
			-- Object List case
			select objWithInst[instructions_List.selection]
		)

		instructionsApplied_List.selection = 0
		removeInst_Button.enabled = false
		removeAllInst_Button.enabled = false
	)
	
	on instructions_List doubleClicked index do (
		if instset_Check.checked do (
			-- Instruction List case
			currentSelectedInst = index
			(instFctSet[index])()
		)
	)
	
	on removeInst_Button pressed do
	(
		if( ($!=undefined) and (instructionsApplied_List.selection!=0) ) do (
			RemoveCKChunk $ instructionsApplied_List.selected
			updateInstSetList()
		)
	)

	on removeAllInst_Button pressed do
	(
		if( $ != undefined ) do (
			while( (RemoveCKChunk $ "") != undefined ) do ()
			updateInstSetList()
		)
	)

)


-------------------------------------------------------------------------------
-- Add CK CHUNK
-------------------------------------------------------------------------------
fn AddCKChunk obj chunkKey chunkData AllowMultipleChunk:false = (
	
	-- as we add some instruction, we can then create the virtools global helper
	-- if it doesn't exists
  local virtoolsGlobalHelper = $VirtoolsGlobalHelper
  if (virtoolsGlobalHelper==undefined) do (dummy name:"VirtoolsGlobalHelper" pos:[0,0,-100] scale:[0.1,0.1,0.1])
  if (obj==undefined) do (obj=virtoolsGlobalHelper)

	buf = getUserPropBuffer obj
	
	if not AllowMultipleChunk do (
		local startIndex = findString buf (CKCHUNKBEGINSTR + " \"" + chunkKey + "\"")
		if( startIndex != undefined ) do return ok
	)

	buf += CKCHUNKBEGINSTR + " \"" + chunkKey + "\"\x0d\x0a"
	buf += chunkData
	buf += CKCHUNKENDSTR + "\x0d\x0a"
	setUserPropBuffer obj buf
)

-------------------------------------------------------------------------------
-- Remove CK CHUNK
-- if chunkey == "" removes the first CKCHUNK found
-- return value = index of the found CKCHUNK, undefined if not found
-------------------------------------------------------------------------------
fn RemoveCKChunk obj chunkKey = (
	buf = getUserPropBuffer obj

	-- remove doubled carriage return
	local tmpIndex = findstring buf "\x0d\x0a\x0d\x0a"
	while (tmpIndex!=undefined) do (
		buf = replace buf tmpIndex 4 "\x0d\x0a"
		tmpIndex = findstring buf "\x0d\x0a\x0d\x0a"
	)
	--
	
	local startIndex
	if( chunkKey=="" ) then (
		startIndex = findString buf CKCHUNKBEGINSTR
	) else (
		startIndex = findString buf (CKCHUNKBEGINSTR + " \"" + chunkKey + "\"")
	)
	if( startIndex != undefined ) do (
		buf1 = substring buf 1 (startIndex-1)
		buf = substring buf startIndex -1
		endIndex = (findstring buf CKCHUNKENDSTR) + CKCHUNKENDSTR.count
		if( endIndex != undefined ) do (
			buf2 = substring buf endIndex -1
			setUserPropBuffer obj (buf1+buf2)
		)
	)
	startIndex
)


-------------------------------------------------------------------------------
-- Update Applied Instructions List
-------------------------------------------------------------------------------
fn updateInstructionsList = (
	
	local instructionStr = undefined
	instructionList = #()
	if( selection.count==1 ) do (
		buf = getUserPropBuffer selection[1]
		tmpStart = findstring buf (CKCHUNKBEGINSTR+" \"")
		while (tmpStart!=undefined) do (
			tmpStart += (CKCHUNKBEGINSTR+" \"").count
			buf = substring buf tmpStart -1
			tmpEnd = findstring buf "\""
			if (tmpEnd!=undefined) do (
				instructionStr = substring buf 1 (tmpEnd-1)
				append instructionList instructionStr
			)
			tmpStart = findstring buf (CKCHUNKBEGINSTR+" \"")
		)
		

		if not VirtoolsInstructionsManager.instset_Check.checked do (
			VirtoolsInstructionsManager.instructions_List.selection = 0
			if instructionStr!=undefined do (
				local tmp = finditem (VirtoolsInstructionsManager.instructions_List.items) (selection[1].name) 
				VirtoolsInstructionsManager.instructions_List.selection = tmp
			)
		)
	)
	
	VirtoolsInstructionsManager.instructionsApplied_List.items = instructionList
	VirtoolsInstructionsManager.instructionsApplied_List.selection = 0
	VirtoolsInstructionsManager.removeInst_Button.enabled = false
	VirtoolsInstructionsManager.removeAllInst_Button.enabled = false
)


-------------------------------------------------------------------------------
-- Register Instruction Function
-------------------------------------------------------------------------------
fn registerInstruction instName instFct instRollout: instReadFct: = (
	append instNameSet instName
	append instFctSet instFct
	append instRolloutSet instRollout
	
	if VirtoolsInstructionsManager.instset_Check.state do (
		VirtoolsInstructionsManager.instructions_List.items += #(instName)
	)
)




VirtoolsWindow = newrolloutfloater "Virtools Exporter" 428 600 0 1
addrollout VirtoolsExportOpt VirtoolsWindow
addrollout VirtoolsExportProcess VirtoolsWindow
addrollout VirtoolsInstructionsManager VirtoolsWindow

ReadConfig()

VirtoolsInstructionsManager.instructions_List.selection = 0
VirtoolsInstructionsManager.instructionsApplied_List.selection = 0

callbacks.removeScripts #selectionsetchanged id:#VirtoolsUpdateList
callbacks.addScript #selectionsetchanged "updateInstructionsList()" id:#VirtoolsUpdateList
callbacks.broadcastCallback #selectionsetchanged


             
             
-------------------------------------------------------------------------------
-- Register Instructions
-------------------------------------------------------------------------------
files = getFiles (CKInstPath+"CK_*.ms")
for f in files do ( filein f )

⌨️ 快捷键说明

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