Code Monkey home page Code Monkey logo

Comments (13)

mduft avatar mduft commented on May 21, 2024 1

That results currently in something like this (for sliceHeight=3):

image
image

The +/- buttons I added are currently simply incrementing, decrementing sliceHeight on the shader. That would need to change obviously :D

from objtoschematic.

mduft avatar mduft commented on May 21, 2024 1

My initial take on this is at mduft@b5328d0 - however I'm unable to cope with the half-block-rendering issue xD I'm completely lost on where to correct the vertex positions, and how to deal with that in the shader. Maybe what I have so far is of use to someone...

from objtoschematic.

LucasDower avatar LucasDower commented on May 21, 2024 1

No problem, I can take a look and fix up the rest and get it merged in sometime soon! Thanks for getting this in a good position 😁

from objtoschematic.

mduft avatar mduft commented on May 21, 2024

My naive take would be to limit the resulting mesh to a certain height, settable through a slider. If you could give me one or two hints on where to start looking, I would try to do this :)

from objtoschematic.

LucasDower avatar LucasDower commented on May 21, 2024

Firstly you'll need to pass a new uniform variable to the voxel mesh shader called something like u_sliceHeight, this would be in Renderer._drawBlockMesh. Then you'll need to modify the vertex shader file block_vertex.vert to check if the vertex position height is above u_sliceHeight and if so discard the vertex (or set it's position to (0, 0, 0)).

That leaves actually creating a UI element for a slider that sets the u_sliceHeight, there's already a SliderUIElement that could be tweaked and placed on the viewpoint toolbar somewhere.

Hope this helps.

from objtoschematic.

mduft avatar mduft commented on May 21, 2024

Thanks :) Will check and go on an adventure :D

from objtoschematic.

mduft avatar mduft commented on May 21, 2024

OK. Making some progress, but I need a little input if possible please :)

I am at a point where the model is cut off X blocks above the grid (the last blocks are cut in half and miss the closing surface, but I hope that changes when my question is answered :D). However my model does not start at y=0. How would I be able to find the lowest block's starting Y coordinate? I need that offset so I can add the number of blocks I want to show in height.

I added this to the shader:

if(u_sliceHeight > 0.0 && (position.y + u_gridOffset.y) > u_sliceHeight)
    {
        v_sliced = 1.0;
    } else {
        v_sliced = 0.0;
    }

where u_sliceHeight would be a value above 0.0 in amount of blocks I want to show in height. the fragment shader discards if v_sliced > 0.5. Setting the position only to 0,0,0 will result in ugly rendering artifacts.

from objtoschematic.

LucasDower avatar LucasDower commented on May 21, 2024

How would I be able to find the lowest block's starting Y coordinate?

The block mesh is to the renderer in chunks in Renderer.useBlockMeshChunk, it's passed a RenderNextBlockMeshChunkParams.Output parameter which contains a dimensions member variable which is the dimensions of the whole mesh. You can then cache this value somewhere and use it where you need to. An important thing to note is that if dimensions.y is 35, for example, it means the block mesh is 36 blocks tall.

Hope this helps.

from objtoschematic.

LucasDower avatar LucasDower commented on May 21, 2024

As for the other problem what you can do is subtract half of the normal from the vertex to get the actual block position instead of the vertex position.

The problem is that if a block is at (0.0, 30.0, 0.0), the vertices are (-0.5, 29.5, -0.5), (0.5, 29.5, -0.5), (0.5, 29.5, 0.5), (-0.5, 29.5, 0.5), (-0.5, 30.5, -0.5), (0.5, 30.5, -0.5), (0.5, 30.5, 0.5), (-0.5, 30.5, 0.5). (That's before they're multiplied by u_voxelSize). So if your u_sliceHeight is 30, then the bottom vertices will be drawn but the top vertices will be discarded. When you subtract half of each vertex's normal from its position the vertices become (0.0, 30.0, 0.0), (0.0, 30.0, 0.0), (0.0, 30.0, 0.0), (0.0, 30.0, 0.0), (0.0, 30.0, 0.0), (0.0, 30.0, 0.0). Which should then allow you to treat all vertices of the same block in the same manner.

Hope this helps.

from objtoschematic.

LucasDower avatar LucasDower commented on May 21, 2024

There will most definitely be floating-point precision issues, however, so you'll need to incorperate some nearly equals when checking the height of the normal-corrected vertex as.

from objtoschematic.

mduft avatar mduft commented on May 21, 2024

Heyaaa, that sounds incredible :D It will be easier than ever to build things in minecraft :D Thanks a ton for all the advice (even though that resulted in less lines of code than advice written by you xD), and for having a look at it. Feel free to pick the commit and/or tell me if I should open a PR with the unfinished changes.

from objtoschematic.

LucasDower avatar LucasDower commented on May 21, 2024

Opened PR #104, adding to new /0.8-slice-viewer branch.

from objtoschematic.

LucasDower avatar LucasDower commented on May 21, 2024

Closed with 901e83e.

from objtoschematic.

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.