public virtual IEnumerable<Entity> Generate(EntitySystem entitySystem, EntityFieldModel entityDefinition, EntityFieldPositionModel entityPlacing, Vector3 position) { return new List<Entity> { entitySystem.CreateEntityFromDataModel(entityDefinition.Entity, entityPlacing, position) }; }
private Entity CreateEntityFromDataModel(EntityModel entityModel, EntityFieldPositionModel entityPlacing, Vector3 position) { var entity = EntitySystem.CreateEntity(true); entity.Id = entityModel.Id; entity.IsStatic = entityModel.IsStatic; entity.Scale = entityPlacing.Scale?.GetVector3() ?? Vector3.One; if (entityPlacing.Rotation != null) { if (entityPlacing.CardinalRotation) { entity.EulerAngles = new Vector3 { X = entityPlacing.Rotation.X * MathHelper.PiOver2, Y = entityPlacing.Rotation.Y * MathHelper.PiOver2, Z = entityPlacing.Rotation.Z * MathHelper.PiOver2 }; } else { entity.EulerAngles = new Vector3 { X = MathHelper.ToRadians(entityPlacing.Rotation.X), Y = MathHelper.ToRadians(entityPlacing.Rotation.Y), Z = MathHelper.ToRadians(entityPlacing.Rotation.Z) }; } } else { entity.EulerAngles = Vector3.Zero; } entity.Position = position; foreach (var compModel in entityModel.Components) { if (!entity.HasComponent(compModel.Id)) { entity.AddComponent(EntityComponentFactory.GetComponent(entity, compModel)); } } return(entity); }
/// <summary> /// Creates an entity reading json data model. It also attaches all known entity components. /// </summary> /// <param name="entityModel">Deserialized entity model.</param> /// <param name="entityPlacing">Placement of entity.</param> /// <param name="position">position of entity.</param> /// <param name="isInitializing">If the entity should be created in initializing mode. This needs to end initializing.</param> /// <returns>Created entity instance.</returns> public Entity CreateEntityFromDataModel(EntityModel entityModel, EntityFieldPositionModel entityPlacing, Vector3 position, bool isInitializing = false) { var entity = CreateEntity(isInitializing); entity.Id = entityModel.Id; foreach (var compModel in entityModel.Components) { if (!entity.HasComponent(compModel.Id)) { entity.AddComponent(EntityComponentFactory.GetComponent(entity, compModel)); } } entity.Scale = entityPlacing.Scale?.GetVector3() ?? Vector3.One; if (entityPlacing.Rotation != null) { if (entityPlacing.CardinalRotation) { entity.EulerAngles = new Vector3 { X = entityPlacing.Rotation.X * MathHelper.PiOver2, Y = entityPlacing.Rotation.Y * MathHelper.PiOver2, Z = entityPlacing.Rotation.Z * MathHelper.PiOver2 }; } else { entity.EulerAngles = new Vector3 { X = MathHelper.ToDegrees(entityPlacing.Rotation.X), Y = MathHelper.ToDegrees(entityPlacing.Rotation.Y), Z = MathHelper.ToDegrees(entityPlacing.Rotation.Z) }; } } else { entity.EulerAngles = Vector3.Zero; } entity.Position = position; return(entity); }
/// <summary> /// Creates an entity reading json data model. It also attaches all known entity components. /// </summary> /// <param name="entityModel">Deserialized entity model.</param> /// <param name="entityPlacing">Placement of entity.</param> /// <param name="position">position of entity.</param> /// <param name="isInitializing">If the entity should be created in initializing mode. This needs to end initializing.</param> /// <returns>Created entity instance.</returns> public Entity CreateEntityFromDataModel(EntityModel entityModel, EntityFieldPositionModel entityPlacing, Vector3 position, bool isInitializing = false) { var entity = CreateEntity(isInitializing); entity.Id = entityModel.Id; foreach (var compModel in entityModel.Components) { if (!entity.HasComponent(compModel.Id)) { entity.AddComponent(EntityComponentFactory.GetComponent(entity, compModel)); } } entity.Scale = entityPlacing.Scale?.GetVector3() ?? Vector3.One; if (entityPlacing.Rotation != null) { if (entityPlacing.CardinalRotation) { entity.EulerAngles = new Vector3 { X = entityPlacing.Rotation.X * MathHelper.PiOver2, Y = entityPlacing.Rotation.Y * MathHelper.PiOver2, Z = entityPlacing.Rotation.Z * MathHelper.PiOver2 }; } else { entity.EulerAngles = new Vector3 { X = MathHelper.ToDegrees(entityPlacing.Rotation.X), Y = MathHelper.ToDegrees(entityPlacing.Rotation.Y), Z = MathHelper.ToDegrees(entityPlacing.Rotation.Z) }; } } else { entity.EulerAngles = Vector3.Zero; } entity.Position = position; return entity; }
public List <Entity> PlaceEntities(EntityFieldModel entityDefinition, EntityFieldPositionModel entityPlacing, Vector3 offset) { var entities = new List <Entity>(); for (var x = 0; x < (int)entityPlacing.Size.X; x++) { for (var y = 0; y < (int)entityPlacing.Size.Y; y++) { for (var z = 0; z < (int)entityPlacing.Size.Z; z++) { var position = entityPlacing.Position.GetVector3() + new Vector3(x * entityPlacing.Steps.X, y * entityPlacing.Steps.Y, z * entityPlacing.Steps.Z) + offset; entities.Add(CreateEntityFromDataModel(entityDefinition.Entity, entityPlacing, position)); } } } return(entities); }
private Entity CreateEntityFromDataModel(EntityModel entityModel, EntityFieldPositionModel entityPlacing, Vector3 position) { var entity = EntitySystem.CreateEntity(true); entity.Id = entityModel.Id; entity.IsStatic = entityModel.IsStatic; entity.Scale = entityPlacing.Scale?.GetVector3() ?? Vector3.One; if (entityPlacing.Rotation != null) { if (entityPlacing.CardinalRotation) { entity.EulerAngles = new Vector3 { X = entityPlacing.Rotation.X * MathHelper.PiOver2, Y = entityPlacing.Rotation.Y * MathHelper.PiOver2, Z = entityPlacing.Rotation.Z * MathHelper.PiOver2 }; } else { entity.EulerAngles = new Vector3 { X = MathHelper.ToRadians(entityPlacing.Rotation.X), Y = MathHelper.ToRadians(entityPlacing.Rotation.Y), Z = MathHelper.ToRadians(entityPlacing.Rotation.Z) }; } } else { entity.EulerAngles = Vector3.Zero; } entity.Position = position; foreach (var compModel in entityModel.Components) { if (!entity.HasComponent(compModel.Id)) { entity.AddComponent(EntityComponentFactory.GetComponent(entity, compModel)); } } return entity; }
public List<Entity> PlaceEntities(EntityFieldModel entityDefinition, EntityFieldPositionModel entityPlacing, Vector3 offset) { var entities = new List<Entity>(); for (var x = 0; x < (int)entityPlacing.Size.X; x++) { for (var y = 0; y < (int)entityPlacing.Size.Y; y++) { for (var z = 0; z < (int)entityPlacing.Size.Z; z++) { var position = entityPlacing.Position.GetVector3() + new Vector3(x * entityPlacing.Steps.X, y * entityPlacing.Steps.Y, z * entityPlacing.Steps.Z) + offset; entities.Add(CreateEntityFromDataModel(entityDefinition.Entity, entityPlacing, position)); } } } return entities; }
public override IEnumerable <Entity> Generate(EntitySystem entitySystem, EntityFieldModel entityDefinition, EntityFieldPositionModel entityPlacing, Vector3 position) { // scale of the entity is the entire cube's scale. // generate 6 entities from the one definition that is passed in // the definition has to hold either 1, 5 or 6 textures. // if there are only 5 textures, then do not generate a bottom. // This is an option, because often times, there is no bottom needed. // if there is only 1 texture, it gets put on all 6 sides. //int? textureEnumLength = entityDefinition?.Entity?.RenderMode?.Textures?.Length; //if (textureEnumLength.HasValue && (textureEnumLength.Value == 1 || textureEnumLength.Value == 5 || textureEnumLength.Value == 6)) //{ // TextureSourceModel[] textures = null; // if (textureEnumLength.Value == 1) // { // textures = new TextureSourceModel[] // { // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0] // }; // } // else if (textureEnumLength.Value == 5) // { // textures = new TextureSourceModel[] // { // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[1], // entityDefinition.Entity.RenderMode.Textures[2], // entityDefinition.Entity.RenderMode.Textures[3], // entityDefinition.Entity.RenderMode.Textures[4] // }; // } // else if (textureEnumLength.Value == 6) // { // textures = new TextureSourceModel[] // { // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[1], // entityDefinition.Entity.RenderMode.Textures[2], // entityDefinition.Entity.RenderMode.Textures[3], // entityDefinition.Entity.RenderMode.Textures[4], // entityDefinition.Entity.RenderMode.Textures[5] // }; // } // // Front side: // var frontEntityModel = entityDefinition.Entity.CloneModel(); // var frontEntityPlacing = new EntityFieldPositionModel(); // frontEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[0] }; // frontEntityPlacing.CardinalRotation = true; // frontEntityPlacing.Rotation = new Vector3Model() // { // X = 0, // Y = 0, // Z = 0 // }; // frontEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var frontEntityPosition = new Vector3() // { // X = position.X, // Y = position.Y, // Z = position.Z + entityPlacing.Scale.Z / 2 // }; // yield return entitySystem.CreateEntityFromDataModel(frontEntityModel, frontEntityPlacing, frontEntityPosition); // // Back side: // var backEntityModel = entityDefinition.Entity.CloneModel(); // var backEntityPlacing = new EntityFieldPositionModel(); // backEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[1] }; // backEntityPlacing.CardinalRotation = true; // backEntityPlacing.Rotation = new Vector3Model() // { // X = 0, // Y = 2, // Z = 0 // }; // backEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var backEntityPosition = new Vector3() // { // X = position.X, // Y = position.Y, // Z = position.Z - entityPlacing.Scale.Z / 2 // }; // yield return entitySystem.CreateEntityFromDataModel(backEntityModel, backEntityPlacing, backEntityPosition); // //Left side: // var leftEntityModel = entityDefinition.Entity.CloneModel(); // var leftEntityPlacing = new EntityFieldPositionModel(); // leftEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[2] }; // leftEntityPlacing.CardinalRotation = true; // leftEntityPlacing.Rotation = new Vector3Model() // { // X = 0, // Y = 3, // Z = 0 // }; // leftEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var leftEntityPosition = new Vector3() // { // X = position.X - entityPlacing.Scale.X / 2, // Y = position.Y, // Z = position.Z // }; // yield return entitySystem.CreateEntityFromDataModel(leftEntityModel, leftEntityPlacing, leftEntityPosition); // //right side: // var rightEntityModel = entityDefinition.Entity.CloneModel(); // var rightEntityPlacing = new EntityFieldPositionModel(); // rightEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[3] }; // rightEntityPlacing.CardinalRotation = true; // rightEntityPlacing.Rotation = new Vector3Model() // { // X = 0, // Y = 1, // Z = 0 // }; // rightEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var rightEntityPosition = new Vector3() // { // X = position.X + entityPlacing.Scale.X / 2, // Y = position.Y, // Z = position.Z // }; // yield return entitySystem.CreateEntityFromDataModel(rightEntityModel, rightEntityPlacing, rightEntityPosition); // //top: // var topEntityModel = entityDefinition.Entity.CloneModel(); // var topEntityPlacing = new EntityFieldPositionModel(); // topEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[4] }; // topEntityPlacing.CardinalRotation = true; // topEntityPlacing.Rotation = new Vector3Model() // { // X = 3, // Y = 0, // Z = 0 // }; // topEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var topEntityPosition = new Vector3() // { // X = position.X, // Y = position.Y + entityPlacing.Scale.Y / 2, // Z = position.Z // }; // yield return entitySystem.CreateEntityFromDataModel(topEntityModel, topEntityPlacing, topEntityPosition); // //bottom: // if (textureEnumLength.Value != 5) // { // var bottomEntityModel = entityDefinition.Entity.CloneModel(); // var bottomEntityPlacing = new EntityFieldPositionModel(); // bottomEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[5] }; // bottomEntityPlacing.CardinalRotation = true; // bottomEntityPlacing.Rotation = new Vector3Model() // { // X = 1, // Y = 0, // Z = 0 // }; // bottomEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var bottomEntityPosition = new Vector3() // { // X = position.X, // Y = position.Y - entityPlacing.Scale.Y / 2, // Z = position.Z // }; // yield return entitySystem.CreateEntityFromDataModel(bottomEntityModel, bottomEntityPlacing, bottomEntityPosition); // } //} throw new NotImplementedException(); }
public virtual IEnumerable <Entity> Generate(EntitySystem entitySystem, EntityFieldModel entityDefinition, EntityFieldPositionModel entityPlacing, Vector3 position) { return(new List <Entity> { entitySystem.CreateEntityFromDataModel(entityDefinition.Entity, entityPlacing, position) }); }
public override IEnumerable<Entity> Generate(EntitySystem entitySystem, EntityFieldModel entityDefinition, EntityFieldPositionModel entityPlacing, Vector3 position) { // scale of the entity is the entire cube's scale. // generate 6 entities from the one definition that is passed in // the definition has to hold either 1, 5 or 6 textures. // if there are only 5 textures, then do not generate a bottom. // This is an option, because often times, there is no bottom needed. // if there is only 1 texture, it gets put on all 6 sides. //int? textureEnumLength = entityDefinition?.Entity?.RenderMode?.Textures?.Length; //if (textureEnumLength.HasValue && (textureEnumLength.Value == 1 || textureEnumLength.Value == 5 || textureEnumLength.Value == 6)) //{ // TextureSourceModel[] textures = null; // if (textureEnumLength.Value == 1) // { // textures = new TextureSourceModel[] // { // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[0] // }; // } // else if (textureEnumLength.Value == 5) // { // textures = new TextureSourceModel[] // { // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[1], // entityDefinition.Entity.RenderMode.Textures[2], // entityDefinition.Entity.RenderMode.Textures[3], // entityDefinition.Entity.RenderMode.Textures[4] // }; // } // else if (textureEnumLength.Value == 6) // { // textures = new TextureSourceModel[] // { // entityDefinition.Entity.RenderMode.Textures[0], // entityDefinition.Entity.RenderMode.Textures[1], // entityDefinition.Entity.RenderMode.Textures[2], // entityDefinition.Entity.RenderMode.Textures[3], // entityDefinition.Entity.RenderMode.Textures[4], // entityDefinition.Entity.RenderMode.Textures[5] // }; // } // // Front side: // var frontEntityModel = entityDefinition.Entity.CloneModel(); // var frontEntityPlacing = new EntityFieldPositionModel(); // frontEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[0] }; // frontEntityPlacing.CardinalRotation = true; // frontEntityPlacing.Rotation = new Vector3Model() // { // X = 0, // Y = 0, // Z = 0 // }; // frontEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var frontEntityPosition = new Vector3() // { // X = position.X, // Y = position.Y, // Z = position.Z + entityPlacing.Scale.Z / 2 // }; // yield return entitySystem.CreateEntityFromDataModel(frontEntityModel, frontEntityPlacing, frontEntityPosition); // // Back side: // var backEntityModel = entityDefinition.Entity.CloneModel(); // var backEntityPlacing = new EntityFieldPositionModel(); // backEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[1] }; // backEntityPlacing.CardinalRotation = true; // backEntityPlacing.Rotation = new Vector3Model() // { // X = 0, // Y = 2, // Z = 0 // }; // backEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var backEntityPosition = new Vector3() // { // X = position.X, // Y = position.Y, // Z = position.Z - entityPlacing.Scale.Z / 2 // }; // yield return entitySystem.CreateEntityFromDataModel(backEntityModel, backEntityPlacing, backEntityPosition); // //Left side: // var leftEntityModel = entityDefinition.Entity.CloneModel(); // var leftEntityPlacing = new EntityFieldPositionModel(); // leftEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[2] }; // leftEntityPlacing.CardinalRotation = true; // leftEntityPlacing.Rotation = new Vector3Model() // { // X = 0, // Y = 3, // Z = 0 // }; // leftEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var leftEntityPosition = new Vector3() // { // X = position.X - entityPlacing.Scale.X / 2, // Y = position.Y, // Z = position.Z // }; // yield return entitySystem.CreateEntityFromDataModel(leftEntityModel, leftEntityPlacing, leftEntityPosition); // //right side: // var rightEntityModel = entityDefinition.Entity.CloneModel(); // var rightEntityPlacing = new EntityFieldPositionModel(); // rightEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[3] }; // rightEntityPlacing.CardinalRotation = true; // rightEntityPlacing.Rotation = new Vector3Model() // { // X = 0, // Y = 1, // Z = 0 // }; // rightEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var rightEntityPosition = new Vector3() // { // X = position.X + entityPlacing.Scale.X / 2, // Y = position.Y, // Z = position.Z // }; // yield return entitySystem.CreateEntityFromDataModel(rightEntityModel, rightEntityPlacing, rightEntityPosition); // //top: // var topEntityModel = entityDefinition.Entity.CloneModel(); // var topEntityPlacing = new EntityFieldPositionModel(); // topEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[4] }; // topEntityPlacing.CardinalRotation = true; // topEntityPlacing.Rotation = new Vector3Model() // { // X = 3, // Y = 0, // Z = 0 // }; // topEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var topEntityPosition = new Vector3() // { // X = position.X, // Y = position.Y + entityPlacing.Scale.Y / 2, // Z = position.Z // }; // yield return entitySystem.CreateEntityFromDataModel(topEntityModel, topEntityPlacing, topEntityPosition); // //bottom: // if (textureEnumLength.Value != 5) // { // var bottomEntityModel = entityDefinition.Entity.CloneModel(); // var bottomEntityPlacing = new EntityFieldPositionModel(); // bottomEntityModel.RenderMode.Textures = new TextureSourceModel[] { textures[5] }; // bottomEntityPlacing.CardinalRotation = true; // bottomEntityPlacing.Rotation = new Vector3Model() // { // X = 1, // Y = 0, // Z = 0 // }; // bottomEntityPlacing.Scale = new Vector3Model() // { // X = entityPlacing.Scale.X, // Y = entityPlacing.Scale.Y, // Z = 1 // }; // var bottomEntityPosition = new Vector3() // { // X = position.X, // Y = position.Y - entityPlacing.Scale.Y / 2, // Z = position.Z // }; // yield return entitySystem.CreateEntityFromDataModel(bottomEntityModel, bottomEntityPlacing, bottomEntityPosition); // } //} throw new NotImplementedException(); }