void InitArchFile()
 {
     if (arch3dFile == null)
     {
         arch3dFile = new Arch3dFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, Arch3dFile.Filename), FileUsage.UseMemory, true);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads model data for conversion.
        /// </summary>
        /// <param name="id">Model ID.</param>
        /// <param name="scale">Amount to scale model.</param>
        private void LoadModelData(uint id, float scale)
        {
            // Open ARCH3D.BSA
            Arch3dFile arch3dFile = new Arch3dFile(
                Path.Combine(arena2Path, "ARCH3D.BSA"),
                FileUsage.UseDisk,
                true);

            // Get DFMesh
            int    record = arch3dFile.GetRecordIndex(id);
            DFMesh dfMesh = arch3dFile.GetMesh(record);

            // Scale DFMesh
            if (scale != 1.0f)
            {
                foreach (var mesh in dfMesh.SubMeshes)
                {
                    foreach (var plane in mesh.Planes)
                    {
                        for (int point = 0; point < plane.Points.Length; point++)
                        {
                            plane.Points[point].X *= scale;
                            plane.Points[point].Y *= scale;
                            plane.Points[point].Z *= scale;
                        }
                    }
                }
            }

            // Load model data
            model        = new ModelData();
            model.DFMesh = dfMesh;
            LoadVertices(ref model);
            LoadIndices(ref model);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="device">Graphics Device.</param>
 /// <param name="arena2Path">Path to Arena2 folder.</param>
 public ModelManager(GraphicsDevice device, string arena2Path)
 {
     // Setup
     graphicsDevice         = device;
     arch3dFile             = new Arch3dFile(Path.Combine(arena2Path, Arch3dFile.Filename), FileUsage.UseDisk, true);
     arch3dFile.AutoDiscard = true;
     this.arena2Path        = arena2Path;
     modelDataDict          = new Dictionary <uint, ModelData>();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="arena2Path">Path to Arena2 folder.</param>
        public DFCollada(string arena2Path)
        {
            // Arena2
            this.arena2Path = arena2Path;

            // Textures
            this.textureFile         = new TextureFile();
            this.textureFile.Palette = new DFPalette(
                Path.Combine(arena2Path, textureFile.PaletteName));

            // ARCH3D.BSA
            this.arch3dFile = new Arch3dFile(
                Path.Combine(arena2Path, "ARCH3D.BSA"),
                FileUsage.UseDisk,
                true);
        }
        /// <summary>
        /// ARCH3D.BSA: Modify base texture assigned to plane.
        /// </summary>
        /// <param name="MeshID">ID of mesh.</param>
        /// <param name="planeIndex">Plane index.</param>
        /// <param name="textureArchive">New texture archive index to set.</param>
        /// <param name="textureRecord">New texture record inex to set.</param>
        public void ModPlaneTexture(uint MeshID, int planeIndex, int textureArchive, int textureRecord)
        {
            // Load resources
            string     path       = Path.Combine(arena2Path, "ARCH3D.BSA");
            Arch3dFile arch3dFile = new Arch3dFile(
                path,
                FileUsage.UseMemory,
                true);
            BsaFile bsaFile = new BsaFile(
                path,
                FileUsage.UseDisk,
                false);

            // Get mesh record
            int index = arch3dFile.GetRecordIndex(MeshID);

            arch3dFile.LoadRecord(index);
            Arch3dFile.MeshRecord record = arch3dFile.MeshRecords[index];

            // Get binary record
            byte[] buffer = bsaFile.GetRecordBytes(index);

            // Compose new texture bitfield
            UInt16 textureBitfield = (UInt16)((textureArchive << 7) + textureRecord);

            // Get start position of plane header
            long position = record.PureMesh.Planes[planeIndex].Header.Position;

            // Offset to texture bitfield
            position += 2;

            // Create stream to binary record
            MemoryStream ms = new MemoryStream(buffer);

            ms.Position = position;

            // Write new bitfield
            BinaryWriter writer = new BinaryWriter(ms, Encoding.UTF8);

            writer.Write(textureBitfield);
            writer.Close();

            // Save back binary record
            bsaFile.RewriteRecord(index, buffer);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="core">Engine core.</param>
        public ModelManager(DeepCore core)
        {
            // Save references
            this.core            = core;
            this.materialManager = core.MaterialManager;
            this.graphicsDevice  = core.GraphicsDevice;
            this.arena2Path      = core.Arena2Path;

            // Setup
            arch3dFile             = new Arch3dFile(Path.Combine(arena2Path, Arch3dFile.Filename), FileUsage.UseDisk, true);
            modelDataDict          = new Dictionary <uint, ModelData>();
            arch3dFile.AutoDiscard = true;

            // Load effect
            modelEffect            = core.ContentManager.Load <Effect>("Effects/RenderGeometry");
            modelEffect_World      = modelEffect.Parameters["World"];
            modelEffect_View       = modelEffect.Parameters["View"];
            modelEffect_Projection = modelEffect.Parameters["Projection"];
        }
        static void Main(string[] args)
        {
            // Specify Arena2 path of local Daggerfall installation
            string MyArena2Path = "C:\\dosgames\\DAGGER\\ARENA2";

            // Path to BSA file
            string FilePath = Path.Combine(MyArena2Path, "ARCH3D.BSA");

            // Open file
            Arch3dFile arch3dFile = new Arch3dFile(
                FilePath,
                FileUsage.UseDisk,
                true);

            // Output some information about the file
            Console.WriteLine("{0} has {1} records",
                              Path.GetFileName(FilePath),
                              arch3dFile.Count);

            // Get a mesh record
            int    record = 5557;
            DFMesh mesh   = arch3dFile.GetMesh(record);

            // Output some information about this record
            Console.WriteLine("Record {0} has {1} total vertices and ObjectID {2}",
                              record,
                              mesh.TotalVertices,
                              mesh.ObjectId);

            // Output the texture archives used for this mesh
            Console.WriteLine("The following textures are used:");
            foreach (DFMesh.DFSubMesh sm in mesh.SubMeshes)
            {
                Console.WriteLine("TEXTURE.{0:000} (Record {1})",
                                  sm.TextureArchive,
                                  sm.TextureRecord);
            }
        }
Ejemplo n.º 8
0
        private bool ReadyCheck()
        {
            // Ensure we have a DaggerfallUnity reference
            if (dfUnity == null)
            {
                dfUnity = DaggerfallUnity.Instance;
            }

            // Do nothing if DaggerfallUnity not ready
            if (!dfUnity.IsReady)
            {
                DaggerfallUnity.LogMessage("MeshReader: DaggerfallUnity component is not ready. Have you set your Arena2 path?");
                return(false);
            }

            // Ensure reader is created
            if (arch3dFile == null)
            {
                arch3dFile = new Arch3dFile(Path.Combine(dfUnity.Arena2Path, Arch3dFile.Filename), FileUsage.UseMemory, true);
            }

            return(true);
        }