1 registered members (TipmyPip),
18,466
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
wmpmdl7 SDK Open, Save - buffer
#391472
01/12/12 21:55
01/12/12 21:55
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Hi,
is it possible to add an overloaded method to the reader and writer classes -of the wmpmdl7 SDK- to read/write from/to a memory buffer instead? This way it would be possible to construct a model/terrain correctly in memory with the SDK, so that the engine could read it from a named buffer without using the hard disc inbetween; this also enables the support for reading models/terrains from WRS ressources.
Best regards, -Christian
Last edited by HeelX; 01/12/12 23:20.
|
|
|
Re: wmpmdl7 SDK Open, Save - buffer
[Re: HeelX]
#391475
01/12/12 23:14
01/12/12 23:14
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
add_buffer()? Or are you not working with acknex.dll?
void makeMdlBuffer()
{
var vSize;
byte* buffer;
/* the minimum MDL5 has no vertices and one single frame.
It requires 120 Byte of Memory
header: 84 bytes
frame: 36 bytes
byte pack info: 4 bytes
bounding box: 16 bytes (word packed)
frame name: 16 bytes
This is a hack to overcome the incompatibility between
NULL-Entities and ent_setmesh().
MDL5 format info taken from Acknex manual
*/
vSize = 120;
buffer = (byte*)malloc(sizeof(byte) * vSize);
/* since there is no skin, no uv map, no lod, most bytes can remain zero */
memset(buffer, 0x0, vSize);
/* set file type info */
buffer[0] = 'M';
buffer[1] = 'D';
buffer[2] = 'L';
buffer[3] = '5';
/* set number of frames at bytes 69-72 */
buffer[68] = 1;
/* MDL5 seems to support word packed vertex data only.
Enable word packing at bytes 85-88 */
buffer[84] = 2;
/* that's it. Amazingly simple */
add_buffer("simple.mdl", buffer, vSize);
}
...
entDummy = ent_create("simple.mdl", vecPos, NULL);
...
|
|
|
Re: wmpmdl7 SDK Open, Save - buffer
[Re: HeelX]
#391476
01/12/12 23:20
01/12/12 23:20
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
I use the acknex.dll, but as the thread title indicates, I meant the and yes, then I could use add_buffer to write with the SDK into the buffer and load from there. Or load from the resource into a buffer and read with the SDK from there. I construct, load and save at the moment terrains with the SDK and would love to do everything in-memory, e.g. to create for instance procedural terrains and save it to file at an undefined point in time later. Since the runtime functions are very very limited (for all other use cases as well), I use at the moment the HD. Which actually works, but, as I said, in memory would be more useful, especially when you are in the need to load a model/terrain from a WRS resource.
Last edited by HeelX; 01/12/12 23:26.
|
|
|
Re: wmpmdl7 SDK Open, Save - buffer
[Re: FBL]
#391499
01/13/12 12:09
01/13/12 12:09
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
OK, I checked it again. There is a public method in both the reader classes for mdl's and hmp's called
long Load(unsigned char * ptr, int size);
which might do the job for the opening from a buffer --- but that is just a guess, because comments are rare along the SDK sources. Though, in the writer classes there is just a method and nothing more. So, @JCL: can you confirm 1.) that the method "Load" is intended for reading from a buffer and 2.) that there is no method for writing to a buffer at the moment? In the case of 2.), would you mind to add methods to the hmp and mdl writer classes for that? Best regards, -Christian
|
|
|
Re: wmpmdl7 SDK Open, Save - buffer
[Re: HeelX]
#391683
01/14/12 22:56
01/14/12 22:56
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
@JCL: can you confirm 1.) that the method "Load" is intended for reading from a buffer No hurry, I confirm this by myself. It is also more robust, because if I open a file which is not in the work dir, the reader confirms that the file is opened (sic!), but I get a NULL-header... weird. Here is the pattern:
// load file into buffer
long buffersize = 0;
void* buffer = file_load(filename, NULL, &buffersize);
HMP7R hmp;
if (hmp.Load((unsigned char*)buffer, buffersize))
{
// get header
const HMP5_HEADER* header = NULL;
bool bHeader = hmp.Head(&header);
if (bHeader && (header != NULL))
{
// do some magic!
}
hmp.Close(); // close file
}
// free the buffer
file_load(NULL, buffer, NULL);
So, @JCL: Do you think you can add saving to a buffer or so?  please!
Last edited by HeelX; 01/14/12 22:57.
|
|
|
|