示例#1
0
        void ConvertContext(VFXNodeProvider.Descriptor d, Vector2 mPos)
        {
            VFXView           view           = GetFirstAncestorOfType <VFXView>();
            VFXViewController viewController = controller.viewController;

            if (view == null)
            {
                return;
            }

            mPos = view.contentViewContainer.ChangeCoordinatesTo(view, controller.position);

            var newNodeController    = view.AddNode(d, mPos);
            var newContextController = newNodeController as VFXContextController;

            //transfer blocks
            foreach (var block in controller.model.children.ToArray()) // To array needed as the IEnumerable content will change
            {
                newContextController.AddBlock(-1, block);
            }


            //transfer settings
            var contextType = controller.model.GetType();

            foreach (var setting in newContextController.model.GetSettings(true))
            {
                if ((newContextController.model is VFXPlanarPrimitiveOutput || newContextController.model.GetType().Name == "VFXLitPlanarPrimitiveOutput") && setting.field.Name == "primitiveType")
                {
                    continue;
                }

                if (!setting.valid || setting.field.GetCustomAttributes(typeof(VFXSettingAttribute), true).Length == 0)
                {
                    continue;
                }

                var sourceSetting = controller.model.GetSetting(setting.name);
                if (!sourceSetting.valid)
                {
                    continue;
                }

                object value;
                if (VFXConverter.TryConvertTo(sourceSetting.value, setting.field.FieldType, out value))
                {
                    newContextController.model.SetSettingValue(setting.field.Name, value);
                }
            }

            //transfer flow edges
            if (controller.flowInputAnchors.Count == 1)
            {
                foreach (var output in controller.flowInputAnchors[0].connections.Select(t => t.output).ToArray())
                {
                    newContextController.model.LinkFrom(output.context.model, output.slotIndex);
                }
            }

            // Apply the slot changes that can be the result of settings changes
            newContextController.ApplyChanges();

            VFXSlot firstTextureSlot = null;

            //transfer master slot values
            foreach (var slot in newContextController.model.inputSlots)
            {
                VFXSlot mySlot = controller.model.inputSlots.FirstOrDefault(t => t.name == slot.name);
                if (mySlot == null)
                {
                    if (slot.valueType == VFXValueType.Texture2D && firstTextureSlot == null)
                    {
                        firstTextureSlot = slot;
                    }
                    continue;
                }

                object value;
                if (VFXConverter.TryConvertTo(mySlot.value, slot.property.type, out value))
                {
                    slot.value = value;
                }
            }
            //Hack to copy the first texture in the first texture slot if not found by name
            if (firstTextureSlot != null)
            {
                VFXSlot mySlot = controller.model.inputSlots.FirstOrDefault(t => t.valueType == VFXValueType.Texture2D);

                if (mySlot != null)
                {
                    firstTextureSlot.value = mySlot.value;
                }
            }

            foreach (var anchor in newContextController.inputPorts)
            {
                string path     = anchor.path;
                var    myAnchor = controller.inputPorts.FirstOrDefault(t => t.path == path);

                if (myAnchor == null || !myAnchor.HasLink())
                {
                    continue;
                }

                //There should be only one
                var output = myAnchor.connections.First().output;

                viewController.CreateLink(anchor, output);
            }

            // Apply the change so that it won't unlink the blocks links
            controller.ApplyChanges();

            viewController.RemoveElement(controller);
        }
示例#2
0
        void AddLinkedNode(VFXNodeProvider.Descriptor d, Vector2 mPos)
        {
            var mySlot = controller.model;

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

            if (view == null)
            {
                return;
            }

            var newNodeController = view.AddNode(d, mPos);

            if (newNodeController == null)
            {
                return;
            }

            IEnumerable <Type> validTypes = null;

            var op = controller.sourceNode.model as VFXOperatorNumericCascadedUnified;

            if (mySlot == null && op != null)
            {
                validTypes = op.validTypes;
            }

            // If linking to a new parameter, copy the slot value and space
            if (direction == Direction.Input && controller.model != null) //model will be null for upcomming which won't have a value
            {
                if (newNodeController is VFXOperatorController)
                {
                    var inlineOperator = (newNodeController as VFXOperatorController).model as VFXInlineOperator;
                    if (inlineOperator != null)
                    {
                        var    value          = controller.model.value;
                        object convertedValue = null;
                        if (VFXConverter.TryConvertTo(value, inlineOperator.type, out convertedValue))
                        {
                            inlineOperator.inputSlots[0].value = convertedValue;
                        }

                        if (inlineOperator.inputSlots[0].spaceable && controller.model.spaceable)
                        {
                            inlineOperator.inputSlots[0].space = controller.model.space;
                        }
                    }
                }
            }

            var ports = direction == Direction.Input ? newNodeController.outputPorts : newNodeController.inputPorts;
            int count = ports.Count();

            for (int i = 0; i < count; ++i)
            {
                var port = ports[i];
                if (mySlot != null)
                {
                    if (viewController.CreateLink(direction == Direction.Input ? controller : port, direction == Direction.Input ? port : controller))
                    {
                        AlignNodeToLinkedPort(view, port, newNodeController);
                        break;
                    }
                }
                else if (validTypes != null)
                {
                    if (validTypes.Contains(port.model.property.type))
                    {
                        if (viewController.CreateLink(controller, port))
                        {
                            break;
                        }
                    }
                }
            }
        }
示例#3
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);
        }
        void ConvertContext(VFXNodeProvider.Descriptor d, Vector2 mPos)
        {
            VFXView           view           = GetFirstAncestorOfType <VFXView>();
            VFXViewController viewController = controller.viewController;

            if (view == null)
            {
                return;
            }

            mPos = view.contentViewContainer.ChangeCoordinatesTo(view, controller.position);

            var newNodeController    = view.AddNode(d, mPos);
            var newContextController = newNodeController as VFXContextController;

            //transfer blocks
            foreach (var block in controller.model.children.ToArray()) // To array needed as the IEnumerable content will change
            {
                newContextController.AddBlock(-1, block);
            }

            //transfer settings
            var contextType = controller.model.GetType();

            foreach (var setting in newContextController.model.GetSettings(true))
            {
                FieldInfo myField = contextType.GetField(setting.Name, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic);
                if (myField == null || myField.GetCustomAttributes(typeof(VFXSettingAttribute), true).Length == 0)
                {
                    continue;
                }

                object value;
                if (VFXConverter.TryConvertTo(myField.GetValue(controller.model), setting.FieldType, out value))
                {
                    newContextController.model.SetSettingValue(setting.Name, value);
                }
            }

            //transfer flow edges
            if (controller.flowInputAnchors.Count == 1)
            {
                foreach (var output in controller.flowInputAnchors[0].connections.Select(t => t.output).ToArray())
                {
                    newContextController.model.LinkFrom(output.context.model, output.slotIndex);
                }
            }

            // Apply the slot changes that can be the result of settings changes
            newContextController.ApplyChanges();

            //transfer master slot values
            foreach (var slot in newContextController.model.inputSlots)
            {
                VFXSlot mySlot = controller.model.inputSlots.FirstOrDefault(t => t.name == slot.name);
                if (mySlot == null)
                {
                    continue;
                }

                object value;
                if (VFXConverter.TryConvertTo(mySlot.value, slot.property.type, out value))
                {
                    slot.value = value;
                }
            }

            foreach (var anchor in newContextController.inputPorts)
            {
                string path     = anchor.path;
                var    myAnchor = controller.inputPorts.FirstOrDefault(t => t.path == path);

                if (myAnchor == null || !myAnchor.HasLink())
                {
                    continue;
                }

                //There should be only one
                var output = myAnchor.connections.First().output;

                viewController.CreateLink(anchor, output);
            }

            // Apply the change so that it won't unlink the blocks links
            controller.ApplyChanges();

            viewController.RemoveElement(controller);
        }
示例#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)
                {
                    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);
        }
示例#6
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);
        }