Ejemplo n.º 1
0
        static unsafe BRenderGrannyMesh LoadGR2Internal(granny_file *grannyFile)
        {
            try
            {
                if (grannyFile != null)
                {
                    // It's a file Granny can load (but might be just a raw bunch of bits).
                    granny_file_info *file_info = GrannyGetFileInfo((IntPtr)grannyFile);
                    if (file_info != null)
                    {
                        ConvertCoordinateSystem(file_info, true, true);

                        //file has been transformed, load our meshes
                        BRenderGrannyMesh mesh = new BRenderGrannyMesh();
                        createMeshFromGR2(ref mesh, file_info);

                        return(mesh);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error loading granny file");
            }
            return(null);
        }
Ejemplo n.º 2
0
 public static extern unsafe void GrannyTransformFile(granny_file_info *FileInfo,
                                                      ref Vector3 Affine3,
                                                      float *Linear3x3,
                                                      float *InverseLinear3x3,
                                                      float AffineTolerance,
                                                      float LinearTolerance,
                                                      int Flags);
Ejemplo n.º 3
0
 public static extern unsafe bool GrannyComputeBasisConversion(granny_file_info *FileInfo,
                                                               float DesiredUnitsPerMeter,
                                                               ref Vector3 DesiredOrigin3,
                                                               ref Vector3 DesiredRight3,
                                                               ref Vector3 DesiredUp3,
                                                               ref Vector3 DesiredBack3,
                                                               ref Vector3 ResultAffine3,
                                                               float *ResultLinear3x3,
                                                               float *ResultInverseLinear3x3);
Ejemplo n.º 4
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.º 5
0
        static public unsafe void ConvertCoordinateSystem(granny_file_info *pGrannyFileInfo, bool model, bool flipWinding)
        {
            //pGrannyFileInfo->ArtToolInfo->FromArtToolName
            IntPtr strPtr = new IntPtr((byte *)pGrannyFileInfo->ArtToolInfo->FromArtToolName);
            string name   = Marshal.PtrToStringAnsi(strPtr);

            //POST_GRANNY_EXPORT_TOOL_NAME "ESPostExport"
            if (name != "ESPostExport")
            {
                Vector3 affine3          = new Vector3();
                float[] linear3x3        = new float[9];
                float[] inverseLinear3x3 = new float[9];

                Vector3 forward  = new Vector3(0, 0, 1);
                Vector3 right    = new Vector3(-1, 0, 0);
                Vector3 origin   = new Vector3(0, 0, 0);
                Vector3 upVector = new Vector3(0, 1, 0);


                fixed(float *lfp = linear3x3)
                {
                    fixed(float *ilfp = inverseLinear3x3)
                    {
                        GrannyComputeBasisConversion(pGrannyFileInfo, (float)(pGrannyFileInfo->ArtToolInfo->UnitsPerMeter / 64.0),
                                                     ref origin, ref right, ref upVector, ref forward, ref affine3, lfp, ilfp);

                        if (model)
                        {
                            GrannyTransformFile(pGrannyFileInfo, ref affine3, lfp, ilfp, 1e-5f, 1e-5f, (flipWinding ? GrannyReorderTriangleIndices : 0) | GrannyRenormalizeNormals);
                        }
                        else
                        {
                            //not implemented
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        static private unsafe void createMeshFromGR2(ref BRenderGrannyMesh mesh, granny_file_info *fileInfo)
        {
            int NumMeshes = fileInfo->ModelCount;

            for (int i = 0; i < NumMeshes; i++)
            {
                try
                {
                    if (fileInfo->Models[i]->MeshBindingCount == 0)
                    {
                        //  CoreGlobals.getErrorManager().OnSimpleWarning(String.Format("No Mesh Binding for model# {0} out of {1} in {2}", i, NumMeshes, filename));
                    }
                    else
                    {
                        processMesh(ref mesh, fileInfo->Models[i]->MeshBindings[0].Mesh);
                    }
                }
                catch (System.Exception ex)
                {
                    //  CoreGlobals.getErrorManager().OnSimpleWarning(String.Format("Error processing mesh #{0} out of {1} in {2}.  {3}", i, NumMeshes, filename, ex.ToString()));
                }
            }
        }
Ejemplo n.º 7
0
        static public unsafe int getMeshVerts(granny_file_info *fileInfo, int meshIndex)
        {
            granny_mesh *gMesh = fileInfo->Meshes[meshIndex];

            return(gMesh->PrimaryVertexData->VertexCount);
        }