Esempio n. 1
0
        public static Model loadFromPath(string path)
        {
            var io=new ByteReader(File.ReadAllBytes(path));

            var model=new Model();

            model.Magic=io.GetAscii(30);
            model.ModelName=io.GetSJIS(20);

            int boneMotionCount=io.GetInt();
            model.BoneMotions=Enumerable.Range(1, boneMotionCount).Select(_
                    =>GetBoneMotion(io)).ToArray();

            return model;
        }
Esempio n. 2
0
        public static Model loadFromPath(string path)
        {
            var io=new ByteReader(File.ReadAllBytes(path));
            // pmx header
            var magic=io.GetAscii(4);
            if(magic!="PMX "){
                throw new PmxException("invalid magic");
            }
            var version=io.GetFloat();
            if(version!=2.0f){
                throw new PmxException("invalid version");
            }
            // flags
            int flags=io.GetByte();
            if(flags!=8){
                throw new PmxException("invalid byte");
            }
            TEXT_ENCODING encoding=(TEXT_ENCODING)io.GetByte();
            byte additional_uv=io.GetByte();
            byte vertex_index_bytes=io.GetByte();
            byte texture_index_bytes=io.GetByte();
            byte material_index_bytes=io.GetByte();
            byte bone_index_bytes=io.GetByte();
            byte morph_index_bytes=io.GetByte();
            byte rigidbody_index_bytes=io.GetByte();

            var loader=new Loader(
                    GetTextFunc(encoding),
                    GetIndexFunc(vertex_index_bytes),
                    GetIndexFunc(texture_index_bytes),
                    GetIndexFunc(bone_index_bytes)
                    );

            return loader.load(io);
        }