コード例 #1
0
ファイル: EntityBuilders.cs プロジェクト: GreyArmor/d3dlab
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: EntityBuilders.cs プロジェクト: GreyArmor/d3dlab
        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)));
        }
コード例 #4
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));
        }
コード例 #5
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));
        }
コード例 #6
0
ファイル: ArrowGameObject.cs プロジェクト: GreyArmor/d3dlab
        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));
        }
コード例 #7
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);
        }
コード例 #8
0
        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);
                }
            }
        }