package org.example; import com.mokiat.data.front.parser.IOBJParser; import com.mokiat.data.front.parser.OBJModel; import com.mokiat.data.front.parser.OBJParser; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; import java.text.MessageFormat; import java.util.Scanner; public class Entity { OBJModel model; ShaderProgram shader; public Entity(String object_file_path, String fragment_shader_path, String vertex_shader_path) { // Load Object try (InputStream in = this.getClass().getResourceAsStream(object_file_path)) { // Create an OBJParser and parse the resource final IOBJParser parser = new OBJParser(); this.model = parser.parse(in); // Use the model representation to get some basic info System.out.println(MessageFormat.format( "OBJ model has {0} vertices, {1} normals, {2} texture coordinates, and {3} objects.", model.getVertices().size(), model.getNormals().size(), model.getTexCoords().size(), model.getObjects().size())); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // Load Shaders try { this.shader = new ShaderProgram(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } try { String vertex_shader_code = new Scanner(new File(vertex_shader_path)).useDelimiter("\\Z").next(); this.shader.createVertexShader(vertex_shader_code); } catch (Exception e) { System.out.println("ERROR Initializing the vertex shader"); e.printStackTrace(); } try { String fragment_shader_code = new Scanner(new File(fragment_shader_path)).useDelimiter("\\Z").next(); this.shader.createFragmentShader(fragment_shader_code); } catch (Exception e) { System.out.println("ERROR Initializing the fragment shader"); e.printStackTrace(); } } }