예제 #1
0
        public static string GetStoreAttributeCode(this VFXData data, VFXAttribute attribute, string value, string index)
        {
            var storeAttributeCode = data.GetStoreAttributeCode(attribute, value);
            var result             = $"{storeAttributeCode.Replace("(index *", $"({index} *")};";

            return(result);
        }
예제 #2
0
        private void PasteDatas(ref SerializableGraph serializableGraph)
        {
            for (int i = 0; i < newContexts.Count; ++i)
            {
                VFXNodeController nodeController = null;
                newControllers.TryGetValue(ContextFlag | (uint)i, out nodeController);
                var contextController = nodeController as VFXContextController;

                if (contextController != null)
                {
                    if ((contextController.flowInputAnchors.Count() == 0 ||
                         contextController.flowInputAnchors.First().connections.Count() == 0 ||
                         contextController.flowInputAnchors.First().connections.First().output.context.model.GetData() == null) &&
                        serializableGraph.contexts[i].dataIndex >= 0)
                    {
                        var     data       = serializableGraph.datas[serializableGraph.contexts[i].dataIndex];
                        VFXData targetData = contextController.model.GetData();
                        if (targetData != null)
                        {
                            PasteModelSettings(targetData, data.settings, targetData.GetType());
                            targetData.Invalidate(VFXModel.InvalidationCause.kSettingChanged);
                        }
                    }
                }
            }
        }
예제 #3
0
        public static string GetCodeOffset(this VFXData data, VFXAttribute attribute, string index)
        {
            // HACK: Reflection
            var layout = data.GetFieldValue <StructureOfArrayProvider>("m_layoutAttributeCurrent");

            return(layout.GetCodeOffset(attribute, index));
        }
        public void CheckAttributes()
        {
            var init   = ScriptableObject.CreateInstance <ContextTestInit>();
            var update = ScriptableObject.CreateInstance <ContextTestUpdate>();
            var output = ScriptableObject.CreateInstance <ContextTestOutput>();

            init.LinkTo(update);
            update.LinkTo(output);

            VFXData data = init.GetData();

            data.CollectAttributes();

            Assert.AreEqual(4, data.GetNbAttributes());

            Assert.IsTrue(data.IsAttributeStored(attrib1));
            Assert.IsTrue(data.IsAttributeStored(attrib2));
            Assert.IsTrue(data.IsAttributeLocal(attrib3));
            Assert.IsTrue(data.IsAttributeLocal(attrib4));

            Assert.IsTrue(data.IsCurrentAttributeRead(attrib1));
            Assert.IsTrue(data.IsCurrentAttributeRead(attrib2));
            Assert.IsTrue(data.IsCurrentAttributeRead(attrib3));
            Assert.IsFalse(data.IsCurrentAttributeRead(attrib4));

            Assert.IsTrue(data.IsCurrentAttributeWritten(attrib1));
            Assert.IsTrue(data.IsCurrentAttributeWritten(attrib2));
            Assert.IsFalse(data.IsCurrentAttributeWritten(attrib3));
            Assert.IsTrue(data.IsCurrentAttributeWritten(attrib4));
        }
예제 #5
0
        public static string GetLoadAttributeCode(this VFXData data, VFXAttribute attribute, string name, string index)
        {
            var r = new VFXShaderWriter();

            r.WriteVariable(
                attribute.type,
                name,
                data.GetLoadAttributeCode(attribute, VFXAttributeLocation.Current));
            var result = r.builder.ToString().Replace("(index *", $"({index} *");

            return(result);
        }
예제 #6
0
        internal static string CheckAlive(VFXData data)
        {
            var hasLifetime = data?.IsCurrentAttributeWritten(VFXAttribute.Alive) == true;

            if (hasLifetime)
            {
                return($@"{data.GetLoadAttributeCode(VFXAttribute.Alive, "isAlive", "index")}
if (!isAlive) return;
");
            }

            return("");
        }
예제 #7
0
        public static string GetStoreArrayCode(
            this VFXData data,
            VFXAttribute array0,
            string value,
            string index,
            string subIndex)
        {
            var array0Code = GetStoreAttributeCode(data, array0, value, "index");
            var result     = array0Code
                             .Replace("(index *", $"({index} *")
                             .Replace(") << ", $" + ({subIndex})) << ");

            return(result);
        }
예제 #8
0
        public string GetSource(VFXData data)
        {
            return($@"{FluvioFXBlock.CheckAlive(data)}
float invMass = 1.0f / mass;
float3 acceleration = force * invMass;
float3 v = dt * acceleration;

// Discard excessive velocities
if (any(isnan(v) || isinf(v)) || dot(v, v) > FLUVIO_MAX_SQR_VELOCITY_CHANGE)
{{
    v = 0;
}}
{source}");
        }
예제 #9
0
        public static string GetCompareExchangeCode(
            this VFXData data,
            VFXAttribute array0,
            string index,
            string dest,
            string compareValue,
            string value,
            string original
            )
        {
            var codeOffset = GetCodeOffset(data, array0, index)
                             .Replace(") << ", $" + ({dest})) << ");

            return($@"attributeBuffer.InterlockedCompareExchange({codeOffset}, {compareValue}, {value}, {original});");
        }
예제 #10
0
        public static VFXData GetVFXData(int offset)
        {
            VFXData vfxData = new VFXData();

            int datNum = ((offset / 8) & 0x000f) / 2;

            var decompBytes = Helper.GetType2DecompressedData(offset, datNum);

            using (BinaryReader br = new BinaryReader(new MemoryStream(decompBytes)))
            {
                int data = br.ReadInt32();

                while (data != 5531000)
                {
                    data = br.ReadInt32();
                }

                while (data == 5531000)
                {
                    var pathLength = br.ReadInt32();

                    string fullPath = Encoding.ASCII.GetString(br.ReadBytes(pathLength)).Replace("\0", "");

                    vfxData.VFXPaths.Add(fullPath);

                    int space = br.ReadByte();

                    while (space == 0)
                    {
                        space = br.ReadByte();
                    }

                    if (br.ReadInt16() == 21605)
                    {
                        br.ReadByte();
                    }
                    else
                    {
                        data = 0;
                    }
                }
            }
            return(vfxData);
        }
예제 #11
0
        public static IEnumerable <VFXAttributeInfo> GetReadableSizeAttributes(VFXData data, int nbComponents = 3)
        {
            if (nbComponents < 1 || nbComponents > 3)
            {
                throw new ArgumentException("NbComponents must be between 1 and 3");
            }

            if (nbComponents >= 1)
            {
                yield return(new VFXAttributeInfo(VFXAttribute.SizeX, VFXAttributeMode.Read));
            }
            if (nbComponents >= 2 && data.IsCurrentAttributeWritten(VFXAttribute.SizeY))
            {
                yield return(new VFXAttributeInfo(VFXAttribute.SizeY, VFXAttributeMode.Read));
            }
            if (nbComponents >= 3 && data.IsCurrentAttributeWritten(VFXAttribute.SizeZ))
            {
                yield return(new VFXAttributeInfo(VFXAttribute.SizeZ, VFXAttributeMode.Read));
            }
        }
예제 #12
0
        protected override void ModelChanged(UnityEngine.Object obj)
        {
            SyncControllers();
            // make sure we listen to the right data

            if (!object.ReferenceEquals(m_Data, null) && model.GetData() != m_Data)
            {
                viewController.UnRegisterNotification(m_Data, DataChanged);
                m_Data = null;
            }
            if (m_Data == null && model.GetData() != null)
            {
                m_Data = model.GetData();

                viewController.RegisterNotification(m_Data, DataChanged);
            }

            viewController.FlowEdgesMightHaveChanged();

            base.ModelChanged(obj);
        }
예제 #13
0
        static void PasteNodes(VFXViewController viewController, Vector2 center, Data copyData, ScriptableObject[] allSerializedObjects, VFXView view, VFXGroupNodeController groupNode)
        {
            var     graph       = viewController.graph;
            Vector2 pasteOffset = (copyData.bounds.width > 0 && copyData.bounds.height > 0) ? center - copyData.bounds.center : Vector2.zero;

            // look if pasting there will result in the first element beeing exactly on top of other
            while (true)
            {
                bool foundSamePosition = false;
                if (copyData.contexts != null && copyData.contexts.Length > 0)
                {
                    VFXContext firstContext = copyData.contexts[0];

                    foreach (var existingContext in viewController.graph.children.OfType <VFXContext>())
                    {
                        if ((firstContext.position + pasteOffset - existingContext.position).sqrMagnitude < 1)
                        {
                            foundSamePosition = true;
                            break;
                        }
                    }
                }
                else if (copyData.slotContainers != null && copyData.slotContainers.Length > 0)
                {
                    VFXModel firstContainer = copyData.slotContainers[0];

                    foreach (var existingSlotContainer in viewController.graph.children.Where(t => t is IVFXSlotContainer))
                    {
                        if ((firstContainer.position + pasteOffset - existingSlotContainer.position).sqrMagnitude < 1)
                        {
                            foundSamePosition = true;
                            break;
                        }
                    }
                }
                else
                {
                    VFXUI ui = allSerializedObjects.OfType <VFXUI>().First();

                    if (ui != null)
                    {
                        if (ui.stickyNoteInfos != null && ui.stickyNoteInfos.Length > 0)
                        {
                            foreach (var stickyNote in viewController.stickyNotes)
                            {
                                if ((ui.stickyNoteInfos[0].position.position + pasteOffset - stickyNote.position.position).sqrMagnitude < 1)
                                {
                                    foundSamePosition = true;
                                    break;
                                }
                            }
                        }
                        else if (ui.groupInfos != null && ui.groupInfos.Length > 0)
                        {
                            foreach (var gn in viewController.groupNodes)
                            {
                                if ((ui.groupInfos[0].position.position + pasteOffset - gn.position.position).sqrMagnitude < 1)
                                {
                                    foundSamePosition = true;
                                    break;
                                }
                            }
                        }
                    }
                }

                if (foundSamePosition)
                {
                    pasteOffset += Vector2.one * 30;
                }
                else
                {
                    break;
                }
            }


            if (copyData.contexts != null)
            {
                foreach (var slotContainer in copyData.contexts)
                {
                    var newContext = slotContainer;
                    newContext.position += pasteOffset;
                    ClearLinks(newContext);
                }
            }

            if (copyData.slotContainers != null)
            {
                foreach (var slotContainer in copyData.slotContainers)
                {
                    var newSlotContainer = slotContainer;
                    newSlotContainer.position += pasteOffset;
                    ClearLinks(newSlotContainer as IVFXSlotContainer);
                }
            }


            for (int i = 0; i < allSerializedObjects.Length; ++i)
            {
                ScriptableObject obj = allSerializedObjects[i];

                if (obj is VFXContext || obj is VFXOperator)
                {
                    graph.AddChild(obj as VFXModel);
                }
                else if (obj is VFXParameter)
                {
                    int paramIndex = System.Array.FindIndex(copyData.parameters, t => t.index == i);

                    VFXParameter existingParameter = graph.children.OfType <VFXParameter>().FirstOrDefault(t => t.GetInstanceID() == copyData.parameters[paramIndex].originalInstanceID);
                    if (existingParameter != null)
                    {
                        // The original parameter is from the current graph, add the nodes to the original
                        copyData.parameters[paramIndex].parameter       = existingParameter;
                        copyData.parameters[paramIndex].copiedParameter = obj as VFXParameter;

                        copyData.parameters[paramIndex].infoIndexOffset = existingParameter.nodes.Count;

                        foreach (var info in copyData.parameters[paramIndex].infos)
                        {
                            info.position += pasteOffset;
                        }

                        var oldIDs = copyData.parameters[paramIndex].infos.ToDictionary(t => t, t => t.id);

                        existingParameter.AddNodeRange(copyData.parameters[paramIndex].infos);

                        //keep track of new ids for groupnodes
                        copyData.parameters[paramIndex].idMap = copyData.parameters[paramIndex].infos.ToDictionary(t => oldIDs[t], t => t.id);
                    }
                    else
                    {
                        // The original parameter is from another graph : create the parameter in the other graph, but replace the infos with only the ones copied.
                        copyData.parameters[paramIndex].parameter = obj as VFXParameter;
                        copyData.parameters[paramIndex].parameter.SetNodes(copyData.parameters[paramIndex].infos);

                        graph.AddChild(obj as VFXModel);
                    }
                }
            }


            VFXUI copiedUI              = allSerializedObjects.OfType <VFXUI>().FirstOrDefault();
            int   firstCopiedGroup      = -1;
            int   firstCopiedStickyNote = -1;

            if (copiedUI != null)
            {
                VFXUI ui = viewController.graph.UIInfos;
                firstCopiedStickyNote = ui.stickyNoteInfos != null ? ui.stickyNoteInfos.Length : 0;

                if (copiedUI.groupInfos != null && copiedUI.groupInfos.Length > 0)
                {
                    if (ui.groupInfos == null)
                    {
                        ui.groupInfos = new VFXUI.GroupInfo[0];
                    }
                    firstCopiedGroup = ui.groupInfos.Length;

                    foreach (var groupInfos in copiedUI.groupInfos)
                    {
                        for (int i = 0; i < groupInfos.contents.Length; ++i)
                        {
                            // if we link the parameter node to an existing parameter instead of the copied parameter we have to patch the groupnode content to point the that parameter with the correct id.
                            if (groupInfos.contents[i].model is VFXParameter)
                            {
                                VFXParameter parameter = groupInfos.contents[i].model as VFXParameter;
                                var          paramInfo = copyData.parameters.FirstOrDefault(t => t.copiedParameter == parameter);
                                if (paramInfo.parameter != null) // parameter will not be null unless the struct returned is the default.
                                {
                                    groupInfos.contents[i].model = paramInfo.parameter;
                                    groupInfos.contents[i].id    = paramInfo.idMap[groupInfos.contents[i].id];
                                }
                            }
                            else if (groupInfos.contents[i].isStickyNote)
                            {
                                groupInfos.contents[i].id += firstCopiedStickyNote;
                            }
                        }
                    }

                    ui.groupInfos = ui.groupInfos.Concat(copiedUI.groupInfos.Select(t => new VFXUI.GroupInfo(t)
                    {
                        position = new Rect(t.position.position + pasteOffset, t.position.size)
                    })).ToArray();
                }
                if (copiedUI.stickyNoteInfos != null && copiedUI.stickyNoteInfos.Length > 0)
                {
                    if (ui.stickyNoteInfos == null)
                    {
                        ui.stickyNoteInfos = new VFXUI.StickyNoteInfo[0];
                    }
                    ui.stickyNoteInfos = ui.stickyNoteInfos.Concat(copiedUI.stickyNoteInfos.Select(t => new VFXUI.StickyNoteInfo(t)
                    {
                        position = new Rect(t.position.position + pasteOffset, t.position.size)
                    })).ToArray();
                }
            }

            CopyDataEdges(copyData, allSerializedObjects);


            if (copyData.flowEdges != null)
            {
                foreach (var flowEdge in copyData.flowEdges)
                {
                    VFXContext inputContext  = allSerializedObjects[flowEdge.input.contextIndex] as VFXContext;
                    VFXContext outputContext = allSerializedObjects[flowEdge.output.contextIndex] as VFXContext;

                    inputContext.LinkFrom(outputContext, flowEdge.input.flowIndex, flowEdge.output.flowIndex);
                }
            }

            foreach (var dataAndContexts in copyData.dataAndContexts)
            {
                VFXData data = allSerializedObjects[dataAndContexts.dataIndex] as VFXData;

                foreach (var contextIndex in dataAndContexts.contextsIndexes)
                {
                    VFXContext context = allSerializedObjects[contextIndex] as VFXContext;
                    data.CopySettings(context.GetData());
                }
            }

            // Create all ui based on model
            viewController.LightApplyChanges();

            if (view != null)
            {
                view.ClearSelection();

                var elements = view.graphElements.ToList();


                List <VFXNodeUI>    newSlotContainerUIs = new List <VFXNodeUI>();
                List <VFXContextUI> newContextUIs       = new List <VFXContextUI>();

                foreach (var slotContainer in allSerializedObjects.OfType <VFXContext>())
                {
                    VFXContextUI contextUI = elements.OfType <VFXContextUI>().FirstOrDefault(t => t.controller.model == slotContainer);
                    if (contextUI != null)
                    {
                        newSlotContainerUIs.Add(contextUI);
                        newSlotContainerUIs.AddRange(contextUI.GetAllBlocks().Cast <VFXNodeUI>());
                        newContextUIs.Add(contextUI);
                        view.AddToSelection(contextUI);
                    }
                }
                foreach (var slotContainer in allSerializedObjects.OfType <VFXOperator>())
                {
                    VFXOperatorUI slotContainerUI = elements.OfType <VFXOperatorUI>().FirstOrDefault(t => t.controller.model == slotContainer);
                    if (slotContainerUI != null)
                    {
                        newSlotContainerUIs.Add(slotContainerUI);
                        view.AddToSelection(slotContainerUI);
                    }
                }

                foreach (var param in copyData.parameters)
                {
                    foreach (var parameterUI in elements.OfType <VFXParameterUI>().Where(t => t.controller.model == param.parameter && param.parameter.nodes.IndexOf(t.controller.infos) >= param.infoIndexOffset))
                    {
                        newSlotContainerUIs.Add(parameterUI);
                        view.AddToSelection(parameterUI);
                    }
                }

                // Simply selected all data edge with the context or slot container, they can be no other than the copied ones
                foreach (var dataEdge in elements.OfType <VFXDataEdge>())
                {
                    if (newSlotContainerUIs.Contains(dataEdge.input.GetFirstAncestorOfType <VFXNodeUI>()))
                    {
                        view.AddToSelection(dataEdge);
                    }
                }
                // Simply selected all data edge with the context or slot container, they can be no other than the copied ones
                foreach (var flowEdge in elements.OfType <VFXFlowEdge>())
                {
                    if (newContextUIs.Contains(flowEdge.input.GetFirstAncestorOfType <VFXContextUI>()))
                    {
                        view.AddToSelection(flowEdge);
                    }
                }

                if (groupNode != null)
                {
                    foreach (var newSlotContainerUI in newSlotContainerUIs)
                    {
                        groupNode.AddNode(newSlotContainerUI.controller);
                    }
                }

                //Select all groups that are new
                if (firstCopiedGroup >= 0)
                {
                    foreach (var gn in elements.OfType <VFXGroupNode>())
                    {
                        if (gn.controller.index >= firstCopiedGroup)
                        {
                            view.AddToSelection(gn);
                        }
                    }
                }

                //Select all groups that are new
                if (firstCopiedStickyNote >= 0)
                {
                    foreach (var gn in elements.OfType <VFXStickyNote>())
                    {
                        if (gn.controller.index >= firstCopiedStickyNote)
                        {
                            view.AddToSelection(gn);
                        }
                    }
                }
            }
        }