private void PasteParameters(VFXViewController viewController, ref SerializableGraph serializableGraph) { newParameters.Clear(); if (serializableGraph.parameters != null) { foreach (var parameter in serializableGraph.parameters) { // if we have a parameter with the same name use it else create it with the copied data VFXParameter p = viewController.graph.children.OfType <VFXParameter>().FirstOrDefault(t => t.GetInstanceID() == parameter.originalInstanceID); if (p == null) { Type type = parameter.value.type; VFXModelDescriptorParameters desc = VFXLibrary.GetParameters().FirstOrDefault(t => t.model.type == type); if (desc != null) { p = viewController.AddVFXParameter(Vector2.zero, desc); p.value = parameter.value.Get(); p.hasRange = parameter.range; if (parameter.range) { p.m_Min = parameter.min; p.m_Max = parameter.max; } p.SetSettingValue("m_Exposed", parameter.exposed); if (viewController.model.visualEffectObject is VisualEffectSubgraphOperator) { p.isOutput = parameter.isOutput; } p.SetSettingValue("m_ExposedName", parameter.name); // the controller will take care or name unicity later p.tooltip = parameter.tooltip; } } if (p == null) { newParameters.Add(new KeyValuePair <VFXParameter, List <int> >(null, null)); continue; } var newParameterNodes = new List <int>(); foreach (var node in parameter.nodes) { int nodeIndex = p.AddNode(node.position + pasteOffset); var nodeModel = p.nodes.LastOrDefault(t => t.id == nodeIndex); nodeModel.expanded = !node.collapsed; nodeModel.expandedSlots = AllSlots(p.outputSlots).Where(t => node.expandedOutput.Contains(t.path)).ToList(); m_NodesInTheSameOrder[node.indexInClipboard] = new VFXNodeID(p, nodeModel.id); newParameterNodes.Add(nodeIndex); } newParameters.Add(new KeyValuePair <VFXParameter, List <int> >(p, newParameterNodes)); } } }
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) })); } }
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) })); } } }
void TransfertDataEdges() { m_SourceControllersWithBlocks = m_SourceControllers.Concat(m_SourceControllers.OfType <VFXContextController>().SelectMany(t => t.blockControllers)); // Search for links between with inputs in the selected part and the output in other parts of the graph. Dictionary <VFXDataAnchorController, List <VFXDataAnchorController> > traversingInEdges = new Dictionary <VFXDataAnchorController, List <VFXDataAnchorController> >(); foreach (var edge in m_SourceController.dataEdges.Where( t => { if (parameterNodeControllers.Contains(t.output.sourceNode)) { return(false); } var inputInControllers = m_SourceControllersWithBlocks.Contains(t.input.sourceNode); var outputInControllers = m_SourceControllersWithBlocks.Contains(t.output.sourceNode); return(inputInControllers && !outputInControllers); } )) { List <VFXDataAnchorController> outputs = null; if (!traversingInEdges.TryGetValue(edge.input, out outputs)) { outputs = new List <VFXDataAnchorController>(); traversingInEdges[edge.input] = outputs; } outputs.Add(edge.output); } var newSourceInputs = traversingInEdges.Keys.ToArray(); for (int i = 0; i < newSourceInputs.Length; ++i) { VFXParameter newTargetParameter = m_TargetController.AddVFXParameter(Vector2.zero, VFXLibrary.GetParameters().First(t => t.model.type == newSourceInputs[i].portType)); m_TargetController.LightApplyChanges(); VFXParameterController newTargetParamController = m_TargetController.GetParameterController(newTargetParameter); newTargetParamController.exposed = true; var outputs = traversingInEdges[newSourceInputs[i]]; var linkedParameter = outputs.FirstOrDefault(t => t.sourceNode is VFXParameterNodeController); if (linkedParameter != null) { newTargetParamController.exposedName = (linkedParameter.sourceNode as VFXParameterNodeController).parentController.exposedName; } else { newTargetParamController.exposedName = newSourceInputs[i].name; } //first the equivalent of sourceInput in the target VFXNodeController targetNode = null; Vector2 position; if (newSourceInputs[i].sourceNode is VFXBlockController) { var blockController = newSourceInputs[i].sourceNode as VFXBlockController; if (m_TargetBlocks != null) { targetNode = m_TargetBlocks[m_SourceBlockControllers.IndexOf(blockController)]; position = blockController.contextController.position; } else { var targetContext = m_TargetControllers[m_SourceControllers.IndexOf(blockController.contextController)] as VFXContextController; targetNode = targetContext.blockControllers[blockController.index]; position = blockController.contextController.position; } } else { targetNode = m_TargetControllers[m_SourceControllers.IndexOf(newSourceInputs[i].sourceNode)]; position = targetNode.position; } VFXDataAnchorController targetAnchor = targetNode.inputPorts.First(t => t.path == newSourceInputs[i].path); position.y += targetAnchor.model.owner.inputSlots.IndexOf(targetAnchor.model) * 32; VFXNodeController parameterNode = m_TargetController.AddVFXParameter(position - new Vector2(200, 0), newTargetParamController, null); // Link the parameternode and the input in the target m_TargetController.CreateLink(targetAnchor, parameterNode.outputPorts[0]); if (m_SourceSlotContainer is VFXOperator) { (m_SourceSlotContainer as VFXOperator).ResyncSlots(true); } else if (m_SourceSlotContainer is VFXSubgraphBlock) { VFXSubgraphBlock blk = (m_SourceSlotContainer as VFXSubgraphBlock); blk.RecreateCopy(); blk.ResyncSlots(true); } else if (m_SourceSlotContainer is VFXSubgraphContext) { VFXSubgraphContext ctx = (m_SourceSlotContainer as VFXSubgraphContext); ctx.RecreateCopy(); ctx.ResyncSlots(true); } m_SourceNodeController.ApplyChanges(); //Link all the outputs to the matching input of the subgraph foreach (var output in outputs) { m_SourceController.CreateLink(m_SourceNodeController.inputPorts.First(t => t.model == m_SourceSlotContainer.inputSlots.Last()), output); } } }