I am in the process of updating from 1.8.9 to 1.9.4 and 1.10.x and I have a bunch of custom OBJ models that I created custom IBakedModel classes for that implement IPerspectiveAwareModel. My overriden handlePerspective method looks like this: http://pastebin.com/ikMQPTXd
In 1.8.9, this worked no problem and it ran on every tick for the items. in 1.9.4 and 1.10.2 (as of 2 days ago when I tested) the handlePerspective method never gets called so I can't seem to scale and rotate my item models based on the TransformType.
Looking into forge a bit it seems the OBJBakedModel class, which runs when the custom OBJ model is rendering seems to call the static, state sensitive method in IPerspectiveAwareModel instead of the method that gets overridden. I might be way off on this, but that is what lead me to believe that this may be a bug in forge relating to OBJ models.
I created a thread on the forge forums a couple days ago (http://www.minecraftforge.net/forum/index.php/topic,41193.0.html), but haven't gotten any response, which is another reason I decided to create an issue here.
Thanks.
@williewillus added labels [Bug]
This Bug affected me too. Can someone please fix it? I would be very happy! thx
Has anyone been able to take a look at this yet? I've tried figuring it out on my own, but I haven't been able to make any headway.
Have you tried converting your OBJ models into json models and see if the problem is still there ? :)
@GirafiStudios a large portion of OBJ's are OBJ's for a reason (Namely, they represent shapes that json cannot express), so that's not a really valid solution.
@Nuchaz, if you understand the issue you are probably the best person to fix it quickly. @RainWarrior hasn't made a commit since June.
@Nuchaz can you provide more context on your usage of OBJBakedModel?
What exactly are you subclassing and how do you interact with the Forge OBJBakedModel class?
@RainWarrior welcome back... Hopefully this issue can finally get fixed.
any news on this?
I had some time to look over the code, so let me float the solution below. I found several examples of other mods using custom models, and the paste bin above seems to be identical except in which class it is extending.
public Pair extends IBakedModel, ... rather than extends IPerspectiveAwareModel? If you have created custom model classes, those implement IPerspectiveAwareModel.
I have also seen an example where they do a check before
if (model instanceof IPerspectiveAwareModel) { public Pair extends iBakedModel...
Here is a good example of what I'm attempting to explain, but maybe I'm off base. Sorry if this doesn't help.
That's Forge's own code, and it's job is to take an IBakedModel and modify the GL matrix to rotate the model when it's rendered. It checks if the model is an IPerspectiveAwareModel so it can override the vanilla behavior and use handlePerspective. Although it is the method that makes model transforms work, the bug probably doesn't originate there.
Second, Pair<? extends IPerspectiveAwareModel is a subtype of Pair<? extends IBakedModel>, so it makes no difference, The @Override would make the compiler complain if it did anyway.
If you've made your own custom IModel, IBakedModel, etc. there is no reason for you to not have complete control over everything. Once you have done that, OBJBakedModel and all that is _completely_ irrelevant. Your model's own code is in charge of everything, and the fact that it may load another model, store it in a field, and consult it for quads and such is an implementation detail that can't be meddled with. Without seeing more of your code, I can't say much, but you may have done something wrong, or the bug is not what you think it is.
@Nuchaz ^^
The screenshots that Nuchaz posted seem to be limited to the rendering of the item models only, not the in game block models. Is this simply a case of the model item json files needing updated with the correct orientations for each perspective? I'm not sure if the use of the baked models means that the json files are irrelevant. Not much else I can propose.
Example:
{
"parent": "tyrbuilders:block/crate_acacia",
"display": {
"gui": {
"rotation": [ 30, 225, 0 ],
"translation": [ 0, 0, 0],
"scale":[ 0.625, 0.625, 0.625 ]
},
"ground": {
"rotation": [ 0, 0, 0 ],
"translation": [ 0, 3, 0],
"scale":[ 0.25, 0.25, 0.25 ]
},
"fixed": {
"rotation": [ 0, 0, 0 ],
"translation": [ 0, 0, 0],
"scale":[ 0.5, 0.5, 0.5 ]
},
"thirdperson_righthand": {
"rotation": [ 75, 45, 0 ],
"translation": [ 0, 2.5, 0],
"scale": [ 0.375, 0.375, 0.375 ]
},
"firstperson_righthand": {
"rotation": [ 0, 45, 0 ],
"translation": [ 0, 0, 0 ],
"scale": [ 0.40, 0.40, 0.40 ]
},
"firstperson_lefthand": {
"rotation": [ 0, 225, 0 ],
"translation": [ 0, 0, 0 ],
"scale": [ 0.40, 0.40, 0.40 ]
}
}
}
@Nuchaz Any chance you could post your entire model source? You've not given much info about your implementation at all. Do you extend the forge OBJ model classes?
@durand1w I tried creating a json file for a model but it didn't seem to do anything.
@tterrag1098 sure, here is the code for the waypoint compass: http://pastebin.com/bZzep1Dy
Everything on that model, as well as the other models works, its just handlePerspective never gets called so it isn't rotated or scaled correctly in 1st person, 3rd person, or on the ground, even though I implemented IPerspectiveAwareModel. In 1.8.9, I didn't have any problem with this, it worked as expected.
Tracking down how forge is getting the TRSRTransformation, in IPerspectiveAwareModel.java, line 109:
TRSRTransformation tr = state.apply(Optional.of(cameraTransformType)).or(TRSRTransformation.identity());
It seems to always return the identity matrix instead of passing on the cameraTransformType and getting the transformation matrix from my handlePerspective method. I'm not sure why that is happening though.
@Nuchaz you're returning the result of OBJModel.bake, instead of your wrapper, from the CustomItemOverrideList, which gets called before the perspective handler.
Also, I suggest using something like https://github.com/MinecraftForge/MinecraftForge/blob/1.11.x/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java#L297-L320 (with delegation to the parent state in case the inner if condition doesn't hold) instead of using OBJState, which will be gone eventually.
@RainWarrior Thanks! That makes so much sense. I changed like 2 lines of code and now handlePerspective is getting called. That was the golden advice I was needing.
There is no bug in forge, I was wrong there. It's all me it looks like.
Big thanks for the tip about OBJState too. I seen it is depreciated, but I had no idea how to handle that.
Most helpful comment
@RainWarrior Thanks! That makes so much sense. I changed like 2 lines of code and now handlePerspective is getting called. That was the golden advice I was needing.
There is no bug in forge, I was wrong there. It's all me it looks like.
Big thanks for the tip about OBJState too. I seen it is depreciated, but I had no idea how to handle that.