Skip to content

Commit

Permalink
Implement CommonMCOBJ
Browse files Browse the repository at this point in the history
  • Loading branch information
erich666 committed Mar 27, 2024
1 parent 616a688 commit 359ba26
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
66 changes: 66 additions & 0 deletions Win/ObjFileManip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31872,6 +31872,72 @@ static int writeStatistics(HANDLE fh, int (*printFunc)(char *), WorldGuide* pWor
sprintf_s(outputString, 256, "# Full current path: %s\n", outChar);
WRITE_STAT;

// for project at https://github.com/CommonMCOBJ
#define CMC2OBJ
#ifdef CMC2OBJ
if (gModel.options->pEFD->fileType == FILE_TYPE_WAVEFRONT_ABS_OBJ ||
gModel.options->pEFD->fileType == FILE_TYPE_WAVEFRONT_REL_OBJ) {

/* from https://github.com/CommonMCOBJ/cmc2obj/blob/26fa005b97c6dfa212436f03a687bcaea6fa8978/src/org/jmc/ObjExporter.kt#L405-L421
objWriter.println("# COMMON_MC_OBJ_START");
objWriter.println("# version: 1");
objWriter.println("# exporter: cmc2obj"); // Name of the exporter, all lowercase, with spaces substituted by underscores
objWriter.println("# world_name: ${Options.worldDir?.getName()}"); // Name of the source world
objWriter.println("# world_path: ${Options.worldDir?.toString()}"); // Path of the source world
objWriter.println("# export_bounds_min: (${Options.minX}, ${Options.minY}, ${Options.minZ})"); // The lowest block coordinate exported in the obj file
objWriter.println("# export_bounds_max: (${Options.maxX-1}, ${Options.maxY-1}, ${Options.maxZ-1})"); // The highest block coordinate exported in the obj file
objWriter.println("# export_offset: " + String.format(Locale.US, "(%f, %f, %f)", offsetVec.x, offsetVec.y, offsetVec.z)); // The offset vector the model was exported with
objWriter.println("# block_scale: ${Options.scale}"); // Scale of each block
objWriter.println("# block_origin_offset: (-0.5, -0.5, -0.5)"); // The offset vector of the block model origins
objWriter.println("# z_up: false"); // true if the Z axis is up instead of Y, false is not
objWriter.println("# texture_type: " + (if (Options.singleMaterial) "ATLAS" else "INDIVIDUAL_TILES")); // ATLAS or INDIVIDUAL_TILES
objWriter.println("# has_split_blocks: " + (if (Options.objectPerMaterial) "true" else "false")); // true if blocks have been split, false if not
objWriter.println("# COMMON_MC_OBJ_END");
*/
sprintf_s(outputString, 256, "\n# COMMON_MC_OBJ_START\n# version: 1\n# exporter: mineways\n");
WRITE_STAT;

if (justWorldFileName == NULL || strlen(justWorldFileName) == 0)
{
strcpy_s(outputString, 256, "# world_name: [Block Test World]\n");
}
else {
sprintf_s(outputString, 256, "# world_name: %s\n", justWorldFileName);
}
WRITE_STAT;
sprintf_s(outputString, 256, "# world_path: %s\n", worldChar);
WRITE_STAT;

sprintf_s(outputString, 256, "# export_bounds_min: (%d, %d, %d)\n",
worldBox->min[X], worldBox->min[Y], worldBox->min[Z]);
WRITE_STAT;
sprintf_s(outputString, 256, "# export_bounds_max: (%d, %d, %d)\n",
worldBox->max[X], worldBox->max[Y], worldBox->max[Z]);
WRITE_STAT;

// the translation vector from where the minecraft block coordinates are to where they are exported in the model
// See https://github.com/jmc2obj/j-mc-2-obj/issues/243#issuecomment-2016341301
Point exportOffset;
Vec3Op(exportOffset, =, (float)gWorld2BoxOffset, -, gModel.center);
sprintf_s(outputString, 256, "# export_offset: (%f, %f, %f)\n", exportOffset[X], exportOffset[Y], exportOffset[Z]);
WRITE_STAT;
// in meters, so divide by 1000.
sprintf_s(outputString, 256, "# block_scale: %g\n", gModel.options->pEFD->blockSizeVal[gModel.options->pEFD->fileType] / 1000.0f);
WRITE_STAT;
// lower left corner defined as 0,0,0, if I understand it right.
sprintf_s(outputString, 256, "# block_origin_offset: (0.000000, 0.000000, 0.000000)\n");
WRITE_STAT;
sprintf_s(outputString, 256, "# z_up: %s\n", gModel.options->pEFD->chkMakeZUp[gModel.options->pEFD->fileType] ? "true" : "false");
WRITE_STAT;
sprintf_s(outputString, 256, "# texture_type: %s\n", gModel.exportTiles ? "INDIVIDUAL_TILES" : "ATLAS");
WRITE_STAT;
sprintf_s(outputString, 256, "# has_split_blocks: true\n");
WRITE_STAT;
sprintf_s(outputString, 256, "# COMMON_MC_OBJ_END\n");
WRITE_STAT;
}
#endif

return MW_NO_ERROR;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<p><B>NEW! Physically based material export.</B> Mineways now <a href="textures.html#jgrtx">exports using photorealistic resource packs</a> to Pixar's USD format, which can be displayed in the free <a href="mineways.html#ovcreate">Omniverse USD Composer</a> program, <a href="mineways.html#houdini">Houdini</a>, <a href="mineways.html#c4d">Cinema 4D</a>, and others. Links: <a href="textures.html#candy">screen shot</a>, <a href="mineways.html#ovcreate">written tutorial</a>, <a href="https://youtu.be/tBDGH5v40x8">video tutorial</a>, and <a href="textures.html">how-to guide</a>. Enjoy!

<P>
<b>Donations:</b> Mineways is free and <a href="https://github.com/erich666/Mineways">open source</a>. If you like it, please consider donating to <a href="https://www.givewell.org/">GiveWell</a> (just $7 pays to <a href="https://www.givewell.org/impact-estimates#Impact_metrics_for_GiveWells_top_charities">treat a child for malaria</a>) or <a href="https://www.charitynavigator.org/">your favorite charity</a>. Your donation can significantly improve or even save someone else's life.
<b>Donations:</b> Mineways is free and <a href="https://github.com/erich666/Mineways">open source</a>. If you like it, please consider donating to <a href="https://www.charitynavigator.org/">your favorite charity</a> instead.

<P>
<b>Problems running?</b> If <a href="downloads.html#windows">MSVCR140.DLL is missing</a> or <a href="downloads.html#windows">VCRUNTIME140_1.dll is not found</a>, install <a href="https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads">vc_redist.x64.exe</a>. For more help, see the troubleshooting guides for <a href="downloads.html#windows"><b>Windows</b></a>, <a href="downloads.html#mac"><b>Mac</b></a>, <a href="downloads.html#linux"><b>Linux</b></a>, consult the <a href="downloads.html#troubleshooting"><b>general guide</b></a>, or use the search engine.
Expand Down
4 changes: 2 additions & 2 deletions docs/mineways.html
Original file line number Diff line number Diff line change
Expand Up @@ -2879,12 +2879,12 @@ <h2 id="versions">Version History</h2>

<UL>

<LI>Version 11.06a, 3/29/2024 - <a href="https://erich.realtimerendering.com/minecraft/public/mineways/minewaysV1106a.zip">exe</a>, <a href="https://github.com/erich666/Mineways/tags">source</a>.
<LI>Version 11.07, 3/29/2024 - <a href="https://erich.realtimerendering.com/minecraft/public/mineways/minewaysV1107.zip">exe</a>, <a href="https://github.com/erich666/Mineways/tags">source</a>.
<BR>
<UL>
<LI>Mineways implementation of <a href="https://github.com/CommonMCOBJ/CommonMCOBJ">CommonMCOBJ</a>, a standardized header for OBJ file data.
<LI>Tilemaker: slightly more accurate heightfield to normal texture conversion formula. Fix TGA reader for when the input and output number of channels don't match. Added some more error messages to handle bad PNGs. Now at version 3.23.
<LI>JG-RTX texture pack update.
<LI>No changes to Mineways itself, which stays at version 11.06.
</UL>

<LI>Version 11.06, 1/4/2024 - <a href="https://erich.realtimerendering.com/minecraft/public/mineways/minewaysV1106.zip">exe</a>, <a href="https://github.com/erich666/Mineways/tags">source</a>.
Expand Down

0 comments on commit 359ba26

Please sign in to comment.