Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * MARIO HEAD MODCONV BY MOUNTAINFLAW, REWRITTEN IN C BY SIMON
- * TAKES AN OBJ FILE AND CONVERTS IT INTO MARIO HEAD FORMAT FOR
- * A DECOMPILED ROM.
- * COPYRIGHT MOUNTAINFLAW 2019
- */
- #include <stdio.h>
- #include <assimp/cimport.h>
- #include <assimp/mesh.h>
- #include <assimp/scene.h>
- void model_convert_goddard(char *in, char *output, int scale, int material, int pos1) {
- char out[0x100];
- sprintf(out, "%sdynlist_.c", output);
- const struct aiScene *scene = aiImportFile(in, 0);
- struct aiMesh *mesh = scene->mMeshes[0];
- unsigned int vertexCount = mesh->mNumVertices;
- printf("Output: %s\n", output);
- printf("Verts: %d\n", vertexCount);
- FILE *vertexSourcef = fopen(out, "w");
- fputs("// Dynlist generated by modconv4\n", vertexSourcef);
- puts("Generating Vertex Data...");
- fprintf(vertexSourcef, "#define VTX_NUM %d\n", vertexCount);
- fprintf(vertexSourcef, "s16 verts_%s[VTX_NUM][3] = {\n", output);
- for (size_t i = 0; i < vertexCount; i++) {
- int vertX = (int)mesh->mVertices[i].x * scale;
- int vertY = (int)mesh->mVertices[i].y * scale;
- int vertZ = (int)mesh->mVertices[i].z * scale;
- fprintf(vertexSourcef, "{%d,\t\t%d,\t\t%d},\n", vertX, vertY, vertZ);
- }
- fputs("};\n", vertexSourcef);
- fprintf(vertexSourcef, "struct GdVtxData vtx_%s_data = { VTX_NUM, 0x1, verts_%s };\n#undef VTX_NUM\n", output, output);
- puts("Vertex Generation: OK");
- puts("Generating Face Data...");
- fprintf(vertexSourcef, "#define FACE_NUM %d\n", vertexCount / 3);
- fprintf(vertexSourcef, "u16 facedata_%s[FACE_NUM][4] = {\n", output);
- for (unsigned int i = 0; i < vertexCount; i += 3) // Generate faces.
- fprintf(vertexSourcef, "{%d,\t\t%d,\t\t%d,\t\t%d},\n", material, i + pos1, i + 1 + pos1, i + 2 + pos1);
- fputs("};\n", vertexSourcef);
- fprintf(vertexSourcef, "struct GdFaceData faces_%s_data = { FACE_NUM, 0x1, facedata_%s };\n#undef FACE_NUM\n", output, output);
- puts("FaceData Generation: OK");
- puts("Finished generating Goddard dynlist.");
- puts("Thank you.");
- }
- int main(int argc, char **argv) {
- puts("modconv - mountainflaw");
- if (argc != 6) {
- 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]);
- return 1;
- }
- int scale;
- sscanf(argv[3], "%d", &scale);
- int material;
- sscanf(argv[4], "%d", &material);
- int pos1;
- sscanf(argv[5], "%d", &pos1);
- model_convert_goddard(argv[1], argv[2], scale, material, pos1);
- return 0;
- }
Add Comment
Please, Sign In to add comment