Ejemplo n.º 1
0
        public bool Load(string FileName)
        {
            MaxValue = 0f;
            MinValue = 0f;

            try
            {
                FileStream   fileStream = File.OpenRead(FileName);
                BinaryReader br         = new BinaryReader(fileStream, koreanEncoding);

                bh = new BinaryHelper(br);

                try
                {
                    Height    = bh.ReadDWord();
                    Width     = bh.ReadDWord();
                    GridCount = bh.ReadDWord();
                    GridSize  = br.ReadSingle();
                    for (int i = 0; i < 65; i++)
                    {
                        for (int j = 0; j < 65; j++)
                        {
                            element[i, j] = br.ReadSingle();
                            if (element[i, j] > MaxValue)
                            {
                                MaxValue = element[i, j];
                            }
                            if (element[i, j] < MinValue)
                            {
                                MinValue = element[i, j];
                            }
                        }
                    }
                }
                finally
                {
                    br.Close();
                    fileStream.Close();
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool Load(string FileName)
        {
            try
            {
                FileStream fileStream = File.OpenRead(FileName);
                br = new BinaryReader(fileStream, koreanEncoding);
                bh = new BinaryHelper(br);

                try
                {
                    uint skeleton_count = bh.ReadWord();
                    for (int skeltonID = 0; skeltonID < skeleton_count; skeltonID++)
                    {
                        Skeleton.Add(bh.ReadZString());
                    }

                    uint animation_count = bh.ReadWord();
                    for (int animationID = 0; animationID < animation_count; animationID++)
                    {
                        Animation.Add(bh.ReadZString());
                    }

                    uint effect_count = bh.ReadWord();
                    for (int effectID = 0; effectID < effect_count; effectID++)
                    {
                        Effect.Add(bh.ReadZString());
                    }

                    uint char_count = bh.ReadWord();
                    for (int charID = 0; charID < char_count; charID++)
                    {
                        CHRCharacter chr = new CHRCharacter();
                        chr.isActive = (br.ReadByte() != 0);

                        if (chr.isActive)
                        {
                            chr.SkeletonID = bh.ReadWord();
                            chr.Name       = bh.ReadZString();

                            for (int modelID = 0; modelID < bh.ReadWord(); modelID++)
                            {
                                chr.Model.Add(bh.ReadWord());
                            }

                            for (int charanimID = 0; charanimID < bh.ReadWord(); charanimID++)
                            {
                                chr.Animation.Add(new CHRAnimation()
                                {
                                    Type = bh.ReadWord(),
                                    ID   = bh.ReadWord()
                                });
                            }

                            for (int chareffectID = 0; chareffectID < bh.ReadWord(); chareffectID++)
                            {
                                chr.Effect.Add(new CHREffect()
                                {
                                    BoneID   = bh.ReadWord(),
                                    EffectID = bh.ReadWord()
                                });
                            }
                        } // isActive
                        Character.Add(chr);
                    }     // for char
                }         // tryf
                finally
                {
                    br.Close();
                    fileStream.Close();
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool Load(string FileName)
        {
            try
            {
                FileStream fileStream = File.OpenRead(FileName);
                br = new BinaryReader(fileStream, koreanEncoding);
                bh = new BinaryHelper(br);

                try
                {
                    MeshCount = bh.ReadWord();
                    for (int meshID = 0; meshID < MeshCount; meshID++)
                    {
                        MeshName.Add(bh.ReadZString());
                    }

                    MaterialCount = bh.ReadWord();
                    for (int materialID = 0; materialID < MaterialCount; materialID++)
                    {
                        ZSCMaterial mat = new ZSCMaterial();
                        mat.Path = bh.ReadZString();
                        br.ReadBytes(2); // Skip 2 bytes!
                        mat.UseAlpha    = (bh.ReadWord() > 0);
                        mat.DoubleSided = (bh.ReadWord() > 0);
                        mat.AlphaTest   = bh.ReadWord();
                        mat.AlphaRef    = (bh.ReadWord() / 256.0f);
                        mat.zTest       = (bh.ReadWord() > 0);
                        mat.zWrite      = (bh.ReadWord() > 0);
                        mat.BlendType   = bh.ReadWord();
                        mat.Specular    = bh.ReadWord();
                        mat.Alpha       = br.ReadSingle();
                        mat.GlowType    = bh.ReadWord();
                        mat.r           = br.ReadSingle();
                        mat.g           = br.ReadSingle();
                        mat.b           = br.ReadSingle();
                        Material.Add(mat);
                    }

                    uint effectsNames_count = bh.ReadWord();
                    for (int effID = 0; effID < effectsNames_count; effID++)
                    {
                        EffectName.Add(bh.ReadZString());
                    }

                    uint models_count = bh.ReadWord();
                    for (int modID = 0; modID < models_count; modID++)
                    {
                        ZSCModel model = new ZSCModel();
                        model.BBRadius = bh.ReadDWord();
                        model.BBX      = bh.ReadDWord();
                        model.BBY      = bh.ReadDWord();

                        uint parts_count = bh.ReadWord();
                        if (parts_count > 0)
                        {
                            // PARTS
                            for (int jparts = 0; jparts < parts_count; jparts++)
                            {
                                ZSCPart part = ReadPart();
                                if (jparts == 0)
                                {
                                    part.ParentID = -1;
                                }
                                model.Part.Add(part);
                            } // parts

                            // EFFECTS
                            uint effects_count = bh.ReadWord();
                            for (int jeffects = 0; jeffects < effects_count; jeffects++)
                            {
                                ZSCEffect effect = ReadEffect();
                                model.Effect.Add(effect);
                            }
                        } // if > 0
                        else
                        {
                            Model.Add(model);
                            continue;
                        }

                        model.BBoxMin = bh.ReadVector3f() * 0.01f;
                        model.BBoxMax = bh.ReadVector3f() * 0.01f;
                        Model.Add(model);
                    }
                }
                finally
                {
                    br.Close();
                    fileStream.Close();
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        public bool Load(string FileName)
        {
            Encoding koreanEncoding = Encoding.GetEncoding("EUC-KR");

            try
            {
                FileStream   fileStream = File.OpenRead(FileName);
                BinaryReader br         = new BinaryReader(fileStream, koreanEncoding);

                bh = new BinaryHelper(br);

                try
                {
                    FormatString = koreanEncoding.GetString(br.ReadBytes(7));

                    BonesCount = br.ReadUInt32();

                    if (BonesCount > 0)
                    {
                        for (int i = 0; i < BonesCount; i++)
                        {
                            RoseBone bone = new RoseBone(br.ReadInt32(), bh.ReadZString(), bh.ReadVector3f() /** scaleFactor*/, bh.ReadQuaternion());
                            bone.ID = i;
                            bone.TransformMatrix = new Matrix4();
                            bone.TransformMatrix.MakeTrans(bone.Position);
                            Matrix4 rotationMatrix = new Matrix4(bone.Rotation);
                            bone.TransformMatrix = (rotationMatrix * bone.TransformMatrix);
                            bone.InverseMatrix   = bone.TransformMatrix.Inverse();
                            Bone.Add(bone);
                        } // for
                    }     // if num_bones > 0

                    DummiesCount = br.ReadUInt32();

                    if (DummiesCount > 0)
                    {
                        for (int i = 0; i < DummiesCount; i++)
                        {
                            RoseBone dummy = null;

                            if (FormatString.Equals("ZMD0003"))
                            {
                                // dummies are read different then bones;
                                dummy = new RoseBone(bh.ReadZString(), br.ReadInt32(), bh.ReadVector3f() /* * scaleFactor*/, bh.ReadQuaternion());
                            } // if

                            if (FormatString.Equals("ZMD0002"))
                            {
                                dummy = new RoseBone(bh.ReadZString(), br.ReadInt32(), bh.ReadVector3f() /* * scaleFactor*/);
                            } // if
                            dummy.ID = (int)BonesCount + i;
                            dummy.TransformMatrix = new Matrix4();
                            dummy.TransformMatrix.MakeTrans(dummy.Position);
                            Matrix4 rotationMatrix = new Matrix4(dummy.Rotation);
                            dummy.TransformMatrix = (rotationMatrix * dummy.TransformMatrix);
                            dummy.InverseMatrix   = dummy.TransformMatrix.Inverse();
                            Dummy.Add(dummy);
                        } // for
                    }     // if dummies
                }         // try
                finally
                {
                    br.Close();
                    fileStream.Close();
                }
            } // try open file
            catch (Exception)
            {
                return(false);
            } // catch open file

            TransformChildren(0);

            return(true);
        } // Load
Ejemplo n.º 5
0
        public bool Load(string FileName)
        {
            //Quaternion rotYneg90 = new Quaternion(new Degree(-90f), Vector3.UnitY);
            //rotYneg90 = rotYneg90.Inverse();

            Encoding koreanEncoding = Encoding.GetEncoding("EUC-KR");

            try
            {
                FileStream   fileStream = File.OpenRead(FileName);
                BinaryReader br         = new BinaryReader(fileStream, koreanEncoding);

                bh = new BinaryHelper(br);

                try
                {
                    FormatString = koreanEncoding.GetString(br.ReadBytes(7));

                    BonesCount = br.ReadUInt32();

                    if (BonesCount > 0)
                    {
                        for (int i = 0; i < BonesCount; i++)
                        {
                            RoseBone bone = new RoseBone(br.ReadInt32(), bh.ReadZString(), bh.ReadVector3f() * scaleFactor, bh.ReadQuaternion());
                            bone.ID = i;

                            bone.TransformMatrix = new Matrix4(bone.Rotation);
                            bone.TransformMatrix.SetTrans(bone.Position);

                            if (i != 0)
                            {
                                Bone[bone.ParentID].ChildID.Add(i);
                                bone.TransformMatrix *= Bone[bone.ParentID].TransformMatrix;
                            }

                            Bone.Add(bone);
                        } // for
                    }     // if num_bones > 0

                    DummiesCount = br.ReadUInt32();

                    if (DummiesCount > 0)
                    {
                        for (int i = 0; i < DummiesCount; i++)
                        {
                            RoseBone dummy = null;

                            if (FormatString.Equals("ZMD0003"))
                            {
                                // dummies are read different then bones;
                                dummy = new RoseBone(bh.ReadZString(), br.ReadInt32(), bh.ReadVector3f() * scaleFactor, bh.ReadQuaternion());
                            } // if

                            if (FormatString.Equals("ZMD0002"))
                            {
                                dummy = new RoseBone(bh.ReadZString(), br.ReadInt32(), bh.ReadVector3f() * scaleFactor);
                            } // if
                            dummy.ID = (int)BonesCount + i;


                            dummy.TransformMatrix = new Matrix4(dummy.Rotation);
                            dummy.TransformMatrix.SetTrans(dummy.Position);

                            if (dummy.ParentID < BonesCount)
                            {
                                dummy.TransformMatrix *= Bone[dummy.ParentID].TransformMatrix;
                            }
                            else
                            {
                                dummy.TransformMatrix *= Dummy[dummy.ParentID].TransformMatrix;
                            }

                            Dummy.Add(dummy);
                        } // for
                    }     // if dummies
                }         // try
                finally
                {
                    br.Close();
                    fileStream.Close();
                }
            } // try open file
            catch (Exception)
            {
                return(false);
            } // catch open file

            return(true);
        } // Load
Ejemplo n.º 6
0
        public bool Load(string FileName, ZMD zmd)
        {
            Encoding koreanEncoding = Encoding.GetEncoding("EUC-KR");

            try
            {
                FileStream   fileStream = File.OpenRead(FileName);
                BinaryReader br         = new BinaryReader(fileStream, koreanEncoding);
                bh = new BinaryHelper(br);
                Quaternion rotYneg90 = new Quaternion(new Degree(-90f), Vector3.UnitY);

                try
                {
                    AnimationName = Path.GetFileNameWithoutExtension(FileName);

                    FormatString = koreanEncoding.GetString(br.ReadBytes(7));
                    br.ReadByte();

                    FPS      = br.ReadInt32();
                    Frames   = br.ReadInt32();
                    Channels = br.ReadInt32();

                    Track = new List <ZMOTrack>();

                    Channel = new List <ZMOChannel>();

                    // Read each track description
                    for (int i = 0; i < Channels; i++)
                    {
                        int TracType = br.ReadInt32();
                        int BoneID   = br.ReadInt32();

                        Channel.Add(new ZMOChannel((ZMOTrack.TrackType)TracType, BoneID));
                    }

                    // Read tracks data
                    for (int frameIDX = 0; frameIDX < Frames; frameIDX++)
                    {
                        for (int channelIDX = 0; channelIDX < Channels; channelIDX++)
                        {
                            int BoneID = Channel[channelIDX].BoneID;

                            ZMOTrack track = new ZMOTrack(Channel[channelIDX].Type, Channel[channelIDX].BoneID, frameIDX);

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.POSITION || Channel[channelIDX].Type == ZMOTrack.TrackType.NORMAL)
                            {
                                //read vector
                                track.Position = bh.ReadVector3f() / 100f;
                                if (zmd != null)
                                {
                                    zmd.Bone[BoneID].AddAnimationAt(frameIDX, AnimationName, new BoneFrame()
                                    {
                                        Position = track.Position
                                    }, ZMOTrack.TrackType.POSITION);
                                }
                            } // position

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.ROTATION)
                            {
                                //read quat
                                track.Rotation = bh.ReadQuaternion();
                                if (zmd != null)
                                {
                                    zmd.Bone[BoneID].AddAnimationAt(frameIDX, AnimationName, new BoneFrame()
                                    {
                                        Rotation = zmd.Bone[BoneID].Rotation * track.Rotation.Inverse()
                                    }, ZMOTrack.TrackType.ROTATION);
                                }
                            } // rotation

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.ALPHA || Channel[channelIDX].Type == ZMOTrack.TrackType.TEXTUREANIM)
                            {
                                //read float
                                track.Value = br.ReadSingle();
                            } // alpha

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.SCALE)
                            {
                                track.Value = br.ReadSingle();
                                if (zmd != null)
                                {
                                    zmd.Bone[BoneID].AddAnimationAt(frameIDX, AnimationName, new BoneFrame()
                                    {
                                        Scale = Vector3.One * track.Value
                                    }, ZMOTrack.TrackType.SCALE);
                                }
                            }

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.UV1 || Channel[channelIDX].Type == ZMOTrack.TrackType.UV2 || Channel[channelIDX].Type == ZMOTrack.TrackType.UV3 || Channel[channelIDX].Type == ZMOTrack.TrackType.UV4)
                            {
                                //read vector
                                track.UV = bh.ReadVector2f();
                            } // UV
                            Track.Add(track);
                        }     // bones
                    }         // frames
                }             // try
                finally
                {
                    br.Close();
                    fileStream.Close();
                }
            } // try open file
            catch (Exception)
            {
                return(false);
            } // catch open file
            return(true);
        }     // Load
Ejemplo n.º 7
0
        public bool Load(string FileName, ZMD zmd)
        {
            Encoding koreanEncoding = Encoding.GetEncoding("EUC-KR");

            try
            {
                FileStream   fileStream = File.OpenRead(FileName);
                BinaryReader br         = new BinaryReader(fileStream, koreanEncoding);
                bh = new BinaryHelper(br);

                try
                {
                    FormatString = koreanEncoding.GetString(br.ReadBytes(7));
                    br.ReadByte();

                    FPS      = br.ReadInt32();
                    Frames   = br.ReadInt32();
                    Channels = br.ReadInt32();

                    Track = new List <ZMOTrack>();

                    Channel = new List <ZMOChannel>();

                    // Read each track description
                    for (int i = 0; i < Channels; i++)
                    {
                        int TracType = br.ReadInt32();
                        int BoneID   = br.ReadInt32();

                        Channel.Add(new ZMOChannel((ZMOTrack.TrackType)TracType, BoneID));
                    }

                    // set frames number for each bone
                    foreach (RoseBone bone in zmd.Bone)
                    {
                        bone.InitFrames(Frames);
                    }

                    // Read tracks data
                    for (int frameIDX = 0; frameIDX < Frames; frameIDX++)
                    {
                        for (int channelIDX = 0; channelIDX < Channels; channelIDX++)
                        {
                            int BoneID = Channel[channelIDX].BoneID;

                            ZMOTrack track = new ZMOTrack(Channel[channelIDX].Type, Channel[channelIDX].BoneID, frameIDX);

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.POSITION || Channel[channelIDX].Type == ZMOTrack.TrackType.NORMAL)
                            {
                                //read vector
                                track.Position = bh.ReadVector3f();
                                if (zmd != null)
                                {
                                    zmd.Bone[BoneID].Frame[frameIDX].Position = track.Position;
                                }
                            } // position

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.ROTATION)
                            {
                                //read quat
                                Quaternion q = bh.ReadQuaternion();
                                track.Rotation = q;
                                if (zmd != null)
                                {
                                    zmd.Bone[BoneID].Frame[frameIDX].Rotation = track.Rotation;
                                }
                            } // rotation

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.ALPHA || Channel[channelIDX].Type == ZMOTrack.TrackType.TEXTUREANIM)
                            {
                                //read float
                                track.Value = br.ReadSingle();
                            } // alpha

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.SCALE)
                            {
                                track.Value = br.ReadSingle();
                                if (zmd != null)
                                {
                                    zmd.Bone[BoneID].Frame[frameIDX].Scale = new Vector3(track.Value, track.Value, track.Value);
                                }
                            }

                            if (Channel[channelIDX].Type == ZMOTrack.TrackType.UV1 || Channel[channelIDX].Type == ZMOTrack.TrackType.UV2 || Channel[channelIDX].Type == ZMOTrack.TrackType.UV3 || Channel[channelIDX].Type == ZMOTrack.TrackType.UV4)
                            {
                                //read vector
                                track.UV = bh.ReadVector2f();
                            } // UV
                            Track.Add(track);
                        }     // bones
                    }         // frames
                }             // try
                finally
                {
                    br.Close();
                    fileStream.Close();
                }
            } // try open file
            catch (Exception)
            {
                return(false);
            } // catch open file
            return(true);
        }     // Load