How are the vertices calculated?

TheJustinWalsh

19-06-2006 05:26:20

So i am on my way to wanting to see my terrain in a 3D modeling package before i export it out to the engine. Right now our tool of choice is 3ds max. I just picked up the max SDK, and am going to make a plugin that will load in your plsm2 terrain files, and accurately display them in max. So, i have some questions.

Where and what algorithms does the plsm2 use to determine the exact vertices location based on the heightmap? Maybe a developer just happens to know the algorithm off the top of his head? Or would someone like to point me to a few lines of code that compute these numbers?

There was another post that i tracked down, where a member was discussing the values to plug into max to get a replica of the map, he also said it worked, but never posted his tricks :( Here is the article...

http://www.ogre3d.org/phpBB2/viewtopic.php?t=4833

If you are still out there, come back and reveal your secret please.


That is all, if anyone has had success in doing this, or wants to point my on to some good info i would very much appreciate it.

Thanks,
Justin Walsh

Falagard

19-06-2006 05:41:32

I'm just going to give you a general idea where to find it and you'll have to look it up yourself okay? This isn't the answer to your question because I vaguely remember doing this more than a year ago using the displacement modifier in max and all the paging landscape options have changed since then so it isn't relevant anymore.

You need to look in two places to figure out how the verts are calculated.
If you're loading a 16 bit raw file in the paging landscape manager, then look in OgrePagingLandscapeData2D_HeightFieldRaw.cpp::_load which has the code that calculates the heights (y value of each vert)

Then look in OgrePagingLandscapeRenderable::load for the code that calculates the x and z values for each vert.

You might be better just writing an exporting for PLM2 which exports to a common format like .obj though, and then import into 3ds Max using a regular .obj importer (comes with 3ds Max 8, or available as free plugin for earlier versions).

Clay

TheJustinWalsh

19-06-2006 23:20:16

Well the community would probably benifet from an PLSM2 .obj exporter more than a 3dsmax version, i will look into it. As time is of the essence on my current project i think i am just going to use the max sdk, to read in the data that PLSM2 uses to calculate the map, then recreate the map in max. If i can figure out the pages too, then it would draw each page in max as well, other wise i would just go with one ginormous mesh.

The purpose is to just load it into max untextured as a reference for plotting the other elements in a scene. If anyone knows of anything else, or anyone working on this effort already, let me know, as this portion of our project will be released to the public :)

thanks again.

Falagard

20-06-2006 00:15:22

You could also look into creating a plane in max and applying a displacement modifier.

TheJustinWalsh

21-06-2006 04:12:53

OK, so i did some investigating, and it actually appears that the calculation is fairly simple. Here is what i came up with...


The X and Z values are calculated simply by takeing the current vert in the array and multiplying it by the scaleX and scaleZ that are given in the config file. So if your scale is 9000 then each vertex would be 9000 units away from the next in a grid.

The height is simple done the same, it takes the value of the pixel and multiplies it by the scaleY. There are some checks to make sure the value is always bigger than 0 as well.

Now the size of the map is where i am having some issues. At first i thought it took the full array of pixels in the heightmap, however it appears this may be wrong. But given the amount of data in the height map Y value array, there would need to be one Y value for each X,Z pair, and according to the loading section of raw it computes each and every 16bit value into a Y co-ordinate. Arg...

As to the idea of a displacement modifier, how do i know what value the strength in max represents?

If i could figure out how many verts are in a map, and the equation to compute that, then i could figure out the final size based on the scale.

Any pointers, advise, or help on the matter is welcome :)

TheJustinWalsh

21-06-2006 18:24:11

3ds Max Possible solution...

Ok well i can't get the demo app working [see other topic], but i generated something in max that looks like it may be pretty damn close to the real deal. Just need to test :)

Here is what i did, maybe its right, if someone else wnats to give it a try...

Using the hf_129_3 from the PLSM2 here is what i found
Using the data from the config of...
PageSize 129
ScaleX=15000
ScaleY=3000
ScaleZ=15000

I created a plane size of 128x128 with 128x128 segments.
I then scaled it in max to X = 128 * 15000, Y = 128 * 15000
Then applied the displacement modifier with the hf_129_3.png and set the strength to 128 * 3000

I will let everyone know as soon as i fix the Demo app, until then feel free to try this yourself, if success post back! :)

jacmoe

22-06-2006 01:16:05

Very cool!
Keep us posted! :)

Lshink

29-06-2006 00:41:19

Some nice input here. I'm trying to do the same exact thing, I tried your method and my coordinates still seem to be a bit off. I'm going to try to play with it more and see what I can come up with.

[EDIT] I just tried the scaling w/o multiplying by 128 and they were a lot closer (z coordinate was ~ 2k off but y coordinate was only like ~100 off)

Lshink

03-07-2006 01:02:21

Ok, I'm getting really really close to getting the correct coordinates, I'm only about 50-100 off on most of the coordinates, here is what I did for the hf129_3 map.

Make a plane of size 129x129, with 129 segments
Scale the plane by x and y with 15000.0/129.0 ~= 11627.0 but leave z alone
Next displace the plane with the heightmap with a strength of 3000.0 (scale z value)


Well, thats all I did. I havn't been able to figure out whats causing the coordinates to be slightly off -- its got me boggled. If anyone else figures it out lemme know! I might just have to deal with it as is.