Creating worldmodels from viewmodels: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(this tutorial needs to be cleaned up)
(clean up)
Line 1: Line 1:
{{cleanup}}
This tutorial teaches you how to create a world model from a [[Viewmodel|view model]]. It does not teach you how to do modeling or how to work with a model editor. Even though the screenshot shows 3ds max 7, the same can easily be done in all other model editors if you got sufficient knowledge of them.
{{tutpov}}


==Creating a world model from an existing view model==
Please note that even if this tutorial uses a view model for demonstration a world model should have a lot less polys and / or [[LOD_Models]] to ensure best performance ingame.
 
This tutorial teaches you how to create a world model from a view model. It does not teach you how to do modeling or how to work with a model editor. Even though the screenshot shows 3ds max 7, the same can easily be done in all other model editors if you got sufficient knowledge of them.
 
''Note: Even if this tutorial uses a view model for demonstration a world model should have a lot less polys and / or LOD models to ensure best performance ingame.''


==Setting up your model==
==Setting up your model==


If you'd just take your model and compile it like a physics object, the engine will not know where to put it onto the playermodel. The result can be somewhat hilarious but is most likely not what you are looking for.
If you just take your model and compile it like a [[prop_physic]], the engine will not know where to put it onto the playermodel. The result can be somewhat hilarious but is most likely not what you are looking for.


To change this, load your view model (without hands) into your favorite model editor. It will be helpful (but is not necessary) to remove all bones that you needed for animating your view model, so you end up with one object/bone.
To change this, load your view model (without hands) into your favorite model editor. It will be helpful (but is not necessary) to remove all bones that you needed for animating your view model, so you end up with one object/bone.


[[Image:worldmodel_heatm4.jpg|thumb|200px|[[Media:worldmodel_heatm4.jpg|click to enlarge]]]]
[[Image:worldmodel_heatm4.jpg|thumb|200px|[[Media:worldmodel_heatm4.jpg|click to enlarge]]]]
===Place the hand bone===
Now there are two ways to go. The first one is if you are doing a new model (not a replacement model) or if you don't have the model you want to replace decompiled:
Now there are two ways to go. The first one is if you are doing a new model (not a replacement model) or if you don't have the model you want to replace decompiled:


Create a new bone with the name '''ValveBiped.Bip01_R_Hand'''. Place it so that it is in the position you want the right hand of the playermodel to be. Now '''link your model''' to the bone. (If you move ValveBiped.Bip01_R_Hand now, the weapon moves with it.)
Create a new bone with the name <code>ValveBiped.Bip01_R_Hand</code>. Place it so that it is in the position you want the right hand of the playermodel to be. Now <code>link</code> your model to the bone. (If you move <code>ValveBiped.Bip01_R_Hand</code> now, the weapon moves with it.)


In case you have a decompiled model you want to replace, move your new model into the position of the old one, delete the old one and link your model to the '''ValveBiped.Bip01_R_Hand''' bone.
In case you have a decompiled model you want to replace, move your new model into the position of the old one, delete the old one and <code>link</code> your model to the <code>ValveBiped.Bip01_R_Hand</code> bone.


Now you are ready to export your model. Compile it like any other physic prop (however without $staticprop because that would collapse your bones).
{{Note|<code>ValveBiped.Bip01_R_Hand</code> is part of the standard Valve rig. If you use a custom rig, you'll need to use the bone name of that one.}}


Just for reference I'll post my .qc here but it's rather random:
===Export and compile===
 
Export your model (make sure to export unused bones if your exporter asks you). Compile it like any other physic prop (however without $staticprop because that would collapse your bones).
 
Just for reference here is the .qc that was used to compile the model seen in the screenshots:


<pre>$modelname weapons/w_m4a1.mdl
<pre>$modelname weapons/w_m4a1.mdl
Line 44: Line 45:


[[Image:worldmodel_heatm4alyx.jpg|thumb|150px|[[Media:worldmodel_heatm4alyx.jpg|click to enlarge]]]]
[[Image:worldmodel_heatm4alyx.jpg|thumb|150px|[[Media:worldmodel_heatm4alyx.jpg|click to enlarge]]]]
Now start the model viewer, load a playermodel of your choice and your world model. Most likely your weapon will not be perfectly sitting in the hand, might range from some fingers going through the weapon to weapon pointing in a completely wrong direction.
Now start the model viewer, load a playermodel of your choice and your world model. Most likely your weapon will not be perfectly sitting in the hand, might range from some fingers going through the weapon to the weapon pointing in a completely wrong direction.


Go back to your model editor. The actual position of the weapon or of the bone ''doesn't matter at all!'' Everything that counts is the ''relative position towards each other.'' In some cases you need to rotate. I'd advise not to rotate the weapon model but the bone. Either unlink it and link it later again or edit it without affecting children bones (for max you can find this setting in the hierarchy tab).
Go back to your model editor. The actual position of the weapon or of the bone ''doesn't matter at all!'' Everything that counts is the ''relative position towards each other.'' In some cases you need to rotate. I'd advise not to rotate the weapon model but the bone. Either unlink it and link it later again or edit it without affecting children bones (for max you can find this setting in the hierarchy tab).


If you have aligned everything perfectly, your model will hopefully look like the Alyx model with the M4 of our example.
In case you want to add attachment-bones, like for a muzzle flash, add a bone with an according name (e.g. <code>ValeBiped.muzzle flash</code>) and link it to <code>ValveBiped.Bip01_R_Hand</code>.


In case you want to add attachment-bones, like for a muzzle flash, add a bone with an according name (e.g. ValeBiped.muzzle flash) and link it to ValveBiped.Bip01_R_Hand.
==Technical explanation==


==Technical explenation of what we've just done==
If you want to have a little bit of extra knowledge that helps you to understand how this works, read on.


If you want to have a little bit extra knowledge that helps you to understand what we've just done, read on.
The engine merges the bone <code>ValveBiped.Bip01_R_Hand</code> of your playermodel with the a bone of the same name in your world model (in case it's the root bone). All bones that are a child of this bone will naturally move with it, that's why we have linked the weapon and the muzzle flash to it.
 
The skeleton of the player model and of your world model have become one! When you have loaded both in the model viewer and you activate <code>Bones</code> in the render tab you can easily see it.
The engine merges the bone ValveBiped.Bip01_R_Hand of your playermodel with the a bone of the same name in your world model (in case it's the root bone). All bones that are a child of this bone will naturally move with it, that's why we have linked the weapon and the muzzle flash to it.
The skeleton of the player model and of your world model have become one! When you have loaded both in the model viewer and you activate ''Bones'' in the render tab you can easily see it.




Line 75: Line 74:
end</pre>
end</pre>


As you can see, in ''nodes'' the ValveBiped.Bip01_R_Hand is defined as the root bone while the bone called m4a1 is a child of it. In the ''skeleton'' part the position of both are defined.
As you can see, in <code>nodes</code> the <code>ValveBiped.Bip01_R_Hand</code> is defined as the root bone while the bone called m4a1 is a child of it. In the <code>skeleton</code> part the position of both are defined.
 
If this is not the case, but you are sure that everything is set up correctly, check your exporter settings again.
 
== See also ==
 
* [[Viewmodels_in_XSI | Viewmodels in XSI]]
* [[Attachments]]


[[Category:Modeling]]
[[Category:Modeling]]

Revision as of 03:51, 4 April 2006

This tutorial teaches you how to create a world model from a view model. It does not teach you how to do modeling or how to work with a model editor. Even though the screenshot shows 3ds max 7, the same can easily be done in all other model editors if you got sufficient knowledge of them.

Please note that even if this tutorial uses a view model for demonstration a world model should have a lot less polys and / or LOD_Models to ensure best performance ingame.

Setting up your model

If you just take your model and compile it like a prop_physic, the engine will not know where to put it onto the playermodel. The result can be somewhat hilarious but is most likely not what you are looking for.

To change this, load your view model (without hands) into your favorite model editor. It will be helpful (but is not necessary) to remove all bones that you needed for animating your view model, so you end up with one object/bone.

Place the hand bone

Now there are two ways to go. The first one is if you are doing a new model (not a replacement model) or if you don't have the model you want to replace decompiled:

Create a new bone with the name ValveBiped.Bip01_R_Hand. Place it so that it is in the position you want the right hand of the playermodel to be. Now link your model to the bone. (If you move ValveBiped.Bip01_R_Hand now, the weapon moves with it.)

In case you have a decompiled model you want to replace, move your new model into the position of the old one, delete the old one and link your model to the ValveBiped.Bip01_R_Hand bone.

Note.pngNote:ValveBiped.Bip01_R_Hand is part of the standard Valve rig. If you use a custom rig, you'll need to use the bone name of that one.

Export and compile

Export your model (make sure to export unused bones if your exporter asks you). Compile it like any other physic prop (however without $staticprop because that would collapse your bones).

Just for reference here is the .qc that was used to compile the model seen in the screenshots:

$modelname weapons/w_m4a1.mdl

$cdmaterials models/weapons

$scale 1

$keyvalues { "prop_data" { "base" "metal.medium" } }

$model w_m4a1 "w_m4a1.smd"

$sequence idle "w_m4a1" loop fps 15

$collisionmodel "w_m4a1.smd" {
     // Mass in kilograms
     $Mass 3.0
   $concave
}

Now start the model viewer, load a playermodel of your choice and your world model. Most likely your weapon will not be perfectly sitting in the hand, might range from some fingers going through the weapon to the weapon pointing in a completely wrong direction.

Go back to your model editor. The actual position of the weapon or of the bone doesn't matter at all! Everything that counts is the relative position towards each other. In some cases you need to rotate. I'd advise not to rotate the weapon model but the bone. Either unlink it and link it later again or edit it without affecting children bones (for max you can find this setting in the hierarchy tab).

In case you want to add attachment-bones, like for a muzzle flash, add a bone with an according name (e.g. ValeBiped.muzzle flash) and link it to ValveBiped.Bip01_R_Hand.

Technical explanation

If you want to have a little bit of extra knowledge that helps you to understand how this works, read on.

The engine merges the bone ValveBiped.Bip01_R_Hand of your playermodel with the a bone of the same name in your world model (in case it's the root bone). All bones that are a child of this bone will naturally move with it, that's why we have linked the weapon and the muzzle flash to it. The skeleton of the player model and of your world model have become one! When you have loaded both in the model viewer and you activate Bones in the render tab you can easily see it.


To make sure the you got this correctly, you can also look into your .smd file.

If everything is correct, it should start like this:

version 1
nodes
  0 "ValveBiped.Bip01_R_Hand"  -1
  1 "m4a1"   0
end
skeleton
time 0
  0 # # # # # #
  1 # # # # # #
end

As you can see, in nodes the ValveBiped.Bip01_R_Hand is defined as the root bone while the bone called m4a1 is a child of it. In the skeleton part the position of both are defined.

If this is not the case, but you are sure that everything is set up correctly, check your exporter settings again.

See also