Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.9] Render custom item


TPD
 Share

Recommended Posts

  • Replies 95
  • Created
  • Last Reply

Top Posters In This Topic

Hm ok.

What file-format would you suggest? I can't use a simple .obj-file because the file has to store multiple "sub-objects" (IModelPart) and also other information (for example points where gun attachments/upgrades should be placed).

Should I use a .zip-file that contains .obj files? That would make it possible to edit the model with 3d-programs.

Link to comment
Share on other sites

Do you think it's ok to just have one ICustomModelLoader, store what kind of IModel it describes in the model file and then make the ICustomModelLoader load/instantiate the IModel accordingly?

 

Also what textures do I have to return in getTextures() of IModel and where should I get them from? I mean, aren't textures stored separately?

Link to comment
Share on other sites

No, a baked model is fixed. If you want animations you need to bake new models. The forge animation system already does this for you and provides the AnimationItemOverrideList class.

 

To make the baked quads you basically have to generate the packed vertex data according to the VertexFormat. The example in OBJModel is pretty straightforward, you use UnpackedBakedQuad.Builder and then do something similar to OBJBakedModel::putVertexData.

Link to comment
Share on other sites

Currently the mods stores things like attachments and paintjobs in the ItemStack (as NBT data). Is there a way to get the NBT data during baking? If not: How would I implement attachments and paintjobs?

Link to comment
Share on other sites

Baking happens at startup, there is no information about the items at all yet.

You can either use ModelLoader.setCustomMeshDefinition instead of setCustomModelResourceLocation to basically provide a callback function to determine the model to use based on the ItemStack.

If you need a more dynamic approach you can make a class extending ItemOverrideList. In there override the handleItemState which lets you determine a different IBakedModel based on the ItemStack. Then you return an instance of this new class from the getOverrides method of your IBakedModel.

Link to comment
Share on other sites

I have two more questions:

  • Why is ICustomModelLoader::loadModel called twice for every item?
  • How can I make the Item render in the vanilla way when it's in the inventory/GUIs?

This is what I tried to do in my IPerspectiveAwareModel:

     @Override
    public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
        switch (cameraTransformType) {
            case GUI:
                return Pair.of(Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getModel(new ModelResourceLocation(resourceLocation, null)), null);
        }

        return Pair.of(this, null);
    }

 

The result is just a purple-black square. How can I specify the texture correctly?

Link to comment
Share on other sites

Why is ICustomModelLoader::loadModel called twice for every item?
First of all this has nothing to do with items.

Secondly, this is probably because forge has to reload resources a few times during startup to make mods work properly. Models are reloaded in that process.

 

How can I make the Item render in the vanilla way when it's in the inventory/GUIs?
Not sure what you mean by this. What is "the vanilla way"?

 

This is what I tried to do in my IPerspectiveAwareModel:

[snip]The result is just a purple-black square.

Well, of course. You did not specify a variant for your ModelResourceLocation, meaning that a model with that location likely does not exist.

 

How can I specify the texture correctly?
Please clarify. What texture?
Link to comment
Share on other sites

With normal, I mean a "2D-Item". The way almost all Items in the game are rendered. I also tried ModelResourceLocation(resourceLocation, "inventory") and ModelResourceLocation(resourceLocation, "normal") (which is the same as ModelResourceLocation(resourceLocation, null)) with the same outcome.

Link to comment
Share on other sites

The normal "2D-Item" model is defined in "item/handheld.json". If you want a textured variant of this model, load it using

ModelLoaderRegistry.getModel(new ResourceLocation("item/handheld"))

, cast to

IRetexturableModel

and retexture it to use whichever texture you want (make sure the texture is loaded, if need be via

TextureStitchEvent

). The base texture for this item model is called "layer0", so you'd do

IRetexturableModel::retexture(ImmutableMap.of("layer0", <myTexture>))

.

You can then bake the resulting

IModel

.

Link to comment
Share on other sites

The normal "2D-Item" model is defined in "item/handheld.json". If you want a textured variant of this model, load it using

ModelLoaderRegistry.getModel(new ResourceLocation("item/handheld"))

, cast to

IRetexturableModel

and retexture it to use whichever texture you want (make sure the texture is loaded, if need be via

TextureStitchEvent

). The base texture for this item model is called "layer0", so you'd do

IRetexturableModel::retexture(ImmutableMap.of("layer0", <myTexture>))

.

You can then bake the resulting

IModel

.

 

I think you mean

builtin/generated

or

item/generated

.

builtin/generated

is the base 2D-style model,

item/generated

extends this and defines the standard display transformations. Most basic item models extend

item/generated

.

 

item/handheld

extends

item/generated

and redefines the first/third-person display transformations to change how the item renders when held by an entity. Vanilla tool models extend this.

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

 

I think you mean

builtin/generated

or

item/generated

.

builtin/generated

is the base 2D-style model,

item/generated

extends this and defines the standard display transformations. Most basic item models extend

item/generated

.

 

item/handheld

extends

item/generated

and redefines the first/third-person display transformations to change how the item renders when held by an entity. Vanilla tool models extend this.

 

I only need it for GUIs. I guess both works in that case

Link to comment
Share on other sites

I tried to do something similar but it started to become too "hackey"

 

It is indeed annoying. I have to rewrite half of the mod (probably more) that I'm trying to update. But at least that means it will be done properly this time...

Link to comment
Share on other sites

What limitations have you encountered? Bring them forward and there will be a solution.

The solution will most definitely not be IItemRenderer and it will most likely also not be ModelBase.

 

One thing you mentioned are animations which are still 100% possible. There is a (admittedly not well documented) animation API in forge which can be used to animate both item models through a custom ItemOverrideList implementation and block models through a TileEntitySpecialRenderer (which has been optimized a bit using the FastTESR so that all TESRs can be batched into a single GPU call).

 

 

Link to comment
Share on other sites

Simple easy to understand formatting and method names
I think the IModel / IBakedModel system is pretty straightforward once you understand it. The Animatino API I have not worked with, but you are not bound to use it. The API is just for actually producing the animated models, you can do that yourself, too, if you want. All the API then does is use an ItemOverrideList resp. a TESR to render those animated models (or rather the individual frames, which are all individual models). You can do this yourself if you do not wish to use the API.

Being able to dynamically resize different parts of a ModelBase model using push/pop/scale with variables from the individual item

IModel's bake method takes an IModelState. You can pass in a TRSRTransformation here which will then apply to the model. So you could apply whatever transformation you want to individual parts and then combine them into one big model.

Choose what parts to render, and which not to,with variables from the individual item
Also possible with the above process.

Really you can do whatever the heck you want inside a model's getQuads. It could generate the quads completely on the fly.

Adjust color of individual parts, with variables from the individual item
As long as you use a vertex format that includes color you can specify the color per vertex.

Adjust position and rotation, in finer increments than 22 degrees, with variables from the individual item
Again, possible. You don't even need any code at runtime for this afaik. You can specify a fully fledged transformation matrix in the forge blockstate jsons.

Child parts and nested child parts
What do you mean by this exactly?

GL11 blending to give transparencies
I do not know if this is possible yet, but I also am not 100% sure what exactly you want here. Plus I am not a GL expert by any means.
Link to comment
Share on other sites

First of all, nobody forces you to use JSON models. Forge will load OBJ just fine and they behave like normal vanilla JSON models.

So: Any modeling program that exports to OBJ is one you can use.

 

As for the parts, I think that is exactly what fry worked on with the animation API, but like I said, I have not worked with it and he is currently ... "gone" (where? I do not know). I will ask when he's back (apparently 18th of august according to this IRC nick) or you can come to the IRC and ask yourself.

I also know that there either is full or partial support for B3D animations (B3D being a model format that supports animations, OBJ does not).

 

I know what blend does in theory, but I have not much experience with it. I think it depends case to case whether it is currently already possible or not.

 

A) TESR and IBakedModels and JSON are too disjointed to work under 1 modeling program.

Not sure what makes you say this. You can render baked models in TESRs and you can get models from a modeling program into the game via OBJ.

B) No one friggin understands the system well enough to make such a modeling program

A new modeling program is not needed, the system supports well established model formats and it is extensible so everyone could write their own loader to add support for new model formats if needed.

C) it is just too complicated
It is really not that bad...

Yes, it is badly documented. But that has nothing to do with complexity.

And yes, rendering is complex, there is nothing you can do about that. And ModelBase has even less documentation than any of the new rendering stuff.

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
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.

 Share




×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.