First/Third Person Weapon Model
by Henry Todd · in Torque 3D Professional · 01/12/2010 (8:12 am) · 4 replies
There was an old TGE resource that did this by forcing detail level 1, which technically seems backward, but was unlikely to cause problems because no one uses a detail level 1 (1 pixel LoD version? I think that's known as a dot).
T3D now apparently forces your control object's mounted images to max detail, and this already can work perfectly for a 1st/3rd person model. Simply give your object a detail level with a size value of, say, 1000000. Why so high? The pixel size calculation is based on bounding spheres and distance, not actual screen projection of the object's extents. That means that, with your face against the object, you can hit pixel size 25000 pretty quickly.
There's still one problem: even in 3rd person your Player is still the control object, and will still render his "hands" version of the weapon, resuling in some ghost hands. To be clear, you don't need code changes unless your players are allowed to tab out to 3rd person in your game. Here's a quick fix:
ShapeBase.cpp, around line 2444 (sorry, my file has some mods, might be off a few lines) in the function:
bool ShapeBase::_prepRenderImage
you'll find this:
All we want to do is make sure that we only render the max detail if we're the control object AND in first person. So:
if ( forceHighestDetail ) becomes:
if ( forceHighestDetail && isFirstPerson() )
and it should look like:
That should do it. **Edit 10/11/10: I eventually built a weapon model that has arms at the highest detail level and it works fine, however you can see the shadows from the extra pair of arms (other players won't, just appears when you look at your own shadow). The non-code solution is to map your weapon arms with a material which has cast shadows disabled, however I'll try to come back to this in the near future and make it use the second-highest LOD for the shadow pass.
T3D now apparently forces your control object's mounted images to max detail, and this already can work perfectly for a 1st/3rd person model. Simply give your object a detail level with a size value of, say, 1000000. Why so high? The pixel size calculation is based on bounding spheres and distance, not actual screen projection of the object's extents. That means that, with your face against the object, you can hit pixel size 25000 pretty quickly.
There's still one problem: even in 3rd person your Player is still the control object, and will still render his "hands" version of the weapon, resuling in some ghost hands. To be clear, you don't need code changes unless your players are allowed to tab out to 3rd person in your game. Here's a quick fix:
ShapeBase.cpp, around line 2444 (sorry, my file has some mods, might be off a few lines) in the function:
bool ShapeBase::_prepRenderImage
you'll find this:
// Select detail levels on mounted items but... always
// draw the control object's mounted images in high detail.
if ( forceHighestDetail )
image.shapeInstance->setCurrentDetail( 0 );
else
image.shapeInstance->setDetailFromDistance( state, dist * invScale );All we want to do is make sure that we only render the max detail if we're the control object AND in first person. So:
if ( forceHighestDetail ) becomes:
if ( forceHighestDetail && isFirstPerson() )
and it should look like:
// Select detail levels on mounted items but... always
// draw the control object's mounted images in high detail.
if ( forceHighestDetail && isFirstPerson() )
image.shapeInstance->setCurrentDetail( 0 );
else
image.shapeInstance->setDetailFromDistance( state, dist * invScale );That should do it. **Edit 10/11/10: I eventually built a weapon model that has arms at the highest detail level and it works fine, however you can see the shadows from the extra pair of arms (other players won't, just appears when you look at your own shadow). The non-code solution is to map your weapon arms with a material which has cast shadows disabled, however I'll try to come back to this in the near future and make it use the second-highest LOD for the shadow pass.
About the author
Recent Threads
#2
01/12/2010 (3:40 pm)
Henry can you post a link to that bug report so I can follow eventual progresses? Tnx :-)
#3
EDIT: This issue has been isolated and a workaround produced. It's apparently an issue with the old max2dts exporters that are out there.
01/12/2010 (3:59 pm)
www.torquepowered.com/community/forums/viewthread/109109EDIT: This issue has been isolated and a workaround produced. It's apparently an issue with the old max2dts exporters that are out there.
#4
EDIT: Found where this happens, and as a result, a better place to do your 1st/3rd person weapon rendering switch!
See the edited original post for details.
01/12/2010 (4:13 pm)
Well, to add an interesting issue to this, it looks like the engine always picks the highest LOD for your control object's mounted images regardless of any LOD settings (prefs or model settings).EDIT: Found where this happens, and as a result, a better place to do your 1st/3rd person weapon rendering switch!
See the edited original post for details.
Torque Owner Henry Todd
Atomic Walrus
In fact, the swarmGun model that comes with the game also doesn't like to return pixel values -- go ahead and load it up in the shape editor and zoom in/out, you'll see what I mean. The debris model? Yes. Rocket? No. Something is definitely screwy in pixel size calculation.
Going to post this as a separate bug report.