Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void map(GL4 gl)
- {
- //Zero out the vertex count from last cycle.
- m_vert_count = 0;
- int[] index_array = new int[INDICES_SIZE];
- float[] vertex_array = new float[BUFFER_SIZE / 4];
- float[] model_array = new float[16 * MAX_OBJECTS];
- float[] joint_array = new float[16 * MAX_OBJECTS * IRenderable.MAX_JOINTS];
- float[] inv_bind_array = new float[16 * MAX_OBJECTS * IRenderable.MAX_JOINTS];
- //For each renderable put it in the buffer.
- for(int i = 0; i < m_renderable_meshes.size(); i++)
- {
- IMesh mesh = m_renderable_meshes.get(i);
- int texture_index = mesh.getRenderable().getTextureID(TextureTGA.DIFFUSE_MAP);
- for(int t = 0; t < m_textures.size(); t++)
- {
- if(m_textures.get(t).m_id == texture_index)
- {
- texture_index = t;
- break;
- }
- }
- mesh.getRenderable().setMatrixIndex(i);
- Matrix4f inverse_camera = m_camera.getModelMatrix().invert(new Matrix4f());
- Matrix4f model_mat = inverse_camera.mul(mesh.getTransform(), new Matrix4f());
- float[] model = model_mat.get(new float[16], 0);
- System.arraycopy(model, 0, model_array, i * 16, model.length);
- Joint[] joints = ((SkinnedMesh) mesh).getAnimatedFrame();
- Joint[] inv_binds = ((SkinnedMesh) mesh).getInvBindPose();
- for(int j = 0; j < IRenderable.MAX_JOINTS; j++)
- {
- float[] joint = joints[j].m_matrix.get(new float[16], 0);
- float[] inv_bind = inv_binds[j].m_matrix.get(new float[16], 0);
- System.arraycopy(joint, 0, joint_array, i * 512 + j * 16, joint.length);
- System.arraycopy(inv_bind, 0, inv_bind_array, i * 512 + j * 16, inv_bind.length);
- }
- Vertex[] vertices = mesh.getRenderable().getVertices();
- for(int j = 0; j < vertices.length; j++)
- {
- vertices[j].setTextureIndex(texture_index);
- float[] temp = vertices[j].toArray();
- System.arraycopy(temp, 0, vertex_array, i * vertices.length * Vertex.SIZE_COUNT + j * temp.length, temp.length);
- }
- //Add the indices to the buffer
- int[] indices = mesh.getRenderable().getIndices();
- for(int j = 0; j < indices.length; j++)
- {
- //don't forget the offset...(m_vert_count) or
- //we'll only render the first mesh.
- index_array[i * indices.length + j] = indices[j] + m_vert_count;
- }
- m_vert_count += indices.length;
- }
- map(gl, index_array, vertex_array, model_array, joint_array, inv_bind_array);
- // gl.glBindBuffer(GL4.GL_UNIFORM_BUFFER, 0);
- // gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, 0);
- // gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, 0);
- m_renderable_meshes.clear();
- m_textures.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement