public ParameterNodeFactory(string pinType, NodeCategory category, string name, string defaultValue = null) : base(
         NodeTypes.MakeType(NodeTypes.ParameterPrefix, pinType), name, category.ToString())
 {
     _value    = defaultValue ?? GetDefaultValue(pinType);
     _pinType  = pinType == PinTypes.Special.Color ? PinTypes.Vec4 : pinType;
     _category = category;
 }
 private void SplitOutputs(NodeHelper scriptNode, string nodeTypePrefix)
 {
     for (var i = 0; i < scriptNode.OutputPins.Count; ++i)
     {
         var outputPin = scriptNode.OutputPins[i];
         if (outputPin.Links.Count > 0)
         {
             var node = new NodeHelper();
             node.Id   = scriptNode.Id;
             node.Name = outputPin.Id;
             node.Type = NodeTypes.MakeType(nodeTypePrefix, outputPin.Type);
             node.OutputPins.Add(new PinHelper(outputPin.Type));
             Script.Nodes.Add(node);
             Script.CopyConnections(outputPin, node.OutputPins[0]);
         }
     }
 }
Esempio n. 3
0
 public UniformNodeFactory(string pinType, NodeCategory category, string name, NodeFactoryVisibility visibility = NodeFactoryVisibility.Visible) : base(
         NodeTypes.MakeType(NodeTypes.UniformPrefix, pinType), name, category.ToString(), visibility)
 {
     _pinType  = pinType == PinTypes.Special.Color ? PinTypes.Vec4 : pinType;
     _category = category;
 }
        public DependencyContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterInstance(this).AsSelf().SingleInstance();

            #region ParametersAndValues

            builder.RegisterType <FunctionViewModel>()
            .Named <NodeViewModel>(NodeTypes.Function)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <FunctAloneViewModel>()
            .Named <NodeViewModel>(NodeTypes.FuncAlone)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <SamplerViewModel>()
            .Named <NodeViewModel>(NodeTypes.Sampler2D)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <SamplerCubeViewModel>()
            .Named <NodeViewModel>(NodeTypes.SamplerCube)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <ColorViewModel>()
            .Named <NodeViewModel>(NodeTypes.MakeType(NodeTypes.ParameterPrefix, PinTypes.Special.Color))
            .Named <NodeViewModel>(PinTypes.Special.Color)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <ScalarViewModel>()
            .Named <NodeViewModel>(NodeTypes.MakeType(NodeTypes.ParameterPrefix, PinTypes.Float))
            .Named <NodeViewModel>(PinTypes.Float)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <IntViewModel>()
            .Named <NodeViewModel>(NodeTypes.MakeType(NodeTypes.ParameterPrefix, PinTypes.Int))
            .Named <NodeViewModel>(PinTypes.Int)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <Vector2ViewModel>()
            .Named <NodeViewModel>(NodeTypes.MakeType(NodeTypes.ParameterPrefix, PinTypes.Vec2))
            .Named <NodeViewModel>(PinTypes.Vec2)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <Vector3ViewModel>()
            .Named <NodeViewModel>(NodeTypes.MakeType(NodeTypes.ParameterPrefix, PinTypes.Vec3))
            .Named <NodeViewModel>(PinTypes.Vec3)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <Vector4ViewModel>()
            .Named <NodeViewModel>(NodeTypes.MakeType(NodeTypes.ParameterPrefix, PinTypes.Vec4))
            .Named <NodeViewModel>(PinTypes.Vec4)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <Mat4ViewModel>()
            .Named <NodeViewModel>(PinTypes.Mat4)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <EnumViewModel <Urho.CullMode> >()
            .Named <NodeViewModel>(NodeTypes.Cull)
            .Named <NodeViewModel>(NodeTypes.ShadowCull)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <EnumViewModel <Urho.FillMode> >()
            .Named <NodeViewModel>(NodeTypes.Fill)
            .ExternallyOwned()
            .InstancePerDependency();

            builder.RegisterType <StringViewModel>()
            .Named <NodeViewModel>(NodeTypes.Define)
            .Named <NodeViewModel>(NodeTypes.Undefine)
            .Named <NodeViewModel>(NodeTypes.Special.FinalColor)
            .Named <NodeViewModel>(NodeTypes.Special.FragData0)
            .Named <NodeViewModel>(NodeTypes.Special.FragData1)
            .Named <NodeViewModel>(NodeTypes.Special.FragData2)
            .Named <NodeViewModel>(NodeTypes.Special.FragData3)
            .Named <NodeViewModel>(NodeTypes.Special.ShadowMapOutput)
            .ExternallyOwned()
            .InstancePerDependency();

            {
                var inlinableFunc = builder.RegisterType <InlineableNodeViewModel>();
                foreach (var func in MaterialNodeRegistry.Instance.InlineFunctions)
                {
                    inlinableFunc.Named <NodeViewModel>(func.Type);
                }

                inlinableFunc.ExternallyOwned().InstancePerDependency();
            }

            #endregion

            builder.RegisterType <GraphValidator>().AsSelf().SingleInstance();
            builder.RegisterGeneric(typeof(ConfigurationRepository <>)).AsSelf().SingleInstance();

            builder.RegisterType <ViewModelFactory>().As <INodeViewModelFactory>().SingleInstance();
            builder.RegisterType <MaterialNodeRegistry>().AsSelf().As <INodeRegistry>().SingleInstance();


            builder.RegisterType <UrhoContext>().AsSelf().SingleInstance();
            builder.RegisterType <MainViewModel>().AsSelf().SingleInstance();
            builder.RegisterType <ShaderGenerator>().AsSelf().SingleInstance();
            builder.RegisterType <ScriptViewModel>().AsSelf().SingleInstance();

            _container = builder.Build();
        }