Jump to content

Render entity model from .json


thebest108

Recommended Posts

You probably can't, since entity models rely on raw OpenGL instructions. You can probably render a regular baked model for the simple parts and then render the entity model from a

TESR

. The enchanting table does something like this: the base is a baked model, the book is rendered from the

TESR

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Oh, you have a JSON model that you want to render as an entity? I thought you had an entity model that you wanted to render as an item/block.

 

It's certainly possible to render baked models as entities, look at

RenderFallingBlock

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
                    IBakedModel ibakedmodel = blockrendererdispatcher.getModelFromBlockState(iblockstate, world, (BlockPos)null);
                    blockrendererdispatcher.getBlockModelRenderer().renderModel(world, ibakedmodel, iblockstate, blockpos, worldrenderer, false);

 

RenderFallingBlock requires for the model to already be on a block though. Making a new block for each piece of the model is an organization nightmare D:

 

I'm assuming that I can bypass most of the block requirements, but how do I get an IBakedModel from the .json?

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

Ah, it looks like it's a bit tricky to render a baked model that isn't a

Block

or

Item

(since Minecraft rarely uses baked models for other things).

 

You should be able to subscribe to

ModelBakeEvent

, load the model into an

IModel

using

ModelLoader#getModel

, bake it using

IModel#bake

(look at how this is used in

ModelLoader#setupModelRegistry

) and then add it to the model registry with

IRegistry#putObject

. The

ModelLoader

and model registry are provided as fields of

ModelBakeEvent

.

 

Look at

RenderItemFrame#doRender

to see how you can render an

IBakedModel

that doesn't belong to a

Block

or

Item

.

 

I'm far from an expert in the model/rendering system, so I can't guarantee that this is correct.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Alright, so I got the models loading and rendering, but the problem is the texture is missing.

 

I can apply any texture I want using renderManager.renderEngine.bindTexture(location); but I want it to use the texture described in the .json .

 

Here's the relevant code:

 

Model Baking Code:

IModel cannonBase = event.modelLoader.getModel(RenderCannon.cannonBase);
Function<ResourceLocation, TextureAtlasSprite> textureGetter = new Function<ResourceLocation, TextureAtlasSprite>(){
       public TextureAtlasSprite apply(ResourceLocation location){
              return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
       }
}
RenderCannon.cannonBaseBaked = cannonBase.bake(cannonBase.getDefaultState(), DefaultVertexFormats.BLOCK, textureGetter);

 

Render Code:

BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
IBakedModel ibakedmodel = cannonBaseBaked;
renderManager.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
blockrendererdispatcher.getBlockModelRenderer().renderModelBrightnessColor(ibakedmodel, 1.0F, 1.0F, 1.0F, 1.0F);		

 

And the .json model, textures and all of it:

{
    "__comment": "Cannon model - bracket only (for animation)",
    "textures": {
        "particle": "blocks/Rusty shaft",
        "0": "blocks/wood_spruce",
        "1": "blocks/Rusty shaft",
        "2": "blocks/Other metal thing"
    },
    "elements": [
        {
            "name": "Bracket base",
            "from": [ 4.0, 1.0, 4.0 ], 
            "to": [ 12.0, 2.0, 12.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 1.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 8.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 8.0, 8.0 ] }
            }
        },
        {
            "name": "Bracket left bottom",
            "from": [ 4.0, 2.0, 4.0 ], 
            "to": [ 5.0, 5.0, 12.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 3.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 13.0, 8.0, 16.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 3.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 13.0, 8.0, 16.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] }
            }
        },
        {
            "name": "Bracket right bottom",
            "from": [ 11.0, 2.0, 4.0 ], 
            "to": [ 12.0, 5.0, 12.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 3.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 13.0, 8.0, 16.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 3.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 13.0, 8.0, 16.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 8.0 ] }
            }
        },
        {
            "name": "Bracket left middle",
            "from": [ 4.0, 5.0, 5.0 ], 
            "to": [ 5.0, 7.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 11.0, 6.0, 13.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 11.0, 6.0, 13.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 6.0 ] }
            }
        },
        {
            "name": "Bracket right middle",
            "from": [ 11.0, 5.0, 5.0 ], 
            "to": [ 12.0, 7.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 11.0, 6.0, 13.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 11.0, 6.0, 13.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 6.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 6.0 ] }
            }
        },
        {
            "name": "Bracket left top",
            "from": [ 4.0, 7.0, 6.0 ], 
            "to": [ 5.0, 8.0, 10.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 10.0, 4.0, 11.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 10.0, 4.0, 11.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 4.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 4.0 ] }
            }
        },
        {
            "name": "Bracket right top",
            "from": [ 11.0, 7.0, 6.0 ], 
            "to": [ 12.0, 8.0, 10.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 1.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 0.0, 4.0, 1.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 4.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 1.0, 4.0 ] }
            }
        }
    ]
}

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

Do you have missing texture errors in the log? Your model's texture paths don't have a resource prefix, so it's trying to load them from the

minecraft

domain.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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



×
×
  • Create New...

Important Information

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