Exemplo n.º 1
0
        public IEnumerator CollapseTest()
        {
            EditTestAsset(8);

            var builtInItem = VFXLibrary.GetOperators().Where(t => typeof(VFXDynamicBuiltInParameter).IsAssignableFrom(t.modelType)).First();

            var builtIn = m_ViewController.AddVFXOperator(Vector2.zero, builtInItem);

            yield return(null);

            builtIn.collapsed = true;

            yield return(null);

            yield return(null);

            builtIn.collapsed = false;

            yield return(null);

            yield return(null);

            builtIn.superCollapsed = true;

            yield return(null);

            yield return(null);

            builtIn.superCollapsed = false;
        }
Exemplo n.º 2
0
        public void CopyPasteOperator()
        {
            var crossOperatorDesc = VFXLibrary.GetOperators().Where(t => t.name == "Cross Product").First();

            var newOperator = m_ViewController.AddVFXOperator(new Vector2(100, 100), crossOperatorDesc);

            m_ViewController.ApplyChanges();
            var operatorController = m_ViewController.allChildren.OfType <VFXOperatorController>().First();

            Assert.AreEqual(operatorController.model, newOperator);

            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 aSlot = newOperator.GetInputSlot(0);

            Vector3 originalA = Vector3.one * 123;

            aSlot.value = originalA;

            string copyData = view.SerializeElements(view.selection.OfType <GraphElement>());

            aSlot.value = Vector3.one * 456;

            view.UnserializeAndPasteElements("paste", copyData);

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

            var copyOperator = elements.OfType <VFXOperatorUI>().First(t => t.controller.model != newOperator);

            var copaASlot = copyOperator.controller.model.GetInputSlot(0);

            Assert.AreEqual((Vector3)copaASlot.value, originalA);

            Assert.AreNotEqual(copyOperator.controller.model.position, newOperator.position);

            view.UnserializeAndPasteElements("paste", copyData);

            elements = view.Query().OfType <GraphElement>().ToList();
            var copy2Operator = elements.OfType <VFXOperatorUI>().First(t => t.controller.model != newOperator && t != copyOperator);

            Assert.AreNotEqual(copy2Operator.controller.model.position, newOperator.position);
            Assert.AreNotEqual(copy2Operator.controller.model.position, copyOperator.controller.model.position);
        }
        VFXNodeController CreateNew(string name, Vector2 position, Type nodeType = null)
        {
            var desc = VFXLibrary.GetOperators().FirstOrDefault(o => o.name.Contains(name) && (nodeType == null || o.modelType == nodeType));
            var op   = m_ViewController.AddVFXOperator(position, desc);

            m_ViewController.LightApplyChanges();

            return(m_ViewController.GetRootNodeController(op, 0));
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
        List <VFXOperator> CreateAllOperators()
        {
            List <VFXOperator> operators = new List <VFXOperator>();

            int cpt = 0;

            foreach (var op in VFXLibrary.GetOperators())
            {
                operators.Add(m_ViewController.AddVFXOperator(new Vector2(700, 150 * cpt), op));
                ++cpt;
            }

            return(operators);
        }
        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);
        }