示例#1
0
        public void LoadFrom(Level level, int index)
        {
            DLF_IO_INTER inter = level.ArxLevelNative.DLF.inters[index];

            name = ArxIOHelper.GetString(inter.name);

            string interPath = name.ToLowerInvariant();
            int    graphPos  = interPath.IndexOf("graph");

            interPath = interPath.Substring(graphPos);
            int lastDot = interPath.LastIndexOf('.');

            interPath = interPath.Substring(0, lastDot);

            var ftlPath = Path.Combine(EditorSettings.DataDir, "game", ArxIOHelper.ArxPathToPlatformPath(interPath + ".ftl"));

            if (File.Exists(ftlPath))
            {
                FTL_IO ftl = new FTL_IO();
                using (var fs = new FileStream(ftlPath, FileMode.Open, FileAccess.Read))
                    using (var unp = FTL_IO.EnsureUnpacked(fs))
                    {
                        ftl.ReadFrom(unp);
                    }

                var mesh = ftl.CreateMesh();
                var mf   = gameObject.AddComponent <MeshFilter>();
                mf.sharedMesh = mesh;
                var mr = gameObject.AddComponent <MeshRenderer>();
                mr.sharedMaterial = MaterialsDatabase.TEST;
            }

            //depending on what the path is load item, npc, fix, camera or marker
            if (interPath.Contains("items"))
            {
            }
            else if (interPath.Contains("npc"))
            {
            }
            else if (interPath.Contains("fix"))
            {
            }
            else if (interPath.Contains("camera"))
            {
            }
            else if (interPath.Contains("marker"))
            {
            }

            transform.localPosition    = inter.pos.ToVector3();
            transform.localEulerAngles = inter.angle.ToEuler();
        }
示例#2
0
        static void LoadMesh(Level lvl)
        {
            int       loadedPolys = 0;
            Stopwatch sw          = new Stopwatch();

            sw.Start();

            int lightIndex = 0;
            var fts        = lvl.ArxLevelNative.FTS;
            Dictionary <int, int> tcToIndex = new Dictionary <int, int>();

            //texture indices
            for (int i = 0; i < fts.textureContainers.Length; i++)
            {
                tcToIndex[fts.textureContainers[i].tc] = i;
            }

            //TODO: use external placeholder texture so it can be set to 0 on export
            var notFoundMaterialKey = new EditorMaterial(EditorSettings.DataDir + "graph\\interface\\misc\\default[icon].bmp", PolyType.GLOW, 0);

            for (int c = 0; c < fts.cells.Length; c++)
            {
                var cell = fts.cells[c];
                loadedPolys += cell.polygons.Length;
                for (int p = 0; p < cell.polygons.Length; p++)
                {
                    var poly = cell.polygons[p];

                    var matKey = notFoundMaterialKey;
                    if (tcToIndex.TryGetValue(poly.tex, out int textureIndex))
                    {
                        string texArxPath = ArxIOHelper.GetString(fts.textureContainers[textureIndex].fic);
                        string texPath    = TextureDatabase.GetRealTexturePath(EditorSettings.DataDir + texArxPath);
                        matKey = new EditorMaterial(texPath, poly.type, poly.transval); //TODO: speed up by using a pool of some sort?
                    }

                    MaterialMesh mm = lvl.EditableLevelMesh.GetMaterialMesh(matKey);

                    EditablePrimitiveInfo prim = new EditablePrimitiveInfo
                    {
                        polyType = poly.type,
                        norm     = poly.norm.ToVector3(),
                        norm2    = poly.norm2.ToVector3(),
                        area     = poly.area,
                        room     = poly.room,
                        paddy    = poly.paddy
                    };
                    int vertCount = prim.VertexCount;
                    for (int i = 0; i < vertCount; i++)
                    {
                        var vert = poly.vertices[i];
                        prim.vertices[i] = new EditableVertexInfo(new Vector3(vert.posX, vert.posY, vert.posZ),
                                                                  new Vector2(vert.texU, 1 - vert.texV),
                                                                  poly.normals[i].ToVector3(),
                                                                  ArxIOHelper.FromBGRA(lvl.ArxLevelNative.LLF.lightColors[lightIndex++]));
                    }

                    if (prim.IsTriangle)
                    {
                        //load 4th vertex manually as it has no lighting value and would break lighting otherwise
                        var lastVert = poly.vertices[3];
                        prim.vertices[3] = new EditableVertexInfo(new Vector3(lastVert.posX, lastVert.posY, lastVert.posZ),
                                                                  new Vector2(lastVert.texU, 1 - lastVert.texV),
                                                                  poly.normals[3].ToVector3(),
                                                                  Color.white);
                    }

                    mm.AddPrimitive(prim);
                }
            }

            foreach (var kv in lvl.EditableLevelMesh.MaterialMeshes)
            {
                kv.Value.UpdateMesh();
            }
            UnityEngine.Debug.Log("total load time: " + sw.Elapsed);
            UnityEngine.Debug.Log("Loaded polys: " + loadedPolys);
        }