<commit_before>package io.github.achtern.AchternEngine.core.resource.fileparser.mesh;

import io.github.achtern.AchternEngine.core.math.Vector2f;
import io.github.achtern.AchternEngine.core.math.Vector3f;
import io.github.achtern.AchternEngine.core.util.UString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Inheritance not possible due to incompatible Indices Types...
 */
public class OBJModel implements Model {

    public static final Logger LOGGER = LoggerFactory.getLogger(OBJModel.class);

    private ArrayList<Vector3f> positions;
    private ArrayList<Vector2f> texCoord;
    private ArrayList<Vector3f> normal;
    private ArrayList<OBJIndex> indices;
    private boolean hasTexCoords;
    private boolean hasNormals;

    public OBJModel() {
        positions = new ArrayList<Vector3f>();
        texCoord = new ArrayList<Vector2f>();
        normal = new ArrayList<Vector3f>();
        indices = new ArrayList<OBJIndex>();
        hasTexCoords = false;
        hasNormals = false;
    }

    public void parse(BufferedReader meshReader) throws IOException {

        String line;

        while ((line = meshReader.readLine()) != null) {

            String[] tokens = line.split(" ");
            tokens = UString.removeEmptyFromArray(tokens);

            if (tokens[0].equalsIgnoreCase("v")) {
                positions.add(new Vector3f(
                        Float.valueOf(tokens[1]),
                        Float.valueOf(tokens[2]),
                        Float.valueOf(tokens[3])
                ));
            } else if (tokens[0].equalsIgnoreCase("vt")){
                texCoord.add(new Vector2f(
                        Float.valueOf(tokens[1]),
                        Float.valueOf(tokens[2])
                ));
            } else if (tokens[0].equalsIgnoreCase("vn")){
                normal.add(new Vector3f(
                        Float.valueOf(tokens[1]),
                        Float.valueOf(tokens[2]),
                        Float.valueOf(tokens[3])
                ));
            } else if (tokens[0].equalsIgnoreCase("f")){

                for (int i = 0; i < tokens.length - 3; i++) {

                    indices.add(this.parseOBJIndex(tokens[1]));
                    indices.add(this.parseOBJIndex(tokens[2 + i]));
                    indices.add(this.parseOBJIndex(tokens[3 + i]));
                }

            }
        }<commit_msg>Fixed bug in OBJModel where it would crash on empty lines or commented lines<commit_after>package io.github.achtern.AchternEngine.core.resource.fileparser.mesh;

import io.github.achtern.AchternEngine.core.math.Vector2f;
import io.github.achtern.AchternEngine.core.math.Vector3f;
import io.github.achtern.AchternEngine.core.util.UString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Inheritance not possible due to incompatible Indices Types...
 */
public class OBJModel implements Model {

    public static final Logger LOGGER = LoggerFactory.getLogger(OBJModel.class);

    private ArrayList<Vector3f> positions;
    private ArrayList<Vector2f> texCoord;
    private ArrayList<Vector3f> normal;
    private ArrayList<OBJIndex> indices;
    private boolean hasTexCoords;
    private boolean hasNormals;

    public OBJModel() {
        positions = new ArrayList<Vector3f>();
        texCoord = new ArrayList<Vector2f>();
        normal = new ArrayList<Vector3f>();
        indices = new ArrayList<OBJIndex>();
        hasTexCoords = false;
        hasNormals = false;
    }

    public void parse(BufferedReader meshReader) throws IOException {

        String line;

        while ((line = meshReader.readLine()) != null) {

            String[] tokens = line.split(" ");
            tokens = UString.removeEmptyFromArray(tokens);

            if (tokens.length == 0) {
                // We found an empty line
                continue;
            }

            if (tokens[0].startsWith("#")) {
                // Comment Line
                continue;
            }

            if (tokens[0].equalsIgnoreCase("v")) {
                positions.add(new Vector3f(
                        Float.valueOf(tokens[1]),
                        Float.valueOf(tokens[2]),
                        Float.valueOf(tokens[3])
                ));
            } else if (tokens[0].equalsIgnoreCase("vt")){
                texCoord.add(new Vector2f(
                        Float.valueOf(tokens[1]),
                        Float.valueOf(tokens[2])
                ));
            } else if (tokens[0].equalsIgnoreCase("vn")){
                normal.add(new Vector3f(
                        Float.valueOf(tokens[1]),
                        Float.valueOf(tokens[2]),
                        Float.valueOf(tokens[3])
                ));
            } else if (tokens[0].equalsIgnoreCase("f")){

                for (int i = 0; i < tokens.length - 3; i++) {

                    indices.add(this.parseOBJIndex(tokens[1]));
                    indices.add(this.parseOBJIndex(tokens[2 + i]));
                    indices.add(this.parseOBJIndex(tokens[3 + i]));
                }

            }
        }
{'fraction_non_alphanumeric': 0.11321107784431138, 'fraction_numerical': 0.011601796407185628, 'mean_word_length': 1.9546710889994472, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1224229', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1402, 'n_words': 287}