Fix for Unofficial UnLookAt function

User avatar
trueBlue
Captain
Posts: 5215
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

This looks promising:

Code: Select all

	if(Node.SubObjectCount('/D3DView')==0) return;

	var sel = Node.Selection();if(!sel){return;};
	var selCount = Node.SelectedCount();

	if(selCount > 1) {
		System.Alert("Select one object at a time")
		return
	}

	if(Node.ConExists(Node.FirstSelected(), "Target Matrix"))
	{
		System.Alert("Object is being used to Look At another object\n\nUse the Unlook At tool first");
	return;
	}else{
	RsTool.NormalizeRotation('');
	ToolMng.ActivateTool('{17D544A3-3F58-436B-83E7-F8B4D7D4E7C5}','{4E203C6C-A20D-4e32-82B4-FC482F5A0D06}');
	}
User avatar
clintonman
Captain
Posts: 5430
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Fix for Unofficial UnLookAt function

Post by clintonman »

trueBlue wrote: 23 Aug 2022, 15:17 This looks promising:

Code: Select all

	if(Node.SubObjectCount('/D3DView')==0) return;

	var sel = Node.Selection();if(!sel){return;};
	var selCount = Node.SelectedCount();

	if(selCount > 1) {
		System.Alert("Select one object at a time")
		return
	}

	if(Node.ConExists(Node.FirstSelected(), "Target Matrix"))
	{
		System.Alert("Object is being used to Look At another object\n\nUse the Unlook At tool first");
	return;
	}else{
	RsTool.NormalizeRotation('');
	ToolMng.ActivateTool('{17D544A3-3F58-436B-83E7-F8B4D7D4E7C5}','{4E203C6C-A20D-4e32-82B4-FC482F5A0D06}');
	}
Looks good to me. You don't need the else when using a return

Code: Select all

	if(Node.SubObjectCount('/D3DView')==0) return;

	var sel = Node.Selection();if(!sel){return;};
	var selCount = Node.SelectedCount();

	if(selCount > 1) {
		System.Alert("Select one object at a time")
		return
	}

	if(Node.ConExists(Node.FirstSelected(), "Target Matrix"))
	{
		System.Alert("Object is being used to Look At another object\n\nUse the Unlook At tool first");
		return;
	}
	RsTool.NormalizeRotation('');
	ToolMng.ActivateTool('{17D544A3-3F58-436B-83E7-F8B4D7D4E7C5}','{4E203C6C-A20D-4e32-82B4-FC482F5A0D06}');
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5215
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

It looks like RsTool.NormalizeRotation(''); is only needed for Lights
How would you write that?
User avatar
clintonman
Captain
Posts: 5430
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Fix for Unofficial UnLookAt function

Post by clintonman »

trueBlue wrote: 23 Aug 2022, 15:54 It looks like RsTool.NormalizeRotation(''); is only needed for Lights
How would you write that?
It doesn't matter since the rotations are taken over by the lookat anyway.
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5215
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

clintonman wrote: 23 Aug 2022, 16:14
trueBlue wrote: 23 Aug 2022, 15:54 It looks like RsTool.NormalizeRotation(''); is only needed for Lights
How would you write that?
It doesn't matter since the rotations are taken over by the lookat anyway.
Yeah, but it is kind of funky normalizing the rotation on everything before the Look At command is ran and it is only for Model Lights
I would go even further, isolating the Workspace Lights by looking for the "Intensity" connector

Code: Select all

	if(Node.SubObjectCount('/D3DView')==0) return;

	var sel = Node.Selection();
	var selCount = Node.SelectedCount();
	var fsel = Node.FirstSelected();

	if(!sel){return;}
	if(selCount > 1) {	System.Alert('Select one object at a time');return;}
	if(Node.ConExists(fsel, 'Target Matrix'))	{	System.Alert('Object is being used to Look At another object\n\nUse the Unlook At tool first');return;}
	if(Node.IsLight(fsel) && !Node.ConExists(fsel, 'Intensity')) {	RsTool.NormalizeRotation(fsel);}

	ToolMng.ActivateTool('{17D544A3-3F58-436B-83E7-F8B4D7D4E7C5}','{4E203C6C-A20D-4e32-82B4-FC482F5A0D06}');
User avatar
clintonman
Captain
Posts: 5430
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Fix for Unofficial UnLookAt function

Post by clintonman »

trueBlue wrote: 23 Aug 2022, 16:31
clintonman wrote: 23 Aug 2022, 16:14
trueBlue wrote: 23 Aug 2022, 15:54 It looks like RsTool.NormalizeRotation(''); is only needed for Lights
How would you write that?
It doesn't matter since the rotations are taken over by the lookat anyway.
Yeah, but it is kind of funky normalizing the rotation on everything before the Look At command is ran and it is only for Model Lights
I would go even further, isolating the Workspace Lights by looking for the "Intensity" connector

Code: Select all

	if(Node.SubObjectCount('/D3DView')==0) return;

	var sel = Node.Selection();
	var selCount = Node.SelectedCount();
	var fsel = Node.FirstSelected();

	if(!sel){return;}
	if(selCount > 1) {	System.Alert('Select one object at a time');return;}
	if(Node.ConExists(fsel, 'Target Matrix'))	{	System.Alert('Object is being used to Look At another object\n\nUse the Unlook At tool first');return;}
	if(Node.IsLight(fsel) && !Node.ConExists(fsel, 'Intensity')) {	RsTool.NormalizeRotation(fsel);}

	ToolMng.ActivateTool('{17D544A3-3F58-436B-83E7-F8B4D7D4E7C5}','{4E203C6C-A20D-4e32-82B4-FC482F5A0D06}');
I tried a model infinite light and it didn't have the problem, so you'll want to check the model light types to see which ones need the normalize rotation.
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5215
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

What?
For me the Model Infinite light points in the opposite direction using Workspace's original Look At command
Model Infinte light used in Workspace's original Look At command.png
.
Have not tested any other Model lights yet
User avatar
clintonman
Captain
Posts: 5430
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Fix for Unofficial UnLookAt function

Post by clintonman »

trueBlue wrote: 23 Aug 2022, 17:11 What?
For me the Model Infinite light points in the opposite direction using Workspace's original Look At command
Model Infinte light used in Workspace's original Look At command.png
.
Have not tested any other Model lights yet
I'll double check, maybe I accidentally did a workspace light.

Yep, checks out.
new scene in model
lookat for infinite light is correct
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5215
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

clintonman wrote: 23 Aug 2022, 17:44
trueBlue wrote: 23 Aug 2022, 17:11 What?
For me the Model Infinite light points in the opposite direction using Workspace's original Look At command
Model Infinte light used in Workspace's original Look At command.png
.
Have not tested any other Model lights yet
I'll double check, maybe I accidentally did a workspace light.

Yep, checks out.
new scene in model
lookat for infinite light is correct
Confirm you are correct in your example
Try adding a Model infinite light, switch to Workspace and run Look At
Model infinite light is in opposite direction
Then try Un Look At
Model infinite light is not restored correctly
User avatar
trueBlue
Captain
Posts: 5215
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

What is your util command equivalent to:
Node.Value(fsel,"Matrix") = Node.Value(fsel,"WldMatrix");
Post Reply