• Welcome to World Machine Community. Please login or sign up.
October 16, 2019, 07:30:19 pm


Read the Development Diary for an inside look at World Machine's progress!

Saving and loading a heightfield

Started by skylerd, April 08, 2013, 02:00:58 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Hello again,

In another device I'm working on, I'm looking to store a heightfield of diffs from the original heightfield. i.e. If the original heightfield is
[1 1
1 1]
and I want to zero out the diagonal, my diff heightfield will be:
[-1 0
0 -1]
Can I use your existing HField type to store this data? How should I construct it - is there some place I can grab a buildContext in the constructor (since GetNewHF() requires a context to figure out the size of the HF)? How would I load/save it? And finally, how would I find out if the world size changed?



Hi there,

Certainly -- If you have existing heightfields you want to match against, create as so:

HFPointer original =  < ... >
HFPointer myNewHF = GetNewHF(original->getContext());

getContext() will return the PacketContext that defines the worldspace location, dimensions, etc, which can be used to create heightfields with. You cannot get a context in the constructor since the device hasn't yet been assigned to a world and so it has no defined sizes.

The other answers to your questions depend a fair bit on what you want to do.. for example, you can easily add a HFPointer member to your class that will hold your custom data outside of any activate calls... and If you just want to store them in the TMD file you can load and save it in your Device's Load() and Save() function by simply calling the packet's Load() and Save() functions and providing it the stream you're using.  (If you need to load/save externally from disk, check out the HFieldIO.h file for the built-in I/O formats WM can use)

Your device will receive notice on the notifyWorldChange() function when the world size or extents change, but in general a better place to do any real work or matching is in your Activate() function -- it is also a better place to find out what size the user really wants to create things at -- currently WM has a monolithic resolution throughout the world but this will actually be changing not too far in the future, allowing you to define parts of the network at higher resolutions than others. In that case the world resolution is really only a default.
-- Stephen Schmitt
- Creator of World Machine


So as a follow-up - how do I get an initial HField to call load on? Can I just call GetEmptyHF, and then load will properly initialize it? Or do I have to construct it with a context?


yes -- you can create an empty HF and the load function will set the context and take care of allocating memory, etc.
-- Stephen Schmitt
- Creator of World Machine

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.

Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S save/post or ALT+P preview