PDA

View Full Version : Freeze Rotation, Rotation to Zero for TCB controller


ulukai33
02-01-2005, 07:07 PM
Hi,

I would never think I will do something with maxscript. My only experience with programming is a few simple "things" in pascal when I was on high school years ago (good old days :twisted: ).
But now, I needed to use freeze/restore rotation (in animation quad). I have found out that this works only with Eulers (if you have tcb, it will setup eulers). So I thought I will edit the script to work with TCB. What a heroic thing from me :) .
I have cut out everything except freeze and restore rotation (there is position and transformation too). Than I have edited the script. It almost works (freezes the rotation), but when I try to use TCB Rotation To Zero it says that rotation was never frozen.

Here is the script:

*/
-- Freeze TCB Rotation Only
macroScript FreezeTCBRotation
enabledIn:#("max", "viz") --pfb: 2003.12.12 added product switch
ButtonText:"Freeze TCB Rotation"
Category:"Animation Tools"
internalCategory:"Animation Tools"
Tooltip:"Freeze TCB Rotation"
(
fn FreezeTCBRotation =
(
local Obj = Selection as array
for i = 1 to Obj.count do
(
Try
(
local CurObj = Obj[i]
CurObj.rotation.controller = TCB_rotation()
CurObj.rotation.controller = Rotation_list()

/* "Localization on" */

CurObj.rotation.controller.setname 1 "Inital Rotation"
CurObj.rotation.controller.available.controller = TCB_rotation()
CurObj.rotation.controller.setname 1 "Inital Rotation"
CurObj.rotation.controller.setname 2 "Keyframe TCB"
CurObj.rotation.controller.SetActive 2

/* "Localization off" */
)

/* "Localization on" */

Catch( messagebox "A failure occurred while freezing an object's rotation." title:"FreezeTCBRotation")

/* "Localization off" */
)
select Obj
)

FreezeTCBRotation()
)


--Set TCB Rotation to Zero
MacroScript TCBRotationToZero
enabledIn:#("max", "viz") --pfb: 2003.12.12 added product switch
ButtonText:"TCB Rotation To Zero"
Category:"Animation Tools"
internalCategory:"Animation Tools"
Tooltip:"TCB Rotation To Zero"
(
fn TCBRotationToZero =
(
local Obj = Selection as array
for i = 1 to Obj.count do
(
Try
(
local CurObj = Obj[i]
CurObj.rotation.controller[2].x_rotation = 0
CurObj.rotation.controller[2].y_rotation = 0
CurObj.rotation.controller[2].z_rotation = 0
CurObj.rotation.controller[2].angle = 0
)

/* "Localization on" */

Catch( messagebox "One of the object's rotation was never frozen." title:"Freeze Transform")

/* "Localization off" */
)
select Obj
)

TCBRotationToZero()
)


I have simply replaced every sign of Euler_xyz with TCB_rotation.
I think problem is here:


Try
(
local CurObj = Obj[i]
CurObj.rotation.controller[2].x_rotation = 0
CurObj.rotation.controller[2].y_rotation = 0
CurObj.rotation.controller[2].z_rotation = 0
CurObj.rotation.controller[2].angle = 0
)

/* "Localization on" */

Catch( messagebox "One of the object's rotation was never frozen." title:"Freeze Transform")

I don't know how exactly re-set the values of TCB to zero, I have added CurObj.rotation.controller[2].angle = 0 line, but I think that's what is not working.

Could someone help please :sad: ???

marktsang
02-01-2005, 07:27 PM
hi,
tcb controllers dont have separate tracks for each axis so try this instead

Try
(
local CurObj = Obj[i]
CurObj.rotation.controller.value = (quat 0 0 0 1)
)

mark tsang

ulukai33
02-01-2005, 07:35 PM
I think that's it, thanks. :applause:

-EDIT-

I still get the error message (rotation was never frozen) :cry:

-EDIT-

SORRY, IT WORKS. Problem was that after freezing TCB I was using Rotation to Zero and Not TCB to Zero. :banghead:
But I think that "CurObj.rotation.controller.value = (quat 0 0 0 1)" was important, I think it wouldn't work without that.

ulukai33
02-01-2005, 08:12 PM
Well, I have made some beta testing and it doesn't work as it should.

If I use Freeze TCB rotation, new controler is created, but when I use TCB Rotation to Zero, objects rotation is restored to zero rotation and not the frozen one.

Any ideas?

marktsang
02-01-2005, 09:17 PM
are you by any chance zeroing the wrong controller? you should be zeroing the one in slot 2

mark

ulukai33
02-01-2005, 09:30 PM
I'm doing it this way:
1.) I have put Freeze TCB Rotation and TCB Rotation To Zero to animation quad menu
2.) than I select a object, rotate it a bit (to take it out of default rotation)
3.) than - quad menu/freeze tcb rotation
4.) than I rotate the object to completely different orientation
5.) and finaly - quad/tcb rotation to zero

and the problem is that object rotation is not restored to frozen one, but to the default 0,0,0 (as it was when the object was created)

You think that the script is OKi?

marktsang
02-01-2005, 10:33 PM
show me the entire script and i will see if i spot anything wrong

mark

ulukai33
02-01-2005, 11:35 PM
Complete script:


/*
Freeze Transform MacroScript File



Author : Frederick Ruff

Revision History:

Dec 1 2000, created

Aug 22 2003, Larry Minton

12 dec 2003, Pierre-Felix Breton,
added product switcher: this macroscript file can be shared with all Discreet products
Feb 1 2005, Ulukai, changed to freeze/restore TCB rotation



This script adds tools for freezing a transform
This is done via adding a second controller to the controllers stack.
--***********************************************************************************************
-- MODIFY THIS AT YOUR OWN RISK
*/
-- Freeze TCB Rotation Only
macroScript FreezeTCBRotation
enabledIn:#("max", "viz") --pfb: 2003.12.12 added product switch
ButtonText:"Freeze TCB Rotation"
Category:"Animation Tools"
internalCategory:"Animation Tools"
Tooltip:"Freeze TCB Rotation"
(
fn FreezeTCBRotation =
(
local Obj = Selection as array
for i = 1 to Obj.count do
(
Try
(
local CurObj = Obj[i]
CurObj.rotation.controller = TCB_rotation()
CurObj.rotation.controller = Rotation_list()

/* "Localization on" */

CurObj.rotation.controller.setname 1 "Inital Rotation"
CurObj.rotation.controller.available.controller = TCB_rotation()
CurObj.rotation.controller.setname 1 "Inital Rotation"
CurObj.rotation.controller.setname 2 "Keyframe TCB"
CurObj.rotation.controller.SetActive 2

/* "Localization off" */
)

/* "Localization on" */

Catch( messagebox "A failure occurred while freezing an object's rotation." title:"FreezeTCBRotation")

/* "Localization off" */
)
select Obj
)

FreezeTCBRotation()
)


--Set TCB Rotation to Zero
MacroScript TCBRotationToZero
enabledIn:#("max", "viz") --pfb: 2003.12.12 added product switch
ButtonText:"TCB Rotation To Zero"
Category:"Animation Tools"
internalCategory:"Animation Tools"
Tooltip:"TCB Rotation To Zero"
(
fn TCBRotationToZero =
(
local Obj = Selection as array
for i = 1 to Obj.count do
(
Try
(
local CurObj = Obj[i]
CurObj.rotation.controller.value = (quat 0 0 0 1)
)

/* "Localization on" */

Catch( messagebox "One of the object's rotation was never frozen." title:"Freeze Transform")

/* "Localization off" */
)
select Obj
)

TCBRotationToZero()
)


I don't know if formating can do something "bad" to the script, so here is a link to file:

http://test333.szm.sk/Macro_FreezeTCBRotation.zip

And thanks for the help!
Great site with great people here.

marktsang
02-02-2005, 12:14 AM
as i susected you were zeroing the wrong controller - which is partial my fault as when i answered earlier i didn't specify that you need to indicate which controller.- any way

fn TCBRotationToZero =
(
local Obj = Selection as array
for i = 1 to Obj.count do
(
Try
(
local CurObj = Obj[i]
CurObj.rotation.controller[2].value = (quat 0 0 0 1)
)

/* "Localization on" */

Catch( messagebox "One of the object's rotation was never frozen." title:"Freeze Transform")

/* "Localization off" */
)
select Obj
)

TCBRotationToZero()


mark

ulukai33
02-02-2005, 09:00 AM
Oh..., you thought by "if I'm zeroing wrong controller" if I'm zeroing wrong controller in script? I thought If I'm not using the script somehow wrong.... But I really never did anything in maxscript or any other programming language, so I apologize for my amateurism :) .

It works perfectly now!
Really, really BIG THANK YOU !!!

There is a one disadvantage with internet, I really don't like that I can't buy you a beer (or whatever you are drinking) on times like these :beer: .

SO ONCE AGAIN - THANKS :wavey:

CGTalk Moderation
02-02-2006, 10:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.