Beispiel #1
0
        private static unsafe bool getMeshOutputs(Xenko.Rendering.Mesh modelMesh, out List <Vector3> positions, out List <int> indicies)
        {
            if (modelMesh.Draw is StagedMeshDraw)
            {
                StagedMeshDraw smd = modelMesh.Draw as StagedMeshDraw;

                object verts = smd.Verticies;

                if (verts is VertexPositionNormalColor[])
                {
                    VertexPositionNormalColor[] vpnc = verts as VertexPositionNormalColor[];
                    positions = new List <Vector3>(vpnc.Length);
                    for (int k = 0; k < vpnc.Length; k++)
                    {
                        positions.Add(vpnc[k].Position);
                    }
                }
                else if (verts is VertexPositionNormalTexture[])
                {
                    VertexPositionNormalTexture[] vpnc = verts as VertexPositionNormalTexture[];
                    positions = new List <Vector3>(vpnc.Length);
                    for (int k = 0; k < vpnc.Length; k++)
                    {
                        positions.Add(vpnc[k].Position);
                    }
                }
                else if (verts is VertexPositionNormalTextureTangent[])
                {
                    VertexPositionNormalTextureTangent[] vpnc = verts as VertexPositionNormalTextureTangent[];
                    positions = new List <Vector3>(vpnc.Length);
                    for (int k = 0; k < vpnc.Length; k++)
                    {
                        positions.Add(vpnc[k].Position);
                    }
                }
                else
                {
                    throw new ArgumentException("Couldn't get StageMeshDraw mesh, unknown vert type for " + modelMesh.Name);
                }

                // take care of indicies
                indicies = new List <int>(smd.Indicies.Length);
                for (int i = 0; i < smd.Indicies.Length; i++)
                {
                    indicies.Add((int)smd.Indicies[i]);
                }
            }
            else
            {
                Xenko.Graphics.Buffer buf  = modelMesh.Draw?.VertexBuffers[0].Buffer;
                Xenko.Graphics.Buffer ibuf = modelMesh.Draw?.IndexBuffer.Buffer;
                if (buf == null || buf.VertIndexData == null ||
                    ibuf == null || ibuf.VertIndexData == null)
                {
                    throw new ArgumentException("Couldn't get mesh for " + modelMesh.Name + ", buffer wasn't stored probably. Try Xenko.Graphics.Buffer.CaptureAllModelBuffers to true.");
                }

                if (ModelBatcher.UnpackRawVertData(buf.VertIndexData, modelMesh.Draw.VertexBuffers[0].Declaration,
                                                   out Vector3[] arraypositions, out Core.Mathematics.Vector3[] normals, out Core.Mathematics.Vector2[] uvs,
Beispiel #2
0
        private static unsafe bool getMeshOutputs(Xenko.Rendering.Mesh modelMesh, out List <Vector3> positions, out List <int> indicies)
        {
            if (modelMesh.Draw is StagedMeshDraw)
            {
                StagedMeshDraw smd = modelMesh.Draw as StagedMeshDraw;

                object verts = smd.Verticies;

                if (verts is VertexPositionNormalColor[])
                {
                    VertexPositionNormalColor[] vpnc = verts as VertexPositionNormalColor[];
                    positions = new List <Vector3>(vpnc.Length);
                    for (int k = 0; k < vpnc.Length; k++)
                    {
                        positions[k] = vpnc[k].Position;
                    }
                }
                else if (verts is VertexPositionNormalTexture[])
                {
                    VertexPositionNormalTexture[] vpnc = verts as VertexPositionNormalTexture[];
                    positions = new List <Vector3>(vpnc.Length);
                    for (int k = 0; k < vpnc.Length; k++)
                    {
                        positions[k] = vpnc[k].Position;
                    }
                }
                else if (verts is VertexPositionNormalTextureTangent[])
                {
                    VertexPositionNormalTextureTangent[] vpnc = verts as VertexPositionNormalTextureTangent[];
                    positions = new List <Vector3>(vpnc.Length);
                    for (int k = 0; k < vpnc.Length; k++)
                    {
                        positions[k] = vpnc[k].Position;
                    }
                }
                else
                {
                    positions = null;
                    indicies  = null;
                    return(false);
                }

                // take care of indicies
                indicies = new List <int>((int[])(object)smd.Indicies);
            }
            else
            {
                Xenko.Graphics.Buffer buf  = modelMesh.Draw?.VertexBuffers[0].Buffer;
                Xenko.Graphics.Buffer ibuf = modelMesh.Draw?.IndexBuffer.Buffer;
                if (buf == null || buf.VertIndexData == null ||
                    ibuf == null || ibuf.VertIndexData == null)
                {
                    positions = null;
                    indicies  = null;
                    return(false);
                }

                if (ModelBatcher.UnpackRawVertData(buf.VertIndexData, modelMesh.Draw.VertexBuffers[0].Declaration,
                                                   out Vector3[] arraypositions, out Core.Mathematics.Vector3[] normals, out Core.Mathematics.Vector2[] uvs,