Example #1
0
        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)));
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
Example #5
0
        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);
        }