Ejemplo n.º 1
0
        static public unsafe int getTotalVerts(granny_file_info *fileInfo)
        {
            int totalVerts = 0;

            for (int meshIndex = 0; meshIndex < fileInfo->MeshCount; ++meshIndex)
            {
                granny_mesh *gMesh = fileInfo->Meshes[meshIndex];
                totalVerts += gMesh->PrimaryVertexData->VertexCount;
            }
            return(totalVerts);
        }
Ejemplo n.º 2
0
 public static extern unsafe granny_tri_material_group *GrannyGetMeshTriangleGroups(granny_mesh *mesh);
Ejemplo n.º 3
0
 public static extern unsafe granny_data_type_definition *GrannyGetMeshVertexType(granny_mesh *mesh);
Ejemplo n.º 4
0
 public static extern unsafe int GrannyGetMeshTriangleGroupCount(granny_mesh *mesh);
Ejemplo n.º 5
0
 public static extern unsafe void GrannyCopyMeshVertices(granny_mesh *mesh, granny_data_type_definition *vertType, void *dstVertexData);
Ejemplo n.º 6
0
 public static extern unsafe int GrannyGetMeshVertexCount(granny_mesh *mesh);
Ejemplo n.º 7
0
 public static extern unsafe void GrannyCopyMeshIndices(granny_mesh *mesh, int bytesPerIndex, void *dstIndexData);
Ejemplo n.º 8
0
        static public unsafe int getMeshVerts(granny_file_info *fileInfo, int meshIndex)
        {
            granny_mesh *gMesh = fileInfo->Meshes[meshIndex];

            return(gMesh->PrimaryVertexData->VertexCount);
        }
Ejemplo n.º 9
0
        static private unsafe void processMesh(ref BRenderGrannyMesh mesh, granny_mesh *grannyMesh)
        {
            BRenderPrimitive prim = new BRenderPrimitive();

            //indicies
            prim.mNumInds = GrannyGetMeshTriangleCount(grannyMesh) * 3;
            int[] indData = new int[prim.mNumInds];

            int    indexSize          = prim.mNumInds * sizeof(int);
            IntPtr pMarshaledIndexMem = System.Runtime.InteropServices.Marshal.AllocHGlobal(indexSize);

            GrannyCopyMeshIndices(grannyMesh, 4, (int *)pMarshaledIndexMem);
            System.Runtime.InteropServices.Marshal.Copy(pMarshaledIndexMem, indData, 0, prim.mNumInds);
            System.Runtime.InteropServices.Marshal.FreeHGlobal(pMarshaledIndexMem);


            //ib's
            prim.mIB = new IndexBuffer(typeof(int), prim.mNumInds, BRenderDevice.getDevice(), Usage.None, Pool.Managed);
            GraphicsStream stream  = prim.mIB.Lock(0, 0, LockFlags.None);
            int *          outInds = (int *)stream.InternalDataPointer;

            for (int q = 0; q < prim.mNumInds; q++)
            {
                outInds[q] = indData[q];
            }

            prim.mIB.Unlock();
            stream.Close();


            //verticies
            prim.mVertexSize = 0;


            granny_data_type_definition *grnyVertTypeDef = GrannyGetMeshVertexType(grannyMesh);

            granny_data_type_definition[] grnDTD = null;
            VertexDeclaration             grnVD  = null;

            if (!getVertexTypeFromGranny(grnyVertTypeDef, ref prim.mVertexSize, ref grnDTD, ref grnVD, ref prim.mVDecl))
            {
                //already logged
                //CoreGlobals.getErrorManager().OnSimpleWarning(String.Format("Error loading {0} getVertexTypeFromGranny failed", filename));

                return;
            }

            prim.mNumVerts = GrannyGetMeshVertexCount(grannyMesh);

            {
                int    size          = prim.mNumVerts * prim.mVertexSize;
                IntPtr pMarshaledMem = System.Runtime.InteropServices.Marshal.AllocHGlobal(size);
                byte[] tGrnVerts     = new byte[size];


                fixed(granny_data_type_definition *grnPD = grnDTD)
                GrannyCopyMeshVertices(grannyMesh, grnPD /*grnyVertTypeDef*/, (void *)pMarshaledMem);

                System.Runtime.InteropServices.Marshal.Copy(pMarshaledMem, tGrnVerts, 0, size);
                System.Runtime.InteropServices.Marshal.FreeHGlobal(pMarshaledMem);

                byte[] d3dVerts = new byte[size];

                //swizzle the granny verts to be d3d friendly before copying them to the device
                swzzlGrnyVertsToD3DVerts(tGrnVerts, grnVD, prim.mVertexSize, prim.mNumVerts,
                                         ref d3dVerts, prim.mVDecl);



                prim.mVB = new VertexBuffer(BRenderDevice.getDevice(), (int)prim.mNumVerts * prim.mVertexSize, Usage.None, VertexFormats.None, Pool.Managed);
                stream   = prim.mVB.Lock(0, 0, LockFlags.None);

                stream.Write(d3dVerts, 0, size);
                prim.mVB.Unlock();
                stream.Close();


                tGrnVerts = null;
                grnVD.Dispose();
                grnVD = null;
            }
            //SUB GROUPS
            int groupCount = GrannyGetMeshTriangleGroupCount(grannyMesh);
            granny_tri_material_group *GrannyMatGroups = GrannyGetMeshTriangleGroups(grannyMesh);


            //process our material groups for this mesh


            for (int k = 0; k < groupCount; k++)
            {
                BRenderMaterialGroup group = new BRenderMaterialGroup();


                group.mStartIndex = GrannyMatGroups[k].TriFirst * 3;
                group.mPrimCount  = GrannyMatGroups[k].TriCount;

                //load your texture here.
                prim.mGroups.Add(group);
            }


            mesh.addRenderPrimitive(prim);
        }
Ejemplo n.º 10
0
 public static extern unsafe void *GrannyGetMeshVertices(granny_mesh *Mesh);
Ejemplo n.º 11
0
 public static extern unsafe bool GrannyMeshIsRigid(granny_mesh *Mesh);
Ejemplo n.º 12
0
 public static extern unsafe int GrannyGetMeshIndexCount(granny_mesh *Mesh);
Ejemplo n.º 13
0
 public static extern unsafe granny_mesh_binding *GrannyNewMeshBinding(granny_mesh *Mesh,
                                                                       granny_skeleton *FromSkeleton,
                                                                       granny_skeleton *ToSkeleton);