Code Monkey home page Code Monkey logo

Comments (5)

fenomas avatar fenomas commented on June 1, 2024

Hi, so this voxel engine doesn't impose any particular rules on what voxels can go where - so the task of making "plausible" voxel worlds, like where trees don't grow out of water, is entirely up to the game logic above the engine.

One common approach is to pick a y value for the world's water level, then have a general height-map function that defines a value for terrain height everywhere in the world, and then assign land/water/tree blocks depending on whether each voxel is above or below the terrain or water heights. That's what the stress-test code above is doing, so for example if you wanted to not have "pillars" spawn on top of water, you'd want to skip that bit (or set the pillar height to 0) wherever the terrain height ht is below the water line (which here is 0).

But it's a big topic and there are lots of possible ways to go - you might like to check out r/procedural/ or similar communities for ideas.

from noa.

officialblueify avatar officialblueify commented on June 1, 2024

Thanks for that. How would I go about making trees?

from noa.

fenomas avatar fenomas commented on June 1, 2024

Making large structures is a bit thorny, because if a tree is at the edge of a chunk then parts of it will need to be generated at different times. In my own content I went through several iterations. One relatively easy approach is to just only generate trees on the "internal" parts of a chunk, not at the edges. If you don't have very many trees this winds up not being that noticeable.

But the more robust thing to do is something like:

  1. have one function that, given a world (x,z) coordinate, returns the terrain height at that position
  2. have a second function that, given a world (x,z) coord, returns a list of all tree positions nearby.
  3. have a third function which, given a world data chunk and a tree position, draws that tree into the chunk wherever they overlap. E.g. if the tree is slightly outside of the chunk then this function wouldn't set any voxels for the trunk, but it might set voxels for leaves.

Then at runtime, for each chunk you'd get a list of nearby trees (2), and for each tree you draw it (3) into the current chunk, relative to the terrain height (1) at the tree center (which is where the trunk starts). But note that all of the logic involved needs to be deterministic - if tree locations are random then you'll have half-trees at chunk borders.

Or at least, that's what I wound up doing. There may be better ways!

from noa.

officialblueify avatar officialblueify commented on June 1, 2024

Ok. I'm a beginner trying to make sense of this lol.

from noa.

officialblueify avatar officialblueify commented on June 1, 2024

My main problem is actually adding leaves on the pillars

from noa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.