Fix for Unofficial UnLookAt function

User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Fix for Unofficial UnLookAt function

Post by clintonman »

I just discovered that the Unlookat does not work for lights. Attached is a fix for the 7.61 Unofficial Update version of truespace.

On a side note I also discovered that when you use lookat with a light it may not work if it is a new light with the default orientation. Rotate it a little bit before lookat and it works.
Attachments
UnLookAt Fix.zip
(8.14 KiB) Downloaded 295 times
Clinton Reese

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

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

Thanks Clinton! I guess nobody has used the LookAt tool on lights since hummmmm...2009?
Would you mind using your script that is created in tS76 so that it is compatible with tS76 too?
Also it is necessary to include the xml file so that when you reset the default context the script is rebuilt.
You can overwrite it in:
C:\trueSpace76\tS\Scripts\ScriptCommands\UnLookAt.xml
Both files created in tS76 included here and are compatible with tS761.

One way a user could install this would be to replace the UnLookAt.xml file in tS76 or tS761 and then reset the default context. No need to replace the UnLookAt.RsObj in System/Scripts/Commands
Attachments
UnLookAt_tS76.zip
(2.97 KiB) Downloaded 287 times
User avatar
Draise
Captain
Posts: 3198
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Fix for Unofficial UnLookAt function

Post by Draise »

I've used it before... wondered why they didn't' work quite as expected!!!
User avatar
clintonman
Captain
Posts: 5422
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 »

I stuck an installer script on my utilities page:
http://www.clintons3d.com/plugins/trues ... index.html" onclick="window.open(this.href);return false;

Installation steps:

unzip the file
load the rsobj script and run it

the script will install and the xml file will copy to the scripts folder
Clinton Reese

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

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

Added Model lights

Code: Select all

function Execute(params)
{
if (Node.ConExists(Node.FirstSelected(), "WldMatrix"))
{
Node.Value(Node.FirstSelected(),"Matrix") = Node.Value(Node.FirstSelected(),"WldMatrix");
Node.ConRemove(Node.Selection(), "Target Matrix");
Node.ConnectTo(Node.Selection() + "/Transform", "WldMatrix", Node.Selection(), "WldMatrix");
Node.ConnectTo(Node.Selection() + "/Transform", "ObjMatrix", Node.Selection(), "ObjMatrix");
Node.Delete(Node.Selection() + "/LookAt2");
Node.Delete(Node.Selection() + "/LookAt2");
Node.Delete(Node.Selection() + "/LookAt2, 1");
Node.Delete(Node.Selection() + "/LookAt2, 2");
Node.Delete(Node.Selection() + "/LookAt2, 3");
Node.Delete(Node.Selection() + "/LookAt2, 4");
if(Node.Exists(Node.FirstSelected() + "/DirlightShader"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/DirlightShader", "Input_position");
else if(Node.Exists(Node.FirstSelected() + "/Infinite Preferences"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Infinite Preferences", "Input_position");
else if(Node.Exists(Node.FirstSelected() + "/Spot Preferences"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Spot Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Projector Preferences"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Projector Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Directional Preferences"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Directional Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Area Preferences"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Area Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/AreaLight"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/AreaLight", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/LocalLight"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/LocalLight", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Omni Preferences"))
	Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Omni Preferences", "In Matrix");
}
}
User avatar
clintonman
Captain
Posts: 5422
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: 12 Aug 2019, 13:52 Added Model lights
...
Nice.
I did some tests and workspace look at doesn't work properly for modelspace lights. They point in the opposite direction.
Attached is an updated installer for your convenience.

The original installer was moved to the obsolete section of my site.
http://www.clintons3d.com/plugins/trues ... index.html

"Unzip and load the script from the file menu and run it from the link editor. If the script is not loaded from the file menu then the change will be lost on the next reset to the default context."
Attachments
UnlookAtInstall.zip
(9.66 KiB) Downloaded 235 times
Clinton Reese

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

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

UnLookAt
Add Command at the start to check for the Target Matrix connector, if it exists, return (Do not run the script)
Add Disconnects before Connecting

Code: Select all

//	UnLookAt Update: 11/22/2021
function Execute(params)
{
if(!Node.ConExists(Node.FirstSelected(), "Target Matrix")) {
System.Alert("Object is not using UnLook At");
params.SetTerminationFlag()
return;
}
Node.Value(Node.FirstSelected(),"Matrix") = Node.Value(Node.FirstSelected(),"WldMatrix");
Node.ConRemove(Node.Selection(), "Target Matrix");

Node.Disconnect(Node.Selection() + "/Transform", "WldMatrix", Node.Selection(), "WldMatrix");
Node.ConnectTo(Node.Selection() + "/Transform", "WldMatrix", Node.Selection(), "WldMatrix");

Node.Disconnect(Node.Selection() + "/Transform", "ObjMatrix", Node.Selection(), "ObjMatrix");
Node.ConnectTo(Node.Selection() + "/Transform", "ObjMatrix", Node.Selection(), "ObjMatrix");

Node.Delete(Node.Selection() + "/LookAt2");
Node.Delete(Node.Selection() + "/LookAt2, 1");
Node.Delete(Node.Selection() + "/LookAt2, 2");
Node.Delete(Node.Selection() + "/LookAt2, 3");
Node.Delete(Node.Selection() + "/LookAt2, 4");
Node.Delete(Node.Selection() + "/LookAt2, 5");
Node.Delete(Node.Selection() + "/LookAt2, 6");
Node.Delete(Node.Selection() + "/LookAt2, 7");
Node.Delete(Node.Selection() + "/LookAt2, 8");
Node.Delete(Node.Selection() + "/LookAt2, 9");
Node.Delete(Node.Selection() + "/LookAt2, 10");

if(Node.Exists(Node.FirstSelected() + "/DirlightShader"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/DirlightShader", "Input_position");
else if(Node.Exists(Node.FirstSelected() + "/DirlightShader"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/DirlightShader", "Input_position");

else if(Node.Exists(Node.FirstSelected() + "/Infinite Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Infinite Preferences", "Input_position");
else if(Node.Exists(Node.FirstSelected() + "/Infinite Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Infinite Preferences", "Input_position");

else if(Node.Exists(Node.FirstSelected() + "/Spot Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Spot Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Spot Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Spot Preferences", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/Projector Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Projector Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Projector Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Projector Preferences", "In Matrix");

//Duplicate???
else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/Directional Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Directional Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Directional Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Directional Preferences", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/Area Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Area Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Area Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Area Preferences", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/AreaLight"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/AreaLight", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/AreaLight"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/AreaLight", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/LocalLight"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/LocalLight", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/LocalLight"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/LocalLight", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/Omni Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Omni Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Omni Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Omni Preferences", "In Matrix");
}
RsApp.ClearHistory()
}
Last edited by trueBlue on 22 Nov 2021, 18:15, edited 1 time in total.
User avatar
clintonman
Captain
Posts: 5422
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: 22 Nov 2021, 18:07 UnLookAt
Add Command at the start to check for the Target Matrix connector, if it exists, return (Do not run the script)
Add Disconnects before Connecting

Code: Select all

//	UnLookAt Update: 11/22/2021
function Execute(params)
{
if(!Node.ConExists(Node.FirstSelected(), "Target Matrix")){System.Alert("Object is not using UnLook At");return;}else{Activity.Run("/Scripts/Commands/UnLookAt");}
if (Node.ConExists(Node.FirstSelected(), "WldMatrix"))
{
Node.Value(Node.FirstSelected(),"Matrix") = Node.Value(Node.FirstSelected(),"WldMatrix");
Node.ConRemove(Node.Selection(), "Target Matrix");

Node.Disconnect(Node.Selection() + "/Transform", "WldMatrix", Node.Selection(), "WldMatrix");
Node.ConnectTo(Node.Selection() + "/Transform", "WldMatrix", Node.Selection(), "WldMatrix");

Node.Disconnect(Node.Selection() + "/Transform", "ObjMatrix", Node.Selection(), "ObjMatrix");
Node.ConnectTo(Node.Selection() + "/Transform", "ObjMatrix", Node.Selection(), "ObjMatrix");

Node.Delete(Node.Selection() + "/LookAt2");
Node.Delete(Node.Selection() + "/LookAt2, 1");
Node.Delete(Node.Selection() + "/LookAt2, 2");
Node.Delete(Node.Selection() + "/LookAt2, 3");
Node.Delete(Node.Selection() + "/LookAt2, 4");
Node.Delete(Node.Selection() + "/LookAt2, 5");
Node.Delete(Node.Selection() + "/LookAt2, 6");
Node.Delete(Node.Selection() + "/LookAt2, 7");
Node.Delete(Node.Selection() + "/LookAt2, 8");
Node.Delete(Node.Selection() + "/LookAt2, 9");
Node.Delete(Node.Selection() + "/LookAt2, 10");

if(Node.Exists(Node.FirstSelected() + "/DirlightShader"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/DirlightShader", "Input_position");
else if(Node.Exists(Node.FirstSelected() + "/DirlightShader"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/DirlightShader", "Input_position");

else if(Node.Exists(Node.FirstSelected() + "/Infinite Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Infinite Preferences", "Input_position");
else if(Node.Exists(Node.FirstSelected() + "/Infinite Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Infinite Preferences", "Input_position");

else if(Node.Exists(Node.FirstSelected() + "/Spot Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Spot Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Spot Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Spot Preferences", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/Projector Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Projector Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Projector Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Projector Preferences", "In Matrix");

//Duplicate???
else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/SpotlightShader"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/SpotlightShader", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/Directional Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Directional Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Directional Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Directional Preferences", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/Area Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Area Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Area Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Area Preferences", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/AreaLight"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/AreaLight", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/AreaLight"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/AreaLight", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/LocalLight"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/LocalLight", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/LocalLight"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/LocalLight", "In Matrix");

else if(Node.Exists(Node.FirstSelected() + "/Omni Preferences"))
Node.Disconnect(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Omni Preferences", "In Matrix");
else if(Node.Exists(Node.FirstSelected() + "/Omni Preferences"))
Node.ConnectTo(Node.FirstSelected() + "/Transform", "WldMatrix", Node.FirstSelected() + "/Omni Preferences", "In Matrix");
}
RsApp.ClearHistory()
}
The UU version already checks for the target matrix and it uses RsApp.RunScriptBuffer and it doesn't clear history. Are you modifying an old version of the script?
Clinton Reese

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

Re: Fix for Unofficial UnLookAt function

Post by trueBlue »

Actually, I was working in tS7.6 when I modified the script
You are correct, in the UUv8, it does check for the Target Matrix, but the Disconnects do not exist
I'll check and see if RsApp.RunScriptBuffer runs in tS7.6
Edit: Yep, looks like it is available.
But they are hard to write! :(
User avatar
trueBlue
Captain
Posts: 5208
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: 12 Aug 2019, 16:22
trueBlue wrote: 12 Aug 2019, 13:52 Added Model lights
...
I did some tests and workspace look at doesn't work properly for modelspace lights. They point in the opposite direction.
Wow! This slipped by me and just confirmed this
As an example, using an InfLight from Model and Workspace
Looks like the differences is the Roll values being completely opposite (-180)
If you Normalize the Rotation, Workspace's Look At works correctly with the Model's InfLight

I wonder if Workspace's Look At could be modified for Model Lights using something similar to:
Space.NodeMatrixElement('%THIS_NAME%','roll') = 180;
Post Reply