Exemplo n.º 1
0
        public VertexBuffer GetVertexBuffer(IMeshPart meshPart)
        {
            var e = getEntry(meshPart);

            if (e.VertexBuffer == null)
            {
                var geomData  = meshPart.GetGeometryData();
                var positions = geomData.GetSourceVector3(MeshPartGeometryData.Semantic.Position);
                var normals   = geomData.GetSourceVector3(MeshPartGeometryData.Semantic.Normal);
                var texcoords = geomData.GetSourceVector2(MeshPartGeometryData.Semantic.Texcoord); // This might not work when no texcoords

                var vertices = new TangentVertex[positions.Length];
                for (int j = 0; j < vertices.Length; j++)
                {
                    vertices[j].pos    = positions[j];
                    vertices[j].normal = normals[j];
                    if (texcoords != null)
                    {
                        vertices[j].uv = texcoords[j];
                    }
                    //TODO: tangent
                }

                var vb = new VertexBuffer(game.GraphicsDevice, typeof(TangentVertex), vertices.Length, BufferUsage.None);
                vb.SetData(vertices);

                e.VertexBuffer = vb;
            }

            return(e.VertexBuffer);
        }
Exemplo n.º 2
0
        private Entry getEntry(IMeshPart meshPart)
        {
            Entry ret;

            if (!entries.TryGetValue(meshPart, out ret))
            {
                ret = new Entry();
                entries[meshPart] = ret;
            }
            return(ret);
        }
        public MeshPartRenderData GetMeshPartRenderData(IMeshPart part)
        {
            if (pool.ContainsKey(part))
            {
                return((MeshPartRenderData)pool[part]);
            }

            var ret = meshFactory.CreateMeshPartData(part);

            pool.Add(part, ret);

            return(ret);
        }
Exemplo n.º 4
0
        private void addPartToPart(IMeshPart source, IMeshPart dest, Matrix sourceTransform)
        {
            var sPositions = source.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Position);
            var sNormals   = source.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Normal);
            var sTexcoords = source.GetGeometryData().GetSourceVector2(MeshPartGeometryData.Semantic.Texcoord);

            var dPositions = dest.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Position);

            if (dPositions == null)
            {
                dPositions = new Vector3[0];
            }
            var dNormals = dest.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Normal);

            if (dNormals == null)
            {
                dNormals = new Vector3[0];
            }
            var dTexcoords = dest.GetGeometryData().GetSourceVector2(MeshPartGeometryData.Semantic.Texcoord);

            if (dTexcoords == null)
            {
                dTexcoords = new Vector2[0];
            }


            var nPositions = new Vector3[sPositions.Length + dPositions.Length];
            var nNormals   = new Vector3[sNormals.Length + dNormals.Length];
            var nTexcoords = new Vector2[sTexcoords.Length + dTexcoords.Length];


            dPositions.CopyTo(nPositions, 0);
            dNormals.CopyTo(nNormals, 0);
            dTexcoords.CopyTo(nTexcoords, 0);


            Vector3.Transform(sPositions, 0, ref sourceTransform, nPositions, dPositions.Length, sPositions.Length);
            Vector3.TransformNormal(sNormals, 0, ref sourceTransform, nNormals, dNormals.Length, sNormals.Length);
            sTexcoords.CopyTo(nTexcoords, dTexcoords.Length);


            dest.GetGeometryData().SetSource(MeshPartGeometryData.Semantic.Position, nPositions);
            dest.GetGeometryData().SetSource(MeshPartGeometryData.Semantic.Normal, nNormals);
            dest.GetGeometryData().SetSource(MeshPartGeometryData.Semantic.Texcoord, nTexcoords);
        }
Exemplo n.º 5
0
        public IndexBuffer GetIndexBuffer(IMeshPart meshPart)
        {
            var e = getEntry(meshPart);

            if (e.IndexBuffer == null)
            {
                var geomData  = meshPart.GetGeometryData();
                var positions = geomData.GetSourceVector3(MeshPartGeometryData.Semantic.Position);

                var indices = new int[positions.Length];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = j;
                }

                var ib = new IndexBuffer(game.GraphicsDevice, typeof(int), indices.Length, BufferUsage.None);
                ib.SetData(indices);
                e.IndexBuffer = ib;
            }

            return(e.IndexBuffer);
        }
Exemplo n.º 6
0
        public static BoundingSphere CalculateBoundingSphere(IMeshPart mesh)
        {
            var positions = mesh.GetGeometryData().GetSourceVector3(MeshPartGeometryData.Semantic.Position);

            return(Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(positions).dx());
        }
Exemplo n.º 7
0
 private MeshPartRenderData createRenderData(IMeshPart part)
 {
     return(renderDataFactory.CreateMeshPartData(part));
 }
 public MeshPartRenderData CreateMeshPartData(IMeshPart part)
 {
     return(CreateMeshPartData(part.GetGeometryData().ToRawMeshData()));
 }