Raised This Month: $41 Target: $400
 10% 

[TUT] How to make model to be compact


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
Old 01-26-2020 , 09:56   [TUT] How to make model to be compact
Reply With Quote #1

What is it for?

Tutorial is intended for:

- model makers to find missing (or unused) textures before publishing it.
- server admins and plugin creators who
  • port models to his game
  • convert model from client to server side
and attempt to make model have as minimal disk size as possible.

Note: tutorial has no instructions on how to port model or how convert it on server side.
You must already know it on your own.


Introduction

When I ported models it's often I saw common mistakes like:
  • missing textures
  • unused files
  • wrong vmt syntax
making model much larger or working incorrect.

Also, sometimes textures are just too large.


Preparation.

Install:
- GCFScape
- Crowbar. Set up its required paths according to internal manual.
- VTFEdit
- (optional) WinHEX or similar.
- (optional) Total Commander or just Windows Explorer with disabled hiding of file extensions.
- (optional) Everything

Unpack:
- list_missing_textures.cmd (attached, see later in stage 2).
- list_files.cmd (attached, see later in stage 6).


How to fix and where?

If you downloaded model from steam workshop, it's packed in VPK, so you need unpack it firstly
with "GCFScape" tool to folder with short full path name, better without whitespaces.

Now, you have custom model (in separate, not game folder) that consists of such subfolders:
  • models
  • materials
rarely:
  • particles
  • sound


Step 1. Remove obviously unnecessary files.

Usually model consists of:

- models\subfolder\*.mdl
- models\subfolder\*.vvd
- models\subfolder\*.dx90.vtx
- models\subfolder\*.phy

- materials\models\subfolder\*.vtf
- materials\models\subfolder\*.vmt

All other files and folders (excepting "particles", "sound" if exist) can be safely removed.
It's often:

- *.bmp
- *.tga
- *.txt
- *.dx80.vtx
- *.sw.vtx
- folder with model sources (excepting subfolders, that have other *.vtf *.vmt files)




Step 2. Find and fix missing textures (VTF) / remove unused one.

0. Go to your game folder in the subfolder where "addons", "materials", "models" folder lie, e.g.:
- CSGO: \steamapps\common\Counter-Strike Global Offensive\csgo
- L4D2: \steamapps\common\Left 4 Dead 2\left4dead2

Now, temporarily rename (backup):
- "materials" folder => to "materials.bak"

Go to "Steam" tool => Right click on your game => Properties => Local Files => Press "Check integrity of game files".

This step ensures your game contains only stock materials.

1. Run GCFScape, use it to unpack all *_dir.VPK of your game (don't forget DLC as well), e.g:
- For CSGO:
* \steamapps\common\Counter-Strike Global Offensive\csgo\pak01_dir.vpk
* \steamapps\common\Counter-Strike Global Offensive\csgo\pakxv_lowviolence_dir.vpk
* \steamapps\common\Counter-Strike Global Offensive\csgo\pakxv_lowviolence_dir.vpk

- For L4D2:
* \steamapps\common\Left 4 Dead 2\left4dead2\pak01_dir.vpk
* \steamapps\common\Left 4 Dead 2\left4dead2_dlc1\pak01_dir.vpk
* \steamapps\common\Left 4 Dead 2\left4dead2_dlc2\pak01_dir.vpk
* \steamapps\common\Left 4 Dead 2\left4dead2_dlc3\pak01_dir.vpk

Let's say we unpacked everything in one folder called: "D:\L4D\pack"

2. Unpack attached "list_missing_textures.cmd" file, right click on it => Edit:
- change
Code:
 
set "pack_folder=D:\L4D\pack"
to your folder with unpacked *_dir.VPK.

- change
Code:
set "base_folder=D:\Steam2\steamapps\common\left 4 dead\left4dead"
to main subfolder of your game (should contain "materials", "models" subfolders).

Save cmd file.

Let's return to your model.
Note: we work with separate your custom model's folder only! Don't touch game folder.

3. Temporarily move all materials\models\...\*.vtf files to another place (e.g. to "c:\temp\mdl")
4. Place edited "list_missing_textures.cmd" batch file inside "materials" folder.
5. Run (double-click) that file.

You'll receive report, like:

Quote:
MISSING in [brumak-arms-legs-d.vmt] file: models\locust_brumak\Brumak-Arms-Legs-D.vtf
that means [brumak-arms-legs-d.vmt] has reference to vtf file,
that doesn't exist neither in the game folder nor in custom model's folder.

Now, back to your "c:\temp\mdl" folder and return each *.vtf file one by one
in required place of your custom model's folder exactly as reported by above script.

6. Run "list_missing_textures.cmd" again and check report.

Here such cases can happen:

- all files are moved back and "c:\temp\mdl" remains empty (so, you didn't have unused files)
- some files are left in "c:\temp\mdl" (so, they was redundant and can be safely omitted)
- script reported that there are still more vtf (texture) files are missing.

In the last case you should search for missing vtf manually:

- usually author just forget to put them, because they are used in his other model.
Solution: try download other models from same author and find texture there.

- sometimes authors use texture of other game
Solution: I suggest upack all *_dir.VPK of all source engine games available for you
and use tool like "Everything" to search missing texture there.

- obviously, PM to author


Step 3. Find and fix missing texture references (VMT) / remove unused one.

1. (optionally, potentially dangerous, skip it in most cases)

Sometimes model contains reference that is really not used (dunno why).
Solution: use "Crowbar" tool to re-compile the model (decompile and compile it again).

2. Inspect list of references:

Copy "materials" folder of your model to your game folder
(in the same place where "materials" folder is already exist there).

Open "Crowbar" tool, tab "View" => Browse to model .mdl file. Press "View as Replacement",
"Model Viewer" tool will be opened. Press tab "Model", and look "VMTs loaded" window:

if you received:
Quote:
*** ERROR *** Model attempted to load one or more VMTs it can't find.


than you have a problem with missing .vmt files.

To understand which one, use WinHEX.
Please, comment my post if you know a better solution.

Usually, vmt references are located at the very end of file.
So, in WinHEX or convenient Text Editor open .mdl file, scroll to end of file.



In the following example:
Quote:
witch_moon
witch_moon_hair
these files are what we searching for, where "witch_moon_hair.vmt" is already present in "Model Viever",
so we only missing "witch_moon.vmt". Search it and recover in materials folder.

After this, repeating step 2 is recommended.


Step 4. Compressing textures (VTF).

Personally I didn't have experience with that. Comment if you want add something specific.

Common algorithm is:

- Open "VTFEdit" => file "Open" vtf file you want to compress.
- File => "Export" in format tga.
- Compress tga with any tool, like Photoshop or so.
- "VTFEdit" => "Import" your compressed tga, select appropriate* settings.
* todo. To see are settings OK, compare tab "Info" of original vtf and new one, they should almost match.
- File => "Save as" vtf. And replace original file.


Step 5. Fix wrong vmt syntax.

It's very often vmt files have missing } closing quote.
Solution: just add } symbol at the very end of the file.

I admit some program generate such bug.

You can study each vmt file manually or you can install model to server,
ensure model is correctly visible, open client console and search for "red lines",
like:
Quote:
KeyValues Error: RecursiveLoadFromBuffer: got EOF instead of keyname in file <path and name of vmt>

Step 6. Packing all files to archive.

To transmit model files to client faster you can upload files to content-server in packed form.
Only BZ2 archive format is supported.

Use:
- [Batch] BZ2 compress/decompress/verify: - to pack all files in one click
- list_files.cmd (attached) to generate 2 txt files with list of all model files to use in your source code directly or in downloader plugin.


Credits:

Joshe Gatito - for studying me some basics in model stuff, video guides and various help


Disclaimer:

I'm not enough skilled in model work and not a model maker at all, so some inaccuracies and mistakes are possible.
Please, comment if you have better solutions / tools / experience. Thanks.

// TODO: add more screenshots, maybe video.
Attached Images
File Type: jpg model_ref_error.jpg (37.6 KB, 110 views)
File Type: jpg superfluous.jpg (58.3 KB, 118 views)
File Type: jpg winhex.jpg (80.4 KB, 142 views)
Attached Files
File Type: zip list_files.zip (429 Bytes, 76 views)
File Type: zip list_missing_textures.zip (710 Bytes, 70 views)
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch) (my New server L4D2)
[My plugins] [My tools] [GitHub] [Articles] [Donate]

Last edited by Dragokas; 01-28-2020 at 02:36.
Dragokas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:58.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode