Author Topic: Saving and loading a heightfield  (Read 1918 times)

0 Members and 1 Guest are viewing this topic.

skylerd

  • World Machine Veteran
  • ***
  • Posts: 23
    • View Profile
Saving and loading a heightfield
« on: April 08, 2013, 02:00:58 PM »
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?

Thanks.

Remnant

  • Author
  • World Machine Guru
  • *****
  • Posts: 2311
    • View Profile
    • http://www.world-machine.com/
Re: Saving and loading a heightfield
« Reply #1 on: April 08, 2013, 06:25:59 PM »
Hi there,

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

Code: [Select]
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

skylerd

  • World Machine Veteran
  • ***
  • Posts: 23
    • View Profile
Re: Saving and loading a heightfield
« Reply #2 on: April 09, 2013, 07:00:45 AM »
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?

Remnant

  • Author
  • World Machine Guru
  • *****
  • Posts: 2311
    • View Profile
    • http://www.world-machine.com/
Re: Saving and loading a heightfield
« Reply #3 on: April 09, 2013, 12:52:08 PM »
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