Saving a modified model ingame as mdl

Posted By: Pappenheimer

Saving a modified model ingame as mdl - 10/06/11 19:19

Is it likely that you add a function to save a mesh from within the engine as an mdl?

I'm giving workshops about game making for kids, and get more and more younger children who are hardly able to get satisfying results within MED.
So I worked on an editor that allows to modify existing models in game by vec_to_vertex. I save them by a code contributed by ventilator, http://www.opserver.de/ubb7/ubbthreads.p...true#Post185155, but it saves only in the format .obj.
First the models with the format .obj don't load reliable, means sometimes they load, sometimes they don't.
Second the format doesn't store animations or bones, but I would like to let the children modify animated characters as well.

Thank you for your time.
Posted By: Aku_Aku

Re: Saving a modified model ingame as mdl - 10/06/11 20:17

What a great contribution to the community.
Great job ventilator!
If we would have an mdl exporter i definitly would use that...
Posted By: Timothy

Re: Saving a modified model ingame as mdl - 10/06/11 21:36

What about this?
http://server.conitec.net/down/wmpmdlsdk7.zip
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 10/07/11 07:16

Yes, there is the SDK, but it is still a lot of work to use it as a base for an exporter.
Its probably less work for conitec than for anyone else.
If there is anyone in the community who wanna do it and who _can_ do it, that's great, but I don't know how to do it.
Posted By: Aku_Aku

Re: Saving a modified model ingame as mdl - 10/07/11 07:38

+1

I totally agree.
Posted By: HeelX

Re: Saving a modified model ingame as mdl - 10/07/11 08:39

It is not so easy to use it. I did. If you don't call the functions in a specific order (at least for reading a MDL7) it crashes. But if you do, you can easily transfer the model data into your own datastructues, which might be better engineered than the SDK' ones.

Saving a model in the engine with the SDK includes much more than just calling some functions in the SDK, though. If someone shows, how to e.g. read out which triangles connect which vertices and how one could access the UV coordinates (I, for instance, don't know that), one could write a very basic function that translates that into suitable datastructures for the SDK and then you can save it.
Posted By: Aku_Aku

Re: Saving a modified model ingame as mdl - 10/07/11 09:11

I would really like to use a function to saving modified models in fbx.
My knowledge simply isn't enough to do it.
As i thought, and as it turned out there are hidden or semi-hidden tricks do the whole process like this:
Quote:
If you don't call the functions in a specific order (at least for reading a MDL7) it crashes.
And so on...
Posted By: Sajeth

Re: Saving a modified model ingame as mdl - 10/09/11 06:54

If this gets implemented, please for hmp-terrains too. Would save _a lot_ of trouble to have an engine function for this.
Posted By: TechMuc

Re: Saving a modified model ingame as mdl - 10/09/11 06:59

from my experience it's pretty easy if you can live with some drawbacks, like maybe changing texture formats. If everything should stay exactly the same, it can get an pretty annoying task as you have to convert e.g. the engine textures back to the right save format.. (and especially read out the mdl file before saving..)

but as already said, generally it's not too hard, and i could implement it in the next weeks (weeks not days!), as i'll work on a resave functionality..
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 10/09/11 12:21

To save the model with _external_ textures, while ignoring the textures and their formats, is absolutely sufficient, IMO.
I guess, when you save the model with external textures, there is only the path to the texture that you save within the model.
Posted By: TechMuc

Re: Saving a modified model ingame as mdl - 10/09/11 15:20

the main question is: do you want to store changed textures or not? if so external textures are another nice task, as ofc you'll have to overwrite the external files too (without changing the file format).

If changing textures is not needed there is no real problem, as you can just take the data from the "old" model/terrain.
Posted By: HeelX

Re: Saving a modified model ingame as mdl - 10/09/11 15:29

And what if I procedurally generate a texture and want to save it as external DDS? wink
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 10/09/11 15:37

Originally Posted By: TechMuc
[...]there is no real problem, as you can just take the data from the "old" model/terrain.

To me it _is_ a problem. laugh
I look at this the other way round:
I can change the format of a texture and save it with pixel_to_vec and pixel_for_vec without problems.
That's probably a slow function, because it re-paints each pixel again, but for saving a model - who cares?
Posted By: jcl

Re: Saving a modified model ingame as mdl - 10/10/11 07:46

There's a source code example for saving HMP and MDL in the SDK - so it shouldn't be much of a problem?
Posted By: HeelX

Re: Saving a modified model ingame as mdl - 10/10/11 08:31

Yes, but we don't know how to read all necessary information from an entity, like, triangles (connected to which vertices), 1st and 2nd UV map coordinates, groups, and so on.
Posted By: Superku

Re: Saving a modified model ingame as mdl - 10/10/11 12:38

For the triangles, have a look at ent_buffers.
Posted By: HeelX

Re: Saving a modified model ingame as mdl - 10/10/11 12:43

Uh, I heard the first time of ent_buffers... thanks!
Posted By: jcl

Re: Saving a modified model ingame as mdl - 10/12/11 10:21

ent_buffers is the easy method. The other possibility is loading the model not with the engine but with the MDL7 SDK, but of course that's a lot more lengthy and complicated. Best go the quick and easy way first.
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 10/16/11 11:44

If there is anyone who is willing and able to code an export function for an mdl, please contact me to discuss the conditions and timeframe for that.

Me, myself, I am very interested in learning how to do it, but I have no time for this for now.

I don't mind to pay for a solution, even if it shall be open to everyone in the community.

I prefer a solution that is as lucid as ventilator's obj-exporter, because I could learn from it.
Posted By: TechMuc

Re: Saving a modified model ingame as mdl - 10/16/11 21:04

if the time does not matter for you, i can write a pretty clean code in the next weeks (not longer than a month), as i'm implementing a resaving feature atm for my editor. Though at the moment i'm working on the wmp files, and not on mdl files ==> Will need ~2 weeks to start that. If you need it earlier, a small payment would be nice - otherwise without a timeframe - i'll release it open source - but again please don't held your breath - just remember me of this topic in ~2 weeks laugh
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 10/16/11 22:21

Thank you very much for your offer!
I will remember you in about two weeks! laugh
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 11/02/11 00:26

Reminder! wink
Posted By: Sajeth

Re: Saving a modified model ingame as mdl - 11/02/11 02:01

I'll drop in a few bucks if you include a hassle-free function to save modified hmp terrains.
Posted By: TechMuc

Re: Saving a modified model ingame as mdl - 11/02/11 12:13

ah nice - i remember now tongue - will work on it tomorrow while studying.
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 11/02/11 16:18

Originally Posted By: TechMuc
will work on it tomorrow while studying.

Uh, that's what I call multitasking! wink
Posted By: TechMuc

Re: Saving a modified model ingame as mdl - 11/13/11 19:48

Hi,

as promised here the first version of the mdl resave dll. Please always be aware that i've done this code in around 2 hours, so do NOT expect really good quality (good quality is not for free tongue ) - espcially as big parts of this code are from my old project GED. So there will be probably a lot of bugs to fix, as i just do not have the time currently to check the code with a lot of different models and configurations. Espcially the speed & the memory consumtpion of the project is far from beeing optimal laugh I did NOT have the time to test a free plugin properly, so:
BACKUP YOUR MODELS BEFORE USING THIS PLUGIN and read the bug section before committing bugs.

Enough warnings. Very short tutorial:

Folder Structure
Basically there are two folders:
1) bin: Contains DLL File mdl_resave.dll. Copy this file to your acknex_plugins folder to get things runnings
2) mdl_resave: Contains Source of the DLL. There are not dependencies besides the MDL and the Gamestudio SDK, so everyone should get this code running.

Get Plugin working
As already said, copy the mdl_resave.dll out of the "bin" folder into your acknex_plugins (or any PRAGMA_PLUGIN) folder. Open SED and add the following six function definitions anywhere to the top of one of your headers:

Code:
void* LoadModel(ENTITY* ent);
void* LoadModelFromFile(STRING* str);

BOOL SaveModel(ENTITY* ent);
BOOL SaveModelWithLoader(ENTITY* ent,void* loader);

BOOL FreeLoader(void* loader);



You can find a very basic example how to use the resave plugin in the mdl_resave folder (file: test.c).

Available Functions

Probably you'll only need the function SaveModel(ENTITY* ent). You pass an ENTITY to the function and the entity will be saved.
The functions LoadModel and LoadModelFromFile will return an internal loader object. In future - if anyone needs it - this loader object COULD be used to change any option in the mdl file you wish (e.g. even ADDING or REMOVING vertices or changing bones / lod-settings etc.). In the case you want to use the SaveModelWithLoader / LoadModel functionalities - PLEASE: use the FreeLoader function, otherwise there will be giantic memory leaks. The plugin is not clever enough to detected entity removal, and will therefore NOT clear up on it's own.

What does the Plugin change?

At the moment the only thing which is changed are the vertices. So any changes you make to your skins are NOT accepted or changed by the mdl resave plugin.

Where to download

http://www.dev-software.com/mdl_save.rar

How to submit bugs

Yep - as already said there will be bugs with a lot of models, as i do NOT have the time to test properly. If you have a model where the resaving crashs and / or changes please do NOT say: "blabla - does not work - blabla" but upload the model and send a link to this model via pm. Reproducing problems should be just a matter of time.


best regards,
Timo
Posted By: TechMuc

Re: Saving a modified model ingame as mdl - 11/13/11 19:57

@Sajeth: Please send me a pm if you still need this functionality (resaving hmp). I'm afraid i just do not have the time to do this for free right know, but if you're willing to spend some bucks, i'm pretty sure i can help you out wink

regards,
Timo
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 11/13/11 20:45

Your efforts are very much appreciated! laugh
I tried "SaveModelToFileFile(ENTITY* ent,void* loader,STRING* new_fl);", because I want to save a modified model under a different name, but it doesn't work, error message 'empty prototype'.
EDIT: In case this is a dump question or request, don't be shy, tell me my fault! blush
Posted By: TechMuc

Re: Saving a modified model ingame as mdl - 11/13/11 21:49

New Header. Please redownload.

Code:
void* LoadModel(ENTITY* ent);
void* LoadModelFromFile(STRING* str);
BOOL  FreeLoader(void* ld);

BOOL SaveModel(ENTITY* ent);
BOOL SaveModelToFile(ENTITY* ent,STRING* str);
BOOL SaveModelWithLoader(ENTITY* ent,void* loader);
BOOL SaveModelWithLoaderToFile(ENTITY* ent,void* loader,STRING* new_fl);


Posted By: EvilSOB

Re: Saving a modified model ingame as mdl - 11/14/11 02:52

God-damn typos.... They'll be the death of us awll. wink
Posted By: Aku_Aku

Re: Saving a modified model ingame as mdl - 11/20/11 11:41

Any news?
Posted By: Pappenheimer

Re: Saving a modified model ingame as mdl - 11/20/11 11:54

What news?
Did you try TechMuc's contribution a few posts above?
It works nicely so far, I made a test with simplysid.mdl, and it keeps the animations as well.

Don't forget to follow the instructions that TechMuc posted.

Try something like this to see the resulting model, instead of the given values in the test.c file:

c.v.y -= random(3);

Code:
function raise_terrain(ENTITY* terrain)
{
	int i = ent_status(terrain,0); // number of vertices
	for (; i>0; i--)
	{
		CONTACT* c = ent_getvertex(terrain,NULL,i);
		c.v.y -= random(3);
		ent_setvertex(terrain,c,i);
	}
}



This is the whole test, how I modified it to see a fast and easy result:
Code:
#include <acknex.h>
#include <windows.h>
#include <default.c>


//exported functions
void* LoadModel(ENTITY* ent);
void* LoadModelFromFile(STRING* str);

BOOL SaveModel(ENTITY* ent);
BOOL SaveModelWithLoader(ENTITY* ent,void* loader);
BOOL SaveModelToFileFile(ENTITY* ent,void* loader,STRING* new_fl);

BOOL FreeLoader(void* loader);

// raise all terrain vertices by 5 units
function raise_terrain(ENTITY* terrain)
{
	int i = ent_status(terrain,0); // number of vertices
	for (; i>0; i--)
	{
		CONTACT* c = ent_getvertex(terrain,NULL,i);
		c.v.y -= random(2);
		ent_setvertex(terrain,c,i);
	}
}



int main() {
	wait(1);
	level_load("");
	wait(3);
	ENTITY* ent = ent_create("simplysid.mdl",vector(10,10,10),0);
	wait(1);
	void* loader = LoadModel(ent);
	wait(1);
	raise_terrain(ent);
	wait(1);
//	SaveModelWithLoader(ent,loader);
	SaveModelToFileFile(ent, loader, "test.mdl");
	FreeLoader(loader);
	
	while(1) {
		wait(1);
	}
	return true;
}


© 2024 lite-C Forums