save hmp file dll

Posted By: Wjbender

save hmp file dll - 04/07/15 09:37

here's a contribution to save hmp terrain

--- http://www.datafilehost.com/d/5998324b

declare this function in your project:

Code:
int save_hmp(char* filename,ENTITY* terrain,int skip_original_pixels);



set skip_original_pixels to 1 ,if you want to skip the original image
pixel data , and try to rather use the pixel data from the bmap buffers,
use this if you want to save modified pixel operations .


else set it to 0.

---

include save_hmp.dll in your project folder .

then call this function to save your terrain entity out to file .

---

has skin support , bmp and tga supports modified pixel data .

dds and png and jpg only supports non modified pixel data and "skip_original_pixels" wil default to 0 , no matter what the value "skip_original_pixels" was set to when you called the function (for now anyway)...
Posted By: 3run

Re: save hmp file dll - 04/07/15 09:51

Wjbender@ thank you very much! it's very useful contribution! laugh

Best regards!
Posted By: Wjbender

Re: save hmp file dll - 04/07/15 10:48

roger that , over and out
Posted By: sivan

Re: save hmp file dll - 04/07/15 10:55

thanks!
do you plan to support skin changes in future?
in MapBuilder I use a dll which works fine, but saves hmp with original skins.
Posted By: Wjbender

Re: save hmp file dll - 04/07/15 11:47

did you write that dll ? or where did you get it .

I am surely planning on that , however my current understanding of the ctexture & cskin information ,is a bit vague , especially working from the bmap pointers of the skin's data towards completely correct data for ctexture and cskin , well I believe that's where I am supposed to retrieve my data to fill up ctexture and cskin .
Posted By: sivan

Re: save hmp file dll - 04/07/15 11:50

I got from an old user called Widi with the permission to use it.
as I remember HeelX has a working version, and you can search his related questions to jcl, to get some useful info...
Posted By: Wjbender

Re: save hmp file dll - 04/07/15 12:02

well it appears to be just arrays of (color per pixel) with bmap->bytespp, either arranged as rgb or bgr , I think I can manage .
Posted By: Wjbender

Re: save hmp file dll - 04/07/15 14:03

http://www.datafilehost.com/d/c21e74d7

tested with 2 bmap skins , worked fine , however I am a bit confused with the mipmaps .
Posted By: sivan

Re: save hmp file dll - 04/07/15 14:21

this thread might help: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=390018&page=1
Posted By: Wjbender

Re: save hmp file dll - 04/07/15 14:27


hhmm maby I should add dds and whatever , currently I only have simple bmp skins
Posted By: Superku

Re: save hmp file dll - 04/08/15 04:26

Neat, thanks for the contribution!
Posted By: sivan

Re: save hmp file dll - 04/08/15 06:42

I use mainly tga skins, because it enables runtime pixel manipulations without conversions (which is also possible). but supporting more formats is better laugh
Posted By: Wjbender

Re: save hmp file dll - 04/08/15 09:40

thanks superku.

@sivan well tga ,bmp worked okay when I tested , jpg dds png however is a different story .
Posted By: Wjbender

Re: save hmp file dll - 04/08/15 10:57



latest updated link is on page 1
Posted By: sivan

Re: save hmp file dll - 04/09/15 07:48

hi
it works fine with mutlitexturing tga skins, but modified skin texture (replaced with another tga, or alpha channel edited for changing coverage) are unsaved i.e. the original skins are coming back after reloading.
Posted By: Wjbender

Re: save hmp file dll - 04/09/15 16:47

can you give me a code example ?

I couldn't reproduce the problem .
Posted By: sivan

Re: save hmp file dll - 04/10/15 07:01

I tried within latest MapBuilder, just replaced the old dll access with yours by some #ifdefs. the actual texture editing stuff would be too complex to post here.
Posted By: Wjbender

Re: save hmp file dll - 04/10/15 08:08

the test I did was , I loaded a hmp with textures applied (which is what I presume you do) then I replaced the skins with different textures , I then saved it ,removed the entity , and loaded it ,everything were correctly saved and applied ..

I also tested with ent_reload but this one seems to have a problem , because it doesn't reload the whole mesh , possible a bug there with terrain and ent_reload?

are you saving your modified files before saving the hmp ? or are you altering the skins bmp's then saving just the hmp ?

I wil conduct some bmp_lock ,with alterations on the pixels tests today .

Posted By: sivan

Re: save hmp file dll - 04/10/15 08:29

maybe it is related to bmap_save what I use for speed reasons and to work with bmap_load correctly (bmap_create flips tga).

by the way for the alpha pixel modifications I use a pixel based approach which should work.
Posted By: Wjbender

Re: save hmp file dll - 04/10/15 09:33

the pointer of data I am using to fill the data pointer of the hmp before saving , is the pointer available to palettized pixels of the original image .

oh and the manual states that a bmap_save's image format can only be read back with bmap_load and can not be used for BMAP definitions or textures. .


I see the issue , thank you.
Posted By: Wjbender

Re: save hmp file dll - 04/10/15 14:29

try the new dll , set skip_original_pixels to 1 if you want the modified pixel data to be saved instead of the original pixel data .

jb
Posted By: sivan

Re: save hmp file dll - 04/11/15 15:58

do you mean the 1st post link is updated, and there is a global variable in the dll "skip_original_pixels" to set to 1? (and should it be declared?)
Posted By: Wjbender

Re: save hmp file dll - 04/11/15 16:55

the new function must be declared as :
Code:
int save_hmp(char* filename,ENTITY* terrain,int skip_original_pixels);



to save the original pixel data , if you just replaced the skins with other files :

Code:
if (save_hmp("hmpfilenamehere.hmp",terrain_entity_here,0)) // success



to save the pixel data that was modified with for example bmap_lock operations ,instead :

Code:
if (save_hmp("hmpfilenamehere.hmp",terrain_entity_here,1)) // success



that's how it is for now.

yes the link is updated on the first page first post
Posted By: sivan

Re: save hmp file dll - 04/11/15 20:30

hey, it works! laugh

the only issue happens (crash on save), when there is an empty or NULL skin (skin without texture). I have an optimized shader where I sometimes use such an arrangement.

and dds support would be great! tongue

thanks for the efforts!
Posted By: Wjbender

Re: save hmp file dll - 04/11/15 20:56

okay I'll sort out with more error checking .

I am working on it on and off , between 2 other projects ,sometimes I multitask between all 3 ,coding/ testing and improving a few lines of code at a time .

glad it helps out for now .

edit:
<-- am I now the one who's name they dare not speak 666 posts
Posted By: Wjbender

Re: save hmp file dll - 04/12/15 11:03

fixed ,updated link and info on page 1 , 1st post
Posted By: sivan

Re: save hmp file dll - 04/13/15 12:04

thanks, it help me to find some bugs in MapBuilder laugh (some missing protections of null textures)

further tests:

if the skin texture is not square, and modified, it is not saved, the original is kept (square textures are saved properly)
Posted By: Wjbender

Re: save hmp file dll - 04/13/15 13:09

didn't test it but I believe that should work now .
Posted By: sivan

Re: save hmp file dll - 04/13/15 14:04

unfortunately it doesn't work... or the link is old, dll file size is the same, what can rarely happen.
Posted By: Wjbender

Re: save hmp file dll - 04/13/15 15:32

okay I also noticed a size difference with the one on my pc , I uploaded it , let me know because as I read my code it should work .
Posted By: sivan

Re: save hmp file dll - 04/15/15 09:02

it does not work too
Posted By: Wjbender

Re: save hmp file dll - 04/15/15 11:51

mm I must have missed a line of original width & height code likely.

just to be clear , how are you resizing the images ?

and are you using skip_original_pixels set to 1 or 0
Posted By: Wjbender

Re: save hmp file dll - 04/15/15 20:57

as stated above I found one I missed , and corrected it . if it doesn't save correct now , I would need more details in the methods involved .
Posted By: Wjbender

Re: save hmp file dll - 04/15/15 20:57

as stated above I found one I missed , and corrected it . if it doesn't save correct now , I would need more details in the methods involved .
Posted By: sivan

Re: save hmp file dll - 04/16/15 07:29

hi, no success, only square skins are saved well, here is the colouring code I used for testing:

Code:
void		TerEdit_Tx_SetColor()
{
	wait(3);
	
	int skin_int = teredit_tx_selected+1+(teredit_tx_set-1)*max_teredit_tx_items;
	
	if (skin_int > teredit_tx_count)	return;																// protection
	
	if (!ent_getskin(terrain_entity, skin_int))											
		{
			return;
		}
	
	TerEdit_Tx_Color( bmap_for_entity(terrain_entity , skin_int) , vector(teredit_tx_blue,teredit_tx_green,teredit_tx_red) );
	wait_for(TerEdit_Tx_Color);
}


void		TerEdit_Tx_Color(BMAP* bmap_pointer, COLOR* to_color)				
{
	if (bmap_pointer == NULL)
		{
			return;
		}
	
	var pixel_format  = bmap_lock(bmap_pointer,0);														// lock and get format
	if (pixel_format >= 565) 
		{
			var pixel;
			COLOR pixel_color;
			var pixel_alpha;
			int i,j;
			for(i=0;i<bmap_width(bmap_pointer);i++)
				{
					for(j=0;j<bmap_height(bmap_pointer);j++)
						{
							pixel = pixel_for_bmap( bmap_pointer , i , j );								// get pixel
							pixel_to_vec( pixel_color , pixel_alpha , pixel_format , pixel );		// get color and alpha
							pixel = pixel_for_vec( to_color , pixel_alpha , pixel_format );		// set alpha
							pixel_to_bmap( bmap_pointer , i , j , pixel );								// set pixel
						}
				}
		}	
	bmap_unlock(bmap_pointer);	
	bmap_to_mipmap(bmap_pointer);	// @@@ update mipmaps after unlocking, to avoid the original skin to appear from big distance		
	wait(1);
	
	TerEdit_Tx_UpdateSets32();      // uses bmap_blit to copy skin texture to thumbnail
	TerrHmp_Tx_UpdateMaterialSkins();    // sets material skins to entity skins due to shader requirements
	wait(1);
}

Posted By: Wjbender

Re: save hmp file dll - 04/16/15 07:40

okay I wil look at the code , could it be possible that its a limitation ? I remember reading something about width and height being able to support non square values but the engine keeps it a power of 2 , I may be confusing this with something else but if I find it I wil tel you
Posted By: sivan

Re: save hmp file dll - 04/16/15 09:41

I don't know whether GED supports it or not. if yes, GED's source could help. it was shared a while ago in the forum by jcl. I can upload if you need - if I can find it.
Posted By: Wjbender

Re: save hmp file dll - 04/16/15 10:22

in the manual , I found this :

If the texture had no mipmaps before, modified texture content gets lost when creating the mipmap chain the first time. Thus, create the mipmaps before modifying the texture, and call bmap_to_mipmap afterwards a second time for updating the modified content to the other mipmaps.
This function can not be applied to compressed (DDS), cubic, normal, tangent, rendertarget, or other special bitmaps. If required, create the mipmaps before converting the bitmap to a special format (for instance bmap_to_cubemap(bmap_to_mipmap(skymap)). Creating mipmaps afterwards will otherwise render the special bitmap unusable.

there's a problem with your code there(if you didn't have mipmaps before ) and I do not save mipmaps out to file yet.

I tested by doing pixel operations , followed by bmap_to_mipmap , which destroyed the modifications and results in behaviour you would not want ,if you were planning on keeping the pixel alterations ..

but still , how are you resizing the bmaps to be non square ? I mean what function ?
Posted By: sivan

Re: save hmp file dll - 04/16/15 19:58

ahh thanks! a missed info. I can do that mipmap generation on texture editor initialization.

they are pre-made textures, 4 textures are combined into one, to easily access 8 textures from the terrain shader as 4 entity and 4 material skins (global color map, global normal map, rgba blendmap1, rgba blendmap2, 1st 1x4 color map, 1st 1x4 optional normal map, 2nd 1x4 color map, 2nd 1x4 optional normal map), but I could make 2x2 arrangement instead of 1x4, but with Gimp it is easier to create 1x4.
Posted By: Wjbender

Re: save hmp file dll - 04/16/15 20:35

okay so you made texture atlases ,I understand .

how do you feed the texture parts from the atlas, as new bmap skins , before you save ?

and what format are those bmaps ?
Posted By: sivan

Re: save hmp file dll - 04/16/15 21:02

all the textures are saved as hmp skins, and the last 4 ones are assigned as the 4 material skins on terrain creation (material bmap pointers to entity skins).
I just tried to modify the full texture atlas. they are tga textures. if it will work fine, I think I replace the old dll with yours.
as I remember performance is slightly better when dds textures are used, but they can be converted for the game. currently I have a secondary option to save a terrain texture package (and a terrain lighmap texture) for each level as a set of separate tga files.
Posted By: Wjbender

Re: save hmp file dll - 04/17/15 09:18

I have tested with

bmap_createpart
bmap_createblack
bmap_blitpart

with non square sizes , to try and duplicate your problem when you said it doesn't save non square skins .

but all of those saved them out , however they are filled with black to make them powers of 2, by the engine when applied as a texture skin , that's the only thing I can think of now ,that bears any kind of similarities with your problem , because I am stil not sure what functions your using so that I can try and duplicate the problem .

edit :
let me look in to this a bit more

Posted By: sivan

Re: save hmp file dll - 04/17/15 10:31

unfortunately I cannot give a simple answer as in MapBuilder I use different configurations for single skin + detail map terrains, and for multitexturing where blending is stored in the alpha channel. if you are patient enough and want to read a lot, it is within MBteredit_tx.h/.c and MBterrhmp.h/.c. later I'm planning to upload it to GitHub, it would be easier to discuss.

so it is okay now, this mipmap thingie at least fixed some other issues laugh and I can change my shaders to use square atlas maps. currently I'm mostly using an autotexturing shader, which is much better for using with many levels than to save skins to every hmp-s (and I frequently use the same hmp for many levels beside a deformation info file), thus imo it is better if you don't invest too much time into my problem at the moment. and I'm not sure how much I will work with 3dgs in future... the dll basically works fine beside this limitation.
Posted By: Wjbender

Re: save hmp file dll - 04/17/15 10:40

I found this in the manual under bmap_lock

After locking an uncompressed bitmap, you can access its texture content directly through the bmap.finalbits pointer. The texture size (in bytes) is given through (mybmap.finalwidth * mybmap.finalheight * bmap.finalbytespp). The texture size is normally a power of 2 and not identical to the original image size returned by bmap_width and bmap_height.


I just had to know why and what goes wrong
Posted By: sivan

Re: save hmp file dll - 04/17/15 12:15

okay, I thought you won't sleep until it is resolved grin

basically everything works fine with non-square (but power of 2) sized skin textures, except saving. I can make some further tests, unfortunately no much time because of job, and no time at weekend because of family. I can do them probably only next week.
Posted By: HellThunder

Re: save hmp file dll - 03/30/16 07:45

Is there a way to share the dll again? I know a year has passed - but I would love to play around with this.

Thanks.
Posted By: Wjbender

Re: save hmp file dll - 03/30/16 10:08

wikisend.com/download/829782/save_hmp.dll
Posted By: HellThunder

Re: save hmp file dll - 03/30/16 12:01

@Wjbender
Thank you for your quick reply =)
© 2024 lite-C Forums