Beispiel #1
0
        public static void ReadDotMeshMaterialNames(byte[] vData, out List<string> materials, out string errorMessage)
        {
            materials = new List<string>();
            errorMessage = "";

            try
            {
                MeshSerializerImpl TempSerializer = new MeshSerializerImpl();
                OMesh mesh = TempSerializer.ImportMesh(vData);

                if (mesh == null)
                    return;

                foreach (SubMesh submesh in mesh.subMeshList)
                {
                    materials.Add(submesh.MaterialName);
                }
            }
            catch (Exception e)
            {
                errorMessage = e.Message.ToString();
            }
        }
Beispiel #2
0
        public static void ReadDotMeshModel(byte[] vData, out float[] vertexList, out int[] indexList, out float[] boundsInfo, out string errorMessage)
        {
            vertexList = null;
            indexList = null;
            boundsInfo = null;
            errorMessage = "";

            try
            {
                MeshSerializerImpl TempSerializer = new MeshSerializerImpl();
                OMesh mesh = TempSerializer.ImportMesh(vData);

                if (mesh == null)
                    return;

                // bounds
                boundsInfo = new float[7];
                boundsInfo[0] = mesh.boundingBoxMin.X;
                boundsInfo[1] = mesh.boundingBoxMin.Y;
                boundsInfo[2] = mesh.boundingBoxMin.Z;
                boundsInfo[3] = mesh.boundingBoxMax.X;
                boundsInfo[4] = mesh.boundingBoxMax.Y;
                boundsInfo[5] = mesh.boundingBoxMax.Z;
                boundsInfo[6] = mesh.BoundingSphereRadius;

                Vector3 vert = new Vector3();

                // Only first submesh used in collision at the moment!
                // for(int i=0;i< mesh.subMeshList.Count;i++)
                if (mesh.subMeshList.Count > 0)
                {
                    int i = 0;
                    SubMesh sm = mesh.subMeshList[i];
                    int numFaces = sm.indexData.indexCount / 3;
                    int vCount = 0;
                    int posInc = sm.vertexData.vertexDeclaration.GetVertexSize(0); // fixme, bindindex, where to get it?
                    int index = 0;
                    VertexElement elemPos = sm.vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.Position);

                    vertexList = new float[sm.vertexData.vertexCount * 3];
                    indexList = new int[sm.indexData.indexCount];

                    for (int k = 0; k < sm.vertexData.vertexCount; k++)
                    {
                        index = elemPos.Offset + (posInc * k);
                        vert.X = (float)(BitConverter.ToSingle(sm.vertexData.vertexBuffer, index));
                        vert.Y = (float)(BitConverter.ToSingle(sm.vertexData.vertexBuffer, index + 4));
                        vert.Z = (float)(BitConverter.ToSingle(sm.vertexData.vertexBuffer, index + 8));
                        vertexList[vCount++] = vert.X;
                        vertexList[vCount++] = vert.Y;
                        vertexList[vCount++] = vert.Z;
                    }

                    for (int k = 0; k < sm.indexData.indexCount; k++)
                    {
                        if (sm.indices_i != null)
                        {
                            indexList[k] = sm.indices_i[k];
                        }
                        else
                        {
                            indexList[k] = sm.indices_s[k];
                        }
                    }
                }
            }
            catch (Exception e)
            {
                errorMessage = e.Message.ToString();
            }
        }