Beispiel #1
0
            public override T Construct(MetaT metaResource, ContentPool content)
            {
                if (metaResource.Glyphs == null || metaResource.Glyphs.Count == 0)
                {
                    return(null);
                }

                var mesh = new T
                {
                    MeshType           = MeshType.TriangleStrip,
                    VertexStreamLayout = Software.Vertex.PositionTexcoord.Instance,
                    NVertices          = metaResource.Glyphs.Count * 6,
                    NFaces             = metaResource.Glyphs.Count * 6 - 2
                };

                List <Software.Vertex.PositionTexcoord> verts = new List <Graphics.Software.Vertex.PositionTexcoord>();

                foreach (Content.Glyph g in metaResource.Glyphs)
                {
                    verts.Add(new Software.Vertex.PositionTexcoord(new Vector3(g.Position.X, g.Position.Y, 0), Vector3.UnitZ, Common.Math.ToVector3(g.UVMin)));
                    verts.Add(new Software.Vertex.PositionTexcoord(new Vector3(g.Position.X, g.Position.Y, 0), Vector3.UnitZ, Common.Math.ToVector3(g.UVMin)));
                    verts.Add(new Software.Vertex.PositionTexcoord(new Vector3(g.Position.X, g.Position.Y + g.Size.Y, 0), Vector3.UnitZ, new Vector3(g.UVMin.X, g.UVMax.Y, 0)));
                    verts.Add(new Software.Vertex.PositionTexcoord(new Vector3(g.Position.X + g.Size.X, g.Position.Y, 0), Vector3.UnitZ, new Vector3(g.UVMax.X, g.UVMin.Y, 0)));
                    verts.Add(new Software.Vertex.PositionTexcoord(new Vector3(g.Position.X + g.Size.X, g.Position.Y + g.Size.Y, 0), Vector3.UnitZ, new Vector3(g.UVMax.X, g.UVMax.Y, 0)));
                    verts.Add(new Software.Vertex.PositionTexcoord(new Vector3(g.Position.X + g.Size.X, g.Position.Y + g.Size.Y, 0), Vector3.UnitZ, new Vector3(g.UVMax.X, g.UVMax.Y, 0)));
                }
                mesh.VertexBuffer = new Software.VertexBuffer <Software.Vertex.PositionTexcoord>(verts.ToArray());

                return(mesh);
            }
Beispiel #2
0
 public virtual void Release(MetaT metaResource, ContentPool content, T resource)
 {
     if (resource != null)
     {
         ((IDisposable)resource).Dispose();
     }
 }
            public override void Release(MetaT metaResource, ContentPool content, T resource)
            {
                content.Release(resource.XMesh);
                content.Release(resource.Mesh);
                content.Release(resource.Texture);
                content.Release(resource.SkinnedMesh);
                content.Release(resource.SpecularTexture);
                if (metaResource.SplatTexutre != null)
                {
                    for (int i = 0; i < resource.SplatTexture.Length; i++)
                    {
                        content.Release(resource.SplatTexture[i]);
                    }
                }

                if (metaResource.MaterialTexture != null)
                {
                    for (int i = 0; i < resource.MaterialTexture.Length; i++)
                    {
                        content.Release(resource.MaterialTexture[i]);
                    }
                }

                if (metaResource.BaseTexture != null)
                {
                    content.Release(resource.BaseTexture);
                }
            }
            public override Model10 Construct(TextGraphic metaResource, ContentPool content)
            {
                var fi = content.Acquire <FontImplementation>(metaResource.Font);

                var glyphs = BuildGlyphs(fi, metaResource.Anchor, metaResource.Size, metaResource.Text, out metaResource.TextHeight);

                if (glyphs == null)
                {
                    return(new Model10());
                }
                Model10 m = content.Acquire <Model10>(new GlyphsGraphic
                {
                    Glyphs = new GlyphString {
                        Glyphs = glyphs
                    },
                    Offset   = metaResource.Offset,
                    Overflow = metaResource.Overflow,
                    Position = metaResource.Position,
                    Size     = metaResource.Size,
                    Texture  = new TextureConcretizer {
                        Texture = fi
                    }
                });

                return(m);
            }
Beispiel #5
0
        public static void Init(Content.ContentPool content)
        {
            Intersection.content = content;
            if (!inited)
            {
                inited = true;
                //Common.Intersection.AddIntersector<Ray, Content.SkinnedMesh>(Intersect);
                Common.Intersection.AddIntersector <Ray, Renderer.Renderer.EntityAnimation>(Intersect);
                Common.Intersection.AddIntersector <Ray, Software.Mesh>(Intersect);

                Common.Intersection.AddIntersector <Ray, BoundingMetaMesh>(Intersect);
                Common.Intersection.AddIntersector <Common.Bounding.Line, BoundingMetaMesh>(Intersect);
                Common.Intersection.AddIntersector <Common.Bounding.Cylinder, BoundingMetaMesh>(Intersect);
                Common.Intersection.AddIntersector <Common.Bounding.Frustum, BoundingMetaMesh>(Intersect);

                Common.Intersection.AddIntersector <BoundingBox, MetaBoundingBox>(Intersect);
                Common.Intersection.AddIntersector <Ray, MetaBoundingBox>(Intersect);
                Common.Intersection.AddIntersector <Common.Bounding.Line, MetaBoundingBox>(Intersect);
                Common.Intersection.AddIntersector <Common.Bounding.Frustum, MetaBoundingBox>(Intersect);
                Common.Intersection.AddIntersector <Common.Bounding.Cylinder, MetaBoundingBox>(Intersect);
                Common.Intersection.AddIntersector <System.Drawing.RectangleF, MetaBoundingBox>(Intersect);

                Common.Intersection.AddIntersector <Ray, MetaBoundingImageGraphic>(Intersect);

                //Common.Intersection.AddIntersector<Ray, Content.Model9>(Intersect);
            }
        }
 public override void Release(TextureShaderView metaResource, ContentPool content, SlimDX.Direct3D10.ShaderResourceView resource)
 {
     if (resource == null)
     {
         return;
     }
     resource.Dispose();
 }
 public override void Release(MetaT metaResource, ContentPool content, Model9 resource)
 {
     if (resource.Mesh != null)
     {
         content.Release(resource.Mesh);
     }
     content.Release(resource.Texture);
 }
 public override void Release(StretchingImageGraphic metaResource, ContentPool content, Model10 resource)
 {
     content.Release(resource.Mesh);
     if (!resource.TextureShaderView.Disposed)
     {
         content.Release(resource.TextureShaderView.Resource);
         content.Release(resource.TextureShaderView);
     }
 }
 public static void Init(Content.ContentPool content)
 {
     SpatialRelation.content = content;
     if (!inited)
     {
         inited = true;
         Common.SpatialRelation.AddRelator <Software.Triangle, Plane>(Relation);
         Common.SpatialRelation.AddRelator <BoundingBox, MetaBoundingBox>(Relation);
         Common.SpatialRelation.AddRelator <RectangleF, MetaBoundingBox>(Relation);
     }
 }
 public override void Release(MetaT metaResource, ContentPool content, Model10 resource)
 {
     if (resource.Mesh != null)
     {
         content.Release(resource.Mesh);
     }
     if (!resource.TextureShaderView.Disposed)
     {
         content.Release(resource.TextureShaderView.Resource);
         content.Release(resource.TextureShaderView);
     }
 }
 public override void Release(MetaT metaResource, ContentPool content, T resource)
 {
     throw new NotImplementedException("splatting not added");
     content.Release(resource.XMesh);
     content.Release(resource.Mesh);
     if (resource.TextureShaderView != null && !resource.TextureShaderView.Disposed)
     {
         content.Release(resource.TextureShaderView.Resource);
         content.Release(resource.TextureShaderView);
     }
     content.Release(resource.SkinnedMesh);
 }
            public override Model9 Construct(MetaT metaResource, ContentPool content)
            {
                var    glyphs = metaResource.BuildGlyphs();
                Model9 m      = new Model9
                {
                    Texture = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.Texture),
                    Mesh    = content.Acquire <Mesh9>(new MeshConcretize {
                        MetaMesh = glyphs, Layout = Software.Vertex.PositionTexcoord.Instance
                    })
                };

                return(m);
            }
 public override Software.Mesh Construct(MeshConcretize metaResource, ContentPool content)
 {
     if (metaResource.XMesh != null)
     {
         return(new Graphics.Software.Mesh(metaResource.XMesh));
     }
     else if (metaResource.MetaXMesh != null)
     {
         var mesh = content.Peek <SlimDX.Direct3D9.Mesh>(metaResource.MetaXMesh);
         return(new Graphics.Software.Mesh(mesh));
     }
     return(metaResource.GetSoftwareMesh(content));
 }
            public override Model9 Construct(BorderGraphic metaResource, ContentPool content)
            {
                var texture = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.Texture);
                var ld      = texture.GetLevelDescription(0);

                metaResource.Layout.TextureSize = new Vector2(ld.Width, ld.Height);
                Model9 m = new Model9();

                m.Mesh = content.Acquire <Mesh9>(new MeshConcretize {
                    MetaMesh = metaResource.Layout,
                    Layout   = Software.Vertex.PositionTexcoord.Instance
                });
                m.Texture = texture;
                return(m);
            }
 public Software.Mesh GetSoftwareMesh(ContentPool content)
 {
     if (MeshDescription != null)
     {
         return(Graphics.Software.Meshes.Construct(MeshDescription));
     }
     else if (MetaMesh != null)
     {
         return(content.Peek <Software.Mesh>(MetaMesh));
     }
     else
     {
         return(Mesh.Data);
     }
 }
            public override SkinnedMesh Construct(SkinnedMeshFromFile metaResource, ContentPool content)
            {
                string str = content.ContentPath != null ? content.ContentPath + "/" + metaResource.FileName : metaResource.FileName;
                Stream s   = null;

                if (!Common.FileSystem.Instance.FileExists(str))
                {
                    Application.Log("SkinnedMeshFromFile: File doesn't exist: " + str);
                }
                else
                {
                    s = Common.FileSystem.Instance.OpenRead(str);
                }

                return(new SkinnedMesh(s, content.Device9));
            }
            public override Model10 Construct(StretchingImageGraphic metaResource, ContentPool content)
            {
                Model10 m = new Model10();

                metaResource.square.Glyphs[0].Size = metaResource.Size;
                m.Mesh = content.Acquire <Mesh10>(new MeshConcretize {
                    MetaMesh = metaResource.square, Layout = Software.Vertex.PositionTexcoord.Instance
                });
                m.TextureShaderView = content.Acquire <SlimDX.Direct3D10.ShaderResourceView>(new TextureShaderView
                {
                    Texture =
                        content.Acquire <SlimDX.Direct3D10.Texture2D>(metaResource.Texture)
                });
                m.World = Matrix.Translation(metaResource.Position);
                return(m);
            }
            public override T Construct(MetaT metaResource, ContentPool content)
            {
                T t;

                t = new T
                {
                    XMesh       = content.Acquire <SlimDX.Direct3D9.Mesh>(metaResource.XMesh),
                    Texture     = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.Texture),
                    SkinnedMesh = content.Acquire <SkinnedMesh>(metaResource.SkinnedMesh),
                };
                if (metaResource.MaterialTexture != null)
                {
                    t.MaterialTexture = new SlimDX.Direct3D9.Texture[metaResource.MaterialTexture.Length];
                }
                if (metaResource.MaterialTexture != null)
                {
                    for (int i = 0; i < metaResource.MaterialTexture.Length; i++)
                    {
                        t.MaterialTexture[i] = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.MaterialTexture[i]);
                    }
                }

                if (metaResource.SplatTexutre != null)
                {
                    t.SplatTexture = new SlimDX.Direct3D9.Texture[metaResource.SplatTexutre.Length];
                }

                if (metaResource.SplatTexutre != null)
                {
                    for (int i = 0; i < metaResource.SplatTexutre.Length; i++)
                    {
                        t.SplatTexture[i] = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.SplatTexutre[i]);
                    }
                }

                if (metaResource.BaseTexture != null)
                {
                    t.BaseTexture = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.BaseTexture);
                }

                if (metaResource.SpecularTexture != null)
                {
                    t.SpecularTexture = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.SpecularTexture);
                }

                return(t);
            }
            public override Model9 Construct(StretchingImageGraphic metaResource, ContentPool content)
            {
                Model9 m = new Model9();

                m.Texture = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.Texture);
                Software.Meshes.IndexedPlane plane = new Graphics.Software.Meshes.IndexedPlane();
                plane.Size     = metaResource.Size - metaResource.BorderSize * 2;
                plane.Position = Common.Math.ToVector3(metaResource.BorderSize);
                plane.UVMin    = metaResource.TextureUVMin;
                plane.UVMax    = metaResource.TextureUVMax;
                m.Mesh         = content.Acquire <Mesh9>(new MeshConcretize
                {
                    MeshDescription = plane,
                    Layout          = Software.Vertex.PositionTexcoord.Instance
                });
                return(m);
            }
            public override Model9 Construct(ImageGraphic metaResource, ContentPool content)
            {
                Model9 m = new Model9();

                var tex = content.Acquire <SlimDX.Direct3D9.Texture>(metaResource.Texture);
                var sd  = tex.GetLevelDescription(0);

                var textureSize = new Vector2(sd.Width, sd.Height);
                var plane       = metaResource.GetPlane(textureSize);

                m.Texture = tex;
                m.Mesh    = content.Acquire <Mesh9>(new MeshConcretize
                {
                    MeshDescription = plane,
                    Layout          = Software.Vertex.PositionTexcoord.Instance
                });
                return(m);
            }
            public override Model10 Construct(BorderGraphic metaResource, ContentPool content)
            {
                var texture = content.Acquire <SlimDX.Direct3D10.Texture2D>(metaResource.Texture);
                var ld      = texture.Description;

                metaResource.Layout.TextureSize = new Vector2(ld.Width, ld.Height);
                Model10 m = new Model10();

                m.Mesh = content.Acquire <Mesh10>(new MeshConcretize {
                    MetaMesh = metaResource.Layout,
                    Layout   = Software.Vertex.PositionTexcoord.Instance
                });
                m.TextureShaderView = content.Acquire <SlimDX.Direct3D10.ShaderResourceView>(new TextureShaderView {
                    Texture = texture
                });
                m.World = Matrix.Translation(metaResource.Position);
                return(m);
            }
            public override Model10 Construct(MetaT metaResource, ContentPool content)
            {
                var     glyphs = metaResource.BuildGlyphs();
                Model10 m      = new Model10
                {
                    TextureShaderView = content.Acquire <SlimDX.Direct3D10.ShaderResourceView>(new TextureShaderView
                    {
                        Texture =
                            content.Acquire <SlimDX.Direct3D10.Texture2D>(metaResource.Texture)
                    }),
                    Mesh = content.Acquire <Mesh10>(new MeshConcretize {
                        MetaMesh = glyphs, Layout = Software.Vertex.PositionTexcoord.Instance
                    }),
                    World = Matrix.Translation(metaResource.Position)
                };

                return(m);
            }
 public override T Construct(MetaT metaResource, ContentPool content)
 {
     throw new NotImplementedException("splatting not added");
     return(new T
     {
         XMesh = content.Acquire <SlimDX.Direct3D10.Mesh>(metaResource.XMesh),
         TextureShaderView =
             content.Acquire <SlimDX.Direct3D10.ShaderResourceView>(new TextureShaderView
         {
             Texture = content.Acquire <SlimDX.Direct3D10.Texture2D>(metaResource.Texture)
         }),
         World = metaResource.World,
         Visible = metaResource.Visible,
         IsBillboard = metaResource.IsBillboard,
         SkinnedMesh = content.Acquire <SkinnedMesh>(metaResource.SkinnedMesh),
         HasAlpha = metaResource.HasAlpha,
         AlphaRef = metaResource.AlphaRef,
     });
 }
        public static void Init(Content.ContentPool content)
        {
            Boundings.content = content;
            if (!inited)
            {
                inited = true;
                Common.Boundings.AddTransformer <BoundingMetaMesh>(Transform);
                Common.Boundings.AddTransformer <MetaBoundingBox>(Transform);
                Common.Boundings.AddTransformer <MetaBoundingImageGraphic>(Transform);

                Common.Boundings.AddTranslater <BoundingMetaMesh>(Translation);
                Common.Boundings.AddTranslater <MetaBoundingBox>(Translation);

                Common.Boundings.AddBoundingToBox <BoundingMetaMesh>(BoundingToBox);
                Common.Boundings.AddBoundingToBox <MetaBoundingBox>(BoundingToBox);

                Common.Boundings.AddRadius <MetaBoundingBox>(Radius);
            }
        }
Beispiel #25
0
        public BoundingBox?GetBoundingBox(Content.ContentPool content)
        {
            bool cachedMeshBoundingBoxChanged = false;

            if (cachedMeshBoundingBox == null || !Object.Equals(cachedMesh, Mesh))
            {
                cachedMesh            = (Content.MetaResourceBase)Mesh.Clone();
                cachedMeshBoundingBox = content.Peek <Content.StructBoxer <BoundingBox> >(Mesh).Value;
                cachedBoundingBox     = cachedMeshBoundingBox = new BoundingBox(
                    cachedMeshBoundingBox.Value.Minimum - new Vector3(0.1f, 0.1f, 0.1f),
                    cachedMeshBoundingBox.Value.Maximum + new Vector3(0.1f, 0.1f, 0.1f));
                cachedMeshBoundingBoxChanged = true;
            }
            if (cachedMeshBoundingBoxChanged || Transformation != cachedTransformation)
            {
                cachedTransformation = Transformation;
                cachedBoundingBox    = (BoundingBox)Common.Boundings.Transform(cachedMeshBoundingBox, Transformation);
            }
            return(cachedBoundingBox);
        }
        void InitializeGraphics()
        {
            isInited = true;
            if (!DesignMode)
            {
                if (Direct3DVersion == Direct3DVersion.Direct3D9)
                {
                    GraphicsDevice.Direct3DVersion = Direct3DVersion;
                    GraphicsDevice.View            = this;
                    GraphicsDevice.FullscreenForm  = Application.MainWindow;
                    GraphicsDevice.Create();
                    GraphicsDevice.LostDevice  += new Action(OnLostDevice);
                    GraphicsDevice.ResetDevice += new Action(OnResetDevice);

                    LineDrawer = new Line(Device9);

                    Content = new Content.ContentPool(Device9);
                }
                else
                {
                    GraphicsDevice.Direct3DVersion = Direct3DVersion;
                    GraphicsDevice.View            = this;
                    GraphicsDevice.FullscreenForm  = Application.MainWindow;
                    GraphicsDevice.Create(Handle);
                    GraphicsDevice.LostDevice  += new Action(OnLostDevice);
                    GraphicsDevice.ResetDevice += new Action(OnResetDevice);

                    //lineDrawer = new Line(Device10);

                    Content = new Content.ContentPool(Device10);
                }
                Intersection.Init(Content);
                Boundings.Init(Content);
                SpatialRelation.Init(Content);
            }
            Init();
            if (InitEvent != null)
            {
                InitEvent(this, null);
            }
        }
        public static Mesh10 Concretize10(ContentPool content, Software.Mesh sysmemMesh, Software.Vertex.IVertex layout)
        {
            if (sysmemMesh == null)
            {
                return(null);
            }
            if (layout != null && layout.GetType() != sysmemMesh.VertexStreamLayout.GetType())
            {
                sysmemMesh = sysmemMesh.ConvertTo(layout);
            }

            Graphics.Content.Mesh10 mesh = new Mesh10
            {
                MeshType           = sysmemMesh.MeshType,
                NFaces             = sysmemMesh.NFaces,
                NVertices          = sysmemMesh.NVertices,
                VertexStreamLayout = sysmemMesh.VertexStreamLayout
            };

            mesh.VertexBuffer = sysmemMesh.VertexBuffer.GetD3DBuffer(content.Device10);

            if (sysmemMesh.IndexBuffer != null)
            {
                var indices = new DataStream((sysmemMesh.ShortIndices ? sizeof(short) : sizeof(int)) * sysmemMesh.NFaces * 3, false, true);
                sysmemMesh.IndexBuffer.WriteToStream(indices, sysmemMesh.ShortIndices);
                indices.Seek(0, System.IO.SeekOrigin.Begin);
                mesh.IndexBuffer = new SlimDX.Direct3D10.Buffer(content.Device10, indices, new SlimDX.Direct3D10.BufferDescription
                {
                    BindFlags      = SlimDX.Direct3D10.BindFlags.IndexBuffer,
                    CpuAccessFlags = SlimDX.Direct3D10.CpuAccessFlags.None,
                    OptionFlags    = SlimDX.Direct3D10.ResourceOptionFlags.None,
                    SizeInBytes    = (int)indices.Length,
                    Usage          = SlimDX.Direct3D10.ResourceUsage.Default
                });
            }

            return(mesh);
        }
Beispiel #28
0
        public override object Do(MetaResourceDo evnt, object metaResource, ContentPool content,
                                  object inobject)
        {
            switch (evnt)
            {
            case MetaResourceDo.Construct:
                return(Construct((MetaT)metaResource, content));

            case MetaResourceDo.Release:
                Release((MetaT)metaResource, content, (T)inobject);
                return(null);

            case MetaResourceDo.LostDevice:
                OnLostDevice((MetaT)metaResource, content, (T)inobject);
                return(null);

            case MetaResourceDo.ResetDevice:
                return(OnResetDevice((MetaT)metaResource, content, (T)inobject));

            default:
                throw new ArgumentException();
            }
        }
        public static Mesh9 Concretize9(ContentPool content, Software.Mesh sysmemMesh, Software.Vertex.IVertex layout, SlimDX.Direct3D9.Pool pool)
        {
            if (sysmemMesh == null)
            {
                return(null);
            }
            if (layout != null && layout.GetType() != sysmemMesh.VertexStreamLayout.GetType())
            {
                sysmemMesh = sysmemMesh.ConvertTo(layout);
            }

            Graphics.Content.Mesh9 mesh = new Mesh9
            {
                MeshType           = sysmemMesh.MeshType,
                NFaces             = sysmemMesh.NFaces,
                NVertices          = sysmemMesh.NVertices,
                VertexStreamLayout = sysmemMesh.VertexStreamLayout
            };
            mesh.VertexBuffer = new SlimDX.Direct3D9.VertexBuffer(content.Device9,
                                                                  mesh.VertexStreamLayout.Size * mesh.NVertices,
                                                                  SlimDX.Direct3D9.Usage.None, mesh.VertexStreamLayout.VertexFormat,
                                                                  pool);

            sysmemMesh.VertexBuffer.WriteToD3DBuffer(mesh.VertexBuffer);

            if (sysmemMesh.IndexBuffer != null)
            {
                mesh.IndexBuffer = new SlimDX.Direct3D9.IndexBuffer(content.Device9, (sysmemMesh.ShortIndices ? sizeof(short) : sizeof(int)) * mesh.NFaces * 3,
                                                                    SlimDX.Direct3D9.Usage.None, pool, sysmemMesh.ShortIndices);
                var indices = mesh.IndexBuffer.Lock(0, (sysmemMesh.ShortIndices ? sizeof(short) : sizeof(int)) * mesh.NFaces * 3,
                                                    SlimDX.Direct3D9.LockFlags.None);
                sysmemMesh.IndexBuffer.WriteToStream(indices, sysmemMesh.ShortIndices);
                mesh.IndexBuffer.Unlock();
            }

            return(mesh);
        }
 public override void Release(Font metaResource, ContentPool content, FontImplementation resource)
 {
 }