예제 #1
0
파일: Util.cs 프로젝트: ShitpostMDX/LibRbxl
        public static NumberRange ReadNumberRange(EndianAwareBinaryReader reader)
        {
            var min = reader.ReadSingle();
            var max = reader.ReadSingle();

            return(new NumberRange(min, max));
        }
예제 #2
0
파일: Util.cs 프로젝트: ShitpostMDX/LibRbxl
        public static NumberSequence ReadNumberSequence(EndianAwareBinaryReader reader)
        {
            var keypointCount = reader.ReadInt32();
            var keypoints     = new NumberSequenceKeypoint[keypointCount];

            for (var i = 0; i < keypointCount; i++)
            {
                var time     = reader.ReadSingle();
                var value    = reader.ReadSingle();
                var envelope = reader.ReadSingle();
                keypoints[i] = new NumberSequenceKeypoint(time, value, envelope);
            }

            return(new NumberSequence(keypoints));
        }
예제 #3
0
파일: Util.cs 프로젝트: ShitpostMDX/LibRbxl
        public static ColorSequence ReadColorSequence(EndianAwareBinaryReader reader)
        {
            var keypointCount = reader.ReadInt32();
            var keypoints     = new ColorSequenceKeypoint[keypointCount];

            for (var i = 0; i < keypointCount; i++)
            {
                var time = reader.ReadSingle();
                var r    = reader.ReadSingle();
                var g    = reader.ReadSingle();
                var b    = reader.ReadSingle();
                keypoints[i] = new ColorSequenceKeypoint(time, new Color3(r, g, b));
            }
            return(new ColorSequence(keypoints));
        }
예제 #4
0
파일: Util.cs 프로젝트: ShitpostMDX/LibRbxl
        public static PhysicalProperties ReadPhysicalProperties(EndianAwareBinaryReader reader)
        {
            var enabled = (reader.ReadByte() != 0);

            if (enabled)
            {
                var density          = reader.ReadSingle();
                var friction         = reader.ReadSingle();
                var elasticity       = reader.ReadSingle();
                var frictionWeight   = reader.ReadSingle();
                var elasticityWeight = reader.ReadSingle();
                return(new PhysicalProperties(density, friction, elasticity, frictionWeight, elasticityWeight));
            }
            else
            {
                return(new PhysicalProperties(false));
            }
        }
예제 #5
0
파일: Util.cs 프로젝트: ShitpostMDX/LibRbxl
        public static CFrame[] ReadCFrameArray(EndianAwareBinaryReader reader, int count)
        {
            var values    = new CFrame[count];
            var positions = new Vector3[count];
            var matrices  = new Matrix3[count];

            for (var i = 0; i < count; i++)
            {
                var specialMatrixType = reader.ReadByte();
                if (specialMatrixType == 0)
                {
                    var r00 = reader.ReadSingle();
                    var r01 = reader.ReadSingle();
                    var r02 = reader.ReadSingle();
                    var r10 = reader.ReadSingle();
                    var r11 = reader.ReadSingle();
                    var r12 = reader.ReadSingle();
                    var r20 = reader.ReadSingle();
                    var r21 = reader.ReadSingle();
                    var r22 = reader.ReadSingle();
                    matrices[i] = new Matrix3(r00, r01, r02, r10, r11, r12, r20, r21, r22);
                }
                else
                {
                    var mat = GetSpecialMatrix(specialMatrixType);
                    matrices[i] = mat;
                }
            }

            var xValues = ReadFloatArray(reader, count);
            var yValues = ReadFloatArray(reader, count);
            var zValues = ReadFloatArray(reader, count);

            for (var i = 0; i < count; i++)
            {
                positions[i] = new Vector3(xValues[i], yValues[i], zValues[i]);
            }

            for (var i = 0; i < count; i++)
            {
                values[i] = new CFrame(positions[i], matrices[i]);
            }
            return(values);
        }
예제 #6
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="bytController"></param>
    /// <param name="cntlMsgs"></param>
    /// <param name="strControllerData"></param>
    public static void DecodeControllerData(byte[] bytController, ref ControllerMessages cntlMsgs)
    {
        //UnityEngine.Debug.Log("Entered DecodeControllerData()");
        int intMsgType = 0;

        MemoryStream stream = new MemoryStream(bytController);
        using (EndianAwareBinaryReader reader = new EndianAwareBinaryReader(stream, false))
        {
            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                intMsgType = reader.ReadInt32();
                //UnityEngine.Debug.Log("intMsgType = " + intMsgType);

                if (intMsgType == ViewerConstants.MESSAGE_TOUCH_INPUT)
                {
                    UnityEngine.Debug.Log("reading touch");
                    cntlMsgs.TouchMessage.X = reader.ReadSingle();
                    cntlMsgs.TouchMessage.Y = reader.ReadSingle();
                    cntlMsgs.TouchMessage.Timestamp = reader.ReadInt64();
                    cntlMsgs.TouchMessage.Pointer = reader.ReadInt32();
                    cntlMsgs.TouchMessage.Active = reader.ReadInt32();
                }
                else if (intMsgType == ViewerConstants.MESSAGE_ACCELEROMETER_INPUT)
                {
                    //UnityEngine.Debug.Log("reading accel");
                    cntlMsgs.AccelMessage.X = reader.ReadSingle();
                    cntlMsgs.AccelMessage.Y = reader.ReadSingle();
                    cntlMsgs.AccelMessage.Z = reader.ReadSingle();
                    cntlMsgs.AccelMessage.Timestamp = reader.ReadInt32();
                }
                else if (intMsgType == ViewerConstants.MESSAGE_MAGNOTOMETER_INPUT)
                {
                    //UnityEngine.Debug.Log("reading magnotometer");
                    cntlMsgs.MagnoMessage.X = reader.ReadSingle();
                    cntlMsgs.MagnoMessage.Y = reader.ReadSingle();
                    cntlMsgs.MagnoMessage.Z = reader.ReadSingle();
                    cntlMsgs.MagnoMessage.Timestamp = reader.ReadInt32();
                }
                else if (intMsgType == ViewerConstants.MESSAGE_ATTITUDE_INPUT)
                {
                    //UnityEngine.Debug.Log("reading attitude");
                    cntlMsgs.AttMessage.X = reader.ReadSingle();
                    cntlMsgs.AttMessage.Y = reader.ReadSingle();
                    cntlMsgs.AttMessage.Z = reader.ReadSingle();
                    cntlMsgs.AttMessage.Timestamp = reader.ReadInt32();
                }

                else if (intMsgType == ViewerConstants.MESSAGE_TRACKBALL_INPUT)
                {
                    UnityEngine.Debug.Log("reading trackball");
                    cntlMsgs.TrackMessage.X = reader.ReadSingle();
                    cntlMsgs.TrackMessage.Y = reader.ReadSingle();
                }
                else if (intMsgType == ViewerConstants.MESSAGE_OPTIONS)
                {
                    UnityEngine.Debug.Log("reading options");
                    cntlMsgs.OptionMessage.ScreenWidth = reader.ReadInt32();
                    cntlMsgs.OptionMessage.ScreenHeight = reader.ReadInt32();
                }
                else if (intMsgType == ViewerConstants.MESSAGE_KEY)
                {
                    UnityEngine.Debug.Log("reading keys");
                    cntlMsgs.KeyMessage.State = reader.ReadInt32();
                    cntlMsgs.KeyMessage.Key = reader.ReadInt32();
                    cntlMsgs.KeyMessage.Unicode = reader.ReadInt32();
                }
            }
        }
    }
예제 #7
0
            public Vector3 Scale; //!< Scaling information

            #endregion Fields

            #region Methods

            /// <summary>
            /// Load a mesh from a stream
            /// </summary>
            /// <param name="filename">Filename and path of the file containing the reference mesh</param>
            public virtual void LoadMesh(string filename)
            {
                using(FileStream meshStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                using (EndianAwareBinaryReader reader = new EndianAwareBinaryReader(meshStream))
                {
                    Header = TrimAt0(reader.ReadString(24));
                    if (!String.Equals(Header, MeshHeader))
                        throw new FileLoadException("Unrecognized mesh format");

                    // Populate base mesh parameters
                    HasWeights = (reader.ReadByte() != 0);
                    HasDetailTexCoords = (reader.ReadByte() != 0);
                    Position = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                    RotationAngles = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                    RotationOrder = reader.ReadByte();
                    Scale = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                    NumFaces = reader.ReadUInt16();

                    Faces = new Face[NumFaces];

                    for (int i = 0; i < NumFaces; i++)
                        Faces[i].Indices = new[] { reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16() };
                }
            }
예제 #8
0
        /// <summary>
        /// Load the mesh from a stream
        /// </summary>
        /// <param name="filename">The filename and path of the file containing the mesh data</param>
        public virtual void LoadMesh(string filename)
        {
            using(FileStream meshData = new FileStream(filename, FileMode.Open, FileAccess.Read))
            using (EndianAwareBinaryReader reader = new EndianAwareBinaryReader(meshData))
            {
                Header = TrimAt0(reader.ReadString(24));
                if (!String.Equals(Header, MeshHeader))
                    throw new FileLoadException("Unrecognized mesh format");

                // Populate base mesh parameters
                HasWeights = (reader.ReadByte() != 0);
                HasDetailTexCoords = (reader.ReadByte() != 0);
                Position = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                RotationAngles = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                /* RotationOrder = */ reader.ReadByte();
                Scale = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                // Populate the vertex array
                NumVertices = reader.ReadUInt16();
                Vertices = new Vertex[NumVertices];
                for (int i = 0; i < NumVertices; i++)
                    Vertices[i].Coord = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                for (int i = 0; i < NumVertices; i++)
                    Vertices[i].Normal = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                for (int i = 0; i < NumVertices; i++)
                    Vertices[i].BiNormal = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                for (int i = 0; i < NumVertices; i++)
                    Vertices[i].TexCoord = new Vector2(reader.ReadSingle(), reader.ReadSingle());

                if (HasDetailTexCoords)
                {
                    for (int i = 0; i < NumVertices; i++)
                        Vertices[i].DetailTexCoord = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                }

                if (HasWeights)
                {
                    for (int i = 0; i < NumVertices; i++)
                        Vertices[i].Weight = reader.ReadSingle();
                }

                NumFaces = reader.ReadUInt16();
                Faces = new Face[NumFaces];

                for (int i = 0; i < NumFaces; i++)
                    Faces[i].Indices = new[] { reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16() };

                if (HasWeights)
                {
                    NumSkinJoints = reader.ReadUInt16();
                    SkinJoints = new string[NumSkinJoints];

                    for (int i = 0; i < NumSkinJoints; i++)
                    {
                        SkinJoints[i] = TrimAt0(reader.ReadString(64));
                    }
                }
                else
                {
                    NumSkinJoints = 0;
                    SkinJoints = new string[0];
                }

                // Grab morphs
                List<Morph> morphs = new List<Morph>();
                string morphName = TrimAt0(reader.ReadString(64));

                while (morphName != MorphFooter)
                {
                    if (reader.BaseStream.Position + 48 >= reader.BaseStream.Length)
                        throw new FileLoadException("Encountered end of file while parsing morphs");

                    Morph morph = new Morph();
                    morph.Name = morphName;
                    morph.NumVertices = reader.ReadInt32();
                    morph.Vertices = new MorphVertex[morph.NumVertices];

                    for (int i = 0; i < morph.NumVertices; i++)
                    {
                        morph.Vertices[i].VertexIndex = reader.ReadUInt32();
                        morph.Vertices[i].Coord = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        morph.Vertices[i].Normal = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        morph.Vertices[i].BiNormal = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        morph.Vertices[i].TexCoord = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                    }

                    morphs.Add(morph);

                    // Grab the next name
                    morphName = TrimAt0(reader.ReadString(64));
                }

                Morphs = morphs.ToArray();

                // Check if there are remaps or if we're at the end of the file
                if (reader.BaseStream.Position < reader.BaseStream.Length - 1)
                {
                    NumRemaps = reader.ReadInt32();
                    VertexRemaps = new VertexRemap[NumRemaps];

                    for (int i = 0; i < NumRemaps; i++)
                    {
                        VertexRemaps[i].RemapSource = reader.ReadInt32();
                        VertexRemaps[i].RemapDestination = reader.ReadInt32();
                    }
                }
                else
                {
                    NumRemaps = 0;
                    VertexRemaps = new VertexRemap[0];
                }
            }

            // uncompress the skin weights
            if (Skeleton != null)
            {
                // some meshes aren't weighted, which doesn't make much sense.
                // we check for left and right eyeballs, and assign them a 100%
                // to their respective bone
                List<string> expandedJointList = Skeleton.BuildExpandedJointList(SkinJoints);
                if (expandedJointList.Count == 0)
                {
                    if (Name == "eyeBallLeftMesh")
                    {
                        expandedJointList.AddRange(new[] { "mEyeLeft", "mSkull" });
                    }
                    else if (Name == "eyeBallRightMesh")
                    {
                        expandedJointList.AddRange(new[] { "mEyeRight", "mSkull" });
                    }
                }

                if (expandedJointList.Count > 0)
                    ExpandCompressedSkinWeights(expandedJointList);
            }
        }
예제 #9
0
        public object Deserialize(EndianAwareBinaryReader reader, SerializedType serializedType, int?length = null)
        {
            int?effectiveLength = null;

            var typeParent = TypeNode.Parent as TypeNode;

            if (length != null)
            {
                effectiveLength = length.Value;
            }
            else if (TypeNode.FieldLengthBinding != null)
            {
                object lengthValue = TypeNode.FieldLengthBinding.GetValue(this);
                effectiveLength = Convert.ToInt32(lengthValue);
            }
            else if (typeParent != null && typeParent.ItemLengthBinding != null)
            {
                object lengthValue = typeParent.ItemLengthBinding.GetValue((ValueNode)Parent);
                effectiveLength = Convert.ToInt32(lengthValue);
            }
            else if (TypeNode.FieldCountBinding != null)
            {
                object countValue = TypeNode.FieldCountBinding.GetValue(this);
                effectiveLength = Convert.ToInt32(countValue);
            }
            else if (serializedType == SerializedType.ByteArray || serializedType == SerializedType.SizedString)
            {
                checked
                {
                    effectiveLength = (int)_remainder;
                }
            }

            object value;

            switch (serializedType)
            {
            case SerializedType.Int1:
                value = reader.ReadSByte();
                break;

            case SerializedType.UInt1:
                value = reader.ReadByte(GetBitSize());
                break;

            case SerializedType.Int2:
                value = reader.ReadInt16();
                break;

            case SerializedType.UInt2:
                value = reader.ReadUInt16();
                break;

            case SerializedType.Int4:
                value = reader.ReadInt32();
                break;

            case SerializedType.UInt4:
                value = reader.ReadUInt32();
                break;

            case SerializedType.Int8:
                value = reader.ReadInt64();
                break;

            case SerializedType.UInt8:
                value = reader.ReadUInt64();
                break;

            case SerializedType.Float4:
                value = reader.ReadSingle();
                break;

            case SerializedType.Float8:
                value = reader.ReadDouble();
                break;

            case SerializedType.ByteArray:
            {
                Debug.Assert(effectiveLength != null, "effectiveLength != null");
                value = reader.ReadBytes(effectiveLength.Value);
                break;
            }

            case SerializedType.NullTerminatedString:
            {
                byte[] data = ReadNullTerminatedString(reader).ToArray();
                value = Encoding.GetString(data, 0, data.Length);
                break;
            }

            case SerializedType.SizedString:
            {
                Debug.Assert(effectiveLength != null, "effectiveLength != null");
                byte[] data = reader.ReadBytes(effectiveLength.Value);
                value = Encoding.GetString(data, 0, data.Length).TrimEnd('\0');
                break;
            }

            case SerializedType.LengthPrefixedString:
            {
                value = reader.ReadString();
                break;
            }

            default:
                throw new NotSupportedException();
            }

            return(value);
        }
예제 #10
0
파일: Util.cs 프로젝트: ShitpostMDX/LibRbxl
 public static Vector3 ReadVector3(EndianAwareBinaryReader reader)
 {
     return(new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
 }