Exemplo n.º 1
0
        static Model convertAndInsertModel(GeoSet tgt, Model32 v)
        {
            Model z = new Model();

            z.flags             = (ModelFlags)v.flg1;
            z.visibility_radius = v.radius;
            z.num_textures      = v.num_textures;
            z.m_id            = v.id;
            z.boneinfo_offset = v.boneinfo;

            z.BlendMode       = (CoHBlendMode)v.blend_mode;
            z.vertex_count    = v.vertex_count;
            z.model_tri_count = v.model_tri_count;
            z.scale           = v.m_scale;
            z.box.SetMinMax(v.m_min, v.m_max);
            for (byte i = 0; i < 7; ++i)
            {
                DeltaPack dp_blk = z.packed_data.get(i);
                PackInfo  pi     = v.pack_data[i];
                dp_blk.compressed_size = pi.compressed_size;
                dp_blk.uncomp_size     = pi.uncomp_size;
                dp_blk.compressed_data = null;
                dp_blk.buffer_offset   = pi.compressed_data_off;
            }

            tgt.subs.Add(z);
            return(z);
        }
Exemplo n.º 2
0
        private static GeoSet findAndPrepareGeoSet(string fname, string base_path)
        {
            GeoSet     geoset     = null;
            string     name_fixed = fname.Replace(".anm", ".geo");
            string     true_path  = Tools.getFilepathCaseInsensitive(base_path + name_fixed);
            FileStream fp;

            try
            {
                fp = File.Open(true_path, FileMode.Open);
            }
            catch (Exception)
            {
                Debug.LogError("Can't find .geo file" + fname);
                return(null);
            }

            geoset = new GeoSet();
            if (true_path.StartsWith(base_path))
            {
                geoset.geopath = true_path.Substring(base_path.Length);
            }
            else
            {
                throw new InvalidOperationException("True path is not a sub-path of base directory");
            }

            geoset.geosetLoadHeader(fp);
            geoset.full_geo_path = true_path;
            fp.Close();
            RuntimeData rd = RuntimeData.get();

            rd.s_name_to_geoset[fname] = geoset;
            return(geoset);
        }
Exemplo n.º 3
0
        public Model modelFind(string geoset_name, string model_name)
        {
            Model ptr_sub = null;

            if (string.IsNullOrEmpty(model_name) || string.IsNullOrEmpty(geoset_name))
            {
                Debug.LogError("Bad model/geometry set requested:");
                if (!string.IsNullOrEmpty(model_name))
                {
                    Debug.LogError("Model: " + model_name);
                }
                if (!string.IsNullOrEmpty(geoset_name))
                {
                    Debug.LogError("GeoFile: " + geoset_name);
                }
                return(null);
            }

            GeoSet geoset = GeoSet.Load(geoset_name, m_base_path);

            if (null == geoset) // failed to load the geometry set
            {
                Debug.LogErrorFormat("Geoset load failed {0},{1}", geoset_name, m_base_path);
                return(null);
            }

            int end_of_name_idx = model_name.IndexOf("__");

            if (end_of_name_idx == -1)
            {
                end_of_name_idx = model_name.Length;
            }

            string basename = model_name.Substring(0, end_of_name_idx);

            foreach (Model m in geoset.subs)
            {
                string modelname = m.name;
                if (modelname.Length == 0)
                {
                    continue;
                }

                bool subs_in_place = (modelname.Length <= end_of_name_idx ||
                                      modelname.Substring(end_of_name_idx).StartsWith("__"));
                if (subs_in_place && modelname.StartsWith(basename, StringComparison.OrdinalIgnoreCase))
                {
                    ptr_sub = m; // TODO: return immediately
                }
            }

            return(ptr_sub);
        }
Exemplo n.º 4
0
        public bool loadNamedPrefab(string name, LoadingContext ctx)
        {
            GeoStoreDef geo_store = groupGetFileEntryPtr(name);

            if (null == geo_store)
            {
                return(false);
            }
            if (geo_store.loaded)
            {
                return(true);
            }

            geo_store.loaded = true;
            // load given prefab's geoset
            GeoSet.Load(geo_store.geopath, m_base_path);
            ctx.loadSubgraph(geo_store.geopath, this);
            return(loadPrefabForNode(ctx.m_target.getNodeByName(name), ctx));
        }
Exemplo n.º 5
0
        void addModelStubs(GeoSet geoset)
        {
            RuntimeData rd = RuntimeData.get();

            foreach (Model m in geoset.subs)
            {
                GeometryModifiersData gmod = rd.m_modifiers.findGeomModifier(m.name, "");
                if (gmod != null)
                {
                    if (null == m.trck_node)
                    {
                        m.trck_node = new ModelModifiers();
                    }
                    if (m.name == "_FLRSHPS_WIN_H__FLRSHPS_Window")
                    {
                        Debug.LogFormat("GMod for geoset model {0}", gmod);
                    }
                    m.trck_node = gmod.node.clone();
                    m.src_mod   = gmod;
                }
            }
        }
Exemplo n.º 6
0
        internal bool loadPrefabForNode(SceneNode node, LoadingContext ctx) //groupLoadRequiredLibsForNode
        {
            GeoStoreDef gf;

            if (null == node || false == node.in_use)
            {
                return(false);
            }

            if (null != node.m_geoset_info)
            {
                gf = node.m_geoset_info;
            }
            else
            {
                gf = groupGetFileEntryPtr(node.m_name);
                node.m_geoset_info = gf;
                if (null == node.m_geoset_info)
                {
                    node.m_geoset_info = m_geostore_sentinel; // prevent future load attempts
                }
            }

            if (null == gf || gf == m_geostore_sentinel)
            {
                return(false);
            }

            if (!gf.loaded)
            {
                gf.loaded = true;
                GeoSet.Load(gf.geopath, m_base_path); // load given subgraph's root geoset
                ctx.loadSubgraph(gf.geopath, this);
            }

            return(true);
        }
Exemplo n.º 7
0
        private void geosetLoadHeader(FileStream fp)
        {
            int          anm_hdr_size;
            int          headersize;
            BinaryReader br = new BinaryReader(fp, new ASCIIEncoding());

            anm_hdr_size  = br.ReadInt32();
            anm_hdr_size -= 4;
            headersize    = br.ReadInt32();

            byte[] zipmem = br.ReadBytes(anm_hdr_size);
            byte[] decompr;
            Tools.DecompressData(zipmem, out decompr, headersize);

            Stream       unc_arr    = new MemoryStream(decompr);
            BinaryReader decomp_hdr = new BinaryReader(unc_arr, new ASCIIEncoding());

            //const uint8_t * mem = (const uint8_t *)unc_arr.data();
            TexBlockInfo info = readTexBlock(decomp_hdr);

            this.geo_data_size = info.size1;

            var ver = decomp_hdr.BaseStream.Position;

            tex_names = convertTextureNames(decomp_hdr);


            decomp_hdr.BaseStream.Seek(ver + info.texname_blocksize, SeekOrigin.Begin);

            MemoryStream bone_name_stream = new MemoryStream(decomp_hdr.ReadBytes(info.bone_names_size));
            BinaryReader bone_name_reader = new BinaryReader(bone_name_stream, new ASCIIEncoding());

            MemoryStream tex_binds_stream = new MemoryStream(decomp_hdr.ReadBytes(info.tex_binds_size));
            BinaryReader tex_bind_reader  = new BinaryReader(tex_binds_stream, new ASCIIEncoding());


            GeosetHeader32 header32 = readGeosetHeader(decomp_hdr);

            Model32[] ptr_subs = readModel32(decomp_hdr, header32.num_subs);
            parent_geoset = this;
            name          = new string(header32.name);
            name          = name.Substring(0, Math.Max(0, name.IndexOf('\0')));
            bool has_alt_pivot = false;

            for (int idx = 0; idx < header32.num_subs; ++idx)
            {
                Model32            sub_model = ptr_subs[idx];
                List <TextureBind> binds     = new List <TextureBind>();
                if (info.tex_binds_size != 0)
                {
                    binds = convertTexBinds(sub_model.num_textures, sub_model.texture_bind_offsets, tex_bind_reader);
                }

                if (sub_model.num_altpivots > 0)
                {
                    has_alt_pivot |= true;
                }
                Model m = convertAndInsertModel(this, sub_model);
                m.texture_bind_info = binds;
                m.geoset            = this;
                m.name        = readCStringAtOffset(bone_name_reader, sub_model.bone_name_offset);
                ptr_subs[idx] = sub_model;
            }

            if (this.subs.Count != 0)
            {
                addModelStubs(this);
            }
            if (has_alt_pivot)
            {
                Debug.Log("Alternate model pivots were not converted");
            }
        }