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