コード例 #1
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));
        }
コード例 #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);
        }