Skip to content
/ objmc Public
forked from Godlander/objmc

python script to convert .OBJ files into Minecraft, rendering them in game with a core shader.

License

Notifications You must be signed in to change notification settings

Web7283/objmc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 

Repository files navigation

usage:

make sure Python and Pillow is installed, and place the script in the same directory as the input obj and texture files.

place the shaders in the correct location in a resourcepack, and any model generated with this tool should display properly.

make sure your minecraft version is vanilla 1.18.1. the shader will not work with older versions, and any mods that change rendering (Optifine, Sodium, etc) will likely be incompatible with core shaders.

script inputs

objs: array of string names of obj files in the same folder to read. these must have same number of vertices if used in same animation.

frames: array of strings of digits defining which index of the obj to use as each frame.

texs: array of one single name of the texture file.

duration: integer duration of frames in ticks.

script output

output: array of two string file names: the json model, and the texture.

advanced:

for custom entity model rotation and controllable animation to work, the model has to be a Potion item (can use CustomModelData).

the CustomPotionColor R,G,B values defines the X,Y,Z rotation of the model or the animation time, depending on what colorbehavior is set to in the Python script as you exported the texture.

samples:

teapot

cat

cube

robo

ring

image

random notes about the tool

general output format:

this is just a reference, actual format may change as i add/change stuff

image

flipped uv

the uv ends up being upside down for some reason when exporting from Blockbench. idk why, so i just flip the texture while encoding to compensate.

this doesnt seem to happen through Blender tho

gltf animation to obj per frame

Blockbench exports animations to gltf format, which objmc doesn't support

you can import gltf format into blender and then export as waveform .obj, check the animation checkbox when exporting to generate .obj files per frame of the animation.

by default blender outputs a lot more frames than you will likely need, especially since objmc shader does interpolation between the frames. you can change the time stretching and frame range in blender to be lower to potentially decrease file size by a lot

image

vertex id

Minecraft's gl_VertexID isn't per model, so it's difficult to find the relative id of a vertex in a model unless you have a constant number of vertices

i thought up a trick to assign each face a unique pixel uv, then encoding the offset of the pixel from top left (relative 0,0 in the texture, some random place in the atlas)

with the offset data i am able to calculate the relative face id, and gl_VertexID % 4 gives the corner.

image

preserving rgb

basically anything to do with images in js does alpha premultiplying, which ruins rgb values when alpha is anything less than 255. afaik only way to not suffer this is to directly interact with the raw file instead of as an image. so if you wanted to send an image with alpha to someone over discord or something, don't send it as an image. instead, you can zip it and send the zip to preserve data, or just change the file extension so discord treats it as some unknown file.

questions

feel free to contact me on any of the linked social media icons in my github profile readme.

About

python script to convert .OBJ files into Minecraft, rendering them in game with a core shader.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • GLSL 61.1%
  • Python 38.9%