Beispiel #1
0
        public void Space_Slot_Sanitize_Still_Possible_ArcSphere([ValueSource("trueOrFalse")] bool fromParentToChildSanitize, [ValueSource("trueOrFalse")] bool hackChildSphere)
        {
            var branch = ScriptableObject.CreateInstance <Operator.Branch>();

            branch.SetOperandType(typeof(ArcSphere));

            var slot = branch.inputSlots[1];

            Assert.AreEqual(typeof(ArcSphere), slot.property.type);

            slot.space = VFXCoordinateSpace.World;
            Assert.AreEqual(VFXCoordinateSpace.World, slot.space);

            var slotToHack = hackChildSphere ? slot : slot.children.First();

            slotToHack.AddChild(VFXSlot.Create(new VFXProperty(typeof(float), "hacked"), VFXSlot.Direction.kInput), -1, false);
            if (fromParentToChildSanitize)
            {
                slot.Sanitize(-1);
                slot.children.First().Sanitize(-1);
            }
            else
            {
                slot.children.First().Sanitize(-1);
                slot.Sanitize(-1);
            }
            Assert.AreEqual(VFXCoordinateSpace.World, branch.inputSlots[1].space);
        }
Beispiel #2
0
        private static bool IsSlotCompatible(Type output, Type input)
        {
            var slotOutput = VFXSlot.Create(new VFXProperty(output, "o"), VFXSlot.Direction.kOutput);
            var slotInput  = VFXSlot.Create(new VFXProperty(input, "i"), VFXSlot.Direction.kInput);

            return(slotOutput.CanLink(slotInput));
        }
        public void ImplicitExpressionTransferWithCompoundType()
        {
            var outputSlot = VFXSlot.Create(new VFXProperty(typeof(ArcSphere), "o"), VFXSlot.Direction.kOutput);
            var inputSlot  = VFXSlot.Create(new VFXProperty(typeof(ArcSphere), "i"), VFXSlot.Direction.kInput);

            var radius = 123.0f;

            outputSlot.children.FirstOrDefault(o => o.name == "sphere").children.FirstOrDefault(o => o.name == "radius").value = radius;
            inputSlot.Link(outputSlot);
            Assert.AreEqual(radius, inputSlot.children.FirstOrDefault(o => o.name == "sphere").children.FirstOrDefault(o => o.name == "radius").GetExpression().Get <float>());
        }
Beispiel #4
0
        private static int FindOrComputeExpressionCountPerType(Type type)
        {
            int count = -1;

            if (!s_ExpressionCountPerType.TryGetValue(type, out count))
            {
                var tempInstance = VFXSlot.Create(new VFXPropertyWithValue(new VFXProperty(type, "temp")), VFXSlot.Direction.kInput);
                count = tempInstance.GetExpressionSlots().Count();
                s_ExpressionCountPerType.Add(type, count);
            }
            return(count);
        }
Beispiel #5
0
        private static Dictionary <Type, Type[]> ComputeHeuristcalAffinity()
        {
            /* Heuristical function which is a bit expensive but expects the same result as kTypeAffinity */
            var inputType = new[]
            {
                typeof(Matrix4x4),
                typeof(Vector4),
                typeof(Color),
                typeof(Vector3),
                typeof(Position),
                typeof(DirectionType),
                typeof(Vector),
                typeof(Vector2),
                typeof(float),
                typeof(int),
                typeof(uint),
            };

            var inputTypeHeurisicalDict = inputType.Select(o =>
            {
                var baseValueType       = VFXSlot.Create(new VFXProperty(o, "temp1"), VFXSlot.Direction.kOutput).DefaultExpr.valueType;
                var baseChannelCount    = VFXExpression.TypeToSize(baseValueType);
                var baseIsKindOfInteger = o == typeof(uint) || o == typeof(int);

                var compatibleSlotMetaData = inputType
                                             .Where(s => s != o && IsSlotCompatible(o, s))
                                             .Select(s =>
                {
                    var otherValueType       = VFXSlot.Create(new VFXProperty(s, "temp2"), VFXSlot.Direction.kOutput).DefaultExpr.valueType;
                    var otherChannelCount    = VFXExpression.TypeToSize(otherValueType);
                    var otherIsKindOfInteger = s == typeof(uint) || s == typeof(int);

                    return(new
                    {
                        type = s,
                        diffType = otherValueType == baseValueType ? 0 : 1,
                        diffChannelCount = Mathf.Abs(baseChannelCount - otherChannelCount),
                        diffPreferInteger = baseIsKindOfInteger == otherIsKindOfInteger ? 0 : 1
                    });
                }).OrderBy(s => s.diffType)
                                             .ThenBy(s => s.diffChannelCount)
                                             .ThenBy(s => s.diffPreferInteger)
                                             .ToArray();

                return(new KeyValuePair <Type, Type[]>
                       (
                           o,
                           compatibleSlotMetaData.Select(s => s.type).ToArray()
                       ));
            }).ToDictionary(x => x.Key, x => x.Value);

            return(inputTypeHeurisicalDict);
        }
Beispiel #6
0
        public void Link()
        {
            VFXSlot input  = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput);
            VFXSlot output = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kOutput);

            input.Link(output);

            Assert.AreEqual(1, input.GetNbLinks());
            Assert.AreEqual(1, output.GetNbLinks());
            Assert.AreEqual(output, input.refSlot);
            Assert.AreEqual(output, output.refSlot);
        }
        public void DynamicSlots()
        {
            var model = ScriptableObject.CreateInstance <DynamicSlotContainer>();

            Assert.AreEqual(1, model.GetNbInputSlots());
            Assert.AreEqual(new VFXProperty(typeof(float), "f"), model.GetInputSlot(0).property);
            Assert.AreEqual(1.0f, model.GetInputSlot(0).value);

            model.SetSettingValue("slotSetting", 1);
            Assert.AreEqual(2, model.GetNbInputSlots());
            Assert.AreEqual(new VFXProperty(typeof(Vector3), "v"), model.GetInputSlot(0).property);
            Assert.AreEqual(Vector3.one, model.GetInputSlot(0).value);
            Assert.AreEqual(new VFXProperty(typeof(float), "f"), model.GetInputSlot(1).property);
            Assert.AreEqual(1.0f, model.GetInputSlot(1).value); // Must have conserve the value from previous slot

            model.SetSettingValue("slotSetting", 2);
            Assert.AreEqual(3, model.GetNbInputSlots());
            Assert.AreEqual(new VFXProperty(typeof(float), "f"), model.GetInputSlot(0).property);
            Assert.AreEqual(1.0f, model.GetInputSlot(0).value);
            Assert.AreEqual(new VFXProperty(typeof(Vector3), "v"), model.GetInputSlot(1).property);
            Assert.AreEqual(Vector3.one, model.GetInputSlot(1).value);
            Assert.AreEqual(new VFXProperty(typeof(float), "f"), model.GetInputSlot(2).property);
            Assert.AreEqual(2.0f, model.GetInputSlot(2).value);

            var outputSlot = VFXSlot.Create(new VFXProperty(typeof(Vector3), "o"), VFXSlot.Direction.kOutput);

            model.GetInputSlot(1).Link(outputSlot);
            model.GetInputSlot(1).value = new Vector3(1.0f, 2.0f, 3.0f);

            model.SetSettingValue("slotSetting", 3);
            Assert.AreEqual(2, model.GetNbInputSlots());
            Assert.AreEqual(new VFXProperty(typeof(Vector3), "v"), model.GetInputSlot(0).property);
            Assert.AreEqual(new Vector3(1.0f, 2.0f, 3.0f), model.GetInputSlot(0).value);
            Assert.AreEqual(1, model.GetInputSlot(0).GetNbLinks());
            Assert.AreEqual(new VFXProperty(typeof(Vector2), "v2"), model.GetInputSlot(1).property);
            Assert.AreEqual(Vector2.zero, model.GetInputSlot(1).value);

            model.SetSettingValue("slotSetting", 4);
            Assert.AreEqual(2, model.GetNbInputSlots());
            Assert.AreEqual(new VFXProperty(typeof(Vector3), "v"), model.GetInputSlot(0).property);
            Assert.AreEqual(new Vector3(1.0f, 2.0f, 3.0f), model.GetInputSlot(0).value);
            Assert.AreEqual(1, model.GetInputSlot(0).GetNbLinks());
            Assert.AreEqual(new VFXProperty(typeof(Vector2), "v2"), model.GetInputSlot(1).property);
            Assert.AreEqual(Vector2.zero, model.GetInputSlot(1).value);


            model.SetSettingValue("slotSetting", 1);
            Assert.IsTrue(model.GetInputSlot(0).property.attributes.Length == 0);

            model.SetSettingValue("slotSetting", 5);
            Assert.IsTrue(model.GetInputSlot(0).property.attributes.Length == 1);
        }
Beispiel #8
0
 public override void Sanitize()
 {
     if (mode == Mode.LookAtPosition)
     {
         /* Slot of type position has changed from undefined VFXSlot to VFXSlotPosition*/
         if (GetNbInputSlots() > 0 && !(GetInputSlot(0) is VFXSlotPosition))
         {
             var oldValue = GetInputSlot(0).value;
             RemoveSlot(GetInputSlot(0));
             AddSlot(VFXSlot.Create(new VFXProperty(typeof(Position), "Position"), VFXSlot.Direction.kInput, oldValue));
         }
     }
     base.Sanitize();
 }
Beispiel #9
0
        private void CheckVectorSlotCreation(Type type, VFXSlot.Direction direction, int expectionChildrenNb)
        {
            VFXSlot slot = VFXSlot.Create(new VFXProperty(type, "test"), direction);

            Assert.IsNotNull(slot);
            Assert.AreEqual(expectionChildrenNb, slot.GetNbChildren());
            Assert.IsInstanceOf <VFXExpressionCombine>(slot.GetExpression());

            foreach (var child in slot.children)
            {
                Assert.IsNotNull(child);
                Assert.AreEqual(0, child.GetNbChildren());
                Assert.IsInstanceOf <VFXExpressionExtractComponent>(child.GetExpression());
            }
        }
Beispiel #10
0
 public override void Sanitize(int version)
 {
     if (mode == Mode.LookAtPosition)
     {
         /* Slot of type position has changed from undefined VFXSlot to VFXSlotPosition*/
         if (GetNbInputSlots() > 0 && !(GetInputSlot(0) is VFXSlotPosition))
         {
             VFXSlot oldSlot  = GetInputSlot(0);
             var     oldValue = oldSlot.value;
             VFXSlot newSlot  = VFXSlot.Create(new VFXProperty(typeof(Position), "Position"), VFXSlot.Direction.kInput, oldValue);
             ReplaceSlot(oldSlot, newSlot);
         }
     }
     base.Sanitize(version);
 }
Beispiel #11
0
        public void Space_Slot_Sanitize_Still_Possible_Simple_Sphere()
        {
            var branch = ScriptableObject.CreateInstance <Operator.Branch>();

            branch.SetOperandType(typeof(Sphere));

            var slot = branch.inputSlots[1];

            Assert.AreEqual(typeof(Sphere), slot.property.type);

            slot.space = VFXCoordinateSpace.World;
            Assert.AreEqual(VFXCoordinateSpace.World, slot.space);
            slot.AddChild(VFXSlot.Create(new VFXProperty(typeof(float), "hacked"), VFXSlot.Direction.kInput), -1, false);
            slot.Sanitize(-1);
            Assert.AreEqual(VFXCoordinateSpace.World, branch.inputSlots[1].space);
        }
Beispiel #12
0
        public void Link_Fail()
        {
            VFXSlot input0 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput);
            VFXSlot input1 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput);

            VFXSlot output0 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput);
            VFXSlot output1 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput);

            input0.Link(input1);
            output0.Link(output1);

            Assert.AreEqual(0, input0.GetNbLinks());
            Assert.AreEqual(0, input1.GetNbLinks());
            Assert.AreEqual(0, output0.GetNbLinks());
            Assert.AreEqual(0, output1.GetNbLinks());
        }
Beispiel #13
0
        public void UnlinkAll()
        {
            const int NB_INPUTS = 10;

            VFXSlot output = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kOutput);

            for (int i = 0; i < NB_INPUTS; ++i)
            {
                output.Link(VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput));
            }

            Assert.AreEqual(NB_INPUTS, output.GetNbLinks());

            output.UnlinkAll();

            Assert.AreEqual(0, output.GetNbLinks());
        }
        public void AddSlot()
        {
            var model = ScriptableObject.CreateInstance <TestSlotContainer>();

            var inputSlot = VFXSlot.Create(new VFXProperty(typeof(Texture2D), "t"), VFXSlot.Direction.kInput);

            Assert.IsNull(inputSlot.owner);
            model.AddSlot(inputSlot);
            Assert.AreEqual(model, inputSlot.owner);
            Assert.AreEqual(3, model.GetNbInputSlots());
            Assert.AreEqual(inputSlot, model.GetInputSlot(2));

            var outputSlot = VFXSlot.Create(new VFXProperty(typeof(Texture2D), "t"), VFXSlot.Direction.kOutput);

            Assert.IsNull(outputSlot.owner);
            model.AddSlot(outputSlot);
            Assert.AreEqual(model, outputSlot.owner);
            Assert.AreEqual(3, model.GetNbOutputSlots());
            Assert.AreEqual(outputSlot, model.GetOutputSlot(2));
        }
Beispiel #15
0
        public void CheckExpression()
        {
            VFXSlot sphereSlot = VFXSlot.Create(new VFXProperty(typeof(Sphere), "sphere"), VFXSlot.Direction.kInput);
            VFXSlot floatSlot  = VFXSlot.Create(new VFXProperty(typeof(float), "float"), VFXSlot.Direction.kOutput);

            sphereSlot[0][0].Link(floatSlot);
            sphereSlot[1].Link(floatSlot);

            var expr = sphereSlot[0][0].GetExpression();

            Assert.IsInstanceOf <VFXExpressionExtractComponent>(expr);
            Assert.AreEqual(floatSlot.GetExpression(), expr.parents[0].parents[0]);
            Assert.AreEqual(floatSlot.GetExpression(), sphereSlot[1].GetExpression());

            floatSlot.UnlinkAll();
            expr = sphereSlot[0][0].GetExpression();
            Assert.IsInstanceOf <VFXExpressionExtractComponent>(expr);
            Assert.AreNotEqual(floatSlot.GetExpression(), expr.parents[0].parents[0]);
            Assert.AreNotEqual(floatSlot.GetExpression(), sphereSlot[1].GetExpression());
        }
Beispiel #16
0
        public void Link_Multiple()
        {
            VFXSlot input0  = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput);
            VFXSlot input1  = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kInput);
            VFXSlot output0 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kOutput);
            VFXSlot output1 = VFXSlot.Create(new VFXProperty(typeof(float), "test"), VFXSlot.Direction.kOutput);

            output0.Link(input0);
            output0.Link(input1);

            Assert.AreEqual(2, output0.GetNbLinks());

            output1.Link(input0);

            Assert.AreEqual(1, input0.GetNbLinks());
            Assert.AreEqual(1, input1.GetNbLinks());
            Assert.AreEqual(1, output0.GetNbLinks());
            Assert.AreEqual(1, output1.GetNbLinks());
            Assert.AreEqual(output1, input0.refSlot);
            Assert.AreEqual(output0, input1.refSlot);
        }
Beispiel #17
0
        public void Space_Slot_Sanitize_Still_Possible_Even_With_Linked_Slot([ValueSource("trueOrFalse")] bool reverseSanitizeOrdering, [ValueSource("trueOrFalse")] bool hackArcSphere, [ValueSource("trueOrFalse")] bool hackSphere)
        {
            var inlineOpSphere = ScriptableObject.CreateInstance <VFXInlineOperator>();

            inlineOpSphere.SetSettingValue("m_Type", (SerializableType)typeof(Sphere));
            inlineOpSphere.inputSlots[0].space = VFXCoordinateSpace.World;

            var inlineOpArcSphere = ScriptableObject.CreateInstance <VFXInlineOperator>();

            inlineOpArcSphere.SetSettingValue("m_Type", (SerializableType)typeof(ArcSphere));
            inlineOpArcSphere.inputSlots[0].space = VFXCoordinateSpace.Local;

            inlineOpSphere.outputSlots[0].Link(inlineOpArcSphere.inputSlots[0][0]);
            Assert.IsTrue(inlineOpSphere.outputSlots[0].HasLink());
            {
                var allExpr = CollectParentExpression(inlineOpArcSphere.outputSlots[0][0][0].GetExpression()).ToArray();
                Assert.IsTrue(allExpr.Count(o =>
                {
                    return(o.operation == VFXExpressionOperation.WorldToLocal);
                }) == 1);
            }

            var objs = new HashSet <ScriptableObject>();

            inlineOpSphere.CollectDependencies(objs);
            inlineOpArcSphere.CollectDependencies(objs);

            //Hacking type to simulation a change of type description
            var allSlot    = objs.OfType <VFXSlot>();
            var hackedSlot = Enumerable.Empty <VFXSlot>();

            if (hackArcSphere)
            {
                hackedSlot = hackedSlot.Concat(allSlot.Where(o => o.property.type == typeof(ArcSphere)));
            }

            if (hackSphere)
            {
                hackedSlot = hackedSlot.Concat(allSlot.Where(o => o.property.type == typeof(Sphere)));
            }

            foreach (var slotToHack in hackedSlot)
            {
                slotToHack.AddChild(VFXSlot.Create(new VFXProperty(typeof(float), "hacked"), VFXSlot.Direction.kInput), -1, false);
            }

            //Apply Sanitize
            var objsEnumerable = objs.AsEnumerable <ScriptableObject>();

            if (reverseSanitizeOrdering)
            {
                objsEnumerable = objsEnumerable.Reverse();
            }

            foreach (var obj in objsEnumerable.OfType <VFXModel>())
            {
                obj.Sanitize(-1);
            }

            if (!hackArcSphere)
            {
                Assert.IsTrue(inlineOpSphere.outputSlots[0].HasLink());
            } // else, expected disconnection, parent has changed (log a message like this " didnt match the type layout. It is recreated and all links are lost.")

            if (inlineOpSphere.outputSlots[0].HasLink())
            {
                var allExpr = CollectParentExpression(inlineOpArcSphere.outputSlots[0][0][0].GetExpression()).ToArray();
                Assert.IsTrue(allExpr.Count(o =>
                {
                    return(o.operation == VFXExpressionOperation.WorldToLocal);
                }) == 1);
            }
        }