How to import whole .vmf map into Blender?

teamwork.tf

L1: Registered
May 20, 2016
20
41
So I'm interested to export whole TF2 maps into Blender, because this way I can render them in the browser (which can be really useful with some cool ideas).

Anwyay, the suggested way to do this on the internet, is:

1. Decompile .bsp with BSPSource
2. Fix any issues by opening the .vmf in Hammer and re-saving it.
3. Open Crafty and export as .obj.
4. Import .obj in Blender
.

Now this was already quite a hassle as there seem to be some key differences in .bsp and .vmf files, but there is another crucial problem.

When I open the map in Crafty, all the props are there (e.g. all the trees, signs, vents etc. in cp_mercenarypark). However, when I export to a .obj file, there are no references of those props (.vmt's) in there anymore. No references to the properties themself, or where they should be in the map.

Is there any way to convert all these assets with the map? Maybe there is another way to export a map to Blender without removing all props from the map?
 

B!scuit

L4: Comfortable Member
Aug 12, 2016
195
266
AFAIK going straight from .bsp to Blender (props included) isn't possible yet.
I've also been looking at loading maps into a browser but I'm making my own de-compiler. (the hard way :3)

Your main problem is that the .mdl files (all static and dynamic props) have to identified from the .bsp
(.mdl name, file address relative to /tf/ folder etc.)

Ideally you'd want to have a system where you:
1. load the map geometry
2. write a list of all prop model's names and positions (making sure you're not loading the twice because...)
3. de-compile every single model in the map uses
4. load the individual de-compiled models and place them throughout the map
And of course you'd want that in some kind of automated blender addon

It's also worth noting a fully loaded map would take up a massive amount of memory to display
Valve seriously compress everything in a bsp (don't get me started on lightmap compression)

A neat approach would be to peek into the entity and vis lumps and just cut out a portion of the map where an objective likely is, or around an info_observer point and have that as a small de-compiled chunk of the map.
But what you do exactly is up to you.

I'm looking at making this system to extract props RIGHT NOW (and then a way to automate it)
but tbh I'm still struggling with handling faces

bsp.jpg
(it's Blu's first spawn on pl_upward)

However if I can just rip all a map's props into an .obj you could use I'll be sure to let you know.
I'd really love to see a "Preview Map in Browser" button on teamwork.tf so I'll be sure to keep looking into this!
 

henke37

aa
Sep 23, 2011
2,075
515
You will very much want some kind of scene setup where you just instantiate the prop models.
 

AsG_Alligator

qhull precision error
aa
Aug 5, 2016
595
1,191
Wallworm tools for 3DSMax can import mdl's which allows exporting entire map with all models, but it's for 3DSMax not blender.
 

teamwork.tf

L1: Registered
May 20, 2016
20
41
Thanks for the replies! Using a direct .bsp to Blender or even directly to Three.js de-compiler would be the most awesome solution. Would love to hear how your progress goes, Biscuit! I would like to help you, but I'm a novice in terms of mapping. I just learned the basics yesterday, and still struggling with the most basic things.

Also, using 3DSMax seems to be able to import VMF maps through the tip from AsG Alligator, and it even has a plugin to export it to Three.js. However, it does not seem to work with such a huge amount of brushes. I was able to export it to a web-variant with the help of A3dsViewer, which sort of works (see image). It's not really usable though, because the render distance is limited, the browser is lagging like hell and the map is 400MB in size. Not to mention, no textures or lightning.

As for now, it seems unfeasible for me to try and setup something like this for inspecting maps through the browser.
 

Attachments

  • 3dsmax.jpg
    3dsmax.jpg
    160.6 KB · Views: 278

AsG_Alligator

qhull precision error
aa
Aug 5, 2016
595
1,191
You could use sketchfab instead of javascript, it's free and can be embedded pretty easilly afaik.

I don't think you'll be able to just import a map to be viewed without editing it somewhat - removing skybox brushes and such.
 

B!scuit

L4: Comfortable Member
Aug 12, 2016
195
266
Well this code is far from user friendly but it's been over a month so I'll upload it anyway.
Inside the import_bsp.zip:
bsp_import_props.blend (layer 3 is mercenary park)
bsp_import_props.vmf & bsp (imported to layer 1 of the .blend file)
import_props_a1.py (a slightly tidier version of the script)

Currently the .blend is 50MB which inflates to 200MB in memory (RAM)
However after a full rip of all MercPark's props it's about 400MB (presumably all the data the script doesn't throw away after executing)
Also unpacking all of a map's props from a .vpk is a slow process that leaves a lot of files
Oh also textures aren't loaded because that's way too much data

And there's no UI. There's a lot I'd like to do to improve in this script but here's how to use in in it's current state:
If you haven't already, Install Crowbar Decompiler and Blender Source Tools (links near the top of the script)
Open up bsp_import_props.blend
Go into the text window on the left (should be import_bsp_props)
if there isn't a file open in the text window Text > Open Text Block > import_props_a1.py
Set the TF_FOLDER, CROWBAR_EXE and MAP_TO_IMPORT (the last entry overrides all previous)
make sure all folders end with '/' and don't use '\' because python treats it differently to '/'
On Blender select Window in the top row and 'Toggle System Console', this will serve as a progress bar of sorts as well as reporting errors where you can see them
If all your variables are set, press Run Script
The script should:

open MAP_TO_IMPORT
interpret the sprp and entity lumps
copy all .mdl files used in MAP_TO_IMPORT
ask you to decompile the folder with crowbar and open crowbar for you (you to select the folder yourself)
tell crowbar to decompile folder and subfolders of WORK_FOLDER (should be next to MAP_TO_IMPORT)
ensure the out folder is called "decompiled 0.49" and tick folder for each model (this is the format the script expects)
then close Crowbar and the import will resume
for MercPark this step took 20 or so minutes. If you don't have the console open blender will seem to freeze.
once all the .smd files that can be imported they will be placed around the active blender layer with anything it couldn't import as a ERROR
Sorry the system's a little complex, I've been trying to simplify it to something more like Blender Source Tools'
But for now it's workable so I figured I'd release

I'd like to work towards something more automatic and some type of webGL (three.js maybe) export as well as UI and maybe even importing bsp geometry
I'll put this up in the Resources & Tutorials sections just so there's a seperate update thread
Hope you find my code useful!
 

Attachments

  • import_bsp.zip
    10.2 MB · Views: 733

RobDub

L1: Registered
Jan 13, 2018
1
1
Hey!

Thought I might be able to add something to the conversation even though I have nothing to do with TF2.

I wanted to be able to export CS:GO maps to obj and import them to Blender. To be able to do so I had to port my CS:GO maps to an older Source version because Crafty is not able to read the new BSP files. My process looked like this:

1. Decompile CS:GO map to .vmf using BSPSRC.
2. Open the .vmf in Notepad++ and replace all ESC characters to "," commas. This will make the .vmf readable in Hammer and not crash it.
3. Extract all Material and Model folders from the CS:GO, CS:S and HL2 .vpk files to the Half Life 2 folder in the Steam "Common" directory. I used GFCFScape to do this.
4. I made sure to convert all Materials from CS:GO to .vtf version 7.4 using VTFVer as well as making sure all models each had a dx80 and a dx90 .vtx file in their respective folders. (Don't know if this is necessary)
5. Load the .vmf in to the Half Life 2 Hammer and fix any problems if there is any. (I tried using CS:S hammer but then I wouldn't have any models in Crafty later on.)
6. Compile the map. (I put VVIS on fast in the compile menu because it would take a long time to compile otherwise and I don't want to optimize the map)
7. Open Crafty and set up your Steam directory, Username: Common and select the Half Life: 2 option in Profiles.
8. Load the newly compiled map in Crafty. Everything should be ok. Export to .obj.

When I exported I got an obj and a mtl file along with all the textures wich I have in the .tga format.

TOOLS used:
BSPSRC
GCFScape
VTFVer
Hammer
Crafty
Notepad++

I don't know how you're going to be able to do this with Team Fortress 2 but I though my story might be a helping hand to someone. I can explain more if it is needed but I think I covered everything. Contact me on Steam if you want to ask anything.

+ In the past I've had to edit .mdl files and change the first line from "IDST1" to "IDST," in Notepad++ to be able to use them in Blender. I think I used Crowbar to decompile the models and then I used the Blender Source Tools addon to import the SMD file.

Hope it all works out!
:)
 
Last edited: