public void Init(VFXViewController viewController, IVFXSlotContainer owner, string name, System.Type type)
 {
     m_Owner             = owner;
     m_Name              = name;
     m_SettingType       = type;
     this.viewController = viewController;
 }
Ejemplo n.º 2
0
 void ValidateSlotsLinks(IEnumerable <VFXSlot> slots, IVFXSlotContainer expectedOwner)
 {
     foreach (var slot in slots)
     {
         ValidateSlotLinks(slot);
     }
 }
 public void AddExpressionsFromSlotContainer(IVFXSlotContainer slotContainer, int blockId)
 {
     foreach (var master in slotContainer.inputSlots)
     {
         AddExpressionsFromSlot(master, blockId);
     }
 }
Ejemplo n.º 4
0
 void ValidateSlots(IEnumerable <VFXSlot> slots, IVFXSlotContainer expectedOwner)
 {
     foreach (var slot in slots)
     {
         ValidateSlot(slot, expectedOwner, null);
     }
 }
Ejemplo n.º 5
0
        bool ProviderFilter(VFXNodeProvider.Descriptor d)
        {
            var mySlot = controller.model;
            var parameterDescriptor = d.modelDescriptor as VFXParameterController;
            IVFXSlotContainer container = null;
            if (parameterDescriptor != null)
            {
                container = parameterDescriptor.model;
            }
            else
            {
                VFXModelDescriptor desc = d.modelDescriptor as VFXModelDescriptor;
                if (desc == null)
                {
                    string path = d.modelDescriptor as string;

                    if (path != null && !path.StartsWith(VisualEffectAssetEditorUtility.templatePath))
                    {
                        if (Path.GetExtension(path) == VisualEffectSubgraphOperator.Extension)
                        {
                            var subGraph = AssetDatabase.LoadAssetAtPath<VisualEffectSubgraphOperator>(path);
                            if (subGraph != null && (!controller.viewController.model.isSubgraph || !subGraph.GetResource().GetOrCreateGraph().subgraphDependencies.Contains(controller.viewController.model.subgraph) && subGraph.GetResource() != controller.viewController.model))
                                return true;
                        }
                    }
                    return false;
                }

                container = desc.model as IVFXSlotContainer;
                if (container == null)
                    return false;

                if (direction == Direction.Output
                    &&  mySlot != null
                    && container is VFXOperatorDynamicOperand
                    && (container as VFXOperatorDynamicOperand).validTypes.Contains(mySlot.property.type))
                    return true;
            }

            IEnumerable<Type> validTypes = null;
            if (mySlot == null)
            {
                var op = controller.sourceNode.model as VFXOperatorDynamicOperand;
                if (op != null)
                    validTypes = op.validTypes;
            }

            var getSlots = direction == Direction.Input ? (System.Func<int, VFXSlot>)container.GetOutputSlot : (System.Func<int, VFXSlot>)container.GetInputSlot;
            int count = direction == Direction.Input ? container.GetNbOutputSlots() : container.GetNbInputSlots();
            for (int i = 0; i < count; ++i)
            {
                var slot = getSlots(i);
                if (mySlot != null && slot.CanLink(mySlot))
                    return true;
                else if (validTypes != null && validTypes.Contains(slot.property.type))
                    return true;
            }
            return false;
        }
Ejemplo n.º 6
0
        private static void CopyDataEdges(Data copyData, ScriptableObject[] allSerializedObjects)
        {
            if (copyData.dataEdges != null)
            {
                foreach (var dataEdge in copyData.dataEdges)
                {
                    VFXSlot inputSlot = null;
                    if (dataEdge.inputContext)
                    {
                        VFXContext targetContext = allSerializedObjects[dataEdge.input.targetIndex] as VFXContext;
                        if (dataEdge.inputBlockIndex == -1)
                        {
                            inputSlot = FetchSlot(targetContext, dataEdge.input.slotPath, true);
                        }
                        else
                        {
                            inputSlot = FetchSlot(targetContext[dataEdge.inputBlockIndex], dataEdge.input.slotPath, true);
                        }
                    }
                    else
                    {
                        VFXModel model = allSerializedObjects[dataEdge.input.targetIndex] as VFXModel;
                        inputSlot = FetchSlot(model as IVFXSlotContainer, dataEdge.input.slotPath, true);
                    }

                    IVFXSlotContainer outputContainer = null;
                    if (dataEdge.outputParameter)
                    {
                        var parameter = copyData.parameters[dataEdge.outputParameterIndex];
                        outputContainer = parameter.parameter;
                    }
                    else
                    {
                        outputContainer = allSerializedObjects[dataEdge.output.targetIndex] as IVFXSlotContainer;
                    }

                    VFXSlot outputSlot = FetchSlot(outputContainer, dataEdge.output.slotPath, false);

                    if (inputSlot != null && outputSlot != null)
                    {
                        if (inputSlot.Link(outputSlot) && dataEdge.outputParameter)
                        {
                            var parameter = copyData.parameters[dataEdge.outputParameterIndex];
                            var node      = parameter.parameter.nodes[dataEdge.outputParameterNodeIndex + parameter.infoIndexOffset];
                            if (node.linkedSlots == null)
                            {
                                node.linkedSlots = new List <VFXParameter.NodeLinkedSlot>();
                            }
                            node.linkedSlots.Add(new VFXParameter.NodeLinkedSlot()
                            {
                                inputSlot = inputSlot, outputSlot = outputSlot
                            });
                        }
                    }
                }
            }
        }
 static public IEnumerable <VFXNamedExpression> GetExpressionsFromSlots(IVFXSlotContainer slotContainer)
 {
     foreach (var master in slotContainer.inputSlots)
     {
         foreach (var slot in master.GetExpressionSlots())
         {
             var expression = slot.GetExpression();
             yield return(new VFXNamedExpression(expression, slot.fullName));
         }
     }
 }
Ejemplo n.º 8
0
 static void ClearLinks(IVFXSlotContainer container)
 {
     foreach (var slot in container.inputSlots)
     {
         slot.UnlinkAll(true, false);
     }
     foreach (var slot in container.outputSlots)
     {
         slot.UnlinkAll(true, false);
     }
 }
Ejemplo n.º 9
0
 public void AddExpressionFromSlotContainer(IVFXSlotContainer slotContainer, int blockId)
 {
     foreach (var master in slotContainer.inputSlots)
     {
         foreach (var slot in master.GetExpressionSlots())
         {
             var exp = slot.GetExpression();
             if (!Contains(exp))
             {
                 AddExpression(exp, slot.fullName, blockId);
             }
         }
     }
 }
Ejemplo n.º 10
0
        void ValidateSlotContainerLinks(IVFXSlotContainer slotContainer, VFXModel expectedParent)
        {
            ValidateSlotsLinks(slotContainer.inputSlots, slotContainer);
            ValidateSlotsLinks(slotContainer.outputSlots, slotContainer);

            if (slotContainer is VFXContext)
            {
                VFXContext context = slotContainer as VFXContext;
                foreach (var block in context.children)
                {
                    ValidateSlotContainerLinks(block, context);
                }
            }
        }
Ejemplo n.º 11
0
 void ValidateSlot(VFXSlot slot, IVFXSlotContainer expectedOwner, VFXSlot expectedParent)
 {
     if (!ValidateVFXModel(slot, expectedParent))
     {
         return;
     }
     m_SlotOwners[slot] = expectedOwner;
     if (slot.owner != expectedOwner)
     {
         LogError("Slot error : wrong owner. expected:" + GetVFXModelDesc(expectedOwner) + " actual:" + GetVFXModelDesc(slot.owner));
     }
     foreach (var subSlot in slot.children)
     {
         ValidateSlot(subSlot, expectedOwner, slot);
     }
 }
Ejemplo n.º 12
0
        void ValidateSlotContainer(IVFXSlotContainer slotContainer, VFXModel expectedParent)
        {
            if (!ValidateVFXModel(slotContainer as VFXModel, expectedParent))
            {
                return;
            }

            ValidateSlots(slotContainer.inputSlots, slotContainer);
            ValidateSlots(slotContainer.outputSlots, slotContainer);

            if (slotContainer is VFXContext)
            {
                VFXContext context = slotContainer as VFXContext;
                foreach (var block in context.children)
                {
                    ValidateSlotContainer(block, context);
                }
            }
        }
Ejemplo n.º 13
0
        static VFXSlot FetchSlot(IVFXSlotContainer container, int[] slotPath, bool input)
        {
            int containerSlotIndex = slotPath[slotPath.Length - 1];

            VFXSlot slot = null;

            if (input)
            {
                if (container.GetNbInputSlots() > containerSlotIndex)
                {
                    slot = container.GetInputSlot(slotPath[slotPath.Length - 1]);
                }
            }
            else
            {
                if (container.GetNbOutputSlots() > containerSlotIndex)
                {
                    slot = container.GetOutputSlot(slotPath[slotPath.Length - 1]);
                }
            }
            if (slot == null)
            {
                return(null);
            }

            for (int i = slotPath.Length - 2; i >= 0; --i)
            {
                if (slot.GetNbChildren() > slotPath[i])
                {
                    slot = slot[slotPath[i]];
                }
                else
                {
                    return(null);
                }
            }

            return(slot);
        }
Ejemplo n.º 14
0
        bool ProviderFilter(VFXNodeProvider.Descriptor d)
        {
            var mySlot = controller.model;
            var parameterDescriptor     = d.modelDescriptor as VFXParameterController;
            IVFXSlotContainer container = null;

            if (parameterDescriptor != null)
            {
                container = parameterDescriptor.model;
            }
            else
            {
                VFXModelDescriptor desc = d.modelDescriptor as VFXModelDescriptor;
                if (desc == null)
                {
                    string path = d.modelDescriptor as string;

                    if (path != null && !path.StartsWith(VisualEffectAssetEditorUtility.templatePath))
                    {
                        if (Path.GetExtension(path) == VisualEffectSubgraphOperator.Extension)
                        {
                            var subGraph = AssetDatabase.LoadAssetAtPath <VisualEffectSubgraphOperator>(path);
                            if (subGraph != null && (!controller.viewController.model.isSubgraph || !subGraph.GetResource().GetOrCreateGraph().subgraphDependencies.Contains(controller.viewController.model.subgraph) && subGraph.GetResource() != controller.viewController.model))
                            {
                                return(true);
                            }
                        }
                    }
                    return(false);
                }

                container = desc.model as IVFXSlotContainer;
                if (container == null)
                {
                    return(false);
                }

                if (direction == Direction.Output &&
                    mySlot != null &&
                    container is VFXOperatorDynamicOperand &&
                    (container as VFXOperatorDynamicOperand).validTypes.Contains(mySlot.property.type))
                {
                    return(true);
                }
            }

            IEnumerable <Type> validTypes = null;

            if (mySlot == null)
            {
                var op = controller.sourceNode.model as VFXOperatorDynamicOperand;
                if (op != null)
                {
                    validTypes = op.validTypes;
                }
            }

            var getSlots = direction == Direction.Input ? container.GetOutputSlot : (System.Func <int, VFXSlot>)container.GetInputSlot;
            var count    = direction == Direction.Input ? container.GetNbOutputSlots() : container.GetNbInputSlots();

            // Template containers are not sync initially to save time during loading
            // For container with no input or output this can be called everytime, but should also be very fast
            if (count == 0)
            {
                container.ResyncSlots(false);
                count = direction == Direction.Input ? container.GetNbOutputSlots() : container.GetNbInputSlots();
            }

            for (int i = 0; i < count; ++i)
            {
                var slot = getSlots(i);
                if (mySlot != null && slot.CanLink(mySlot))
                {
                    return(true);
                }
                else if (validTypes != null && validTypes.Contains(slot.property.type))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 15
0
        void IEdgeConnectorListener.OnDropOutsidePort(Edge edge, Vector2 position)
        {
            VFXSlot startSlot = controller.model;

            VFXView           view           = this.GetFirstAncestorOfType <VFXView>();
            VFXViewController viewController = view.controller;


            List <VisualElement> picked = new List <VisualElement>();

            panel.PickAll(position, picked);
            VFXNodeUI endNode = null;

            foreach (var element in picked)
            {
                if (element is VFXNodeUI node)
                {
                    endNode = node;
                    break;
                }
            }


            VFXDataEdge dataEdge = edge as VFXDataEdge;
            bool        exists   = false;

            if (dataEdge.controller != null)
            {
                exists = true;
                view.controller.RemoveElement(dataEdge.controller);
            }

            if (endNode != null)
            {
                VFXNodeController nodeController = endNode.controller;

                if (nodeController != null)
                {
                    IVFXSlotContainer slotContainer = nodeController.slotContainer;
                    if (controller.direction == Direction.Input)
                    {
                        foreach (var output in nodeController.outputPorts.Where(t => t.model == null || t.model.IsMasterSlot()))
                        {
                            if (viewController.CreateLink(controller, output))
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (var input in nodeController.inputPorts.Where(t => t.model == null || t.model.IsMasterSlot() && !t.model.HasLink(true)))
                        {
                            if (viewController.CreateLink(input, controller))
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else if (controller.direction == Direction.Input && Event.current.modifiers == EventModifiers.Alt)
            {
                var targetType = controller.portType;

                var attribute = VFXLibrary.GetAttributeFromSlotType(controller.portType);
                VFXModelDescriptorParameters parameterDesc;
                if (attribute != null && attribute.usages.HasFlag(VFXTypeAttribute.Usage.ExcludeFromProperty))
                {
                    parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t =>
                    {
                        if (!t.model.outputSlots[0].CanLink(controller.model))
                        {
                            return(false);
                        }
                        var attributeCandidate = VFXLibrary.GetAttributeFromSlotType(t.model.type);
                        return(attributeCandidate == null || !attributeCandidate.usages.HasFlag(VFXTypeAttribute.Usage.ExcludeFromProperty));
                    });
                }
                else
                {
                    parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t =>
                    {
                        return(t.model.type == targetType);
                    });
                }

                if (parameterDesc != null)
                {
                    Vector2 pos = view.contentViewContainer.GlobalToBound(position) - new Vector2(140, 20);
                    view.UpdateSelectionWithNewNode();
                    VFXParameter parameter = viewController.AddVFXParameter(pos, parameterDesc, false);
                    parameter.SetSettingValue("m_Exposed", true);
                    startSlot.Link(parameter.outputSlots[0]);

                    CopyValueToParameter(parameter);

                    viewController.AddVFXModel(pos, parameter);
                }
            }
            else if (!exists)
            {
                var window = VFXViewWindow.GetWindow(view);

                if (direction == Direction.Input || viewController.model.visualEffectObject is VisualEffectSubgraphOperator || viewController.model.visualEffectObject is VisualEffectSubgraphBlock) // no context for subgraph operators.
                {
                    VFXFilterWindow.Show(window, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter) }));
                }
                else
                {
                    VFXFilterWindow.Show(window, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter), typeof(VFXContext) }));
                }
            }
        }
Ejemplo n.º 16
0
 string GetVFXModelDesc(IVFXSlotContainer model)
 {
     return(GetVFXModelDesc(model as VFXModel));
 }
Ejemplo n.º 17
0
        bool ProviderFilter(VFXNodeProvider.Descriptor d)
        {
            var mySlot = controller.model;
            var parameterDescriptor     = d.modelDescriptor as VFXParameterController;
            IVFXSlotContainer container = null;

            if (parameterDescriptor != null)
            {
                container = parameterDescriptor.model;
            }
            else
            {
                VFXModelDescriptor desc = d.modelDescriptor as VFXModelDescriptor;
                if (desc == null)
                {
                    return(false);
                }

                container = desc.model as IVFXSlotContainer;
                if (container == null)
                {
                    return(false);
                }

                if (direction == Direction.Output &&
                    mySlot != null &&
                    container is VFXOperatorDynamicOperand &&
                    (container as VFXOperatorDynamicOperand).validTypes.Contains(mySlot.property.type))
                {
                    return(true);
                }
            }

            IEnumerable <Type> validTypes = null;

            if (mySlot == null)
            {
                var op = controller.sourceNode.model as VFXOperatorDynamicOperand;
                if (op != null)
                {
                    validTypes = op.validTypes;
                }
            }

            var getSlots = direction == Direction.Input ? (System.Func <int, VFXSlot>)container.GetOutputSlot : (System.Func <int, VFXSlot>)container.GetInputSlot;
            int count    = direction == Direction.Input ? container.GetNbOutputSlots() : container.GetNbInputSlots();

            for (int i = 0; i < count; ++i)
            {
                var slot = getSlots(i);
                if (mySlot != null && slot.CanLink(mySlot))
                {
                    return(true);
                }
                else if (validTypes != null && validTypes.Contains(slot.property.type))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 18
0
        void IEdgeConnectorListener.OnDropOutsidePort(Edge edge, Vector2 position)
        {
            VFXSlot startSlot = controller.model;

            VFXView           view           = this.GetFirstAncestorOfType <VFXView>();
            VFXViewController viewController = view.controller;


            VFXNodeUI endNode = null;

            foreach (var node in view.GetAllNodes())
            {
                if (node.worldBound.Contains(position))
                {
                    endNode = node;
                }
            }

            VFXDataEdge dataEdge = edge as VFXDataEdge;
            bool        exists   = false;

            if (dataEdge.controller != null)
            {
                exists = true;
                view.controller.RemoveElement(dataEdge.controller);
            }

            if (endNode != null)
            {
                VFXNodeController nodeController = endNode.controller;

                if (nodeController != null)
                {
                    IVFXSlotContainer slotContainer = nodeController.slotContainer;
                    if (controller.direction == Direction.Input)
                    {
                        foreach (var output in nodeController.outputPorts.Where(t => t.model == null || t.model.IsMasterSlot()))
                        {
                            if (viewController.CreateLink(controller, output))
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (var input in nodeController.inputPorts.Where(t => t.model == null || t.model.IsMasterSlot()))
                        {
                            if (viewController.CreateLink(input, controller))
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else if (controller.direction == Direction.Input && Event.current.modifiers == EventModifiers.Alt)
            {
                VFXModelDescriptorParameters parameterDesc = VFXLibrary.GetParameters().FirstOrDefault(t => t.name == controller.portType.UserFriendlyName());
                if (parameterDesc != null)
                {
                    VFXParameter parameter = viewController.AddVFXParameter(view.contentViewContainer.GlobalToBound(position) - new Vector2(140, 20), parameterDesc);
                    parameter.SetSettingValue("m_Exposed", true);
                    startSlot.Link(parameter.outputSlots[0]);

                    CopyValueToParameter(parameter);
                }
            }
            else if (!exists)
            {
                VFXFilterWindow.Show(VFXViewWindow.currentWindow, Event.current.mousePosition, view.ViewToScreenPosition(Event.current.mousePosition), new VFXNodeProvider(viewController, AddLinkedNode, ProviderFilter, new Type[] { typeof(VFXOperator), typeof(VFXParameter), typeof(VFXContext) }));
            }
        }
Ejemplo n.º 19
0
 void PostSetup()
 {
     SetupTargetParameters();
     m_SourceSlotContainer = m_SourceNode as IVFXSlotContainer;
 }
 public void Init(IVFXSlotContainer owner, string name, System.Type type)
 {
     m_Owner       = owner;
     m_Name        = name;
     m_SettingType = type;
 }
Ejemplo n.º 21
0
        bool ProviderFilter(VFXNodeProvider.Descriptor d)
        {
            var mySlot = controller.model;

            IEnumerable <Type> validTypes = null;

            if (mySlot == null)
            {
                var op = controller.sourceNode.model as VFXOperatorNumericCascadedUnified;
                if (op != null)
                {
                    validTypes = op.validTypes;
                }
            }
            var parameterDescriptor     = d.modelDescriptor as VFXParameterController;
            IVFXSlotContainer container = null;

            if (parameterDescriptor != null)
            {
                container = parameterDescriptor.model;
            }
            else
            {
                VFXModelDescriptor desc = d.modelDescriptor as VFXModelDescriptor;
                if (desc == null)
                {
                    return(false);
                }

                container = desc.model as IVFXSlotContainer;
                if (container == null)
                {
                    return(false);
                }
            }

            var getSlots = direction == Direction.Input ? (System.Func <int, VFXSlot>)container.GetOutputSlot : (System.Func <int, VFXSlot>)container.GetInputSlot;

            int count = direction == Direction.Input ? container.GetNbOutputSlots() : container.GetNbInputSlots();

            bool oneFound = false;

            for (int i = 0; i < count; ++i)
            {
                VFXSlot slot = getSlots(i);

                if (mySlot != null)
                {
                    if (slot.CanLink(mySlot))
                    {
                        oneFound = true;
                        break;
                    }
                }
                else if (validTypes != null)
                {
                    if (validTypes.Contains(slot.property.type))
                    {
                        oneFound = true;
                        break;
                    }
                }
            }

            return(oneFound);
        }
Ejemplo n.º 22
0
 void PostSetup()
 {
     SetupTargetParameters();
     m_SourceNode.SetSettingValue("m_Subgraph", m_TargetSubgraph);
     m_SourceSlotContainer = m_SourceNode as IVFXSlotContainer;
 }