Exemplo n.º 1
0
        public static string AdaptNodeOutput(AbstractMaterialNode node, int outputSlotId, ConcreteSlotValueType convertToType)
        {
            var outputSlot = node.FindOutputSlot <MaterialSlot>(outputSlotId);

            if (outputSlot == null)
            {
                return(kErrorString);
            }

            var convertFromType = outputSlot.concreteValueType;
            var rawOutput       = node.GetVariableNameForSlot(outputSlotId);

            if (convertFromType == convertToType)
            {
                return(rawOutput);
            }

            switch (convertToType)
            {
            case ConcreteSlotValueType.Vector1:
                return(string.Format("({0}).x", rawOutput));

            case ConcreteSlotValueType.Vector2:
                switch (convertFromType)
                {
                case ConcreteSlotValueType.Vector1:
                    return(string.Format("({0}.xx)", rawOutput));

                case ConcreteSlotValueType.Vector3:
                case ConcreteSlotValueType.Vector4:
                    return(string.Format("({0}.xy)", rawOutput));

                default:
                    return(kErrorString);
                }

            case ConcreteSlotValueType.Vector3:
                switch (convertFromType)
                {
                case ConcreteSlotValueType.Vector1:
                    return(string.Format("({0}.xxx)", rawOutput));

                case ConcreteSlotValueType.Vector2:
                    return(string.Format("({0}3({1}, 0.0))", node.precision, rawOutput));

                case ConcreteSlotValueType.Vector4:
                    return(string.Format("({0}.xyz)", rawOutput));

                default:
                    return(kErrorString);
                }

            case ConcreteSlotValueType.Vector4:
                switch (convertFromType)
                {
                case ConcreteSlotValueType.Vector1:
                    return(string.Format("({0}.xxxx)", rawOutput));

                case ConcreteSlotValueType.Vector2:
                    return(string.Format("({0}4({1}, 0.0, 1.0))", node.precision, rawOutput));

                case ConcreteSlotValueType.Vector3:
                    return(string.Format("({0}4({1}, 1.0))", node.precision, rawOutput));

                default:
                    return(kErrorString);
                }

            case ConcreteSlotValueType.Matrix3:
                return(rawOutput);

            case ConcreteSlotValueType.Matrix2:
                return(rawOutput);

            default:
                return(kErrorString);
            }
        }