public static GraphicEntity BuildTextured(IContextState context, IReadOnlyCollection <Vector3> pos, IReadOnlyCollection <int> indexes, IReadOnlyCollection <Vector2> texCoor, FileInfo texture, CullMode cullMode) { if (texCoor == null) { throw new Exception("Geo must have TextCoor."); } var manager = context.GetEntityManager(); var en = manager.CreateEntity(new ElementTag("TexturedGeometry" + Guid.NewGuid())); var material = MaterialColorComponent.CreateTransparent().ApplyAlpha(1); var geo = context.GetGeometryPool() .AddGeometry(new ImmutableGeometryData( pos, pos.ToList().CalculateNormals(indexes.ToList()).AsReadOnly(), indexes, texCoor)); en.AddComponent(TransformComponent.Identity()) .AddComponent(geo) .AddComponent(material) .AddComponent(new D3DTexturedMaterialSamplerComponent(texture)) .AddComponent(RenderableComponent.AsTriangleTexturedList(cullMode)); return(en); }
public static MaterialStructBuffer From(MaterialColorComponent color) { var material = new MaterialStructBuffer(); material.ColorDiffuse = color.Diffuse; material.ColorAmbient = color.Ambient; material.ColorSpecular = color.Specular; material.ColorReflection = color.Reflection; material.SpecularFactor = color.SpecularFactor; return(material); }
public static GraphicEntity BuildColored(IContextState context, ElementTag tag, ImmutableGeometryData geometry, Vector4 v4color, CullMode cullMode) { var material = MaterialColorComponent.Create(v4color); var manager = context.GetEntityManager(); var geo = context.GetGeometryPool() .AddGeometry(geometry); return(manager.CreateEntity(tag) .AddComponent(TransformComponent.Identity()) .AddComponent(material) .AddComponent(geo) .AddComponent(RenderableComponent.AsTriangleColoredList(cullMode))); }
public static VisualSphereObject SphereGeo(IContextState context, ElementTag tag, Data data) { var geo = GeometryBuilder.BuildSphere(data.Center, data.Radius); var geoId = context.GetGeometryPool() .AddGeometry(geo); var en = context.GetEntityManager() .CreateEntity(tag) .AddComponent(RenderableComponent.AsTriangleColored(SharpDX.Direct3D.PrimitiveTopology.TriangleStrip)) .AddComponent(TransformComponent.Identity()) .AddComponent(MaterialColorComponent.Create(data.Color)) .AddComponent(geoId) ; return(new VisualSphereObject(en.Tag)); }
public static VisualSphereObject Create(IContextState context, ElementTag elet, Data data) { var geo = GeometryBuilder.BuildSphere(data.Center, data.Radius); var geoId = context.GetGeometryPool() .AddGeometry(geo); var tag = context.GetEntityManager() .CreateEntity(elet) .AddComponent(SpherePointComponent.Create(data.Center, data.Radius)) .AddComponent(MaterialColorComponent.Create(data.Color)) .AddComponent(GeometryBoundsComponent.Create(AxisAlignedBox.FromSphere(data.Center, data.Radius))) .AddComponent(RenderableComponent.AsPoints()) .AddComponent(TransformComponent.Identity()) .Tag; return(new VisualSphereObject(tag)); }
public static ArrowGameObject Create(IContextState context, ElementTag tag, ArrowData data, bool visible = true) { var geo = GeometryBuilder.BuildArrow(data); var geoId = context.GetGeometryPool() .AddGeometry(geo); var en = context.GetEntityManager() .CreateEntity(tag) .AddComponent(visible ? RenderableComponent.AsTriangleColored(SharpDX.Direct3D.PrimitiveTopology.TriangleStrip) : RenderableComponent.AsTriangleColored(SharpDX.Direct3D.PrimitiveTopology.TriangleStrip).Disable()) .AddComponent(TransformComponent.Identity()) .AddComponent(MaterialColorComponent.Create(data.color)) .AddComponent(geoId) ; return(new ArrowGameObject(en.Tag)); }
static ElementTag Create(IContextState context, ElementTag tag, GeometryStructures gdata, FileInfo texture, out GeometryBoundsComponent boundsComponent) { var manager = context.GetEntityManager(); if (!gdata.Normals.Any()) { gdata.ReCalculateNormals(); } gdata.BuildTreeAsync(); var cullmode = SharpDX.Direct3D11.CullMode.Front; var geo = context.GetGeometryPool().AddGeometry(gdata); var en = manager.CreateEntity(tag); MaterialColorComponent material; RenderableComponent renderable; if (gdata.TexCoor.Any() && texture != null) { material = MaterialColorComponent.CreateTransparent().ApplyAlpha(1); renderable = RenderableComponent.AsTriangleTexturedList(cullmode); en.AddComponent(new D3DTexturedMaterialSamplerComponent(texture)); } else { material = MaterialColorComponent.Create(V4Colors.NextColor(random)); renderable = RenderableComponent.AsTriangleColoredList(cullmode); } boundsComponent = GeometryBoundsComponent.Create(gdata.Positions); en.AddComponent(TransformComponent.Identity()) .AddComponent(HittableComponent.Create(0)) .AddComponent(boundsComponent) .AddComponent(material) .AddComponent(geo) .AddComponent(renderable); return(tag); }
protected void UpdateMaterial(GraphicsDevice graphics, D3DRenderComponent render, MaterialColorComponent material) { if (material.IsValid) { var buf = MaterialStructBuffer.From(material); if (render.MaterialBuffer.HasValue) { var buff = render.MaterialBuffer.Get(); graphics.UpdateDynamicBuffer(ref buf, buff); } else { var buff = graphics.CreateDynamicBuffer(ref buf, Unsafe.SizeOf <MaterialStructBuffer>()); render.MaterialBuffer.Set(buff); } } }