Exemple #1
0
        public bool Deserialize(object data)
        {
            if (data is BinaryReader)
            {
                BinaryReader br = data as BinaryReader;

                Vector3 trans = Vector3.Zero;
                Vector3 rot   = Vector3.Zero;
                Vector3 scale = Vector3.One;

                CBinaryConverter.Read(br, out trans);
                CBinaryConverter.Read(br, out rot);
                CBinaryConverter.Read(br, out scale);

                LclTranslate = trans;
                Quaternion qx = Quaternion.FromAxisAngle(Vector3.UnitX, MathHelper.DegreesToRadians(rot.X));
                Quaternion qy = Quaternion.FromAxisAngle(Vector3.UnitY, MathHelper.DegreesToRadians(rot.Y));
                Quaternion qz = Quaternion.FromAxisAngle(Vector3.UnitZ, MathHelper.DegreesToRadians(rot.Z));
                LclRotation = qz * qy * qx;
                LclScaling  = scale;
            }
            else if (data is JObject)
            {
                JObject jkf = data as JObject;
                if (jkf == null)
                {
                    return(false);
                }

                if (jkf["LT"] == null || jkf["LS"] == null || jkf["LR"] == null)
                {
                    return(false);
                }

                LclTranslate = CJsonConverter.ConvertVector3(jkf["LT"].Value <JArray>());
                LclScaling   = CJsonConverter.ConvertVector3(jkf["LS"].Value <JArray>());

                Vector3    rot = CJsonConverter.ConvertVector3(jkf["LR"].Value <JArray>());
                Quaternion qx  = Quaternion.FromAxisAngle(Vector3.UnitX, MathHelper.DegreesToRadians(rot.X));
                Quaternion qy  = Quaternion.FromAxisAngle(Vector3.UnitY, MathHelper.DegreesToRadians(rot.Y));
                Quaternion qz  = Quaternion.FromAxisAngle(Vector3.UnitZ, MathHelper.DegreesToRadians(rot.Z));
                LclRotation = qz * qy * qx;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public bool Serialize(ref object writer)
        {
            if (writer is BinaryWriter)
            {
                BinaryWriter bw = writer as BinaryWriter;

                bw.Write(BoneIndex);
                CBinaryConverter.Write(bw, ref Position);
                CBinaryConverter.Write(bw, ref Normal);
                CBinaryConverter.Write(bw, ref Texcoord);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
        public bool Serialize(ref object writer)
        {
            if (writer is BinaryWriter)
            {
                BinaryWriter bw = writer as BinaryWriter;

                Vector3 trans  = LclTranslate;
                Vector3 radian = CUtility.ToDegree(CUtility.ToEulerAngle(LclRotation));
                Vector3 scale  = LclScaling;
                CBinaryConverter.Write(bw, ref trans);
                CBinaryConverter.Write(bw, ref radian);
                CBinaryConverter.Write(bw, ref scale);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemple #4
0
        public bool Deserialize(object data)
        {
            if (data is BinaryReader)
            {
                BinaryReader br = data as BinaryReader;

                BoneIndex = br.ReadInt32();
                CBinaryConverter.Read(br, out Position);
                CBinaryConverter.Read(br, out Normal);
                CBinaryConverter.Read(br, out Texcoord);
            }
            else if (data is JObject)
            {
                JObject jv = data as JObject;

                if (jv["Pos"] != null)
                {
                    Position = CJsonConverter.ConvertVector3(jv["Pos"].Value <JArray>());
                }
                if (jv["Nor"] != null)
                {
                    Normal = CJsonConverter.ConvertVector3(jv["Nor"].Value <JArray>());
                }
                if (jv["UV"] != null)
                {
                    Texcoord = CJsonConverter.ConvertVector2(jv["UV"].Value <JArray>());
                }
                if (jv["BI"] != null)
                {
                    BoneIndex = jv["BI"].Value <int>();
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }