IceCreamYou / THREE.Terrain

A procedural terrain generation engine for use with the Three.js 3D graphics library for the web.
https://icecreamyou.github.io/THREE.Terrain/
MIT License
706 stars 109 forks source link

bugfix: allow negative z values in heightmap #14

Closed foobarbecue closed 5 years ago

foobarbecue commented 5 years ago

When options.minHeight is unset, THREE.Terrain.toHeightmap calculates a min value for scaling the output image (0 to 255). However, it was not using this value. Presumably this was a bug.

IceCreamYou commented 5 years ago

Thanks for the PR. This does look like a bug, however the provided change does not fix the bug. In order to fix the bug, we additionally need to change the definition of spread to max - min, and change the hasMax and hasMin definitions to check for !== instead of ===. Would you be willing to update this PR with those changes?

Essentially, calling

toHeightmap([{ x: 0, y: -10, z: -10}, { x: 0, y: 10, z: 10 }], { xSegments: 0, ySegments: 1 })

should produce one black pixel and one white pixel.

foobarbecue commented 5 years ago

Ah, yeah... hopefully I'll get to it this weekend.

foobarbecue commented 5 years ago

Oh, wait, this is super simple. I misunderstood. I had actually already fixed the spread definition on my local version failed to commit it.

IceCreamYou commented 5 years ago

Great, thanks!