Beispiel #1
0
        public void CreateFlowEdgesTest()
        {
            CreateTestAsset("GUITest4");

            var eventContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.kEvent).First();
            var eventContext     = m_ViewController.AddVFXContext(new Vector2(300, 100), eventContextDesc);

            var spawnerContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.kSpawner).First();
            var spawnerContext     = m_ViewController.AddVFXContext(new Vector2(300, 100), spawnerContextDesc);

            var initContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.kInit).First();
            var initContext     = m_ViewController.AddVFXContext(new Vector2(300, 100), initContextDesc);

            var updateContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.kUpdate).First();
            var updateContext     = m_ViewController.AddVFXContext(new Vector2(300, 1000), updateContextDesc);

            var outputContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.kOutput).First();
            var outputContext     = m_ViewController.AddVFXContext(new Vector2(300, 2000), outputContextDesc);

            m_ViewController.ApplyChanges();

            var contextControllers = new List <VFXContextController>();

            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == eventContext) as VFXContextController);
            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == spawnerContext) as VFXContextController);
            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == initContext) as VFXContextController);
            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == updateContext) as VFXContextController);
            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == outputContext) as VFXContextController);

            CreateFlowEdges(contextControllers);

            DestroyTestAsset("GUITest4");
        }
Beispiel #2
0
        public void CreateFlowEdgesTest()
        {
            EditTestAsset(3);

            var eventContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.Event).First();
            var eventContext     = m_ViewController.AddVFXContext(new Vector2(300, 100), eventContextDesc);

            var spawnerContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.Spawner).First();
            var spawnerContext     = m_ViewController.AddVFXContext(new Vector2(300, 100), spawnerContextDesc);

            var initContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.Init).First();
            var initContext     = m_ViewController.AddVFXContext(new Vector2(300, 100), initContextDesc);

            var updateContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.Update).First();
            var updateContext     = m_ViewController.AddVFXContext(new Vector2(300, 1000), updateContextDesc);

            var outputContextDesc = VFXLibrary.GetContexts().Where(t => t.model.contextType == VFXContextType.Output && t.model.name.Contains("Particle")).First();
            var outputContext     = m_ViewController.AddVFXContext(new Vector2(300, 2000), outputContextDesc);

            m_ViewController.ApplyChanges();

            var contextControllers = new List <VFXContextController>();

            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == eventContext) as VFXContextController);
            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == spawnerContext) as VFXContextController);
            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == initContext) as VFXContextController);
            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == updateContext) as VFXContextController);
            contextControllers.Add(m_ViewController.allChildren.OfType <VFXContextController>().First(t => t.model == outputContext) as VFXContextController);

            CreateFlowEdges(contextControllers);
        }
Beispiel #3
0
        VFXContextController CreateAllBlocks(VFXViewController viewController, VFXModelDescriptor <VFXContext> context, IEnumerable <VFXModelDescriptor <VFXBlock> > blocks)
        {
            var newContext = viewController.AddVFXContext(new Vector2(300, 2000), context);

            viewController.ApplyChanges();

            var contextController = viewController.nodes.Where(t => t is VFXContextController && (t as VFXContextController).model == newContext).First() as VFXContextController;

            Assert.AreEqual(contextController.model, newContext);

            // Adding every block compatible with an init context
            var newBlocks = new List <VFXBlock>();

            foreach (var block in blocks)
            {
                var newBlock = block.CreateInstance();
                contextController.AddBlock(0, newBlock);
                newBlocks.Add(newBlock);
            }

            viewController.ApplyChanges();

            //We are expecting the same list from block controllers than initial block model
            var intersection = contextController.blockControllers.Select(x => x.model).Intersect(newBlocks);

            Assert.AreEqual(newBlocks.Count, intersection.Count());
            Assert.AreEqual(newBlocks.Count, contextController.blockControllers.Count());

            return(contextController);
        }
Beispiel #4
0
        internal static void CreateSystems(VFXView view, VFXViewController viewController, int count, int offset, string name = null)
        {
            Func <int, VFXContextController> fnContextController = delegate(int i)
            {
                viewController.ApplyChanges();
                var controller = viewController.allChildren.OfType <VFXContextController>().Cast <VFXContextController>().ToArray();
                return(controller[i]);
            };

            var contextInitializeDesc = VFXLibrary.GetContexts().FirstOrDefault(o => o.name.Contains("Init"));
            var contextOutputDesc     = VFXLibrary.GetContexts().FirstOrDefault(o => o.name.StartsWith("Output Particle Quad"));

            for (int i = 0; i < count; ++i)
            {
                var output = viewController.AddVFXContext(new Vector2(2 * i, 2 * i), contextOutputDesc);
                var init   = viewController.AddVFXContext(new Vector2(i, i), contextInitializeDesc);

                var flowEdge = new VFXFlowEdgeController(fnContextController(2 * i + offset).flowInputAnchors.FirstOrDefault(), fnContextController(2 * i + offset + 1).flowOutputAnchors.FirstOrDefault());
                viewController.AddElement(flowEdge);
            }

            viewController.ApplyChanges();

            if (name != null)
            {
                var systems = GetFieldValue <VFXView, List <VFXSystemBorder> >(view, "m_Systems");
                foreach (var sys in systems)
                {
                    SetTextFieldValue(sys, name);
                    CallMethod(sys, "OnTitleBlur", new object[] { null });
                }
            }
        }
Beispiel #5
0
        internal static List <VFXBasicSpawner> CreateSpawners(VFXView view, VFXViewController viewController, int count, string name = null)
        {
            List <VFXBasicSpawner> spawners = new List <VFXBasicSpawner>();

            for (int i = 0; i != count; ++i)
            {
                var spawner = ScriptableObject.CreateInstance <VFXBasicSpawner>();
                spawners.Add(spawner);
                viewController.graph.AddChild(spawner);
            }

            viewController.ApplyChanges();

            if (name != null)
            {
                var elements           = view.Query().OfType <GraphElement>().ToList();
                var UIElts             = elements.OfType <VFXContextUI>().ToList();
                var contextUITextField = GetFieldValue <VFXContextUI, TextField>(UIElts[0], "m_TextField");
                contextUITextField.value = name;

                foreach (var contextUI in UIElts)
                {
                    SetFieldValue(contextUI, "m_TextField", contextUITextField);
                    CallMethod(contextUI, "OnTitleBlur", new object[] { null });
                }
            }

            return(spawners);
        }
Beispiel #6
0
        void CreateDataEdges(VFXViewController viewController, VFXContextController updateContext, List <VFXParameter> parameters)
        {
            viewController.ApplyChanges();
            foreach (var param in parameters)
            {
                VFXParameterNodeController paramController = viewController.allChildren.OfType <VFXParameterNodeController>().First(t => t.model == param);

                VFXDataAnchorController outputAnchor = paramController.outputPorts.First() as VFXDataAnchorController;
                System.Type             type         = outputAnchor.portType;

                bool found = false;
                foreach (var block in updateContext.blockControllers)
                {
                    foreach (var anchor in block.inputPorts)
                    {
                        if (anchor.portType == type)
                        {
                            found = true;
                            Assert.IsTrue((anchor as VFXDataAnchorController).model.Link(outputAnchor.model));
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #7
0
        void CreateFlowEdges(VFXViewController viewController, IList <VFXContextController> contextControllers)
        {
            for (int i = 0; i < contextControllers.Count() - 1; ++i)
            {
                VFXFlowEdgeController edgeController = new VFXFlowEdgeController(contextControllers[i + 1].flowInputAnchors.First(), contextControllers[i].flowOutputAnchors.First());
                viewController.AddElement(edgeController);
            }

            viewController.ApplyChanges();
        }
Beispiel #8
0
        void CreateAllBlocksExperiment(VFXViewController viewController, VFXModelDescriptor <VFXContext> context, IEnumerable <VFXModelDescriptor <VFXBlock> > blocks, bool applyChanges)
        {
            var newContext = viewController.AddVFXContext(new Vector2(300, 2000), context);

            //if (applyChanges) //Needed for retrieving the following contextController
            viewController.ApplyChanges();

            var contextController = viewController.nodes.Where(t => t is VFXContextController ctxController && ctxController.model == newContext).First() as VFXContextController;

            foreach (var block in blocks)
            {
                var newBlock = block.CreateInstance();
                contextController.AddBlock(0, newBlock);
            }

            if (applyChanges)
            {
                viewController.ApplyChanges();
            }
        }
Beispiel #9
0
        void CreateAllOperatorsExperiment(VFXViewController viewController, IEnumerable <VFXModelDescriptor <VFXOperator> > operators, bool applyChanges)
        {
            foreach (var op in operators)
            {
                viewController.AddVFXOperator(new Vector2(300, 2000), op);
            }

            if (applyChanges)
            {
                viewController.ApplyChanges();
            }
        }
        public void CopyPasteContextWithBlock()
        {
            var initContextDesc = VFXLibrary.GetContexts().Where(t => t.name == "Initialize").First();

            var newContext = m_ViewController.AddVFXContext(new Vector2(100, 100), initContextDesc);

            m_ViewController.ApplyChanges();

            Assert.AreEqual(m_ViewController.allChildren.Where(t => t is VFXContextController).Count(), 1);

            var contextController = m_ViewController.allChildren.OfType <VFXContextController>().First();

            Assert.AreEqual(contextController.model, newContext);

            var flipBookBlockDesc = VFXLibrary.GetBlocks().First(t => t.name == "Set Tex Index ");

            contextController.AddBlock(0, flipBookBlockDesc.CreateInstance());

            m_ViewController.ApplyChanges();

            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();

            VFXView view = window.graphView;

            view.controller = m_ViewController;

            view.ClearSelection();
            foreach (var element in view.Query().OfType <GraphElement>().ToList().OfType <ISelectable>())
            {
                view.AddToSelection(element);
            }

            VFXSlot boundsSlot = newContext.GetInputSlot(0);

            AABox originalBounds = new AABox()
            {
                center = Vector3.one, size = Vector3.one * 10
            };

            boundsSlot.value = originalBounds;

            VFXBlock flipBookBlock = m_ViewController.contexts.First().blockControllers.First().model;
            VFXSlot  minValueSlot  = flipBookBlock.GetInputSlot(0);


            float originalMinValue = 123.456f;

            minValueSlot.value = originalMinValue;

            view.CopySelectionCallback();

            boundsSlot.value = new AABox()
            {
                center = Vector3.zero, size = Vector3.zero
            };
            minValueSlot.value = 789f;

            view.PasteCallback();
            var elements = view.Query().OfType <GraphElement>().ToList();

            var contexts    = elements.OfType <VFXContextUI>().ToArray();
            var copyContext = elements.OfType <VFXContextUI>().Select(t => t.controller).First(t => t.model != newContext).model;

            var copyBoundsSlot = copyContext.GetInputSlot(0);
            var copyMinSlot    = copyContext[0].GetInputSlot(0);

            Assert.AreEqual((AABox)copyBoundsSlot.value, originalBounds);
            Assert.AreEqual((float)copyMinSlot.value, originalMinValue);
            Assert.AreNotEqual(copyContext.position, newContext.position);


            view.PasteCallback();

            elements = view.Query().OfType <GraphElement>().ToList();
            contexts = elements.OfType <VFXContextUI>().ToArray();

            var copy2Context = contexts.First(t => t.controller.model != newContext && t.controller.model != copyContext).controller.model;

            Assert.AreNotEqual(copy2Context.position, newContext.position);
            Assert.AreNotEqual(copy2Context.position, copyContext.position);
        }
        public void LinkPositionOrVectorAndDirection([ValueSource("usePosition")] bool usePosition)
        {
            var crossDesc     = VFXLibrary.GetOperators().FirstOrDefault(o => o.name.Contains("Cross"));
            var positionDesc  = VFXLibrary.GetParameters().FirstOrDefault(o => o.name.Contains("Position"));
            var vectorDesc    = VFXLibrary.GetParameters().FirstOrDefault(o => o.name == "Vector");
            var directionDesc = VFXLibrary.GetParameters().FirstOrDefault(o => o.name.Contains("Direction"));

            var cross     = m_ViewController.AddVFXOperator(new Vector2(1, 1), crossDesc);
            var position  = m_ViewController.AddVFXParameter(new Vector2(2, 2), positionDesc);
            var vector    = m_ViewController.AddVFXParameter(new Vector2(3, 3), vectorDesc);
            var direction = m_ViewController.AddVFXParameter(new Vector2(4, 4), directionDesc);

            (cross as IVFXOperatorUniform).SetOperandType(typeof(Vector3));

            m_ViewController.ApplyChanges();

            Func <IVFXSlotContainer, VFXNodeController> fnFindController = delegate(IVFXSlotContainer slotContainer)
            {
                var allController = m_ViewController.allChildren.OfType <VFXNodeController>();
                return(allController.FirstOrDefault(o => o.slotContainer == slotContainer));
            };

            var controllerCross = fnFindController(cross);

            var vA = new Vector3(2, 3, 4);

            position.outputSlots[0].value = new Position()
            {
                position = vA
            };
            vector.outputSlots[0].value = new Vector()
            {
                vector = vA
            };

            var vB = new Vector3(5, 6, 7);

            direction.outputSlots[0].value = new DirectionType()
            {
                direction = vB
            };

            var edgeControllerAppend_A = new VFXDataEdgeController(controllerCross.inputPorts.Where(o => o.portType == typeof(Vector3)).First(), fnFindController(usePosition ? position : vector).outputPorts.First());

            m_ViewController.AddElement(edgeControllerAppend_A);
            (cross as IVFXOperatorUniform).SetOperandType(typeof(Vector3));
            m_ViewController.ApplyChanges();

            var edgeControllerAppend_B = new VFXDataEdgeController(controllerCross.inputPorts.Where(o => o.portType == typeof(Vector3)).Last(), fnFindController(direction).outputPorts.First());

            m_ViewController.AddElement(edgeControllerAppend_B);
            (cross as IVFXOperatorUniform).SetOperandType(typeof(Vector3));
            m_ViewController.ApplyChanges();

            m_ViewController.ForceReload();

            Assert.AreEqual(1, cross.inputSlots[0].LinkedSlots.Count());
            Assert.AreEqual(1, cross.inputSlots[1].LinkedSlots.Count());

            var context = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation | VFXExpressionContextOption.ConstantFolding);

            var currentA = context.Compile(cross.inputSlots[0].GetExpression()).Get <Vector3>();
            var currentB = context.Compile(cross.inputSlots[1].GetExpression()).Get <Vector3>();
            var result   = context.Compile(cross.outputSlots[0].GetExpression()).Get <Vector3>();

            Assert.AreEqual((double)vA.x, (double)currentA.x, 0.001f);
            Assert.AreEqual((double)vA.y, (double)currentA.y, 0.001f);
            Assert.AreEqual((double)vA.z, (double)currentA.z, 0.001f);

            Assert.AreEqual((double)vB.normalized.x, (double)currentB.x, 0.001f);
            Assert.AreEqual((double)vB.normalized.y, (double)currentB.y, 0.001f);
            Assert.AreEqual((double)vB.normalized.z, (double)currentB.z, 0.001f);

            var expectedResult = Vector3.Cross(vA, vB.normalized);

            Assert.AreEqual((double)expectedResult.x, (double)result.x, 0.001f);
            Assert.AreEqual((double)expectedResult.y, (double)result.y, 0.001f);
            Assert.AreEqual((double)expectedResult.z, (double)result.z, 0.001f);
        }