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

📄 ck_translateonclick.ms

📁 3dmax导出3d模型二次开发插件
💻 MS
字号:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Register TranslateOnClick Instruction
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
global instTranslateOnClickStr = "Translate On Click"
global instTranslateOnClickRollout
global instTranslateOnClickFct

--------------------------------------------------------
-- Rollout Fonction
--------------------------------------------------------
rollout instTranslateOnClickRollout "Translate On Click Options" width:408 height:114
(
	label info_Label "Info: Translates an object when you click on it" pos:[8,8] width:232 height:16
	radiobuttons direction_Radio "" pos:[56,48] width:97 height:16 labels:#("X", "Y", "Z") default:2
	spinner speed_Spin "" pos:[96,72] width:50 height:16 range:[-1000,1000,2] type:#float scale:0.1
	checkbutton smoothstart_CheckButton "Smooth Start" pos:[216,72] width:80 height:20
	checkbutton smoothend_CheckButton "Smooth End" pos:[296,72] width:80 height:20 checked:false
	spinner amplitude_Spin "" pos:[290,48] width:50 height:16 range:[-1000,1000,2] type:#float scale:0.1
	GroupBox limited_Group "    " pos:[206,28] width:180 height:72
	checkbox limited_Check "Limited" pos:[220,24] width:56 height:16 checked:true
	label speed_Label "Speed (m/sec): " pos:[8,72] width:88 height:16
	label amplitude_Label "Amplitude (m):" pos:[218,48] width:74 height:16
	label direction_Label "Direction: " pos:[8,48] width:50 height:16

	include "CKInstScripts\\ApplyPreviewButtons.ms"
	
	on limited_Check changed arg do (
		amplitude_Spin.enabled = amplitude_Label.enabled = smoothstart_CheckButton.enabled = smoothend_CheckButton.enabled = arg
	)
	
	on instTranslateOnClickRollout open do (
		direction_Radio.state = 2
	)

	--------------------------------------------------------
	-- Update Rollout From Chunk
	--------------------------------------------------------
	fn UpdateFromChunk = (
		currentChunkBuf = GetCKChunk selection[1] instTranslateOnClickStr
		
		local transDir = ReadCKBufValueAsVector "OC-Translate Direction"
    if (transDir==undefined) then (
			transDir = ReadCKBufValueAsVector "Translation Speed"
 			limited_Check.checked = false
    ) else (
 			limited_Check.checked = true
    )

		-- Axis
		if (transDir.x!=0.0) then (direction_Radio.state=1)
		else if (transDir.y!=0.0) then (direction_Radio.state=3)
		else (direction_Radio.state=2)

    
 		amplitude_Spin.enabled = amplitude_Label.enabled = smoothstart_CheckButton.enabled = smoothend_CheckButton.enabled  = limited_Check.checked

		------------------------------------------
		-- Limited Translation
		if (limited_Check.checked) then (
			
			-- Amplitude
			amplitude_Spin.value = ReadCKBufValueAsNumber "OC-Translate Distance"
			
			-- Speed
			local duration = ReadCKBufValueAsTime "OC-Translate Duration"
			speed_Spin.value = abs(amplitude_Spin.value/duration)
			
			-- Smoothness
			local smoothness = ReadCKBufValueAsNumber "OC-Translate Smooth Mode"
			smoothstart_CheckButton.checked = (smoothness==1 or smoothness==3)
			smoothend_CheckButton.checked = (smoothness==2 or smoothness==3)

		------------------------------------------
		-- Unlimited Translation
		) else (

			-- Speed
			local speedVector = ReadCKBufValueAsVector "Translation Speed"
			speed_Spin.value = case direction_Radio.state of (
				1:(speedVector.x)
				2:(speedVector.z)
				3:(speedVector.y)
			) 
			
		)
	)
	
)


--------------------------------------------------------
-- Apply Instruction
--------------------------------------------------------
fn instTranslateOnClickFct = (
	------------------------------------------
	-- Limited Translation
	transDir = case instTranslateOnClickRollout.direction_Radio.state of (
		1:[1,0,0]
		2:[0,1,0]
		3:[0,0,1]
	)
	
	if( instTranslateOnClickRollout.limited_Check.checked ) then (
		
		-- Attach Script 
		chunkData = "  " + CKAttacheScriptOnThisStr + "(\"OC-Translate On Click\")"
		chunkdata += "\x0d\x0a"

		-- Direction 
		chunkData += "  " + CKSetParamOnThisStr + "(\"OC-Translate Direction\", \"" + (posAsVirtools transDir) + "\" )"
		chunkdata += "\x0d\x0a"

		-- Amplitude
		amplitude = instTranslateOnClickRollout.amplitude_Spin.value
		chunkData += "  " + CKSetParamOnThisStr + "(\"OC-Translate Distance\", \"" + (amplitude as string) + "\" )"
		chunkdata += "\x0d\x0a"

		-- Speed
		duration = abs( amplitude / instTranslateOnClickRollout.speed_Spin.value )
		chunkData += "  " + CKSetParamOnThisStr + "(\"OC-Translate Duration\", \"0m " + (duration as string) + "s 0ms\" )"
		chunkdata += "\x0d\x0a"

		-- Smoothness
		smoothness = (if instTranslateOnClickRollout.smoothstart_CheckButton.checked then 1 else 0) + (if instTranslateOnClickRollout.smoothend_CheckButton.checked then 2 else 0)
		chunkData += "  " + CKSetParamOnThisStr + "(\"OC-Translate Smooth Mode\", \"" + (smoothness as string) + "\" )"
		chunkdata += "\x0d\x0a"

		
	------------------------------------------
	-- Unlimited Translation
	) else (

		-- Attach Script 
		chunkData = "  " + CKAttacheScriptOnThisStr + "(\"Translate On Click\")"
		chunkdata += "\x0d\x0a"
		
		-- Translation Speed
		transSpeed = transDir*instTranslateOnClickRollout.speed_Spin.value
		chunkData += "  " + CKSetParamOnThisStr + "(\"Translation Speed\", \"" + (posAsVirtools transSpeed) + "\" )"
		chunkdata += "\x0d\x0a"

	)

	-- Mouse Hand Rollover
	chunkData += "  " + CKAttacheScriptOnThisStr + "(\"Mouse Hand Rollover\")"
	chunkdata += "\x0d\x0a"
		
	for obj in selection do (

		-- Object Initial Local Matrix
		chunkData2 = "  " + CKSetParamOnThisStr + "(\"Object Initial Local Matrix\", \"" + (matrixInParentAsVirtools obj) + "\" )"
		chunkdata2 += "\x0d\x0a"

		AddCKChunk obj instTranslateOnClickStr (chunkData+chunkData2)
		updateInstructionsList()
	)
	
	-- Virtools Global Helper Stuff
	-- Make 2d Picking Only Once
	chunkData = "  " + CKAttacheScriptOnThisStr + "(\"2dPick to RollOver\")"
	chunkdata += "\x0d\x0a"
	AddCKChunk $VirtoolsGlobalHelper "2dPick to RollOver" chunkData
)

registerInstruction instTranslateOnClickStr instTranslateOnClickFct instRollout:instTranslateOnClickRollout


⌨️ 快捷键说明

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