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); }
public void Preload() { var data = FileLoader.GetFiles(new[] { PrimitivesFilePath, NaturesFilePath, TypesFilePath, PokedexesFilePath }); _primitiveModels = DataModel <PrimitiveModel[]> .FromByteArray(data[0].Data); foreach (var primitiveModel in _primitiveModels) { var geometryData = new GeometryData { Vertices = primitiveModel.Vertices.Select(v => new VertexPositionNormalTexture { Position = v.Position.GetVector3(), TextureCoordinate = v.TexCoord.GetVector2(), Normal = v.Normal.GetVector3() }).ToArray(), Indices = primitiveModel.Indices.Select(i => (ushort)i).ToArray() }; Mesh mesh = null; GameContext.EnsureExecutedInMainThread(() => mesh = new Mesh(GraphicsDevice, geometryData)); _meshPrimitivesByName.Add(primitiveModel.Id, mesh); } _natureModels = DataModel <NatureModel[]> .FromByteArray(data[1].Data); _typeModels = DataModel <TypeModel[]> .FromByteArray(data[2].Data); _pokedexModels = DataModel <PokedexModel[]> .FromByteArray(data[3].Data); var movesFilePaths = FileLoader.GetFilesOfFolder(MoveFilesPath); _moveModels = movesFilePaths.Select(d => DataModel <MoveModel> .FromByteArray(d.Data)).ToArray(); var itemsFiles = FileLoader.GetFilesOfFolder(ItemFilesPath); _itemModels = itemsFiles.Select(d => DataModel <ItemModel> .FromByteArray(d.Data)).ToArray(); var abilityFiles = FileLoader.GetFilesOfFolder(AbilityFilesPath); _abilityModels = abilityFiles.Select(d => DataModel <AbilityModel> .FromByteArray(d.Data)).ToArray(); }
public CollisionManager() { _allColliders = new List<Collider>(); _allTriggers = new List<Collider>(); _allTriggersAndColliders = new List<Collider>(); var geometryBox = new GeometryData { Vertices = new[] { new VertexPositionNormalTexture(new Vector3(-0.5f, -0.5f, -0.5f), Vector3.Zero, Vector2.Zero), new VertexPositionNormalTexture(new Vector3( 0.5f, -0.5f, -0.5f), Vector3.Zero, Vector2.Zero), new VertexPositionNormalTexture(new Vector3(0.5f, -0.5f, 0.5f), Vector3.Zero, Vector2.Zero), new VertexPositionNormalTexture(new Vector3(-0.5f, -0.5f, 0.5f), Vector3.Zero, Vector2.Zero), new VertexPositionNormalTexture(new Vector3(-0.5f, 0.5f, -0.5f), Vector3.Zero, Vector2.Zero), new VertexPositionNormalTexture(new Vector3( 0.5f, 0.5f, -0.5f), Vector3.Zero, Vector2.Zero), new VertexPositionNormalTexture(new Vector3(0.5f, 0.5f, 0.5f), Vector3.Zero, Vector2.Zero), new VertexPositionNormalTexture(new Vector3(-0.5f, 0.5f, 0.5f), Vector3.Zero, Vector2.Zero), }, Indices = new ushort[] { 0,1,1,2,2,3,3,0, 4,5,5,6,6,7,7,4, 0,4,1,5,2,6,3,7 } }; _boundingBoxMesh = new Mesh(GameInstance.GraphicsDevice, geometryBox, PrimitiveType.LineList, false) { PreventDrawCallCount = true }; _lineDrawEffect = GameInstance.Content.Load<Effect>(ResourceNames.Effects.DebugShadowMap); _worldViewProjection = _lineDrawEffect.Parameters["WorldViewProjection"]; _modulateColor = _lineDrawEffect.Parameters["Color"]; _lineTechnique = _lineDrawEffect.Techniques["LineDraw"]; }
public Player(World world) { var playerEntity = world.EntitySystem.CreateEntity(true); var collisionSize = new Vector3(0.35f, 0.6f, 0.35f); var collisionOffset = new Vector3(0.0f, 0.3f, 0.0f); var mesh = new Mesh(GameInstance.GraphicsDevice, Primitives.GenerateQuadForYBillboard()); var diffuseTexture = GameInstance.Content.Load<Texture2D>(ResourceNames.Textures.DefaultGuy); var material = new Material { DiffuseTexture = diffuseTexture, UseTransparency = true, TexcoordScale = diffuseTexture.GetTexcoordsFromPixelCoords(32, 32), IsUnlit = true }; playerEntity.AddComponent(new ModelEntityComponent(playerEntity, mesh, material, true)); playerEntity.AddComponent(new FigureMovementAnimationComponent(playerEntity, diffuseTexture)); playerEntity.AddComponent(new CollisionEntityComponent(playerEntity, collisionSize, collisionOffset, "Player", true)); playerEntity.Position = new Vector3(5, 0, 8); var cameraEntity = world.EntitySystem.CreateEntity(true); cameraEntity.SetParent(playerEntity); _controllerComponent = cameraEntity.AddComponent(new PlayerControllerComponent(cameraEntity)); var cameraComponent = cameraEntity.AddComponent(new CameraEntityComponent(cameraEntity, new Skybox(GameInstance) { Scale = 50, Texture = GameInstance.Content.Load<Texture2D>(ResourceNames.Textures.skybox_texture) })); cameraComponent.FarClipDistance = 50.0f; Camera = cameraComponent.Camera; var overlayCamera = cameraEntity.AddComponent(new CameraEntityComponent(cameraEntity, null, CameraMasks.UiOverlays)); overlayCamera.Camera.FarClipDistance = 100.0f; overlayCamera.Camera.ClearColor = null; overlayCamera.Camera.DepthClear = 1.0f; overlayCamera.Camera.DepthStencilState = DepthStencilState.Default; }
/// <summary> /// Merges a list of entities. These entities must be static and contain a visual component only. /// </summary> /// <param name="entitiesToMerge">Entites to merge.</param> /// <returns>Merged list of entities.</returns> public List<Entity> MergeStaticVisualEntities(IList<Entity> entitiesToMerge) { var entitiesToMergeList = entitiesToMerge.Where(IsVisualEntityToMerge).ToArray(); var entitiesNotToMerge = entitiesToMerge.Except(entitiesToMergeList).ToArray(); var entitiesByCategory = entitiesToMergeList.GroupBy(e => e.GetComponent<ModelEntityComponent>().Material.CompareId); var mergedEntities = new List<Entity>(); foreach (var entityListToMerge in entitiesByCategory) { if (entityListToMerge.Count() == 1) continue; var entity = CreateEntity(true); var mergeData = entityListToMerge.Select(ConvertEntityToGeometryMerge); var mergedGeometry = GeometryData.Merge(mergeData); Mesh mergedMesh = null; GameInstance.EnsureExecutedInMainThread(() => mergedMesh = new Mesh(GameController.Instance.GraphicsDevice, mergedGeometry)); var material = entityListToMerge.First().GetComponent<ModelEntityComponent>().Material; material.TexcoordOffset = Vector2.Zero; material.TexcoordScale = Vector2.One; entity.AddComponent(new ModelEntityComponent(entity, mergedMesh, material, false)); foreach (var entityToRemove in entityListToMerge) { RemoveEntity(entityToRemove); } mergedEntities.Add(entity); } return mergedEntities.Concat(entitiesNotToMerge).ToList(); }
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); }
public void Preload() { var data = FileLoader.GetFiles(new[] { PrimitivesFilePath, NaturesFilePath, TypesFilePath, PokedexesFilePath }); _primitiveModels = DataModel<PrimitiveModel[]>.FromByteArray(data[0].Data); foreach (var primitiveModel in _primitiveModels) { var geometryData = new GeometryData { Vertices = primitiveModel.Vertices.Select(v => new VertexPositionNormalTexture { Position = v.Position.GetVector3(), TextureCoordinate = v.TexCoord.GetVector2(), Normal = v.Normal.GetVector3() }).ToArray(), Indices = primitiveModel.Indices.Select(i => (ushort)i).ToArray() }; Mesh mesh = null; GameContext.EnsureExecutedInMainThread(() => mesh = new Mesh(GraphicsDevice, geometryData)); _meshPrimitivesByName.Add(primitiveModel.Id, mesh); } _natureModels = DataModel<NatureModel[]>.FromByteArray(data[1].Data); _typeModels = DataModel<TypeModel[]>.FromByteArray(data[2].Data); _pokedexModels = DataModel<PokedexModel[]>.FromByteArray(data[3].Data); var movesFilePaths = FileLoader.GetFilesOfFolder(MoveFilesPath); _moveModels = movesFilePaths.Select(d => DataModel<MoveModel>.FromByteArray(d.Data)).ToArray(); var itemsFiles = FileLoader.GetFilesOfFolder(ItemFilesPath); _itemModels = itemsFiles.Select(d => DataModel<ItemModel>.FromByteArray(d.Data)).ToArray(); var abilityFiles = FileLoader.GetFilesOfFolder(AbilityFilesPath); _abilityModels = abilityFiles.Select(d => DataModel<AbilityModel>.FromByteArray(d.Data)).ToArray(); }
public ModelEntityComponent(Entity referringEntity, Mesh mesh, Material material, bool isBillboard) : base(referringEntity) { _drawableElement = GameInstance.GetService<SceneRenderer>().CreateDrawableElement(true); _drawableElement.Material = material; _drawableElement.Mesh = mesh; IsBillboard = isBillboard; }