Open WMB file

Posted By: QuartzLoop

Open WMB file - 03/20/19 22:19

Hello,
I really like the lighting WED does and would love to find any way to extract level geometry & lightmaps from WMB in any useful 3D format. Only thing I found is this:
https://forum.unity.com/threads/importing-wmb-files-from-3dgs.36300
...but it didn't really work.

I don't use Unity, I would only like to have model lightmapped in WED so I can open it in Blender/use it on SketchFab website.
Posted By: QuartzLoop

Re: Open WMB file - 03/21/19 13:37

...small update, I've tried DX3DRipper and NinjaRipper, DX3D was terrible, all my geometry was distorted & half was missing. Ninja was a bit better but also had missing geometry and only lightmaps with no textures.
However both programs did extract lightmaps so I guess it's at least possible. If I could get lightmap UV's they could be manually applied in MED and then all is left is importing lightmap-texture files extracted with DX3D or Ninja.
Posted By: Superku

Re: Open WMB file - 03/21/19 15:55

You could dig through the WMB documentation and write an extractor:
http://www.conitec.net/beta/prog_mdlhmp.htm

If you already have the lightmaps extracted you could use ent_buffers on level_ent and read mesh information from blocks (in particular DirectX vertices with 2 UV sets). Or maybe even try ent_getmesh on level_ent, not sure if that works.
You can then save the directX mesh as a file, or write your own OBJ exporter (the most simple model format).


However... it's probably the better idea to just learn lighting in another program, I bet Blender can do that just as fine/ much better.
Posted By: QuartzLoop

Re: Open WMB file - 03/21/19 17:54

The ent_getmesh sounds great but unfortunately my coding is extremely limited. Can this be done in SED with some sort of on_click event? Can I find ent_getmesh & ent_savemesh in documentation?

I really like the way WED does lights because it creates a nice retro-Quake-Wolfenstein-CBsUndying style that I was unable to do in Blender. The closest program with similar lights that I used is DeleD but he is handling bigger geometry very badly. Also I like the fact that both DeleD and WED are automatically creating lightmap UV/size calculations. In Blender I have to manually unwrap parts of the model for second UV & maps usually have visible seams because of the margins or too much faces so I have to go back, further separate model parts, unwrap new parts again... it becomes very tedious very fast.
Posted By: Superku

Re: Open WMB file - 03/21/19 22:37

Oh, I never realized that ent_getmesh is specifically intended (among others) to be used for level blocks:
http://www.conitec.net/beta/ent_mesh.htm

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <windows.h>
#include <d3d9.h>
///////////////////////////////

HRESULT WINAPI 
D3DXSaveMeshToXA(
char* pFilename,
LPD3DXMESH pMesh,
void* pAdjacency,
void* pMaterials,
void* pEffectInstances, 
DWORD NumMaterials,
DWORD Format
);

#define D3DXF_FILEFORMAT_BINARY 0
#define D3DXF_FILEFORMAT_TEXT 1
#define D3DXF_FILEFORMAT_COMPRESSED 2

char *cTextureFile = "someFile.tga";

D3DXMATERIAL d3dmaterial[2];

void wmbSaveAllBlocksToFiles()
{
	d3dmaterial[0].pTextureFilename = cTextureFile;
	d3dmaterial[1].pTextureFilename = cTextureFile;
	int blockNum = 0;
	while(1)
	{
		LPD3DXMESH mesh = ent_getmesh(NULL,blockNum ,0);
		if(!mesh) break;
		
		STRING *str = str_printf(NULL,"export\block%d.x",blockNum);
		D3DXSaveMeshToXA(str->chars, mesh, NULL, d3dmaterial, NULL, 2, D3DXF_FILEFORMAT_BINARY);
		
		blockNum++;
	}
}

void main()
{
	fps_max = 60;
	video_mode = 10;
	level_load("deathMountain.wmb");
	wait(1);
	wmbSaveAllBlocksToFiles();
}



Just gave it a quick shot, almost worked immediately. You need to supply a material so it exports the UVs as well. Apparently sadly though, only the first UV map is saved. Might be wrong though. (The model shows up as black in MED because I did not fully set up the d3dmaterial.)

MED has some sort of skin mapping import and export. Maybe you could look at it, then write a basic code that outputs the 2nd UV map in the correct format (to a text file) and import in MED.
Could work but might not be that easy.
Posted By: QuartzLoop

Re: Open WMB file - 03/22/19 12:53

Thank you for the code, I tried it but unfortunately nothing happened.
My steps:

I build my level with lights (wmb was created).
Clicked Publish, engine asked for script, I've chosen Empty Script.
I've opened SED and added your script plus:
Copied all c and h files from engine's 'include' folder in folder where EXE is.
Placed 32bit TGA texture (1024/1024) in folder where EXE is, changed the name in script: char *cTextureFile = "oldbricks1tga.tga";
Changed level name to my wmb name: level_load("Kata20old.wmb");
Started EXE file, everything went fine, level started, I was able to look around after clicking 0, closed the app.

Folder 'export' was not created by the engine, so I've created it manually in the EXE folder, started everything again, closed everything, looked inside manually created 'export' folder, still nothing there.

I'm not sure what I'm doing wrong?
Posted By: Superku

Re: Open WMB file - 03/22/19 14:34

Hmmmm. Some things:

Don't "publish" your script or level.
Just create a new text file, rename it to someScript.c, paste my code.
Change the level name.
Do not copy over any files from GStudio include folder. It finds them automatically (copying them over will break stuff should you ever update your GStudio installation).
Just start the script from SED, for example with the left-most triangle/ play button.

If your GStudio installation is in a subfolder of Program Files, well, that's bad, it shouldn't (I just have it in C:GStudio8 for example). Otherwise it will not be allowed to create files because if missing rights.
© 2024 lite-C Forums