Guest User

Untitled

a guest
Jan 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. /*
  2. * MARIO HEAD MODCONV BY MOUNTAINFLAW, REWRITTEN IN C BY SIMON
  3. * TAKES AN OBJ FILE AND CONVERTS IT INTO MARIO HEAD FORMAT FOR
  4. * A DECOMPILED ROM.
  5. * COPYRIGHT MOUNTAINFLAW 2019
  6. */
  7. #include <stdio.h>
  8. #include <assimp/cimport.h>
  9. #include <assimp/mesh.h>
  10. #include <assimp/scene.h>
  11.  
  12. void model_convert_goddard(char *in, char *output, int scale, int material, int pos1) {
  13. char out[0x100];
  14. sprintf(out, "%sdynlist_.c", output);
  15.  
  16. const struct aiScene *scene = aiImportFile(in, 0);
  17. struct aiMesh *mesh = scene->mMeshes[0];
  18. unsigned int vertexCount = mesh->mNumVertices;
  19.  
  20. printf("Output: %s\n", output);
  21. printf("Verts: %d\n", vertexCount);
  22.  
  23. FILE *vertexSourcef = fopen(out, "w");
  24. fputs("// Dynlist generated by modconv4\n", vertexSourcef);
  25.  
  26. puts("Generating Vertex Data...");
  27.  
  28. fprintf(vertexSourcef, "#define VTX_NUM %d\n", vertexCount);
  29. fprintf(vertexSourcef, "s16 verts_%s[VTX_NUM][3] = {\n", output);
  30.  
  31. for (size_t i = 0; i < vertexCount; i++) {
  32. int vertX = (int)mesh->mVertices[i].x * scale;
  33. int vertY = (int)mesh->mVertices[i].y * scale;
  34. int vertZ = (int)mesh->mVertices[i].z * scale;
  35. fprintf(vertexSourcef, "{%d,\t\t%d,\t\t%d},\n", vertX, vertY, vertZ);
  36. }
  37.  
  38. fputs("};\n", vertexSourcef);
  39. fprintf(vertexSourcef, "struct GdVtxData vtx_%s_data = { VTX_NUM, 0x1, verts_%s };\n#undef VTX_NUM\n", output, output);
  40.  
  41. puts("Vertex Generation: OK");
  42. puts("Generating Face Data...");
  43.  
  44. fprintf(vertexSourcef, "#define FACE_NUM %d\n", vertexCount / 3);
  45. fprintf(vertexSourcef, "u16 facedata_%s[FACE_NUM][4] = {\n", output);
  46.  
  47. for (unsigned int i = 0; i < vertexCount; i += 3) // Generate faces.
  48. fprintf(vertexSourcef, "{%d,\t\t%d,\t\t%d,\t\t%d},\n", material, i + pos1, i + 1 + pos1, i + 2 + pos1);
  49.  
  50. fputs("};\n", vertexSourcef);
  51. fprintf(vertexSourcef, "struct GdFaceData faces_%s_data = { FACE_NUM, 0x1, facedata_%s };\n#undef FACE_NUM\n", output, output);
  52.  
  53. puts("FaceData Generation: OK");
  54. puts("Finished generating Goddard dynlist.");
  55. puts("Thank you.");
  56. }
  57.  
  58. int main(int argc, char **argv) {
  59. puts("modconv - mountainflaw");
  60.  
  61. if (argc != 6) {
  62. fprintf(stderr, "Usage: %s <model> <output> <scale> <material id> <triangle starting position>\nMost people should leave <material id> and <triangle starting position> at 0.", argv[0]);
  63. return 1;
  64. }
  65.  
  66. int scale;
  67. sscanf(argv[3], "%d", &scale);
  68.  
  69. int material;
  70. sscanf(argv[4], "%d", &material);
  71.  
  72. int pos1;
  73. sscanf(argv[5], "%d", &pos1);
  74.  
  75. model_convert_goddard(argv[1], argv[2], scale, material, pos1);
  76.  
  77. return 0;
  78. }
Add Comment
Please, Sign In to add comment