Exemple #1
0
        public static PartWrapper GetPartFromDirectory(string path, int partID, bool loadMeshes)
        {
            //var primitivesDir = Path.Combine(path, "db\\Primitives");
            //var meshesDir = Path.Combine(path, "db\\Primitives\\LOD0");

            var primitivesDir = path;
            var meshesDir     = Path.Combine(path, "LOD0");

            var primitiveFile = Path.Combine(primitivesDir, $"{partID}.xml");

            if (!File.Exists(primitiveFile))
            {
                throw new FileNotFoundException($"Primitive file not found. ({partID}.xml)");
            }

            var surfaces = new List <PartSurfaceMesh>();

            if (Directory.Exists(meshesDir))
            {
                foreach (string meshPath in Directory.GetFiles(meshesDir, $"{partID}.g*"))
                {
                    if (!PartSurfaceMesh.ParseSurfaceID(meshPath, out int surfID))
                    {
                        surfID = surfaces.Count;
                    }

                    var surfaceInfo = new PartSurfaceMesh(partID, surfID, loadMeshes ? MeshFile.Read(meshPath) : null)
                    {
                        Filepath = meshPath
                    };
                    surfaces.Add(surfaceInfo);
                }
            }

            if (!surfaces.Any())
            {
                throw new FileNotFoundException($"Mesh file not found. ({partID}.g)");
            }

            return(new PartWrapper(Primitive.Load(primitiveFile), surfaces)
            {
                PartID = partID,
                Filepath = primitiveFile
            });
        }
Exemple #2
0
        public static List <PartSurfaceMesh> FindSurfaceMeshes(string directory, int partID)
        {
            var surfaces = new List <PartSurfaceMesh>();

            if (Directory.Exists(directory))
            {
                foreach (string meshPath in Directory.GetFiles(directory, $"{partID}.g*"))
                {
                    if (!PartSurfaceMesh.ParseSurfaceID(meshPath, out int surfID))
                    {
                        surfID = surfaces.Count;
                    }

                    surfaces.Add(new PartSurfaceMesh(partID, surfID, null));
                }
            }

            return(surfaces);
        }
Exemple #3
0
        public static PartWrapper GetPartFromLif(LifFile lif, int partID, bool loadMeshes)
        {
            var primitiveFolder = lif.GetFolder("Primitives");
            var meshesFolder    = primitiveFolder.GetFolder("LOD0");

            var primitiveEntry = primitiveFolder.GetFile($"{partID}.xml");

            if (primitiveEntry == null)
            {
                throw new FileNotFoundException($"Primitive file not found. ({partID}.xml)");
            }

            var surfaces = new List <PartSurfaceMesh>();

            foreach (var meshEntry in meshesFolder.GetFiles($"{partID}.g*"))
            {
                if (!PartSurfaceMesh.ParseSurfaceID(meshEntry.Name, out int surfID))
                {
                    surfID = surfaces.Count;
                }

                var surfaceInfo = new PartSurfaceMesh(partID, surfID,
                                                      loadMeshes ? MeshFile.Read(meshEntry.GetStream()) : null);
                surfaces.Add(surfaceInfo);
            }

            if (!surfaces.Any())
            {
                throw new FileNotFoundException($"Mesh file not found. ({partID}.g)");
            }

            var primitive = Primitive.Load(primitiveEntry.GetStream());

            primitive.ID = partID;
            return(new PartWrapper(primitive, surfaces)
            {
                PartID = partID
            });
        }