private void Entities_AddItem(EntityCollection sender, EntityCollectionEventArgs e) { if (e.Item.Type == EntityType.Leader) { Leader leader = (Leader)e.Item; if (leader.Annotation != null) { this.entities.Add(leader.Annotation); } } else if (e.Item.Type == EntityType.Hatch) { Hatch hatch = (Hatch)e.Item; foreach (HatchBoundaryPath path in hatch.BoundaryPaths) { foreach (EntityObject entity in path.Entities) { this.entities.Add(entity); } } } else if (e.Item.Type == EntityType.Viewport) { Viewport viewport = (Viewport)e.Item; if (viewport.ClippingBoundary != null) { this.entities.Add(viewport.ClippingBoundary); } } this.OnEntityAddedEvent(e.Item); e.Item.Owner = this; }
private void Entities_BeforeAddItem(EntityCollection sender, EntityCollectionEventArgs e) { // null items, entities already owned by another Block, attribute definitions and attributes are not allowed in the entities list. if (e.Item == null) { e.Cancel = true; } else if (this.entities.Contains(e.Item)) { e.Cancel = true; } else if (this.Flags.HasFlag(BlockTypeFlags.ExternallyDependent)) { e.Cancel = true; } else if (e.Item.Owner != null) { // if the block does not belong to a document, all entities which owner is not null will be rejected if (this.Record.Owner == null) { e.Cancel = true; } // if the block belongs to a document, the entity will be added to the block only if both, the block and the entity document, are the same // this is handled by the BlocksRecordCollection } else { e.Cancel = false; } }
private void RemoveParticuleEmitterEntity(EntityCollectionEventArgs e) { if (e.Entity.Particules == null) { return; } EmitterStaticEntities.RemoveAll(x => x.Entity == e.Entity); }
private void Entities_AddItem(EntityCollection sender, EntityCollectionEventArgs e) { if (this.readOnly) { return; } this.OnEntityAddedEvent(e.Item); e.Item.Owner = this; }
public void OnStaticEntityRemoved(EntityCollectionEventArgs e) { var handler = StaticEntityRemoved; if (handler != null) { handler(this, e); } }
private void Entities_RemoveItem(EntityCollection sender, EntityCollectionEventArgs e) { if (this.readOnly) { return; } this.OnEntityRemovedEvent(e.Item); e.Item.Owner = null; }
private void RemoveOutOfChunkLightSourceStaticEntity(EntityCollectionEventArgs e) { var item = e.Entity as ILightEmitterEntity; if (item == null) { return; } OutOfChunkLightSourceStaticEntities.Remove(item); }
private void RemoveSoundEntity(EntityCollectionEventArgs e) { var item = e.Entity as IItem; if (item == null || item.EmittedSound == null || item.EmittedSound.FilePath == null) { return; } SoundStaticEntities.Remove(item); }
private void OnEntityRemoved(EntityCollectionEventArgs e) { e.Chunk = Chunk; var handler = EntityRemoved; if (handler != null) { handler(this, e); } }
private void Entities_BeforeRemoveItem(EntityCollection sender, EntityCollectionEventArgs e) { if (e.Item.Reactors.Count > 0) { e.Cancel = true; } else { // only items owned by the actual block can be removed e.Cancel = !ReferenceEquals(e.Item.Owner, this); } }
private void AddOutOfChunkLightSourceStaticEntity(EntityCollectionEventArgs e) { var item = e.Entity as ILightEmitterEntity; if (item == null) { return; } if (this.CubeRange.Contains(item.Position.ToCubePosition()) == false) { OutOfChunkLightSourceStaticEntities.Add(item); } }
private void AddParticuleEmitterEntity(EntityCollectionEventArgs e) { if (e.Entity.Particules == null) { return; } foreach (var entityParticules in e.Entity.Particules) { EmitterStaticEntities.Add(new EntityMetaData() { Entity = e.Entity, Particule = entityParticules, EntityLastEmitTime = DateTime.Now }); } }
private void Entities_BeforeAddItem(EntityCollection sender, EntityCollectionEventArgs e) { // null or duplicate items are not allowed in the entities list. if (e.Item == null) { e.Cancel = true; } else if (this.entities.Contains(e.Item)) { e.Cancel = true; } else { e.Cancel = false; } }
private void Entities_RemoveItem(EntityCollection sender, EntityCollectionEventArgs e) { if (this.readOnly) { return; } if (e.Item.Type == EntityType.Hatch) { Hatch hatch = (Hatch)e.Item; foreach (HatchBoundaryPath path in hatch.BoundaryPaths) { this.Hatch_BoundaryPathRemoved(hatch, new ObservableCollectionEventArgs <HatchBoundaryPath>(path)); } hatch.HatchBoundaryPathAdded -= this.Hatch_BoundaryPathAdded; hatch.HatchBoundaryPathRemoved -= this.Hatch_BoundaryPathRemoved; } this.OnEntityRemovedEvent(e.Item); e.Item.Owner = null; }
private void Entities_AddItem(EntityCollection sender, EntityCollectionEventArgs e) { if (this.readOnly) { return; } // if the entity is a hatch we will also add the boundary entities to the block if (e.Item.Type == EntityType.Hatch) { Hatch hatch = (Hatch)e.Item; foreach (HatchBoundaryPath path in hatch.BoundaryPaths) { this.Hatch_BoundaryPathAdded(hatch, new ObservableCollectionEventArgs <HatchBoundaryPath>(path)); } hatch.HatchBoundaryPathAdded += this.Hatch_BoundaryPathAdded; hatch.HatchBoundaryPathRemoved += this.Hatch_BoundaryPathRemoved; } this.OnEntityAddedEvent(e.Item); e.Item.Owner = this; }
private void Entities_BeforeAddItem(EntityCollection sender, EntityCollectionEventArgs e) { // null items, entities already owned by another Block, attribute definitions and attributes are not allowed in the entities list. if (e.Item == null) { e.Cancel = true; } else if (this.Flags.HasFlag(BlockTypeFlags.ExternallyDependent)) { e.Cancel = true; } else if (e.Item.Owner != null) { e.Cancel = true; } else { e.Cancel = false; } }
private void Entities_BeforeAddItem(EntityCollection sender, EntityCollectionEventArgs e) { // null items, entities already owned by another Block, attribute definitions and attributes are not allowed in the entities list. if (e.Item == null) { e.Cancel = true; } else if (e.Item is AttributeDefinition) { e.Cancel = true; } else if (e.Item is Attribute) { e.Cancel = true; } else if (e.Item.Owner != null) { e.Cancel = true; } else { e.Cancel = false; } }
private void Entities_RemoveItem(EntityCollection sender, EntityCollectionEventArgs e) { OnEntityRemovedEvent(e.Item); e.Item.Owner = null; }
private void EntitiesEntityRemoved(object sender, EntityCollectionEventArgs e) { RemoveVoxelEntity(e); RemoveParticuleEmitterEntity(e); RemoveSoundEntity(e); }
private void AddVoxelEntity(EntityCollectionEventArgs e) { var voxelEntity = e.Entity as IVoxelEntity; if (voxelEntity == null) { return; //My static entity is not a Voxel Entity => Not possible to render it so !!! } //Create the Voxel Model Instance for the Item VisualVoxelModel model = null; if (!string.IsNullOrEmpty(voxelEntity.ModelName)) { model = _voxelModelManager.GetModel(voxelEntity.ModelName, false); } if (model != null && voxelEntity.ModelInstance == null) //The model blueprint is existing, and I need to create an instance of it ! { var treeGrowing = e.Entity as TreeGrowingEntity; if (treeGrowing != null) { if (treeGrowing.Scale > 0) { // we need to use generated voxel model TreeBpSeed key; key.TreeTypeId = treeGrowing.TreeTypeId; key.TreeSeed = treeGrowing.TreeRndSeed; VisualVoxelModel treeModel; if (_cachedTrees.TryGetValue(key, out treeModel)) { model = treeModel; } else { var voxelModel = VoxelModel.GenerateTreeModel(treeGrowing.TreeRndSeed, _visualWorldParameters.WorldParameters.Configuration.TreeBluePrintsDico[ treeGrowing.TreeTypeId]); model = new VisualVoxelModel(voxelModel, _voxelModelManager.VoxelMeshFactory); model.BuildMesh(); _cachedTrees.Add(key, model); } } } var treeSoul = e.Entity as TreeSoul; if (treeSoul != null) { TreeBpSeed key; key.TreeTypeId = treeSoul.TreeTypeId; key.TreeSeed = treeSoul.TreeRndSeed; _cachedTrees.Remove(key); } voxelEntity.ModelInstance = new VoxelModelInstance(model.VoxelModel); //Assign state in case of growing entity ! var growingEntity = e.Entity as PlantGrowingEntity; if (growingEntity != null) { voxelEntity.ModelInstance.SetState(growingEntity.GrowLevels[growingEntity.CurrentGrowLevelIndex].ModelState); } var visualVoxelEntity = new VisualVoxelEntity(voxelEntity, _voxelModelManager); //Get default world translation Matrix instanceTranslation = Matrix.Translation(voxelEntity.Position.AsVector3()); //Apply special rotation to the creation instance Quaternion instanceRotation = Quaternion.Identity; if (voxelEntity is IRndYRotation && ((IRndYRotation)voxelEntity).RndRotationAroundY) { instanceRotation = Quaternion.RotationAxis(Vector3.UnitY, (float)(_rnd.NextDouble() * MathHelper.TwoPi)); } else if (voxelEntity is IItem) { var item = voxelEntity as IItem; instanceRotation = item.Rotation; } //Apply special scaling to created entity (By default all blue print are 16 times too big. Matrix instanceScaling = Matrix.Scaling(1.0f / 16.0f); if (treeGrowing != null && treeGrowing.Scale > 0) { instanceScaling = Matrix.Scaling(treeGrowing.Scale); } //Create the World transformation matrix for the instance. //We take the Model instance world matrix where we add a Rotation and scaling proper to the instance visualVoxelEntity.VoxelEntity.ModelInstance.World = instanceScaling * instanceTranslation; visualVoxelEntity.VoxelEntity.ModelInstance.Rotation = instanceRotation; var result = GetCube(visualVoxelEntity.VoxelEntity.Position.ToCubePosition()); if (result.IsValid) { visualVoxelEntity.BlockLight = result.Cube.EmissiveColor; } else { visualVoxelEntity.BlockLight = new ByteColor(255, 255, 255, 255); } if (visualVoxelEntity.VisualVoxelModel.Initialized == false) { visualVoxelEntity.VisualVoxelModel.BuildMesh(); } if (voxelEntity.ModelInstance.CanPlay("Idle")) { voxelEntity.ModelInstance.Play("Idle", true); } lock (_syncRoot) { List <VisualVoxelEntity> list; if (_visualVoxelEntities.TryGetValue(voxelEntity.ModelName, out list)) { list.Add(visualVoxelEntity); } else { _visualVoxelEntities.Add(voxelEntity.ModelName, new List <VisualVoxelEntity> { visualVoxelEntity }); } } var lightEntity = e.Entity as ILightEmitterEntity; if (e.AtChunkCreationTime == false && lightEntity != null) { //Get the Cube where is located the entity var entityWorldPosition = lightEntity.Position; var entityBlockPosition = new Vector3I(MathHelper.Floor(entityWorldPosition.X), MathHelper.Floor(entityWorldPosition.Y), MathHelper.Floor(entityWorldPosition.Z)); //new TerraCubeWithPosition(entityBlockPosition, WorldConfiguration.CubeId.Air, _visualWorldParameters.WorldParameters.Configuration), this.UpdateOrder = 1; var cubeRange = new Range3I { Position = new Vector3I(entityBlockPosition.X, 0, entityBlockPosition.Z), Size = Vector3I.One }; _chunkEntityImpactManager.CheckImpact(this, cubeRange); } } }
private void Entities_BeforeRemoveItem(EntityCollection sender, EntityCollectionEventArgs e) { // only items owned by the actual block can be removed e.Cancel = !ReferenceEquals(e.Item.Owner, this) || this.readOnly; }
private void Entities_AddItem(EntityCollection sender, EntityCollectionEventArgs e) { e.Item.AddReactor(this); this.OnEntityAddedEvent(e.Item); }
private void Entities_AddItem(EntityCollection sender, EntityCollectionEventArgs e) { e.Item.Owner = this; }
private void Entities_RemoveItem(EntityCollection sender, EntityCollectionEventArgs e) { this.OnEntityRemovedEvent(e.Item); }
private void Entities_BeforeRemoveItem(EntityCollection sender, EntityCollectionEventArgs e) { }
private void Entities_AddItem(EntityCollection sender, EntityCollectionEventArgs e) { this.OnEntityAddedEvent(e.Item); }
private void Entities_RemoveItem(EntityCollection sender, EntityCollectionEventArgs e) { e.Item.RemoveReactor(this); this.OnEntityRemovedEvent(e.Item); }
void EntitiesEntityAdded(object sender, EntityCollectionEventArgs e) { GetArea(e.Entity.Position).OnStaticEntityAdded(e); }