Select Node within current node - how?

Smart people ~ Great Scripts
User avatar
Draise
Captain
Posts: 2811
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Select Node within current node - how?

Post by Draise » 23 Jun 2014, 23:22

I know how to select properties and nodes within the space.CurrentScene(), but I'd preferibly select a dynamic property within a series of different nodes, which would depend on the parent node.

Logic: Select current node. Select sub node within current node. Apply disconnection to X property on X node with Y property of Y node.

The following code does what I want it to do, but I need an absolute path to the property relative to the current node, or root node - a dynamic script.

Code: Select all

Node.Disconnect(Space.CurrentScene() + "[NODE]/[SUB-NODE]", "[PROPERTY]", Space.CurrentScene() + [NODE]/[SUB-NODE]", "[PROPERTY]")

Any pointers? What other selection values do we have? Where can I find out? How?

User avatar
Draise
Captain
Posts: 2811
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Select Node within current node - how?

Post by Draise » 23 Jun 2014, 23:41

Code: Select all

Node.FirstSelected() 
could be the solution? I have no idea how it would work..

User avatar
Draise
Captain
Posts: 2811
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Select Node within current node - how?

Post by Draise » 24 Jun 2014, 00:24

Maybe this one? Man, I have no idea how to code scrips in TS, wish i was someone like Clinton or Trueblue.

Code: Select all

System.ThisOwner()

User avatar
Draise
Captain
Posts: 2811
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Select Node within current node - how?

Post by Draise » 24 Jun 2014, 02:45

I’m still having troubles. I am pretty much a newb to this.

Here is an example script I am using to try get it to work. The idea is to have a script inside the D3D material, then run it selecting the appropriate node connectors, connecting and disconnecting when I tell it to - creating a shader switch within the shader node - that could be applied to many objects dynamically.

Code: Select all

first = Space.Select("SolidColorShader")
second = Space.Select("Material")
OR

Code: Select all

first = Node.Select("SolidColorShader")
second = Node.Select("Material")
In order to:

Code: Select all

Node.ConnectTo(first, 'Color_shader', second, 'Color_shader');  
But it’s not working..


How do I dynamically work nested nodes? The name of the object will change, but the controls for the shader switches will remain. I want to toggle materials on an object with such material, any object, with such applied material including the switch.

Example (script placed in object):

Code: Select all

[item] = Space.CurrentScene() + "[Node.Self]/Materials/Material/D3D material/[nested node]"
- then the rest of the script

Or better yet (script placed within parent node - “D3D material”)

Code: Select all

[item] = [Node.Self] + "[nested node]" 

I am very new to this, sorry for all the questions and the bothers.. but I appreciate the help.

User avatar
Draise
Captain
Posts: 2811
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Select Node within current node - how?

Post by Draise » 24 Jun 2014, 03:49

Stan kindly has been sharing some hints, but I'm too new to figure it out..

Code: Select all

var owner = Space.CurrentScene();
var target = owner + '/[object]/[sub-node];
Space.Select(target);

So the idea is that I can get the root of the scene with Space.CurrentScene()

Then I define it with the subobject - which in his code is fixed or absolute. I need to somehow make this dynamic.... which I am not sure is possible.

Then I can use the Space.Select(target) in my little Node.ConnectTo() scripts.

But how do you get say a dynamic "OwnerName" from a node into a script equation?

Do I have to define the absolute path always?

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

Re: Select Node within current node - how?

Post by clintonman » 24 Jun 2014, 15:09

Node.Owner will get the parent of a node you specify.
System.ThisOwner will get the parent of the script node.
Node.FirstSelected gives you the first node of several selected nodes or just the one node if it is the only selected node.
To work with a selection of nodes you use Node.Selection then Node.Selected with an index to loop through the selection.
You do need a full path to get to a node.
Clinton Reese

http://clintons3d.com

User avatar
Draise
Captain
Posts: 2811
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Select Node within current node - how?

Post by Draise » 24 Jun 2014, 15:57

Tanks Clinton, that is helping. Stan also gave me more hints, specially with some example from Yafaray, but I'm still struggling with a "recursive" node selection.

Here is my sample script, I think it would work if only I could select all sub objects in the scene root, or nodes, then recursively search for the right material nodes within the objects to assign the "switch" within the shader of all objects (or of that specific shader assigned to all objects).

Code: Select all

SceneRoot = Space.CurrentScene();

Item = Node.Select(Node.SubObject(SceneRoot)) - ERROR

ShaderRoot = RecurseNode(Item + "/Materials/Material/D3D material");

inputshader = RecurseNode(ShaderRoot + "/SolidColorShader");

Out = RecurseNode(ShaderRoot + "/Material");


Node.Disconnect(inputshader, 'Color_shader', Out, 'Color_shader');  

User avatar
Draise
Captain
Posts: 2811
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Select Node within current node - how?

Post by Draise » 24 Jun 2014, 16:21

Will I need to use an "If" algorithm of a sort? Man, programming and scripting is beyond me... =/


I found that a Node.ConExists - seems dynamic, but no idea how it works as I still need to define the "CurrentNode".


What and how does the Node.ConExit work?

What and how does the Node.SubObject([item]) work?

What and how does the RecurseNode() work?



Here are some attempts and clues.. not sure if they will help...

Code: Select all

     

//how do I define all subobjects in the SceneRoot as the CurrentNode?
     
     if (Node.ConExists(CurrentNode, 'Material'))
     {
         //Something here? 
     }

Another conditional I found was the following:

Code: Select all

    var i=0;
    while (i<Node.SubObjectCount(SceneRoot))
    {  
        if (RecurseNode(SceneRoot + '/' + Node.SubObject(SceneRoot, i)))
        {
//Something here? 
        }
        i = i + 1;

    }
But I don't know how to use it, if it is correct, say, with more than one node in the SceneRoot - then something is supposed to happen. Will this be another script? My new definitions to create the tags I need to connect and disconnect my links in all of the correctly assigned shaders?

Thanks for all the help. Creating a Pass system Shaderwise is kinda working. Here are some images to help give you an idea of why I'm doing it.

Depth Pass, Normal Pass, AO pass (all realtime)
Image
Image
Image

User avatar
Draise
Captain
Posts: 2811
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Select Node within current node - how?

Post by Draise » 24 Jun 2014, 16:40

Also.. we are programming in Jscript right? or is it Java Script? (So I can study up on it?)

stan
Master Chief Petty Officer
Posts: 430
Joined: 21 May 2009, 17:20

Re: Select Node within current node - how?

Post by stan » 24 Jun 2014, 19:24

jscript
you can download it here
http://www.microsoft.com/en-ca/download ... px?id=2764" onclick="window.open(this.href);return false;

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest