Contains methods and members that control a GameMode, a collection of maps, scripts and assets.
Inheritance: Pokemon3D.Common.GameContextObject, IDataModelContainer, IDisposable
Exemple #1
0
        private static ModelMesh LoadPMesh(GameMode gameMode, string filePath)
        {
            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {
                using (var binaryReader = new BinaryReader(fileStream))
                {
                    var vertexCount = binaryReader.ReadInt32();
                    var indicesCount = binaryReader.ReadInt32();
                    var textureName = binaryReader.ReadString();

                    var textureFilePath = Path.Combine(Path.GetDirectoryName(filePath) ?? "", Path.GetFileName(textureName) ?? "");
                    Texture2D texture = null;
                    if (File.Exists(textureFilePath))
                    {
                        texture = gameMode.GetTextureFromRawFolder(textureFilePath);
                    }

                    var geometryData = new GeometryData
                    {
                        Vertices = new VertexPositionNormalTexture[vertexCount],
                        Indices = new ushort[indicesCount]
                    };

                    for (var i = 0; i < vertexCount; i++)
                    {
                        var position = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        var normal = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        var uv = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
                        geometryData.Vertices[i] = new VertexPositionNormalTexture(position, normal, uv);
                    }

                    for(var i = 0; i < indicesCount; i++)
                    {
                        geometryData.Indices[i] = (ushort) binaryReader.ReadInt32();
                    }

                    return new ModelMesh
                    {
                        Mesh = new Mesh(gameMode.GraphicsDevice, geometryData, PrimitiveType.TriangleList, false),
                        Material = new Material
                        {
                            DiffuseTexture = texture
                        }
                    };
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads required data once the <see cref="GameMode"/> is loaded.
        /// </summary>
        /// <param name="gameMode">The GameMode that this save game is linked to.</param>
        public void Load(GameMode gameMode)
        {
            _gameMode = gameMode;

            _loadedItems = 0;
            _loadingCounter = 0;

            if (_dataModel.Pokemon == null)
                _dataModel.Pokemon = new PokemonSaveModel[] { };
            
            _loadingCounter += _dataModel.Pokemon.Length;

            foreach (var pokemon in _dataModel.Pokemon)
            {
                var p = _gameMode.PokemonFactory.GetPokemon(pokemon);
                _loadedItems++;
                PartyPokemon.Add(p);
            }
        }
Exemple #3
0
        private Texture2D GetTextureFromSlot(GameMode gameMode, string modelDirectory, TextureSlot textureSlot)
        {
            if (string.IsNullOrEmpty(textureSlot.FilePath)) return null;

            var fileName = Path.GetFileName(textureSlot.FilePath) ?? "";
            var textureFilePath = Path.Combine(modelDirectory, fileName);

            if (!File.Exists(fileName)) return null;

            return gameMode.GetTextureFromRawFolder(textureFilePath);
        }
Exemple #4
0
        private Material GenerateMaterialFromMesh(int materialIndex, GameMode gameMode, Assimp.Scene assimpScene, string modelDirectory)
        {
            var assimpMaterial = assimpScene.Materials[materialIndex];

            Texture2D texture = null;
            if (assimpMaterial.HasTextureDiffuse)
            {
                texture = GetTextureFromSlot(gameMode, modelDirectory, assimpMaterial.TextureDiffuse);
            }

            return new Material { DiffuseTexture = texture };
        }
Exemple #5
0
        public ModelMesh(GameMode gameMode, Assimp.Scene assimpScene, Assimp.Mesh assimpMesh, string modelDirectory)
        {
            var geometryData = GenerateGeometryDataFromAssimpMesh(assimpMesh);

            gameMode.EnsureExecutedInMainThread(() => Mesh = new Mesh(gameMode.GraphicsDevice, geometryData));
            Material = GenerateMaterialFromMesh(assimpMesh.MaterialIndex, gameMode, assimpScene, modelDirectory);
        }
Exemple #6
-1
        public static ModelMesh[] LoadFromFile(GameMode gameMode, string filePath)
        {
            if (".pmesh".Equals(Path.GetExtension(filePath), StringComparison.OrdinalIgnoreCase))
            {
                return new[] { LoadPMesh(gameMode, filePath) };
            }
            else
            {
                var modelDirectory = Path.GetDirectoryName(filePath);

                var context = new AssimpContext();
                const PostProcessSteps flags = PostProcessSteps.GenerateNormals | PostProcessSteps.GenerateUVCoords
                                               | PostProcessSteps.FlipWindingOrder
                                               | PostProcessSteps.FlipUVs;
                var scene = context.ImportFile(filePath, flags);

                var meshs = new List<ModelMesh>();
                foreach (var assimpMesh in scene.Meshes)
                {
                    var modelMesh = new ModelMesh(gameMode, scene, assimpMesh, modelDirectory);
                    meshs.Add(modelMesh);
                }

                return meshs.ToArray();
            } 
        }