Code Monkey home page Code Monkey logo

Comments (5)

Pandawan avatar Pandawan commented on May 17, 2024 1

Okay, that explains it. Thank you very much!

from noa.

Pandawan avatar Pandawan commented on May 17, 2024

It seems this was worked on 3 years ago but was never really finished...

from noa.

fenomas avatar fenomas commented on May 17, 2024

Hi! Sorry - this is intended but I don't have any good docs explaining it. Here's the basic story.

The implementation I've settled on adds 1-voxel of padding to all chunks. This is done so that the edge blocks of each chunk can be built correctly, since the meshing and ambient occlusion for a given voxel depends on its neighbors. The alternative would to omit the padding but rebuild each chunk when its neighbors first get created - I experimented with that as you saw, but wound up sticking with the current behavior for now.

So, when you set chunk size to 16, and noa wants the chunk for (0,0,0), it sends out an event with an (18, 18, 18) size array for location [-1, -1, -1]. So the correct way to handle it would look like:

    noa.world.on('worldDataNeeded', function (id, array, x, y, z) {

        var size = array.shape[0]
        for (var i = 0; i < size; i++) {
            for (var j = 0; j < size; j++) {
                for (var k = 0; k < size; k++) {
                    var worldx = x + i
                    var worldy = y + j
                    var worldz = z + k
                    var block = decideBlockID(worldx, worldy, worldz)
                    array.set(i, j, k, block)
                }
            }
        }

    }

Hope this helps, let me know if it works!

from noa.

Pandawan avatar Pandawan commented on May 17, 2024

So should you or should you not write to the padding? In the example you gave, you are simply acting as if the chunk was 18x18x18; doesn't that mean you are writing twice but one of them is useless? (I know that you are using worldX, worldY, worldZ to allow terrain generation to know where it is, but it still seems pointless to write if you don't need it).

Right now, I'm simply ignoring the padding and not writing anything there, is that fine/recommended?
Will that mess up with block culling?

// Note: I'm ignoring the x,y,z passed by worldDataNeeded because I don't need them
noa.world.on('worldDataNeeded', function (id, data) {
    for(let x = 1; x < data.shape[0] - 1; x++) {
        for(let y = 1; y < data.shape[1] - 1; y++) {
            for(let z = 1; z < data.shape[2] - 1; z++) {
                if (y === 1) {
                  data.set(x, y, z, game.blocks.stone.id);
                }
            }
        }
    }
}

EDIT: Is this issue related? Should I add blocks in the padding area?

from noa.

fenomas avatar fenomas commented on May 17, 2024

Yes, you should fill in all the blocks in the data array, including the padding.

The engine uses the padding blocks to figure out how to build the edges of each chunk - whether they need meshes on the boundary and whether the edge blocks need AO, so if you leave them out there should be issues at chunk borders.

For reference here's what the hello world demo looks like if you omit the padding blocks - the light-colored bands on the ground are incorrect AO, and the terrain gaps are the same issue you saw in your video.

Screen Shot 2019-06-02 at 12 33 55

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.