Jump to content

[1.16.2] Block with wavefront [.obj] model


ZephyrWolf_

Recommended Posts

Hey all,

 

I am working on implementing a custom model for a block using an .obj file. The OBJLoader.addDomain(domain) method has been removed since I last did this, and I cannot find anywhere what to do now. Does anyone know how to load obj model for blocks in the latest version?

Link to comment
Share on other sites

Ok so I have made some progress. I got the model loading now. But the model renders all in white. I am unconvinced it is the texture file. No errors are thrown and if I move my texture the model doesn't load. Anyone else had a similar issue in the past?

Link to comment
Share on other sites

The forge read the docs wiki is a little out of date. It is a lot easier now. I learnt how to do this from reverse engineering minecraft's and forge's code.

 

I use blender to create my model. A fantastic tutorial on how to create pixel art based models in blender can be found here: 

 

 

To export: go to File>Export->Wavefront (.obj)

 

1.png.81bda88e1758f50e167780dfd044cf96.png

 

Your settings should reflect this. This will convert the Blender coordinate system into Minecraft's.

2.png.827603fe861479b761a53e92eaab2cce.png

 

When you export your model you will get two files, an obj and a mtl. e.g. block_name.obj and block_name.mtl. The obj file describes the shape of the model while mtl file  describes how it looks. Keep both files next to each other. Go into your mod resource directory and place these two files where you want them, e.g. assets/modid/models/block/path

 

Within block_name.obj, make sure the mtllib points to the mtl file. Remember, your obj and mtl file should be next to each other. It should read:

mtllib block_name.mtl

Still within block_name.obj, make sure the correct material library is being loaded (Ill show you where this is declared in a sec.) (Just scroll down until you find the line, don't write your own)

usemtl block_name_mat

Your block_name.mtl file should look like something like this when you export it. If it doesn't have all of these lines, don't worry, Minecraft doesn't care too much about these numbers.

# Blender MTL File: 'bloomery.blend'
# Material Count: 1

newmtl block_name_mat
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2

Pretty much everything here can stay as is. "newmtl" is where we declare the material the obj loads with "usemtl". Make sure these match.

Next we need to let Minecraft know where to find out texture. Still within block_name.mtl add a map_Kd line below newmtl. If you forget this line, Forge will still load your model, but it will be all white.

newmtl block_name_mat
map_Kd modid:block/path/block_name
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2

 

Place your texture within assets/modid/textures/block/path. The map_Kd should point to this location.

 

Next, create a blockstate file for your block as normal. [block_name.json]. This will load a json model file. This has to be next to your obj and mtl files.

{
    "variants": {
        "": { "model": "modid:block/path/block_name" }
    }
}

 

Block Model [block_name.json]

{
	"loader": "forge:obj",
	"model": "modid:models/block/path/block_name.obj",
	"flip-v": true
}

Enabling flip-v will depend your model file. This just flips the way the texture is applied. If your texture looks upside down, change this to false.

 

Your assets folder structure should look like this now:

assets/modid/
	blockstates/
		block_name.json
	models/block/path/
		block_name.json
		block_name.obj
		block_name.mtl
	textures/block/path/
		block_name.png

 

Edited by ZephyrWolf_
  • Thanks 5
Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...
  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.