public static bool IsEntityTransform(this InstancingComponent component, out InstancingEntityTransform instancing) { if (component != null && component.Type is InstancingEntityTransform type) { instancing = type; return(true); } instancing = null; return(false); }
public override async Task <Entity> CreateEntity(EntityHierarchyItemViewModel parent) { var model = await PickupAsset(parent.Editor.Session, new[] { typeof(IModelAsset) }); if (model is null) { return(null); } var name = ComputeNewName(parent, model.Name); var component = new ModelComponent { Model = ContentReferenceHelper.CreateReference <Model>(model) }; var instancingComponent = new InstancingComponent(); return(await CreateEntityWithComponent(name, component, instancingComponent)); }
public void Load(ContentStack content) { var geometry = SphereGenerator.Generate(this.Device, 15); var material = new Material(this.Assets.WhitePixel, this.Assets.NormalPixel(), this.Assets.MetalicnessPixel(0.5f), this.Assets.RoughnessPixel(0.0f), this.Assets.AmbientOcclussionPixel(1.0f)); var entity = this.Entities.Create(); this.Components.Add(new GeometryComponent(entity, new GeometryModel(geometry, material))); this.Components.Add(new TransformComponent(entity)); var transforms = new Matrix[1024]; var i = 0; for (var x = -16; x < 16; x++) { for (var y = -16; y < 16; y++) { var p = new Vector3(x * 2, y * 2, 0.0f); transforms[i++] = Matrix.CreateTranslation(p); } } this.Components.Add(InstancingComponent.Create(entity, transforms)); }