Tuesday, October 4, 2022
HomeGame Developmentvoxels - Easy methods to classify which vertices go to particular faces?

voxels – Easy methods to classify which vertices go to particular faces?


I may need spent the entire time laborious coding the mesh the best way it’s now relatively than making it extra dynamic. How I might classify these vertices to particular faces (North, West, East, South). That manner I might additionally specify which UV cords might go on a face.

bundle most important;

import org.lwjgl.glfw.GLFW;

import engine.graphics.Block;
//import engine.graphics.Block;
import engine.graphics.Materials;
import engine.graphics.Mesh;
import engine.graphics.Renderer;
import engine.graphics.Shader;
import engine.graphics.Vertex;
import engine.io.Enter;
import engine.io.Window;
import engine.maths.Vector2f;
import engine.maths.Vector3f;
import engine.objects.Digicam;
import engine.objects.GameObject;


public class Primary implements Runnable {
    //public closing static int CHUNK_SIZE= 16;
    public Thread sport;
    public Window window;
    public Renderer renderer;
    public Shader shader;
    public Block block;
    public closing int WIDTH = 1280, HEIGHT = 760;    
    public Mesh mesh = new Mesh(new Vertex[] {
            //Again face
            new Vertex(new Vector3f(-0.5f,  0.5f, -0.5f), new Vector2f(0.0f, 0.0f)),
            new Vertex(new Vector3f(-0.5f, -0.5f, -0.5f), new Vector2f(0.0f, 0.5f)),
            new Vertex(new Vector3f( 0.5f, -0.5f, -0.5f), new Vector2f(0.5f, 0.5f)),
            new Vertex(new Vector3f( 0.5f,  0.5f, -0.5f), new Vector2f(0.5f, 0.0f)),
            
            //Entrance face
            new Vertex(new Vector3f(-0.5f,  0.5f,  0.5f), new Vector2f(0.0f, 0.0f)),
            new Vertex(new Vector3f(-0.5f, -0.5f,  0.5f), new Vector2f(0.0f, 0.5f)),
            new Vertex(new Vector3f( 0.5f, -0.5f,  0.5f), new Vector2f(0.5f, 0.5f)),
            new Vertex(new Vector3f( 0.5f,  0.5f,  0.5f), new Vector2f(0.5f, 0.0f)),
            
            //Proper face
            new Vertex(new Vector3f( 0.5f,  0.5f, -0.5f), new Vector2f(0.0f, 0.0f)),
            new Vertex(new Vector3f( 0.5f, -0.5f, -0.5f), new Vector2f(0.0f, 0.5f)),
            new Vertex(new Vector3f( 0.5f, -0.5f,  0.5f), new Vector2f(0.5f, 0.5f)),
            new Vertex(new Vector3f( 0.5f,  0.5f,  0.5f), new Vector2f(0.5f, 0.0f)),
            
            //Left face
            new Vertex(new Vector3f(-0.5f,  0.5f, -0.5f), new Vector2f(0.0f, 0.0f)),
            new Vertex(new Vector3f(-0.5f, -0.5f, -0.5f), new Vector2f(0.0f, 0.5f)),
            new Vertex(new Vector3f(-0.5f, -0.5f,  0.5f), new Vector2f(0.5f, 0.5f)),
            new Vertex(new Vector3f(-0.5f,  0.5f,  0.5f), new Vector2f(0.5f, 0.0f)),
            
            //Prime face
            new Vertex(new Vector3f(-0.5f,  0.5f,  0.5f), new Vector2f(0.5f, 0.0f)),
            new Vertex(new Vector3f(-0.5f,  0.5f, -0.5f), new Vector2f(0.5f, 0.5f)),
            new Vertex(new Vector3f( 0.5f,  0.5f, -0.5f), new Vector2f(1.0f, 0.5f)),
            new Vertex(new Vector3f( 0.5f,  0.5f,  0.5f), new Vector2f(1.0f, 0.0f)),
            
            //Backside face
            new Vertex(new Vector3f(-0.5f, -0.5f,  0.5f), new Vector2f(0.0f, 0.5f)),
            new Vertex(new Vector3f(-0.5f, -0.5f, -0.5f), new Vector2f(0.0f, 1.0f)),
            new Vertex(new Vector3f( 0.5f, -0.5f, -0.5f), new Vector2f(0.5f, 1.0f)),
            new Vertex(new Vector3f( 0.5f, -0.5f,  0.5f), new Vector2f(0.5f, 0.5f)),
    }, new int[] {
            //Again face
            0, 3, 1,    
            1, 3, 2,    
            
            //Entrance face
            4, 5, 7,
            7, 5, 6,
            
            //Proper face
            8, 11, 9,
            9, 11, 10,
            
            //Left face
            12, 13, 15,
            15, 13, 14,
            
            //Prime face
            16, 19, 17,
            17, 19, 18,
            
            //Backside face
            20, 21, 23,
            23, 21, 22
    }, new Materials("/textures/Grass.png"));
    //public Block block = new Block();
    
    //public GameObject object; 
    public GameObject object = new GameObject(new Vector3f(0, 0, 0), new Vector3f(0, 0, 0), new Vector3f(1, 1, 1), mesh);
    public Digicam digicam =new Digicam(new Vector3f(0, 0, 1), new Vector3f(0, 0, 0));
    
    public void begin() {
        sport = new Thread(this, "sport");
        sport.begin();
    }
    public  void init() {
        //System.out.println("Beginning Sport");
        window = new Window(WIDTH, HEIGHT, "GAME");
        shader = new Shader("/shaders/mainVertex.glsl", "/shaders/mainFragment.glsl");
        renderer = new Renderer(window, shader);
        window.setBackgroundColor(.49f , .73f, .91f);
        window.create();
        mesh.create();
        shader.create();
        //objects = new GameObject[CHUNK_SIZE][CHUNK_SIZE][CHUNK_SIZE];
//      for (int x = 0; x < CHUNK_SIZE; x++) {
    //      for (int y = 0; y < CHUNK_SIZE; y++) {
    //          for (int z = 0; z < CHUNK_SIZE; z++) {
    //              objects[x][y][z] = new GameObject(new Vector3f(x, y, z), new Vector3f(0, 0, 0), new Vector3f(1, 1, 1), mesh);
        //      }
//          }
    //  }
        
    }
    public void run() {
        init();
        whereas (!window.shouldClose() && !Enter.iskeyDown(GLFW.GLFW_KEY_ESCAPE)) {
            replace();
            render();
            if (Enter.iskeyDown(GLFW.GLFW_KEY_F11)) window.setFullscreen( !window.isFullscreen());
            if (Enter.isButtonDown(GLFW.GLFW_MOUSE_BUTTON_LEFT)) window.mouseState(true);
                
        }
        shut();
    }
    personal void replace() {
        window.replace();
        digicam.replace();
        }
    
    personal void render() {
    //  for (int x = 0; x < CHUNK_SIZE; x++) {
    //      for (int y = 0; y < CHUNK_SIZE; y++) {
    //          for (int z = 0; z < CHUNK_SIZE; z++) {
            // renderer.renderMesh(object, digicam); //
        renderer.renderMesh(object, digicam);
                
                    
        //      }
    //          }
    //          }
        //renderer.renderMesh(object, digicam);
        window.swapbuffers();
    }
    personal void shut() {
        window.destroy();
        mesh.destroy();
        shader.destroy();

    }
    public static void most important(String[] args) {
        new Primary().begin();

    }

}
 bundle engine.graphics;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL15;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import org.lwjgl.system.MemoryUtil;

public class Mesh {

    personal Vertex[] vertices;
    personal int[] indices;
    personal Materials materials;
    personal int vao, pbo, ibo, cbo, tbo;
    public  Mesh(Vertex[] vertices, int[] indices, Materials materials) {
    
        this.vertices = vertices;
        this.indices = indices;
        this.materials = materials;
    }
    
    public void create() {
        materials.create();
        
        vao = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(vao);
        FloatBuffer positionBuffer = MemoryUtil.memAllocFloat(vertices.size * 3);
        float[] positionData = new float[vertices.length * 3];
        for (int i = 0; i < vertices.size; i++) {
            positionData[i *3] = vertices[i].getPosition().getX();
            positionData[i *3 + 1] = vertices[i].getPosition().getY();
            positionData[i *3 + 2] = vertices[i].getPosition().getZ();
        }
        positionBuffer.put(positionData).flip();
        pbo = storeData(positionBuffer, 0, 3);
        
        FloatBuffer textureBuffer = MemoryUtil.memAllocFloat(vertices.size * 2);
        float[] textureData = new float[vertices.length * 2];
        for (int i = 0; i < vertices.size; i++) {
            textureData[i *2] = vertices[i].getTextureCoord().getX();
            textureData[i *2 + 1] = vertices[i].getTextureCoord().getY();
        }
        textureBuffer.put(textureData).flip();
        tbo = storeData(textureBuffer, 2, 2);
    
        IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.size);
        indicesBuffer.put(indices).flip();
        ibo = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
                    
    }
    personal int storeData(FloatBuffer buffer, int index, int dimension) {
        int bufferID = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferID);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
        GL20.glVertexAttribPointer(index, dimension, GL11.GL_FLOAT, false, 0, 0);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
        return bufferID;
    }
    
    public void destroy() {
        GL15.glDeleteBuffers(pbo);
        GL15.glDeleteBuffers(cbo);
        GL15.glDeleteBuffers(ibo);
        GL15.glDeleteBuffers(tbo);

        GL30.glDeleteVertexArrays(vao);
        materials.destroy();

    }
    
    public Vertex[] getVertices() {
        return vertices;
    }
    public int[] getIndices() {
        return indices;
    }
    public int getVAO() {
        return vao;
    }
    public int getPBO() {
        return pbo;
    }
    public int getCBO() {
        return cbo;
    }
    public int getTBO() {
        return tbo;
    }
    
    public int getIBO() {
        return ibo;
    }
    public Materials getMaterial() {
        return materials;
    }
    

}
    

I may need spent the entire time laborious coding the mesh the best way it's now relatively than making it extra dynamic.However all Im asking is for some enlightenment to how I might Classify these vertices to particular faces.That manner I might additionally specify which uv cords might go on a face. just a few assist .My thoughts can be slightly burnt out.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments