public void ReorderBlock(int index, VFXBlock block) { if (block.GetParent() == base.model && model.GetIndex(block) < index) { --index; } if (index < 0 || index >= base.model.GetNbChildren()) { index = -1; } model.AddChild(block, index); }
internal static IEnumerable <VFXNamedExpression> GetSolverDataExpressions(VFXBlock block) { var context = block.GetParent(); var data = context.GetData(); var initializeBlock = data.owners .SelectMany((c) => c.activeChildrenWithImplicit, (_, b) => b) .FirstOrDefault((b) => b.GetType() == typeof(InitializeSolver)); if (initializeBlock) { return(initializeBlock.parameters.Where((expression) => !expression.name.Contains("_Tex"))); } else { var solverData = SolverData.defaultValue; return(solverData.defaultExpressions.Select((expression) => { expression.name = $"solverData_{expression.name}"; return expression; })); } }
static void CopyDataEdge(Data copyData, IEnumerable <VFXDataEdgeController> dataEdges, ScriptableObject[] allSerializedObjects) { copyData.dataEdges = new DataEdge[dataEdges.Count()]; int cpt = 0; var orderedEdges = new List <VFXDataEdgeController>(); var edges = new HashSet <VFXDataEdgeController>(dataEdges); // Ensure that operators that can change shape always all their input edges created before their output edges and in the same order bool sortFailed = false; try { while (edges.Count > 0) { var edgeInputs = edges.GroupBy(t => t.input.sourceNode).ToDictionary(t => t.Key, t => t.Select(u => u)); //Select the edges that have an input node which all its input edges have an output node that have no input edge // Order them by index var edgesWithoutParent = edges.Where(t => !edgeInputs[t.input.sourceNode].Any(u => edgeInputs.ContainsKey(u.output.sourceNode))).OrderBy(t => t.input.model.GetMasterSlot().owner.GetSlotIndex(t.input.model.GetMasterSlot())).ToList(); /*foreach(var gen in edgesWithoutParent) * { * int index = gen.input.model.GetMasterSlot().owner.GetSlotIndex(gen.input.model.GetMasterSlot()); * Debug.Log("Edge with input:" + gen.input.sourceNode.title + "index"+ index); * }*/ orderedEdges.AddRange(edgesWithoutParent); int count = edges.Count; foreach (var e in edgesWithoutParent) { edges.Remove(e); } if (edges.Count >= count) { sortFailed = true; Debug.LogError("Sorting of data edges failed. Please provide a screenshot of the graph with the selected node to @tristan"); break; } //Debug.Log("------------------------------"); } } catch (Exception e) { Debug.LogError("Sorting of data edges threw. Please provide a screenshot of the graph with the selected node to @tristan" + e.Message); sortFailed = true; } IEnumerable <VFXDataEdgeController> usedEdges = sortFailed ? dataEdges : orderedEdges; foreach (var edge in usedEdges) { DataEdge copyPasteEdge = new DataEdge(); var inputController = edge.input as VFXDataAnchorController; var outputController = edge.output as VFXDataAnchorController; copyPasteEdge.input.slotPath = MakeSlotPath(inputController.model, true); if (inputController.model.owner is VFXContext) { VFXContext context = inputController.model.owner as VFXContext; copyPasteEdge.inputContext = true; copyPasteEdge.input.targetIndex = System.Array.IndexOf(allSerializedObjects, context); copyPasteEdge.inputBlockIndex = -1; } else if (inputController.model.owner is VFXBlock) { VFXBlock block = inputController.model.owner as VFXBlock; copyPasteEdge.inputContext = true; copyPasteEdge.input.targetIndex = System.Array.IndexOf(allSerializedObjects, block.GetParent()); copyPasteEdge.inputBlockIndex = block.GetParent().GetIndex(block); } else { copyPasteEdge.inputContext = false; copyPasteEdge.input.targetIndex = System.Array.IndexOf(allSerializedObjects, inputController.model.owner as VFXModel); copyPasteEdge.inputBlockIndex = -1; } if (outputController.model.owner is VFXParameter) { copyPasteEdge.outputParameter = true; copyPasteEdge.outputParameterIndex = System.Array.FindIndex(copyData.parameters, t => (IVFXSlotContainer)t.parameter == outputController.model.owner); copyPasteEdge.outputParameterNodeIndex = System.Array.IndexOf(copyData.parameters[copyPasteEdge.outputParameterIndex].infos, (outputController.sourceNode as VFXParameterNodeController).infos); } else { copyPasteEdge.outputParameter = false; } copyPasteEdge.output.slotPath = MakeSlotPath(outputController.model, false); copyPasteEdge.output.targetIndex = System.Array.IndexOf(allSerializedObjects, outputController.model.owner as VFXModel); copyData.dataEdges[cpt++] = copyPasteEdge; } // Sort the edge so the one that links the node that have the least links }
internal static IEnumerable <VFXNamedExpression> GetExpressions( VFXBlock block, SolverDataParameters?solverDataParamsOverride = null ) { List <VFXNamedExpression> fluid = null; VFXExpression h = null; VFXExpression mass = null; VFXExpression density = null; VFXExpression gravity = null; var initializeBlock = block as InitializeSolver; if (initializeBlock == null) { var context = block.GetParent(); var data = context.GetData(); initializeBlock = data.owners .SelectMany((c) => c.activeChildrenWithImplicit, (_, b) => b) .FirstOrDefault((b) => b.GetType() == typeof(InitializeSolver)) as InitializeSolver; } if (initializeBlock) { fluid = new List <VFXNamedExpression>(); foreach (var expression in GetExpressionsFromSlots(initializeBlock)) { if (expression.name == $"{nameof(InputProperties.Fluid)}_{nameof(Fluid.SmoothingDistance)}") { // We use solverData_KernelSize instead h = expression.exp; continue; } else if (expression.name == $"{nameof(InputProperties.Fluid)}_{nameof(Fluid.ParticleMass)}") { mass = expression.exp; } else if (expression.name == $"{nameof(InputProperties.Fluid)}_{nameof(Fluid.Density)}") { density = expression.exp; } else if (expression.name == $"{nameof(InputProperties.Gravity)}") { // We'll add solverData_Gravity in separately gravity = expression.exp; continue; } fluid.Add(expression); } } var fluvioFxBlock = block as FluvioFXBlock; var expressions = GetExpressionsImpl( initializeBlock, solverDataParamsOverride ?? fluvioFxBlock?.solverDataParameters ?? SolverDataParameters.All, fluid, h, mass, density, gravity); foreach (var expression in expressions) { yield return(expression); } }