예제 #1
0
        Component_FlowGraphNode AddFlowGraphNode(Component_FlowGraph graph, Component subscribeTo)
        {
            var node = graph.CreateComponent <Component_FlowGraphNode>(enabled: false);

            node.Name     = node.BaseType.GetUserFriendlyNameForInstance();
            node.Position = graph.EditorScrollPosition.ToVector2I();

            var handler = node.CreateComponent <Component_EventHandler>();

            handler.Name  = handler.BaseType.GetUserFriendlyNameForInstance() + " " + _event.Name;
            handler.Event = ReferenceUtility.MakeReference <ReferenceValueType_Event>(
                null, ReferenceUtility.CalculateThisReference(handler, subscribeTo, _event.Signature));

            node.ControlledObject = ReferenceUtility.MakeReference <Component>(null, ReferenceUtility.CalculateThisReference(node, handler));
            node.Enabled          = true;

            return(node);
        }
예제 #2
0
        void MaterialNewObjectCreateShaderGraph(Component_Material material, NewMaterialData data, out Component_FlowGraph graph)
        {
            graph                = material.CreateComponent <Component_FlowGraph>();
            graph.Name           = "Shader graph";
            graph.Specialization = ReferenceUtility.MakeReference(
                MetadataManager.GetTypeOfNetType(typeof(Component_FlowGraphSpecialization_Shader)).Name + "|Instance");

            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name             = "Node " + "Material";    //Name;
                node.Position         = new Vector2I(10, -7);
                node.ControlledObject = ReferenceUtility.MakeThisReference(node, material);
            }

            //configure
            {
                const int step     = 9;
                Vector2I  position = new Vector2I(-20, -data.GetTextureCount() * step / 2);

                //BaseColor
                if (!string.IsNullOrEmpty(data.BaseColorTexture))
                {
                    var node = graph.CreateComponent <Component_FlowGraphNode>();
                    node.Name     = "Node Texture Sample " + "BaseColor";
                    node.Position = position;
                    position.Y   += step;

                    var sample = node.CreateComponent <Component_ShaderTextureSample>();
                    sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                    sample.Texture = new Reference <Component_Image>(null, data.BaseColorTexture);

                    node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                    material.BaseColor = ReferenceUtility.MakeThisReference(material, sample, "RGBA");
                }
                //else if( data.BaseColor.HasValue )
                //	BaseColor = data.BaseColor.Value;

                //Metallic
                if (!string.IsNullOrEmpty(data.MetallicTexture))
                {
                    var node = graph.CreateComponent <Component_FlowGraphNode>();
                    node.Name     = "Node Texture Sample " + "Metallic";
                    node.Position = position;
                    position.Y   += step;

                    var sample = node.CreateComponent <Component_ShaderTextureSample>();
                    sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                    sample.Texture = new Reference <Component_Image>(null, data.MetallicTexture);

                    node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                    material.Metallic = ReferenceUtility.MakeThisReference(material, sample, "R");
                }

                //Roughness
                if (!string.IsNullOrEmpty(data.RoughnessTexture))
                {
                    var node = graph.CreateComponent <Component_FlowGraphNode>();
                    node.Name     = "Node Texture Sample " + "Roughness";
                    node.Position = position;
                    position.Y   += step;

                    var sample = node.CreateComponent <Component_ShaderTextureSample>();
                    sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                    sample.Texture = new Reference <Component_Image>(null, data.RoughnessTexture);

                    node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                    material.Roughness = ReferenceUtility.MakeThisReference(material, sample, "R");
                }

                //Normal
                if (!string.IsNullOrEmpty(data.NormalTexture))
                {
                    var node = graph.CreateComponent <Component_FlowGraphNode>();
                    node.Name     = "Node Texture Sample " + "Normal";
                    node.Position = position;
                    position.Y   += step;

                    var sample = node.CreateComponent <Component_ShaderTextureSample>();
                    sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                    sample.Texture = new Reference <Component_Image>(null, data.NormalTexture);

                    node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                    material.Normal = ReferenceUtility.MakeThisReference(material, sample, "RGBA");
                }

                ////Displacement
                //if( !string.IsNullOrEmpty( data.DisplacementTexture ) )
                //{
                //	var node = graph.CreateComponent<Component_FlowGraphNode>();
                //	node.Name = "Node Texture Sample " + "Displacement";
                //	node.Position = position;
                //	position.Y += step;

                //	var sample = node.CreateComponent<Component_ShaderTextureSample>();
                //	sample.Name = ComponentUtility.GetNewObjectUniqueName( sample );
                //	sample.Texture = new Reference<Component_Image>( null, data.DisplacementTexture );

                //	node.ControlledObject = ReferenceUtility.MakeThisReference( node, sample );

                //	Displacement = ReferenceUtility.MakeThisReference( this, sample, "R" );
                //}

                ////AmbientOcclusion
                //if( !string.IsNullOrEmpty( data.AmbientOcclusionTexture ) )
                //{
                //	var node = graph.CreateComponent<Component_FlowGraphNode>();
                //	node.Name = "Node Texture Sample " + "AmbientOcclusion";
                //	node.Position = position;
                //	position.Y += step;

                //	var sample = node.CreateComponent<Component_ShaderTextureSample>();
                //	sample.Name = ComponentUtility.GetNewObjectUniqueName( sample );
                //	sample.Texture = new Reference<Component_Image>( null, data.AmbientOcclusionTexture );

                //	node.ControlledObject = ReferenceUtility.MakeThisReference( node, sample );

                //	AmbientOcclusion = ReferenceUtility.MakeThisReference( this, sample, "R" );
                //}

                ////Emissive
                //if( !string.IsNullOrEmpty( data.EmissiveTexture ) )
                //{
                //	var node = graph.CreateComponent<Component_FlowGraphNode>();
                //	node.Name = "Node Texture Sample " + "Emissive";
                //	node.Position = position;
                //	position.Y += step;

                //	var sample = node.CreateComponent<Component_ShaderTextureSample>();
                //	sample.Name = ComponentUtility.GetNewObjectUniqueName( sample );
                //	sample.Texture = new Reference<Component_Image>( null, data.EmissiveTexture );

                //	node.ControlledObject = ReferenceUtility.MakeThisReference( node, sample );

                //	Emissive = ReferenceUtility.MakeThisReference( this, sample, "RGBA" );
                //}

                //Opacity
                if (!string.IsNullOrEmpty(data.OpacityTexture))
                {
                    var node = graph.CreateComponent <Component_FlowGraphNode>();
                    node.Name     = "Node Texture Sample " + "Opacity";
                    node.Position = position;
                    position.Y   += step;

                    var sample = node.CreateComponent <Component_ShaderTextureSample>();
                    sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                    sample.Texture = new Reference <Component_Image>(null, data.OpacityTexture);

                    node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                    material.Opacity = ReferenceUtility.MakeThisReference(material, sample, "R");

                    material.BlendMode = Component_Material.BlendModeEnum.Masked;
                }
            }
        }