Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Forums: Cannot travel beyond NT_GEO_PLACEMENT Node from C#
A public forum for discussing and asking questions about the Octane for Unity Alpha

Moderator: ChrisHekman

Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Postby jpetty7317 » Wed Sep 25, 2019 6:44 pm

jpetty7317 Wed Sep 25, 2019 6:44 pm
I know I have made a few posts here recently and have certainly appreciated the help.

But I come with what might be a bug? I unfortunately realized there is 1) no straight forward way of executing the Lua script I've been working on from Unity C#, and 2) there doesn't appear to be a good way for me to be able to get the information I need (given my constraints) to the octane nodes. So I am attempting to replicate the general functionality of my Lua script by using the Unity C# API. I've hit a major snag though.

Below I have my Lua script, my C# code snippet and a screenshot of the Node graph. In my script I start at the RenderTarget node and make my way to a geoGroup in the scene (our container for ALL geometry in the scene). From there I loop through all of the inputNodes for the geoGroup and attempt to grab the Object Layer Node supposedly attached to the inputNode's P_GEOMETRY pin. But I can't.

I've been using the Node.Select() method to make sure I'm getting where I need, as well as debugging Node.Type, and Node.Name to double-triple check. But nothing. My Select() always stops at the inputNode. Even if I call Select on the node that is the supposed result of inputNode.GetConnectedNode(<pin>). I have also tried both overloads of the GetConnectedNode() call, supplying both "geometry" and PinId.P_GEOMETRY. Nothing. I was hoping you might be able to provide some insight into why this is, and if there is any alternative method for getting to those material map nodes from C#.

This is all made doubly confusing by the fact that I have to go through a similarly typed NT_GEO_PLACEMENT node to even get to the scene's geoGroup, and that works perfectly well. Many thanks in advance. As always, please let me know if there is any other information I can provide.

EDIT: Further investigation has yielded some more information that may be useful in this thread. If i hit the 'Render' button on the PBR Render Target Component, the plugin with automatically digest the scene and create a node graph like the one I've described and attempted to traverse above. I cannot traverse if I do this. HOWEVER, if i go into the node graph, and manually create a new input for the geoGroup, a new Geometry->Placement node, and a new Geometry->Object Layer Map node, and hook it all up by hand, then i can indeed run my C# script and gain access to the elusive Object Layer Map node. So there is seemingly something in the auto scene graph creation that is messed up and not creating the proper references beyond a certain point.

Unity v2019.2.5f1
Octane plugin v2019.1 (6000100)
renderer v1.2.0.1376

Lua script:
Code: Select all
graph = octane.project.getSceneGraph()
nodes = octane.nodegraph.findNodes(graph, octane.NT_MAT_MAP, true);
for mm,matMap in ipairs(nodes) do
    print(matMap)
    for mmp,matMapPin in pairs(matMap.pinNames) do
        connectedInput = matMap:getConnectedNode(matMapPin)
        if(connectedInput.type == octane.NT_OUT_MATERIAL) then
            materialGraph = connectedInput.graphOwner
            for mgi,matGraphInput in pairs(materialGraph:getInputNodes()) do
               if(matGraphInput.name == "_BumpMap" or matGraphInput.name == "_DetailNormalMap") then
                    imageTex = matGraphInput:getConnectedNode(octane.P_INPUT)
                    imageTex:setPinValue(octane.P_INVERT, true)
                end
            end
        end
    end
end


C# script:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OctaneUnity;
using Octane;
using OctanePlugin;
using UnityEditor;

public class OctaneMaterialTest : MonoBehaviour
{
    public MeshRenderer vcn;

    [ContextMenu("Find Material")]
    public void FindMaterialWithVCN()
    {
        PBRRenderTargetComponent rtc = FindObjectOfType<PBRRenderTargetComponent>();
        rtc.RenderTarget.Select();
        Node placement = rtc.RenderTarget.GetConnectedNode(PinId.P_MESH);
        Node geoOut = placement.GetConnectedNode("geometry");
        Node geoGroup = geoOut.GetConnectedNode(PinId.P_INPUT);
        for(uint n = 0; n < geoGroup.PinCount; n++)
        {
            Node inputNode = geoGroup.GetConnectedNodeIx(n);
            if(inputNode){
                Node objectLayer = inputNode.GetConnectedNode(PinId.P_GEOMETRY);
                /// This should be the Object Layer Node shown in the screen shot.
                /// but it always returns the same node as inputNode
                objectLayer.Select();
            }
        }
    }
}


Image
jpetty7317
 
Posts: 14
Joined: Fri Sep 20, 2019 1:32 pm

Re: Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Postby ChrisHekman » Thu Sep 26, 2019 1:07 pm

ChrisHekman Thu Sep 26, 2019 1:07 pm
We intended C# node class more as an interface for sending data between C# and C++, not for traversing the nodegraph.
Your way of traversing the graph dosnt work because in the integration we have an Instance class that is derived from node that owns the placement/material map/objectlayer map.
When you try to get a reference to any of those owned nodes, you get the instance object, and not a corresponding node object.


What I can do is expose the converted texture node in a future build. Then you can write the following code:
Code: Select all
Texture yourDetailNormalMap = //your texture here//
Octane.Texture octaneTextureNode = OctaneUnity.Scene.Instance.GetConvertedTexture(yourDetailNormalMap);
octaneTextureNode.SetPinBool(Octane.P_INVERT, true);
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 405
Joined: Wed Jan 18, 2017 3:09 pm

Re: Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Postby jpetty7317 » Thu Sep 26, 2019 4:20 pm

jpetty7317 Thu Sep 26, 2019 4:20 pm
Hi Chris,

Thank you so much for the quick reply! Something like this would be TREMENDOUSLY helpful. As we have a number of cases where we will need to adjust things like the Invert and even things like UV transforms and Projections for adjusting the UV set the texture uses. In some cases we have our Metallic Roughness Maps not only use the 2nd uv channel, but also use the tile scale of our detail maps. All of these things would, I believe, be doable with the functionality you described.

I will be certain to keep an eye out for when this functionality is opened up, as it will be an amazing quality of life improvement. Thanks again!
jpetty7317
 
Posts: 14
Joined: Fri Sep 20, 2019 1:32 pm

Re: Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Postby ChrisHekman » Tue Oct 08, 2019 2:57 pm

ChrisHekman Tue Oct 08, 2019 2:57 pm
I have added the functionality for this in the latest build.
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 405
Joined: Wed Jan 18, 2017 3:09 pm

Re: Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Postby jpetty7317 » Mon Oct 14, 2019 6:56 pm

jpetty7317 Mon Oct 14, 2019 6:56 pm
Hi Chris!

I do apologize for my delay in response. Work had me doing a number of other things last week and I'm just now back here to see the wonderful news. I am also happy to report to you that I have pulled the latest version with your updates, and they do indeed work, and accomplish exactly what our team was looking for. Thank you so much for taking the time to do that, and doubly for doing it so quickly! It is immensely appreciated.
jpetty7317
 
Posts: 14
Joined: Fri Sep 20, 2019 1:32 pm

Re: Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Postby jpetty7317 » Tue Oct 15, 2019 3:22 pm

jpetty7317 Tue Oct 15, 2019 3:22 pm
Hi there,

Wanted to follow up with a question. I have found a great deal of success in this update as previously mentioned. However, I did want to point out an issue I'm now running into and was curious if you might have a suggestion. I can now successfully grab ALMOST any texture node that I need and properly adjust it's values. Where I'm running into issues is with things like Metallic Gloss maps. I need to adjust the UV transform on them based on our content requirements. I can grab and adjust the _MetallicGlossMap just fine (the RGB Image version). But I don't seem to be able to grab the Alpha Image node associated with that texture. I have code pasted below to give you an idea about how I'm attempting to do things. Maybe I'm missing something, but it seems GetConvertedTextureAlpha is not actually working as I would assume. That call is still returning the RGB Image node. So, when I make that attribute call and to test scale of 40x it actually never does anything to the Alpha Image node, and sets it on the RGB Image instead. after I've already set it. Anything I can do here? Also strikes me as weird that if the referenced texture is the same under the hood. why not just have them also share a transform? Thank you in advance!

Code: Select all
        if(mat.HasProperty("_MetallicGlossMap"))
        {
            UnityEngine.Texture mgm = mat.GetTexture("_MetallicGlossMap");
            float scale = 1f / mat.GetTextureScale("_DetailAlbedoMap").x;
           
            Octane.Texture octaneMGM = OctaneUnity.Scene.Instance.GetConvertedTexture(mgm); /// This grabs the texture I'd expect and properly sets the scale I calculate above.
            Octane.Node n = octaneMGM.GetConnectedNode(Octane.PinId.P_TRANSFORM);
            n.SetAttributeFloat3(Octane.AttributeId.A_SCALE, new Vector3(scale,scale,1.0f));
           
            octaneMGM = OctaneUnity.Scene.Instance.GetConvertedTextureAlpha(mgm); /// This seems to be returning the RGB Image node, not the Alpha Image node as the name would suggest to me???
            n = octaneMGM.GetConnectedNode(Octane.PinId.P_TRANSFORM);
            n.SetAttributeFloat3(Octane.AttributeId.A_SCALE, new Vector3(40f,40f,1.0f)); /// At the end here, the 40x scale is applied to the RGB Image node i grabbed in the first block, not the desired Alpha Image node.
        }
jpetty7317
 
Posts: 14
Joined: Fri Sep 20, 2019 1:32 pm

Re: Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Postby ChrisHekman » Wed Oct 16, 2019 11:33 am

ChrisHekman Wed Oct 16, 2019 11:33 am
You are correct, the function is not returning the alpha texture node. I'll fix this for the next build.
ChrisHekman
OctaneRender Team
OctaneRender Team
 
Posts: 405
Joined: Wed Jan 18, 2017 3:09 pm

Re: Cannot travel beyond NT_GEO_PLACEMENT Node from C#

Postby jpetty7317 » Thu Oct 17, 2019 1:46 pm

jpetty7317 Thu Oct 17, 2019 1:46 pm
Thanks, Chris! Really do appreciate all of your help over the last couple of weeks.
jpetty7317
 
Posts: 14
Joined: Fri Sep 20, 2019 1:32 pm

Return to Octane for Unity


Who is online

Users browsing this forum: No registered users and 1 guest

Thu Oct 24, 2019 1:35 am [ UTC ]