public IndexedModel toIndexedModel(){
		IndexedModel result = new IndexedModel();
		IndexedModel normalModel = new IndexedModel();
		HashMap<OBJIndex, Integer> resultIndexMap = new HashMap<>();
		HashMap<Integer, Integer> normalIndexMap = new HashMap<>();
		HashMap<Integer, Integer> indexMap = new HashMap<>();
		
		for(int i=0; i<indices.size(); i++){
			OBJIndex currentIndex = indices.get(i);
			
			Vector3d currentPosition = positions.get(currentIndex.vertexIndex);
			Vector2d currentTexCoord;
			Vector3d currentNormal;
			
			if(hasTexCoords)
				currentTexCoord = texCoords.get(currentIndex.texCoordIndex);
			else
				currentTexCoord = new Vector2d(0,0);
			
			if(hasNormals)
				currentNormal = normals.get(currentIndex.normalIndex);
			else
				currentNormal = new Vector3d(0,0,0);
			
			// Mesh optimisation (re-using vertices):
			Integer modelVertexIndex = resultIndexMap.get(currentIndex);
			
			if(modelVertexIndex == null){
				// result.getPositions().size() acts as counter variable:
				modelVertexIndex = result.getPositions().size();
				resultIndexMap.put(currentIndex, result.getPositions().size());
				
				result.getPositions().add(currentPosition);
				result.getTexCoords().add(currentTexCoord);
				if(hasNormals)
					result.getNormals().add(currentNormal);
			}
			
			Integer normalModelIndex = normalIndexMap.get(currentIndex.vertexIndex);
			
			if(normalModelIndex==null){
				// normalModel.getPositions().size() acts as counter variable:
				normalModelIndex = normalModel.getPositions().size();
				normalIndexMap.put(currentIndex.vertexIndex, normalModel.getPositions().size());
				
				normalModel.getPositions().add(currentPosition);
				normalModel.getTexCoords().add(currentTexCoord);
				normalModel.getNormals().add(currentNormal);
			}
			
			result.getIndices().add(modelVertexIndex);
			normalModel.getIndices().add(normalModelIndex);
			indexMap.put(modelVertexIndex, normalModelIndex);
		}
		
		if(!hasNormals){
			normalModel.calculateNormals();
			
			for(int i=0; i<result.getPositions().size(); i++)
				result.getNormals().add(normalModel.getNormals().get(indexMap.get(i)));
				//result.getNormals().get(i).set(normalModel.getNormals().get(indexMap.get(i)));
		}
		
		return result;
	}