Hello,
First off, I'm new to this website and it seems awesome! I hope we get to share knowledge!
Alright, I'm developing a game in lwjgl and I'm trying to load the models basic information from a CSV file (model file name, texture file name, x, y, z coordinates, & rotations etc..), but I seem to have gotten into a wall..
I first load up the csv file and extract information while adding some of them into a hashmap as seen below in the ModelReader.java class, then I used these information that is in the hashmap in my main class in this way:
code that is used in my main method in my main class:
ModelReader mre = new ModelReader(); Iterator<?> it = ModelReader.getModFTNamesh().entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry)it.next(); RawModel model = OBJLoader.loadObjModel((String) pair.getKey(), loader); TexturedModel modelTex = new TexturedModel(model, new ModelTexture(loader.loadTexture((String) pair.getValue())), true); Entity models = new Entity(modelTex, new Vector3f(mre.getX(), mre.getY(), mre.getZc()), 0,180,0,0.6f); entities.add(models); //it.remove(); } System.out.println(mre.getModFTNamesh() + "Model File & Texture File Names"); System.out.println(mre.getX() + "X coordinates"); System.out.println(mre.getY() + "X coordinates"); System.out.println(mre.getZc() + "Z coordinates");
and when I run the game, I can see the 2 3d models, but they are standing in the same coordinates which is 0,0,0 and whenever I try to change the coordinates for a specific model in the csv file, they move together if I change in the first one, but in the second model nothing interesting happens.. I've tried making a hashmap for the coordinates but the same thing happens and when I println the coordinates it always shows as the first model's coordinates.. I've included the models.csv file and the output of the println.
Any help would be appreciated soooo much!!
ModelReader.java class:
package engine.models; import com.opencsv.CSVReader; import com.opencsv.bean.CsvToBean; import com.opencsv.bean.CsvToBeanBuilder; import engine.models.textures.ModelTexture; import engine.objconverter.Vertex; imports... etc.. import org.lwjgl.util.vector.Vector3f; /** * * Reads the models.csv file * @author * */ public class ModelReader { static int modelTotalNumber; /* * * Start of ArrayList for X,Y,Z coordinates */ //List<Float> x = new ArrayList<Float>(); //List<Float> y = new ArrayList<Float>(); //List<Float> z = new ArrayList<Float>(); /* * * End of ArrayList for X,Y,Z coordinates */ /* * * Start of HashMap test! */ static HashMap<String,String> modFTNamesh = new HashMap<String,String>(); static HashMap<Float, Float> xy = new HashMap<Float,Float>(); float x; float y; float zc; public static HashMap<Float, Float> getXy() { return xy; } public static HashMap<Float, Float> getZ() { return z; } static HashMap<Float, Float> z = new HashMap<Float,Float>(); public static HashMap<String, String> getModFTNamesh() { return modFTNamesh; } /* * * End of Hashmap test! */ public ModelReader() { try { CSVReader reader = new CSVReader(new FileReader("res/read/models.csv")); String[] nextLine; int modelNum = 0; while((nextLine = reader.readNext()) != null) { modelNum++; if(nextLine != null) { String modelNumber = nextLine[0]; String modelName = nextLine[1]; String modelFileName = nextLine[2]; String modelTexture = nextLine[3]; String modelCoordX = nextLine[4]; String modelCoordY = nextLine[5]; String modelCoordZ = nextLine[6]; float modelCoordXFloat = Float.parseFloat(modelCoordX); float modelCoordYFloat = Float.parseFloat(modelCoordY); float modelCoordZFloat = Float.parseFloat(modelCoordZ); zc = modelCoordZFloat; x = modelCoordXFloat; y = modelCoordYFloat; /* * * Start of HashMap */ modFTNamesh.put(modelFileName, modelTexture); xy.put(modelCoordXFloat, modelCoordYFloat); z.put(modelCoordZFloat, 0f); /* * * End of Hashmap */ } } } catch(Exception e) { System.out.println(e); } } //get the value then get the row then get the x y z public float getX() { return x; } public float getY() { return y; } public float getZc() { return zc; } public static int getModelTotalNumber() { return modelTotalNumber; } }
models csv file:
1,stall,s2tall,stallTex,0f,10.0f,0f 2,dragoon,dragon,test1,0f,0f,0f
printLn result of coords and model filename and texture filename hashmap:
Sun Feb 17 01:55:47 EET 2019 INFO:Use Java PNG Loader = true java.lang.ArrayIndexOutOfBoundsException: 1 {s2tall=stallTex, dragon=test1}Model File & Texture File Names 0.0X coordinates 0.0X coordinates 0.0Z coordinates
Any help would be appreciated soooo much!!
Thank you guys