All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.daxie.joglf.gl.model.ModelMgr Maven / Gradle / Ivy

There is a newer version: 11.7.0
Show newest version
package com.daxie.joglf.gl.model;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;

import com.daxie.basis.matrix.Matrix;
import com.daxie.basis.vector.Vector;
import com.daxie.basis.vector.VectorFunctions;
import com.daxie.joglf.gl.model.buffer.BufferedVertices;
import com.daxie.joglf.gl.shader.GLShaderFunctions;
import com.daxie.joglf.gl.shape.Triangle;
import com.daxie.joglf.gl.shape.Vertex3D;
import com.daxie.joglf.gl.texture.TextureMgr;
import com.daxie.joglf.gl.wrapper.GLWrapper;
import com.daxie.log.LogFile;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL4;

/**
 * Model manager
 * @author Daba
 *
 */
public class ModelMgr {
	private List buffered_vertices_list;
	
	private boolean property_updated_flag;
	
	private IntBuffer indices_vbo;
	private IntBuffer pos_vbo;
	private IntBuffer uv_vbo;
	private IntBuffer norm_vbo;
	private IntBuffer vao;
	
	private List program_names;
	
	public ModelMgr(List buffered_vertices_list) {
		this.buffered_vertices_list=buffered_vertices_list;
		
		property_updated_flag=false;
		
		program_names=new ArrayList<>();
		program_names.add("texture");
		
		this.GenerateBuffers();
	}
	
	public void AddProgram(String program_name) {
		program_names.add(program_name);
	}
	public void RemoveProgram(String program_name) {
		program_names.remove(program_name);
	}
	public void RemoveAllPrograms() {
		program_names.clear();
	}
	
	public void Interpolate(ModelMgr frame1,ModelMgr frame2,float blend_ratio) {
		List interpolated_bv_list=new ArrayList<>();
		List frame1_bv_list=frame1.buffered_vertices_list;
		List frame2_bv_list=frame2.buffered_vertices_list;
		
		int element_num=frame1_bv_list.size();
		for(int i=0;i copied_buffered_vertices_list=new ArrayList<>();
		
		for(BufferedVertices buffered_vertices:buffered_vertices_list) {
			BufferedVertices copied_buffered_vertices=buffered_vertices.Copy();
			copied_buffered_vertices_list.add(copied_buffered_vertices);
		}
		
		ModelMgr duplicated_model=new ModelMgr(copied_buffered_vertices_list);
		
		return duplicated_model;
	}
	
	private void GenerateBuffers() {
		int element_num=buffered_vertices_list.size();
		indices_vbo=Buffers.newDirectIntBuffer(element_num);
		pos_vbo=Buffers.newDirectIntBuffer(element_num);
		uv_vbo=Buffers.newDirectIntBuffer(element_num);
		norm_vbo=Buffers.newDirectIntBuffer(element_num);
		vao=Buffers.newDirectIntBuffer(element_num);
		
		GLWrapper.glGenBuffers(element_num, indices_vbo);
		GLWrapper.glGenBuffers(element_num, pos_vbo);
		GLWrapper.glGenBuffers(element_num, uv_vbo);
		GLWrapper.glGenBuffers(element_num, norm_vbo);
		GLWrapper.glGenVertexArrays(element_num, vao);
		
		for(int i=0;i GetFaces(){
		List ret=new ArrayList<>();
		
		for(BufferedVertices buffered_vertices:buffered_vertices_list) {
			FloatBuffer pos_buffer=buffered_vertices.GetPosBuffer();
			FloatBuffer norm_buffer=buffered_vertices.GetNormBuffer();
			FloatBuffer uv_buffer=buffered_vertices.GetUVBuffer();
			
			int capacity=pos_buffer.capacity();
			int triangle_num=capacity/3;
			
			for(int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy