First/Third Person Different Weapon Models
by Chris Byars · 02/23/2006 (10:49 am) · 41 comments
This resource will allow you to have different weapon models for first and third person perspective, so the addition of high quality hands and weapon models in first person are possible without them being visible in third person view.
Now this is a cheap hack, and there's more you can do with it than I'm going to show here, as my knowledge is limited in C++ :)
One code change is all it takes. In engine/game/player.cc, in void Player::renderMountedImage(SceneState* state, ShapeImageRenderImage* rimage), change
IF YOU ARE USING TSE IN MILESTONE 3.5 OR LATER
The image rendering code has been moved to shapeBase.cpp.
In engine/game/shapeBase.cpp, in void ShapeBase::prepBatchRender(...), change:
What this does is, if you are in first person view, the weapon image will render at LOD 1. This LOD will contain the arms/hands and their animations as well as the weapon. All other LODs above 1 will render normally, so you make your LOD 2 the mesh that you want visible in third person view (without hands/arms).
Yes it's cheap, and you won't see your reload animations or anything like that in third person, so if you want those too you will need to script or code in some synchronizing with the player model and the weapon model's animations.
Screenshots:
First Person
Third Person
For reference:
http://www.garagegames.com/mg/forums/result.thread.php?qt=6702
Now this is a cheap hack, and there's more you can do with it than I'm going to show here, as my knowledge is limited in C++ :)
One code change is all it takes. In engine/game/player.cc, in void Player::renderMountedImage(SceneState* state, ShapeImageRenderImage* rimage), change
image.shapeInstance->render();to
if(fogExemption == true)image.shapeInstance->render(1); else image.shapeInstance->render();
IF YOU ARE USING TSE IN MILESTONE 3.5 OR LATER
The image rendering code has been moved to shapeBase.cpp.
In engine/game/shapeBase.cpp, in void ShapeBase::prepBatchRender(...), change:
image.shapeInstance->render();to
if(isFirstPerson())
{
image.shapeInstance->render(1);
}
else
{
image.shapeInstance->render();
}What this does is, if you are in first person view, the weapon image will render at LOD 1. This LOD will contain the arms/hands and their animations as well as the weapon. All other LODs above 1 will render normally, so you make your LOD 2 the mesh that you want visible in third person view (without hands/arms).
Yes it's cheap, and you won't see your reload animations or anything like that in third person, so if you want those too you will need to script or code in some synchronizing with the player model and the weapon model's animations.
Screenshots:
First Person
Third Person
For reference:
http://www.garagegames.com/mg/forums/result.thread.php?qt=6702
#22
Thanks, your game's looking good BTW. Yeah, what was happening was no matter how I changed the eyeOffset, it didn't seem to be changing the in game view. It was blowing my mind because it did work for every other weapon except the M4, and I knew for sure I was editing the right CS file so I was stumped there for a bit.
After doing a TextPad search, I discovered that two of the sgLights scripts had been written with my M4A1 script information! Go figure! I have no clue how that happened. Once they were removed, the eyeOffset worked again...
- Alan
05/13/2006 (7:39 pm)
Hey Tim, Thanks, your game's looking good BTW. Yeah, what was happening was no matter how I changed the eyeOffset, it didn't seem to be changing the in game view. It was blowing my mind because it did work for every other weapon except the M4, and I knew for sure I was editing the right CS file so I was stumped there for a bit.
After doing a TextPad search, I discovered that two of the sgLights scripts had been written with my M4A1 script information! Go figure! I have no clue how that happened. Once they were removed, the eyeOffset worked again...
- Alan
#23
but how do i set the LOD for my models? is there a script i need to edit?
05/21/2006 (4:10 am)
very nice, will get it in my project as soon as i can...but how do i set the LOD for my models? is there a script i need to edit?
#24
@ Charles: LOD is modelled in your model editing program, and then set in the DTS exporter.
06/07/2006 (5:05 pm)
@ Tim: Would you mind sharing that code for movement sense->play animation? It's one heck of a feature I've tried to put in. :)@ Charles: LOD is modelled in your model editing program, and then set in the DTS exporter.
#25
BTW, for anyone who's having some trouble with this part
"if(fogExemption == true)image.shapeInstance->render(1);",
I'd like to advise to check LOD order.
When you open up TorqueDemo, in which player holds crossbow by default,
it will crash because crossbow LOD setting begins from the highest level.
That means level 0 is the highest, while above code supposes level 1 is the highest.
07/11/2006 (8:46 am)
@C2 : Thanks for sharing! It really helped me.BTW, for anyone who's having some trouble with this part
"if(fogExemption == true)image.shapeInstance->render(1);",
I'd like to advise to check LOD order.
When you open up TorqueDemo, in which player holds crossbow by default,
it will crash because crossbow LOD setting begins from the highest level.
That means level 0 is the highest, while above code supposes level 1 is the highest.
#26
07/12/2006 (5:47 am)
Resource updated for usage in TSE as well.
#27
If i'm reading this correctly, one would have to add a mesh to their weaponmodels for arms/hands, only at detail0 (or detail1) depending on how they're building their game. And there's no other way to just render the player from the first person camera so you can see its mesh? (arms and hands specificly)
07/30/2006 (8:18 pm)
this seems to be maybe the only answer for what i was looking for... If i'm reading this correctly, one would have to add a mesh to their weaponmodels for arms/hands, only at detail0 (or detail1) depending on how they're building their game. And there's no other way to just render the player from the first person camera so you can see its mesh? (arms and hands specificly)
#28
08/05/2006 (7:31 pm)
Of course you can simply display the exact arms and weapon that is seen in 3rd person (rather than an "image"). Just change "renderFirstPerson" to true in the PlayerData datablock, I believe. This resource makes for more control over detail and animations, and if done right, will make your first and third person visuals far more advanced than normal, and use the system many current FPS games use.
#29
10/17/2006 (9:36 am)
Thank you much!
#30
Works fine, though, the DEBUG .exe throws an Assert error somewhere.
you can ifdef DEBUG to flip the code back to it's original state.
11/20/2006 (9:50 pm)
Anybody using this w/ 1.5 ?Works fine, though, the DEBUG .exe throws an Assert error somewhere.
you can ifdef DEBUG to flip the code back to it's original state.
#31
How do you define what is seen in 3rd/1st in milkshape 3d?
12/03/2006 (7:59 pm)
I don't understand how you're supposed to model the weapons?How do you define what is seen in 3rd/1st in milkshape 3d?
#32
http://img511.imageshack.us/img511/2950/screenshot00200001kn1.png
Any ideas on what might be happening?
12/16/2006 (9:34 am)
Im having a little problem:http://img511.imageshack.us/img511/2950/screenshot00200001kn1.png
Any ideas on what might be happening?
#33
More seriously though... did you make a LOD 2 for the gun?
12/19/2006 (10:50 am)
haha, that is pretty funny, I might know what is happening, the half invisible man is feeding shotgun to the visible man. :) More seriously though... did you make a LOD 2 for the gun?
#34
01/14/2007 (7:18 pm)
I got it working, now how do I make animations with bones work?
#35
01/15/2007 (4:53 am)
Never mind, It doesnt work still. Basicaly I made my mesh skin1 and skin2 and my detail markers detail1 and detail 2. My skin1 is linked to start01 and skin2 is off on its own. The detail markers are hooked up to base01. I compiled right, no errors and added the new source to my project. Why isnt it woking?
#36
01/26/2007 (5:08 pm)
Can't say. Getting it modelled correctly with two or more LODs to utilize LOD 1 as first person and the rest as 3rd is another story. This resource deals with the code aspect only and general information on what to do to your model. Depends on the program; I use Milkshape.
#37
I have a problem with this resource...
What is "LOD" any person have a weapon for example for function this resource I a noob sorry
I simple weapon for see in first person with arm and in 3 person only weapon..
Thanks help me please...i learn
Very very thanks
I have MILKSHAPE
02/06/2007 (2:17 am)
HI to all...I have a problem with this resource...
What is "LOD" any person have a weapon for example for function this resource I a noob sorry
I simple weapon for see in first person with arm and in 3 person only weapon..
Thanks help me please...i learn
Very very thanks
I have MILKSHAPE
#38
Render(0) tells TGE to go fetch and render the highest detail level in your mesh
Render(1) tells TGE to fetch and render the SECOND highest detail level in your mesh
So if you are using render(1) then, well, there's no nice way to tell you, but you stuffed up you model somehow.
This resource comes from my original post in this thread
07/04/2007 (2:33 pm)
Just to correct some errors I noticed cropping up in some people use of this. If you are having to use render(1) instead of render(0) then u have misunderstood the intention and obviously constructed your models incorrectly.Render(0) tells TGE to go fetch and render the highest detail level in your mesh
Render(1) tells TGE to fetch and render the SECOND highest detail level in your mesh
So if you are using render(1) then, well, there's no nice way to tell you, but you stuffed up you model somehow.
This resource comes from my original post in this thread
Quote:
There is another simple approach. The shape already holds multiple models in the form of LODs so just make you highest detail mesh be the 1st person mesh.
With the camera being that close to the object, it should already be rendering at its highest detail level without the need to change any code, but you can force it if in doubt. i.e. make a HIGH detail mesh and set it's LOD size to 1000 which will pretty much ensure that the screen-size based LOD algorythm never renders it, so to see it, you will have to force it to that detail level.
Fortunately, the render function takes a parameter for the detail level and you can make some code changes to force it to the highest detail level when in 1st person mode and only when rendering your own player plus mounts.
#39
Checking in TST and my third person model is detail-2, so thats correct.
Regards!
11/09/2007 (8:13 am)
Just trying in TGEA 1.2 as a temporary adjustment and it doesn't appear to be working. Regardless of whether im first or third person it only renders detail-1.Checking in TST and my third person model is detail-2, so thats correct.
Regards!
#40
08/20/2009 (12:19 pm)
has anyone been able to make this work in beta 5? ive tryed everything i can think of. any help would be awesome! thanks! 
Torque Owner Tim Heldna
At the moment we're using the eye offset due to inconsistencies with the weapon lining up. When I refer to the weapon lining up, I'm mainly talking about pitching up and down.
If you disable the eye offset the weapon will animate according to your player and emapping will work properly. However, it's a lot harder to line everything up. Hard to explain, you'll have to try it to see what I mean.
So by using an offset, you guarantee the weapon will ALWAYS line up but sacrifice movement animation and emapping.
By not using an offset, your weapon will animate with the player and emapping will work, but it's very hard to get the weapon to line up 100% of the time.
To implement animations on movement we've done some head code modification. Basically, if the player is moving in any direction the appropriate animation is called. I.e. walk forward and the weapon's forward animation is played, same for left / right and backwards etc.
Here's a video of it in action
AIAW Sniper Rifle Video (2.3mb)