Jump to content

[1.12.2] Using Minecraft's Tessellator and BufferBuilder


GooberGunter

Recommended Posts

On 8/29/2018 at 2:47 AM, GooberGunter said:

Hey, I'm trying to add my own complex models to the game, but I'm not sure how to use the Tessellator, are there any good tutorials/guides/books available for me to read up on? Thanks

Directly interacting with the tesselator & buferbuilder is probably not what you want to do unless your already pretty experienced in OpenGL and advanced 3D rendering. What are you trying to achieve exactly? What do you mean by complex models and why & where & when will they be used?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Specifically, I wanna use Wavefront .obj models for custom mobs. My goal is to get familiar with 3D rendering. All I really need to know is how 3D rendering is done. From what I’ve seen it looks like the tessellator just needs the vertices of the model for correct positioning and then the normals of the faces to render the shape of the model. I’m not sure if that’s how it works, but I haven’t checked out too much code yet. Is this right?

Link to comment
Share on other sites

35 minutes ago, GooberGunter said:

Specifically, I wanna use Wavefront .obj models for custom mobs. My goal is to get familiar with 3D rendering. All I really need to know is how 3D rendering is done. From what I’ve seen it looks like the tessellator just needs the vertices of the model for correct positioning and then the normals of the faces to render the shape of the model. I’m not sure if that’s how it works, but I haven’t checked out too much code yet. Is this right?

You definitely don't need to deal with the tesselator & bufferbuilder for this, look at the Forge Animation API, or you could just inject the models you need into the model registry & render them normally with an entity renderer.

 

Example of injecting models

https://github.com/Cadiboo/WIPTechAlpha/blob/fbf25447cd02b3dc4fe4fece749c3558f9342f3f/src/main/java/cadiboo/wiptech/EventSubscriber.java#L464-L509 

(Right below that code is a good example of why not to use the tesselator)

 

Example of rendering an entity with the injected models

https://github.com/Cadiboo/WIPTechAlpha/blob/master/src/main/java/cadiboo/wiptech/client/render/entity/EntityPortableGeneratorRenderer.java

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

46 minutes ago, Cadiboo said:

Forge Animation API

This doesnt support OBJ models.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

BufferBuilder is just a way to specify a vertex collection for OpenGL to render. A vertex is ultimately just a collection of data OpenGL uses to draw things. At the very minimum it needs the position in world-space to render anything at all.

You start by specifying a format and a draw mode. The draw mode specifies what the vertices mean(ex. 4 means a quad with GL_QUADS) and the format specifies the way the data is aligned in each vertex(ex. POSITION_TEXTURE_COLOR means that each vertex contains 3 floats that specify position, followed by 2 floats that specify the uvs for the texture followed by 4 floats that specify the color). The only thing that might confuse you are BLOCK(3 position, 4 color, 2 texture, 2 lightmap) and ITEM(3 position, 4 color, 2 texture, 3 normal, 1 padding) formats.

Then you specify the vertices based on the format you've selected. You do that by calling the respective methods. For example to specify the position you would call BufferBuilder#pos. Keep in mind that the order must be the same as the order defined by the format(ex. if the format is POSITION_TEXTURE_COLOR the vertex definition would be pos(...).tex(...).color(...)). Then you end the definition of each vertex with BufferBuilder#endVertex similar to how you end sentences with a dot. These methods can conviniently be chained to compact the code. So you can do bufferbuilder.pos(...).tex(...).color(...).normal(....).endVertex();

Once you've specified all the vertices needed for your drawing you finally call Tessellator#draw.

Knowing that you can easily adapt the BufferBuilder to render a wavefront object. Parse your object in a way that gives you a collection of vertices each containing the data you need(position, uvs, normals) and then simply iterate over the collection adding each vertex to the buffer. As an example here is the way I parse the wavefront into a collection of vertices and upload those vertices to the buffer. As a bonus here is the way I use a FastTESR to render the parsed wavefront into the buffer provided by the FastTESR(with matrix transformations). 

I hope my explanation and the examples provided help you.

Link to comment
Share on other sites

23 minutes ago, GooberGunter said:

All im really looking for is a guide to how the buffer builder works. I’ve been looking at some sample code from other mods as well as checking some LWJGL tutorials, but I’m still unsure on how to use it.

You put vertexes into it and that creates a face, which is assigned a texture via the points you specify as floats as a 0-1 scale by the bound texture. Which is bound from

Minecraft.getMinecraft().getRenderManager().renderEngine.bindTexture(resource);

Or an instance of RenderManager/TextureManager that you are provided.

You call BufferBuilder.begin(VertextFormat)

then bufferbuilder.pos().tex().normal().endVertex() for all of the vertexes you need.

Then finally call tesselator.draw.

 

If you need an instance of these, use Tesselator.getInstance() and then to get the BufferBuilder instance use Tesselator#getBuffer().

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have done this now but have got the error:   'food(net.minecraft.world.food.FoodProperties)' in 'net.minecraft.world.item.Item.Properties' cannot be applied to                '(net.minecraftforge.registries.RegistryObject<net.minecraft.world.item.Item>)' public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register( "lemon_juice", () -> new Item( new HoneyBottleItem.Properties().stacksTo(1).food( (new FoodProperties.Builder()) .nutrition(3) .saturationMod(0.25F) .effect(() -> new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 1500), 0.01f ) .build() ) )); The code above is from the ModFoods class, the one below from the ModItems class. public static final RegistryObject<Item> LEMON_JUICE = ITEMS.register("lemon_juice", () -> new Item(new Item.Properties().food(ModFoods.LEMON_JUICE)));   I shall keep going between them to try and figure out the cause. I am sorry if this is too much for you to help with, though I thank you greatly for your patience and all the effort you have put in to help me.
    • I have been following these exact tutorials for quite a while, I must agree that they are amazing and easy to follow. I have registered the item in the ModFoods class, I tried to do it in ModItems (Where all the items should be registered) but got errors, I think I may need to revert this and figure it out from there. Once again, thank you for your help! 👍 Just looking back, I have noticed in your code you added ITEMS.register, which I am guessing means that they are being registered in ModFoods, I shall go through the process of trial and error to figure this out.
    • ♈+2349027025197ஜ Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join a brotherhood for protection and wealth here’s is your opportunity, but you should know there’s no ritual without repercussions but with the right guidance and support from this great temple your destiny is certain to be changed for the better and equally protected depending if you’re destined for greatness Call now for enquiry +2349027025197☎+2349027025197₩™ I want to join ILLUMINATI occult without human sacrificeGREATORLDRADO BROTHERHOOD OCCULT , Is The Club of the Riches and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In Greatorldrado BROTHERHOOD we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money Rewards once they join in order to upgrade their lifestyle.; interested viewers should contact us; on. +2349027025197 ۝ஐℰ+2349027025197 ₩Greatorldrado BROTHERHOOD OCCULT IS A SACRED FRATERNITY WITH A GRAND LODGE TEMPLE SITUATED IN G.R.A PHASE 1 PORT HARCOURT NIGERIA, OUR NUMBER ONE OBLIGATION IS TO MAKE EVERY INITIATE MEMBER HERE RICH AND FAMOUS IN OTHER RISE THE POWERS OF GUARDIANS OF AGE+. +2349027025197   SEARCHING ON HOW TO JOIN THE Greatorldrado BROTHERHOOD MONEY RITUAL OCCULT IS NOT THE PROBLEM BUT MAKE SURE YOU'VE THOUGHT ABOUT IT VERY WELL BEFORE REACHING US HERE BECAUSE NOT EVERYONE HAS THE HEART TO DO WHAT IT TAKES TO BECOME ONE OF US HERE, BUT IF YOU THINK YOU'RE SERIOUS MINDED AND READY TO RUN THE SPIRITUAL RACE OF LIFE IN OTHER TO ACQUIRE ALL YOU NEED HERE ON EARTH CONTACT SPIRITUAL GRANDMASTER NOW FOR INQUIRY +2349027025197   +2349027025197 Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join
    • Hi, I'm trying to use datagen to create json files in my own mod. This is my ModRecipeProvider class. public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder { public ModRecipeProvider(PackOutput pOutput) { super(pOutput); } @Override protected void buildRecipes(Consumer<FinishedRecipe> pWriter) { ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', ModItems.COMPRESSED_DIAMOND.get()) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get(),9) .requires(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .unlockedBy(getHasName(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()), has(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get())) .save(pWriter); ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', Blocks.DIAMOND_BLOCK) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); } } When I try to run the runData client, it shows an error:  Caused by: java.lang.IllegalStateException: Duplicate recipe compressed:compressed_diamond I know that it's caused by the fact that there are two recipes for the ModItems.COMPRESSED_DIAMOND. But I need both of these recipes, because I need a way to craft ModItems.COMPRESSED_DIAMOND_BLOCK and restore 9 diamond blocks from ModItems.COMPRESSED_DIAMOND. Is there a way to solve this?
  • Topics

×
×
  • Create New...

Important Information

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