コード例 #1
0
        private void ReadData()
        {
            Console.WriteLine("\n-----Attributes-----");
            Console.WriteLine(_binaryReader.BaseStream.Position);


            List <ArrayList> elementList = new List <ArrayList>();

            //List<ArrayList> elementList = new List<List<ArrayList>>();

            //TODO add support for binary 5, undocumented not sure how to read
            if (pcf.BinaryVersion == 5)
            {
                return;
            }

            for (int i = 0; i < pcf.NumElements; i++)
            {
                //List that stores all types of dmxAttributes
                ArrayList attributeList = new ArrayList();

                //Get number of element attribs
                int numElementAttribs = _binaryReader.ReadInt32();
                for (int w = 0; w < numElementAttribs; w++)
                {
                    //Console.WriteLine($"\n-----Index: {w}-----");

                    DmxAttribute dmxAttribute = new DmxAttribute
                    {
                        typeNameIndex = _binaryReader.ReadUInt16(),
                        attributeType = _binaryReader.ReadByte(),
                    };

                    dmxAttribute.typeName = pcf.StringDict[dmxAttribute.typeNameIndex];

                    //Console.WriteLine($"Number Of Element Attributes: {numElementAttribs}");
                    //Console.WriteLine($"TypeName Index: {dmxAttribute.typeNameIndex}");
                    //Console.WriteLine($"TypeName: {pcf.StringDict[dmxAttribute.typeNameIndex]}");
                    //Console.WriteLine($"Attribute Type: {dmxAttribute.attributeType}");

                    //Read attribute info and store in list

                    attributeList.Add(ReadAttrib(dmxAttribute));

                    //Console.WriteLine("--------------------");
                }
                //Add attributes to element
                pcf.ElementAttributes.Add(attributeList);
            }

            //pcf.ElementAttributes = elementList;
        }
コード例 #2
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeMatrix(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #3
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeQuaternion(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #4
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeQAngle(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #5
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeVector4(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #6
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeColor(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #7
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeTime(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #8
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeBinary(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #9
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeString(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #10
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeBoolean(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #11
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeFloat(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #12
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 public DmxAttributeInteger(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #13
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 //Constructor that copies values from base attribute class
 public DmxAttributeElement(DmxAttribute attribute) : base(attribute)
 {
 }
コード例 #14
0
ファイル: PCF.cs プロジェクト: Exactol/PCFParse
 //Constructor to construct derived classes from this class
 public DmxAttribute(DmxAttribute copy)
 {
     typeNameIndex = copy.typeNameIndex;
     attributeType = copy.attributeType;
     typeName      = copy.typeName;
 }
コード例 #15
0
        //Returns generic type
        private dynamic ReadAttrib(DmxAttribute attribute)
        {
            int attributeType = attribute.attributeType;

            //number of elements in an attribute array
            int numArrayItems = 0;

            //Read different data types depending on what attribute type is
            switch (attributeType)
            {
            case (ELEMENT):
                //Console.WriteLine("Attribute Type: Element");

                DmxAttributeElement dmxElement = new DmxAttributeElement(attribute);
                dmxElement.index = _binaryReader.ReadInt32();

                //Console.WriteLine($"Attribute Int Value: {dmxElement.index}");
                return(dmxElement);

            case (INTEGER):
                //Console.WriteLine("Attribute Type: Integer");

                DmxAttributeInteger dmxInteger = new DmxAttributeInteger(attribute);
                dmxInteger.attribInt = _binaryReader.ReadInt32();

                //Console.WriteLine($"Attribute Int Value: {dmxInteger.attribInt}");
                return(dmxInteger);

            case (FLOAT):
                //Console.WriteLine("Attribute Type: Float");

                DmxAttributeFloat dmxFloat = new DmxAttributeFloat(attribute);
                dmxFloat.attribFloat = _binaryReader.ReadSingle();

                //Console.WriteLine($"Attribute Float Value: {dmxFloat.attribFloat}");
                return(dmxFloat);

            case (BOOLEAN):
                //Console.WriteLine("Attribute Type: Boolean");

                DmxAttributeBoolean dmxBool = new DmxAttributeBoolean(attribute);
                dmxBool.attribBool = _binaryReader.ReadBoolean();

                //Console.WriteLine($"Attribute Bool Value: {dmxBool.attribBool}");
                return(dmxBool);

            case (STRING):
                //Console.WriteLine("Attribute Type: String");

                DmxAttributeString dmxString = new DmxAttributeString(attribute);

                if (pcf.BinaryVersion != 4 && pcf.BinaryVersion != 5)
                {
                    dmxString.attribString = ReadNullTerminatedString();
                }
                else
                {
                    //Binary 4 pcfs store only index into string dict
                    dmxString.stringIndex  = _binaryReader.ReadUInt16();
                    dmxString.attribString = pcf.StringDict[dmxString.stringIndex];
                }
                //Console.WriteLine($"Attribute String Value: {dmxString.attribString}");
                return(dmxString);

            case (BINARY):
                //Console.WriteLine("Attribute Type: Binary");

                DmxAttributeBinary dmxBinary = new DmxAttributeBinary(attribute);
                dmxBinary.length     = _binaryReader.ReadUInt32();
                dmxBinary.attribByte = new byte[dmxBinary.length];

                //Read specified # of bytes
                List <byte> byteBuff = new List <byte>();
                //Console.WriteLine($"Binary Length: {dmxBinary.length}");
                for (int y = 0; y < dmxBinary.length; y++)
                {
                    byteBuff.Add(_binaryReader.ReadByte());
                }
                dmxBinary.attribByte = byteBuff.ToArray();
                byteBuff.Clear();

                //Console.WriteLine($"Attribute Byte Value: {BitConverter.ToString(dmxBinary.attribByte)}");
                return(dmxBinary);

            case (TIME):
                //Console.WriteLine("Attribute Type: Time");

                DmxAttributeTime dmxTime = new DmxAttributeTime(attribute);
                dmxTime.attribTime = _binaryReader.ReadInt32();

                //Console.WriteLine($"Attribute Time Value: {dmxTime.attribTime}");
                return(dmxTime);

            case (COLOR):
                //Console.WriteLine("Attribute Type: Color");

                DmxAttributeColor dmxColor = new DmxAttributeColor(attribute);
                dmxColor.attribRed   = _binaryReader.ReadByte();
                dmxColor.attribGreen = _binaryReader.ReadByte();
                dmxColor.attribBlue  = _binaryReader.ReadByte();
                dmxColor.attribAlpha = _binaryReader.ReadByte();

                //Console.WriteLine($"Attribute Color Value: {dmxColor.attribRed}, {dmxColor.attribBlue}, {dmxColor.attribGreen}, {dmxColor.attribAlpha}");
                return(dmxColor);

            case (VECTOR2):
                //Console.WriteLine("Attribute Type: Vector2");

                DmxAttributeVector2 dmxVec2 = new DmxAttributeVector2(attribute);
                dmxVec2.attribX = _binaryReader.ReadSingle();
                dmxVec2.attribY = _binaryReader.ReadSingle();

                //Console.WriteLine($"Attribute Vector2 Value: {dmxVec2.attribX}, {dmxVec2.attribY}");
                return(dmxVec2);

            case (VECTOR3):
                //Console.WriteLine("Attribute Type: Vector3");

                DmxAttributeVector3 dmxVec3 = new DmxAttributeVector3(attribute);
                dmxVec3.attribX = _binaryReader.ReadSingle();
                dmxVec3.attribY = _binaryReader.ReadSingle();
                dmxVec3.attribZ = _binaryReader.ReadSingle();

                //Console.WriteLine($"Attribute Vector3 Value: {dmxVec3.attribX}, {dmxVec3.attribY}, {dmxVec3.attribZ}");
                return(dmxVec3);

            case (VECTOR4):
                //Console.WriteLine("Attribute Type: Vector4");

                DmxAttributeVector4 dmxVec4 = new DmxAttributeVector4(attribute);
                dmxVec4.attribX = _binaryReader.ReadSingle();
                dmxVec4.attribY = _binaryReader.ReadSingle();
                dmxVec4.attribZ = _binaryReader.ReadSingle();
                dmxVec4.attribW = _binaryReader.ReadSingle();

                //Console.WriteLine($"Attribute Vector3 Value: {dmxVec4.attribX}, {dmxVec4.attribY}, {dmxVec4.attribZ}, {dmxVec4.attribW}");
                return(dmxVec4);

            case (QANGLE):
                //Console.WriteLine("Attribute Type: QAngle");

                DmxAttributeQAngle dmxQangle = new DmxAttributeQAngle(attribute);
                dmxQangle.attribX = _binaryReader.ReadSingle();
                dmxQangle.attribY = _binaryReader.ReadSingle();
                dmxQangle.attribZ = _binaryReader.ReadSingle();

                //Console.WriteLine($"Attribute QAngle Value: {dmxQangle.attribX}, {dmxQangle.attribY}, {dmxQangle.attribZ}");
                return(dmxQangle);

            case (QUATERNION):
                //Console.WriteLine("Attribute Type: Quaternion");

                DmxAttributeQuaternion dmxQuat = new DmxAttributeQuaternion(attribute);
                dmxQuat.attribX = _binaryReader.ReadSingle();
                dmxQuat.attribY = _binaryReader.ReadSingle();
                dmxQuat.attribZ = _binaryReader.ReadSingle();
                dmxQuat.attribW = _binaryReader.ReadSingle();


                //Console.WriteLine($"Attribute Vector3 Value: {dmxQuat.attribX}, {dmxQuat.attribY}, {dmxQuat.attribZ}, {dmxQuat.attribW}");
                return(dmxQuat);

            case (MATRIX):
                //Console.WriteLine("Attribute Type: Matrix");

                DmxAttributeMatrix dmxMatrix = new DmxAttributeMatrix(attribute);
                dmxMatrix.attribByte = new byte[64];

                List <byte> byteBuff2 = new List <byte>();
                for (int y = 0; y < 64; y++)
                {
                    byteBuff2.Add(_binaryReader.ReadByte());
                }
                dmxMatrix.attribByte = byteBuff2.ToArray();
                byteBuff2.Clear();
                return(dmxMatrix);

            case (ELEMENT_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] elementArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = ELEMENT;
                    elementArray[i]             = ReadAttrib(tempAttribute);
                }
                return(elementArray);

            case (INTEGER_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] integerArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = INTEGER;
                    integerArray[i]             = ReadAttrib(tempAttribute);
                }
                return(integerArray);

            case (FLOAT_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] floatArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = FLOAT;
                    floatArray[i] = ReadAttrib(tempAttribute);
                }
                return(floatArray);

            case (BOOLEAN_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] booleanArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = BOOLEAN;
                    booleanArray[i]             = ReadAttrib(tempAttribute);
                }
                return(booleanArray);

            case (STRING_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] stringArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = STRING;
                    stringArray[i] = ReadAttrib(tempAttribute);
                }
                return(stringArray);

            case (BINARY_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] binaryArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = BINARY;

                    //Recursive call
                    binaryArray[i] = ReadAttrib(tempAttribute);
                }
                return(binaryArray);

            case (TIME_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] timeArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = TIME;

                    //Recursive call
                    timeArray[i] = ReadAttrib(tempAttribute);
                }
                return(timeArray);

            case (COLOR_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] colorArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = COLOR;

                    //Recursive call
                    colorArray[i] = ReadAttrib(tempAttribute);
                }
                return(colorArray);

            case (VECTOR2_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] vec2Array = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = VECTOR2;

                    //Recursive call
                    vec2Array[i] = ReadAttrib(tempAttribute);
                }
                return(vec2Array);

            case (VECTOR3_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] vec3Array = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = VECTOR3;

                    //Recursive call
                    vec3Array[i] = ReadAttrib(tempAttribute);
                }
                return(vec3Array);

            case (VECTOR4_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] vec4Array = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = VECTOR4;

                    //Recursive call
                    vec4Array[i] = ReadAttrib(tempAttribute);
                }
                return(vec4Array);

            case (QANGLE_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] qAngleArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = QANGLE;

                    //Recursive call
                    qAngleArray[i] = ReadAttrib(tempAttribute);
                }
                return(qAngleArray);

            case (QUATERNION_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] quatArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = QUATERNION;

                    //Recursive call
                    quatArray[i] = ReadAttrib(tempAttribute);
                }
                return(quatArray);

            case (MATRIX_ARRAY):
                //Console.WriteLine("Attribute Type: Element Array");

                numArrayItems = _binaryReader.ReadInt32();
                DmxAttribute[] matrixArray = new DmxAttribute[numArrayItems];

                for (int i = 0; i < numArrayItems; i++)
                {
                    DmxAttribute tempAttribute = new DmxAttribute();
                    tempAttribute.attributeType = MATRIX;

                    //Recursive call
                    matrixArray[i] = ReadAttrib(tempAttribute);
                }
                return(matrixArray);
            }
            //Default return null
            return(null);
        }