Difference between revisions of "Modeling props with Blender"

From Valve Developer Community
Jump to: navigation, search
(blockquote gives pre icky rendering)
(remove stub, separate out collision model and physics)
Line 1: Line 1:
 
[[Category:Modeling]] [[Category:Tutorials]][[Category:Blender]]
 
[[Category:Modeling]] [[Category:Tutorials]][[Category:Blender]]
{{stub}}
+
 
 
It is possible to create static, non-animated props in [[Blender]], along with appropriate physics collision data, in case Softimage is too much. This requires use of the [http://asrc.pjohnsen.com/downloads/smd_export.py SMD Exporter] by [http://asrc.pjohnsen.com/ Pelle Johnsen].  This exporter does not support skeletons, multiple materials, or animations, but it does support hard/soft edges.
 
It is possible to create static, non-animated props in [[Blender]], along with appropriate physics collision data, in case Softimage is too much. This requires use of the [http://asrc.pjohnsen.com/downloads/smd_export.py SMD Exporter] by [http://asrc.pjohnsen.com/ Pelle Johnsen].  This exporter does not support skeletons, multiple materials, or animations, but it does support hard/soft edges.
  
 
{{note|It is assumed that the reader knows the basic functions of Blender. At the very least you must be comfortable with creating simple models, applying UV texture mapping, and installing plugins. A working knowledge of how to compile models is a significant help.}}
 
{{note|It is assumed that the reader knows the basic functions of Blender. At the very least you must be comfortable with creating simple models, applying UV texture mapping, and installing plugins. A working knowledge of how to compile models is a significant help.}}
  
 +
__TOC__
 
==Creating a basic non-solid prop==
 
==Creating a basic non-solid prop==
  
Line 50: Line 51:
 
8. If everything went right, you'll get some nice output from studiomdl (look carefully for any errors), and you can now find the model in Hammer's model browser for use in-game.
 
8. If everything went right, you'll get some nice output from studiomdl (look carefully for any errors), and you can now find the model in Hammer's model browser for use in-game.
  
==Adding collisions and physics==
+
==Adding collisions==
  
So far we have a basic model which can be used as a prop_static. At the moment, players and objects will pass right through it, and it can't be picked up, or moved. To enable these effects, we need to do two things: create a collision model, and add some physics properties.
+
So far we have a basic model which can be used as a prop_static, but it has no solidity. At the moment, players, objects, and bullets will pass right through it. To prevent this, we need to create a collision model.
  
 
Creating a collision model is easy for a simple prop like this. We can use the same mesh as the reference model, but in Blender, select the whole mesh and hit "Set Smooth" (under the "Link and Materials" panel of the edit mode). We do this because the model compiler expects the collision model mesh for each convex part to have a single texture and be in one smoothing group. Now export the mesh as "pcmag_phys.smd". This is our collision model.
 
Creating a collision model is easy for a simple prop like this. We can use the same mesh as the reference model, but in Blender, select the whole mesh and hit "Set Smooth" (under the "Link and Materials" panel of the edit mode). We do this because the model compiler expects the collision model mesh for each convex part to have a single texture and be in one smoothing group. Now export the mesh as "pcmag_phys.smd". This is our collision model.
  
Now we need to adjust the .qc file to add the collision model, and add physics data to the prop.  
+
Now we need to adjust the .qc file to add the collision model to the prop.  
 
Change pcmag.qc to this:
 
Change pcmag.qc to this:
 
<pre>
 
<pre>
Line 63: Line 64:
 
$scale 3.5
 
$scale 3.5
 
$surfaceprop "paper"
 
$surfaceprop "paper"
 +
$staticprop
 +
$body studio "pcgmag.smd"
 +
$sequence idle "pcgmag_idle" fps 1
 +
 +
$collisionmodel "pcmag_phys.smd"
 +
</pre>
 +
 +
We've just added the $collisionmodel line which refers to the collision mesh. Recompile the model, and when added as a prop_static in Hammer it will be solid. The player and other objects won't be able to pass through it, and if shot it will stop bullets and be marked by bulletholes.
 +
 +
==Adding physics==
 +
 +
Now we have a collision model, but the prop is still static: it can't move, or be affected by explosions or gravity. To do that, we need to add some physics data to the prop.
 +
 +
Edit pcmag.qc again so it looks like this:
 +
<pre>
 +
$modelname pcgmag.mdl
 +
$cdmaterials "models"
 +
$scale 3.5
 +
$surfaceprop "paper"
 +
 
$body studio "pcgmag.smd"
 
$body studio "pcgmag.smd"
 
$sequence idle "pcgmag_idle" fps 1
 
$sequence idle "pcgmag_idle" fps 1
Line 68: Line 89:
 
$collisionmodel "pcmag_phys.smd"
 
$collisionmodel "pcmag_phys.smd"
 
{
 
{
$mass 0.5
+
        $mass 0.5
 
}
 
}
  
Line 78: Line 99:
 
}
 
}
 
}
 
}
 +
 
</pre>
 
</pre>
  
We've deleted the $staticprop line (since we're no longer making a prop_static), and added two sections: a $collisionmodel line which references our collision mesh, and a $keyvalues section which specifies some prop data.
 
  
The $collisionmodel section also specifies the prop's mass, in kilograms, with the $mass command between braces. I've set it to 0.5 kg here, which is a typical mass for an advert-laden PC magazine. The $keyvalues section specifies extra information for the model that the game engine can use - here, we set the [[Prop Data|prop_data]] for the model. I'm using the base prop type of "Cardboard.Small", being the closest thing available to a paper magazine. For a full list, see the <code>scripts/propdata.txt</code> file in <code>source engine.gcf</code> or <code>counter-strike source shared.gcf</code>.
+
We've deleted the $staticprop line (since we're no longer making a prop_static), and added two sections: after the $collisionmodel line, we've added a section in braces, and a new $keyvalues section which specifies some prop data.
 +
 
 +
The section after $collisionmodel specifies the prop's mass, in kilograms, with the $mass command between the braces. I've set it to 0.5 kg here, which is a typical mass for an advert-laden PC magazine. The $keyvalues section specifies extra information for the model that the game engine can use - here, we set the [[Prop Data|prop_data]] for the model. I'm using the base prop type of "Cardboard.Small", being the closest thing available to a paper magazine. For a full list, see the <code>scripts/propdata.txt</code> file in <code>source engine.gcf</code> or <code>counter-strike source shared.gcf</code>.
  
 
Now recompile the .qc file using studiomdl.exe. We can now place the model as a prop_physics in Hammer. It will fall under gravity, collide with objects and the player, and will move around if shot at or caught in an explosion.
 
Now recompile the .qc file using studiomdl.exe. We can now place the model as a prop_physics in Hammer. It will fall under gravity, collide with objects and the player, and will move around if shot at or caught in an explosion.

Revision as of 19:56, 29 January 2006


It is possible to create static, non-animated props in Blender, along with appropriate physics collision data, in case Softimage is too much. This requires use of the SMD Exporter by Pelle Johnsen. This exporter does not support skeletons, multiple materials, or animations, but it does support hard/soft edges.

Note:It is assumed that the reader knows the basic functions of Blender. At the very least you must be comfortable with creating simple models, applying UV texture mapping, and installing plugins. A working knowledge of how to compile models is a significant help.

Creating a basic non-solid prop

1. Create your model and texture it via UV mapping. The result should be a .blend file, plus all the TGA files you used as textures. The example used here is the PC Gamer UK mag I secreted all around de_dust_pcg (so I have pcgmag.blend and pcgmag.tga)

2. Having installed the SMD exporter plugin (http://asrc.pjohnsen.com/downloads/smd_export.py), export your model to a Half-Life 2 SMD file. In this example, I now have pcgmag.smd and pcgmag.tga - these are the files needed by the model compiling tools.
Model blender export.png

3. For a CS:S model, copy the SMD file into SteamApps/username/sourcesdk_content/cstrike/modelsrc and the TGA file(s) into SteamApps/username/sourcesdk_content/cstrike/materialsrc/models

4. The SMD we have already is just the reference model. We also need an additional SMD to declare the 'idle' animation. So, in a text-editor, create a file called 'pcgmag_idle.smd' (or some other name ending in SMD) and enter this as its contents:

version 1
nodes
0 "joint0" -1
end
skeleton
time 0
0 0.000000 0.000000 0.000000 0 0.000000 0.000000
end

5. The compile tools need a QC file containing model information. This is the file I used for pcgmag.smd:

$modelname pcgmag.mdl
$cdmaterials "models"
$scale 3.5
$surfaceprop "paper"
$staticprop
$body studio "pcgmag.smd"
$sequence idle "pcgmag_idle" fps 1

Note the scale factor, which I tweaked to get the magazine to appear at the right size in-game. 6. The texture must also be converted into a VTF file just like any normal texture. However, it must include the 'model' declaration. This was the VMT file used for pcgmag.tga:

"VertexLitGeneric"
{
	"$baseTexture" "models/pcgmag"
	"$model" 1
}

7. Finally, change to the SourceSDK bin folder containing studiomdl.exe, and compile the model using a command like this:

studiomdl.exe "..\..\sourcesdk_content\cstrike\modelsrc\pcgmag.qc"

8. If everything went right, you'll get some nice output from studiomdl (look carefully for any errors), and you can now find the model in Hammer's model browser for use in-game.

Adding collisions

So far we have a basic model which can be used as a prop_static, but it has no solidity. At the moment, players, objects, and bullets will pass right through it. To prevent this, we need to create a collision model.

Creating a collision model is easy for a simple prop like this. We can use the same mesh as the reference model, but in Blender, select the whole mesh and hit "Set Smooth" (under the "Link and Materials" panel of the edit mode). We do this because the model compiler expects the collision model mesh for each convex part to have a single texture and be in one smoothing group. Now export the mesh as "pcmag_phys.smd". This is our collision model.

Now we need to adjust the .qc file to add the collision model to the prop. Change pcmag.qc to this:

$modelname pcgmag.mdl
$cdmaterials "models"
$scale 3.5
$surfaceprop "paper"
$staticprop
$body studio "pcgmag.smd"
$sequence idle "pcgmag_idle" fps 1

$collisionmodel "pcmag_phys.smd"

We've just added the $collisionmodel line which refers to the collision mesh. Recompile the model, and when added as a prop_static in Hammer it will be solid. The player and other objects won't be able to pass through it, and if shot it will stop bullets and be marked by bulletholes.

Adding physics

Now we have a collision model, but the prop is still static: it can't move, or be affected by explosions or gravity. To do that, we need to add some physics data to the prop.

Edit pcmag.qc again so it looks like this:

$modelname pcgmag.mdl
$cdmaterials "models"
$scale 3.5
$surfaceprop "paper"

$body studio "pcgmag.smd"
$sequence idle "pcgmag_idle" fps 1

$collisionmodel "pcmag_phys.smd"
{
        $mass 0.5
}

$keyvalues
{
	"prop_data"
	{
		"base"	"Cardboard.Small"
	}
}


We've deleted the $staticprop line (since we're no longer making a prop_static), and added two sections: after the $collisionmodel line, we've added a section in braces, and a new $keyvalues section which specifies some prop data.

The section after $collisionmodel specifies the prop's mass, in kilograms, with the $mass command between the braces. I've set it to 0.5 kg here, which is a typical mass for an advert-laden PC magazine. The $keyvalues section specifies extra information for the model that the game engine can use - here, we set the prop_data for the model. I'm using the base prop type of "Cardboard.Small", being the closest thing available to a paper magazine. For a full list, see the scripts/propdata.txt file in source engine.gcf or counter-strike source shared.gcf.

Now recompile the .qc file using studiomdl.exe. We can now place the model as a prop_physics in Hammer. It will fall under gravity, collide with objects and the player, and will move around if shot at or caught in an explosion.


For more information: First post on johnstoblog Second post on johnstoblog


Click here for a message board discussion about an almost-complete Blender script with animation capabilities.