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

📄 ck_rotateonclick.ms

📁 3dmax导出3d模型二次开发插件
💻 MS
字号:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Register RotateOnClick Instruction
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
global instRotateOnClickStr = "Rotate On Click"
global instRotateOnClickRollout
global instRotateOnClickFct

--------------------------------------------------------
-- Rollout Fonction
--------------------------------------------------------
rollout instRotateOnClickRollout "Rotate On Click Options" width:408 height:114
(
	label info_Label "Info: Rotates an object when you click on it" pos:[8,8] width:232 height:16
	radiobuttons axis_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,120] 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:true
	spinner angle_Spin "" pos:[280,48] width:50 height:16 range:[-1000,1000,45] 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 (deg/sec): " pos:[8,72] width:88 height:16
	label angle_Label "Angle (deg):" pos:[218,48] width:64 height:16
	label axis_Label "Axis: " pos:[8,48] width:32 height:16

	include "CKInstScripts\\ApplyPreviewButtons.ms"
	
	on limited_Check changed arg do (
		angle_Spin.enabled = angle_Label.enabled = smoothstart_CheckButton.enabled = smoothend_CheckButton.enabled = arg
	)
	
	on instRotateOnClickRollout open do (
		axis_Radio.state = 2
	)
	
	--------------------------------------------------------
	-- Update Rollout From Chunk
	--------------------------------------------------------
	fn UpdateFromChunk = (
		currentChunkBuf = GetCKChunk selection[1] instRotateOnClickStr
		
		local rotAxis = ReadCKBufValue "Open-Close Axis Of Rotation"
    if (rotAxis==undefined) then (
			rotAxis = ReadCKBufValue "Rotate Axis Of Rotation"
 			limited_Check.checked = false
    ) else (
 			limited_Check.checked = true
    )

		-- Axis
		axis_Radio.state = case rotAxis of (
			"1,0,0":1
			"0,1,0":2
			"0,0,1":3
		)
    
 		angle_Spin.enabled = angle_Label.enabled = smoothstart_CheckButton.enabled = smoothend_CheckButton.enabled = limited_Check.checked

		------------------------------------------
		-- Limited Rotation
		if (limited_Check.checked) then (
			
			-- Angle
			angle_Spin.value = ReadCKBufValueAsAngle "Open-Close Angle Of Rotation"
			
			-- Speed
			local duration = ReadCKBufValueAsTime "Open-Close Duration"
			speed_Spin.value = abs(angle_Spin.value/duration)
			
			-- Smoothness
			local smoothness = ReadCKBufValueAsNumber "Open-Close Smooth Mode"
			smoothstart_CheckButton.checked = (smoothness==1 or smoothness==3)
			smoothend_CheckButton.checked = (smoothness==2 or smoothness==3)

		------------------------------------------
		-- Unlimited Rotation
		) else (

			-- Speed
			speed_Spin.value = ReadCKBufValueAsAngle "Rotate Speed"
		)
	) 
	
)


--------------------------------------------------------
-- Apply Instruction
--------------------------------------------------------
fn instRotateOnClickFct = (
	------------------------------------------
	-- Limited Rotation
	rotAxis = case instRotateOnClickRollout.axis_Radio.state of (
		1:"1,0,0"
		2:"0,1,0"
		3:"0,0,1"
	)
	
	if( instRotateOnClickRollout.limited_Check.checked ) then (
		
		-- Attach Script 
		chunkData = "  " + CKAttacheScriptOnThisStr + "(\"Open-Close On Click\")"
		chunkdata += "\x0d\x0a"

		-- Axis 
		chunkData += "  " + CKSetParamOnThisStr + "(\"Open-Close Axis Of Rotation\", \"" + rotAxis + "\" )"
		chunkdata += "\x0d\x0a"

		-- Angle
		angle = instRotateOnClickRollout.angle_Spin.value
		chunkData += "  " + CKSetParamOnThisStr + "(\"Open-Close Angle Of Rotation\", \"0:" + (angle as string) + "\" )"
		chunkdata += "\x0d\x0a"

		-- Speed
		duration = abs( angle / instRotateOnClickRollout.speed_Spin.value )
		chunkData += "  " + CKSetParamOnThisStr + "(\"Open-Close Duration\", \"0m " + (duration as string) + "s 0ms\" )"
		chunkdata += "\x0d\x0a"

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

		
	------------------------------------------
	-- Unlimited Rotation
	) else (

		-- Attach Script 
		chunkData = "  " + CKAttacheScriptOnThisStr + "(\"Rotate On Click\")"
		chunkdata += "\x0d\x0a"
		
		-- Axis 
		chunkData += "  " + CKSetParamOnThisStr + "(\"Rotate Axis Of Rotation\", \"" + rotAxis + "\" )"
		chunkdata += "\x0d\x0a"

		-- Speed
		chunkData += "  " + CKSetParamOnThisStr + "(\"Rotate Speed\", \"0:" + (instRotateOnClickRollout.speed_Spin.value as string) + "\" )"
		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 instRotateOnClickStr (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 instRotateOnClickStr instRotateOnClickFct instRollout:instRotateOnClickRollout


⌨️ 快捷键说明

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