Beispiel #1
0
        public IReadOnlyList <IModel> Load(string name, IFileSystem fileSystem, Scene scene, BinaryReader reader, bool computeCRC)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            //Check if we can actually load this
            if (!SpriteLoader.IsSpriteFile(reader))
            {
                return(null);
            }

            var loader = new SpriteLoader(reader);

            var spriteFile = loader.ReadSpriteFile();

            uint crc = 0;

            if (computeCRC)
            {
                crc = loader.ComputeCRC();
            }

            var model = new SpriteModel(name, crc, spriteFile);

            if (scene != null)
            {
                model.ResourceContainer = new SpriteModelResourceContainer(scene, model);

                scene.AddContainer(model.ResourceContainer);
            }

            return(new[] { model });
        }
        public IReadOnlyList<IModel> Load(string name, IFileSystem fileSystem, Scene scene, BinaryReader reader, bool computeCRC)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            //Check if we can actually load this
            //TODO: because BSP files don't have a separate identifier, this will fail on invalid BSP versions
            //Should remove this once the other formats can be loaded
            if (!BSPLoader.IsBSPFile(reader))
            {
                return null;
            }

            var loader = new BSPLoader(reader);

            var bspFile = loader.ReadBSPFile();

            uint crc = 0;

            if (computeCRC)
            {
                crc = loader.ComputeCRC();
            }

            var hull0 = MakeHull0(bspFile);

            var models = new BSPModel[bspFile.Models.Count];

            models[0] = new BSPModel(name, crc, bspFile, bspFile.Models[0], hull0);

            //add all of its submodels
            //First submodel (0) is the world
            for (var i = 1; i < bspFile.Models.Count; ++i)
            {
                models[i] = new BSPModel($"{_bspModelNamePrefix}{i}", crc, bspFile, bspFile.Models[i], hull0);
            }

            if (scene != null)
            {
                foreach (var model in models)
                {
                    model.ResourceContainer = new BSPModelResourceContainer(scene, model);

                    scene.AddContainer(model.ResourceContainer);
                }
            }

            return models;
        }
 public BrushModelRenderer(Scene scene)
 {
     scene.AddContainer(this);
 }
        public IReadOnlyList <IModel> Load(string name, IFileSystem fileSystem, Scene scene, BinaryReader reader, bool computeCRC)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            //Check if we can actually load this
            if (!StudioLoader.IsStudioFile(reader))
            {
                return(null);
            }

            var loader = new StudioLoader(reader);

            (var studioFile, var rawSequences) = loader.ReadStudioFile();

            var baseName  = Path.GetFileNameWithoutExtension(name);
            var extension = Path.GetExtension(name);

            if (studioFile.Textures == null)
            {
                //Read the textures
                var textureFileName = Path.Combine(Path.GetDirectoryName(name), baseName + "T" + extension);

                var textureLoader = new StudioLoader(new BinaryReader(fileSystem.OpenRead(textureFileName)));

                (var textureFile, _) = textureLoader.ReadStudioFile();

                //Merge into main file
                studioFile.Textures = textureFile.Textures;
                studioFile.Skins    = textureFile.Skins;
            }

            //Read animation data from sequence files
            for (var i = 1; i < studioFile.SequenceGroups.Count; ++i)
            {
                var sequenceFileName = Path.Combine(Path.GetDirectoryName(name), baseName + i.ToString("D2") + extension);

                var sequenceLoader = new StudioSequenceLoader(new BinaryReader(fileSystem.OpenRead(sequenceFileName)));

                sequenceLoader.ReadAnimations(studioFile, i, rawSequences);
            }

            uint crc = 0;

            if (computeCRC)
            {
                crc = loader.ComputeCRC();
            }

            var model = new StudioModel(name, crc, studioFile);

            if (scene != null)
            {
                model.ResourceContainer = new StudioModelResourceContainer(scene, model);

                scene.AddContainer(model.ResourceContainer);
            }

            return(new[] { model });
        }
Beispiel #5
0
        public SpriteModelRenderer(Scene scene, ILogger logger)
        {
            Logger = logger ?? throw new ArgumentNullException(nameof(logger));

            scene.AddContainer(this);
        }