org.lwjgl.assimp.AIMesh Java Examples
The following examples show how to use
org.lwjgl.assimp.AIMesh.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception { AIScene aiScene = aiImportFile(resourcePath, flags); if (aiScene == null) { throw new Exception("Error loading model [resourcePath: " + resourcePath + ", texturesDir:" + texturesDir + "]"); } int numMaterials = aiScene.mNumMaterials(); PointerBuffer aiMaterials = aiScene.mMaterials(); List<Material> materials = new ArrayList<>(); for (int i = 0; i < numMaterials; i++) { AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i)); processMaterial(aiMaterial, materials, texturesDir); } int numMeshes = aiScene.mNumMeshes(); PointerBuffer aiMeshes = aiScene.mMeshes(); Mesh[] meshes = new Mesh[numMeshes]; for (int i = 0; i < numMeshes; i++) { AIMesh aiMesh = AIMesh.create(aiMeshes.get(i)); Mesh mesh = processMesh(aiMesh, materials); meshes[i] = mesh; } return meshes; }
Example #2
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception { AIScene aiScene = aiImportFile(resourcePath, flags); if (aiScene == null) { throw new Exception("Error loading model"); } int numMaterials = aiScene.mNumMaterials(); PointerBuffer aiMaterials = aiScene.mMaterials(); List<Material> materials = new ArrayList<>(); for (int i = 0; i < numMaterials; i++) { AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i)); processMaterial(aiMaterial, materials, texturesDir); } int numMeshes = aiScene.mNumMeshes(); PointerBuffer aiMeshes = aiScene.mMeshes(); Mesh[] meshes = new Mesh[numMeshes]; for (int i = 0; i < numMeshes; i++) { AIMesh aiMesh = AIMesh.create(aiMeshes.get(i)); Mesh mesh = processMesh(aiMesh, materials); meshes[i] = mesh; } return meshes; }
Example #3
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception { AIScene aiScene = aiImportFile(resourcePath, flags); if (aiScene == null) { throw new Exception("Error loading model"); } int numMaterials = aiScene.mNumMaterials(); PointerBuffer aiMaterials = aiScene.mMaterials(); List<Material> materials = new ArrayList<>(); for (int i = 0; i < numMaterials; i++) { AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i)); processMaterial(aiMaterial, materials, texturesDir); } int numMeshes = aiScene.mNumMeshes(); PointerBuffer aiMeshes = aiScene.mMeshes(); Mesh[] meshes = new Mesh[numMeshes]; for (int i = 0; i < numMeshes; i++) { AIMesh aiMesh = AIMesh.create(aiMeshes.get(i)); Mesh mesh = processMesh(aiMesh, materials); meshes[i] = mesh; } return meshes; }
Example #4
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
protected static void processIndices(AIMesh aiMesh, List<Integer> indices) { int numFaces = aiMesh.mNumFaces(); AIFace.Buffer aiFaces = aiMesh.mFaces(); for (int i = 0; i < numFaces; i++) { AIFace aiFace = aiFaces.get(i); IntBuffer buffer = aiFace.mIndices(); while (buffer.remaining() > 0) { indices.add(buffer.get()); } } }
Example #5
Source File: VkAssimpModelLoader.java From oreon-engine with GNU General Public License v3.0 | 5 votes |
public static List<Model> loadModel(String path, String file) { List<Model> models = new ArrayList<>(); // List<Material<VkImage>> materials = new ArrayList<>(); path = VkAssimpModelLoader.class.getClassLoader().getResource(path).getPath(); // For Linux need to keep '/' or else the Assimp.aiImportFile(...) call below returns null! if (System.getProperty("os.name").contains("Windows")) { // TODO Language/region agnostic value for 'Windows' ? if (path.startsWith("/")) path = path.substring(1); } AIScene aiScene = Assimp.aiImportFile(path + "/" + file, 0); // if (aiScene.mMaterials() != null){ // for (int i=0; i<aiScene.mNumMaterials(); i++){ // AIMaterial aiMaterial = AIMaterial.create(aiScene.mMaterials().get(i)); // Material<GLTexture> material = processMaterial(aiMaterial, path); // materials.add(material); // } // } for (int i=0; i<aiScene.mNumMeshes(); i++){ AIMesh aiMesh = AIMesh.create(aiScene.mMeshes().get(i)); Mesh mesh = processMesh(aiMesh); Model model = new Model(); model.setMesh(mesh); // int materialIndex = aiMesh.mMaterialIndex(); // model.setMaterial(materials.get(materialIndex)); models.add(model); } return models; }
Example #6
Source File: AnimMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials, List<Bone> boneList) { List<Float> vertices = new ArrayList<>(); List<Float> textures = new ArrayList<>(); List<Float> normals = new ArrayList<>(); List<Integer> indices = new ArrayList<>(); List<Integer> boneIds = new ArrayList<>(); List<Float> weights = new ArrayList<>(); processVertices(aiMesh, vertices); processNormals(aiMesh, normals); processTextCoords(aiMesh, textures); processIndices(aiMesh, indices); processBones(aiMesh, boneList, boneIds, weights); // Texture coordinates may not have been populated. We need at least the empty slots if ( textures.size() == 0) { int numElements = (vertices.size() / 3) * 2; for (int i=0; i<numElements; i++) { textures.add(0.0f); } } Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures), Utils.listToArray(normals), Utils.listIntToArray(indices), Utils.listIntToArray(boneIds), Utils.listToArray(weights)); Material material; int materialIdx = aiMesh.mMaterialIndex(); if (materialIdx >= 0 && materialIdx < materials.size()) { material = materials.get(materialIdx); } else { material = new Material(); } mesh.setMaterial(material); return mesh; }
Example #7
Source File: AnimMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
public static AnimGameItem loadAnimGameItem(String resourcePath, String texturesDir, int flags) throws Exception { AIScene aiScene = aiImportFile(resourcePath, flags); if (aiScene == null) { throw new Exception("Error loading model"); } int numMaterials = aiScene.mNumMaterials(); PointerBuffer aiMaterials = aiScene.mMaterials(); List<Material> materials = new ArrayList<>(); for (int i = 0; i < numMaterials; i++) { AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i)); processMaterial(aiMaterial, materials, texturesDir); } List<Bone> boneList = new ArrayList<>(); int numMeshes = aiScene.mNumMeshes(); PointerBuffer aiMeshes = aiScene.mMeshes(); Mesh[] meshes = new Mesh[numMeshes]; for (int i = 0; i < numMeshes; i++) { AIMesh aiMesh = AIMesh.create(aiMeshes.get(i)); Mesh mesh = processMesh(aiMesh, materials, boneList); meshes[i] = mesh; } AINode aiRootNode = aiScene.mRootNode(); Matrix4f rootTransfromation = AnimMeshesLoader.toMatrix(aiRootNode.mTransformation()); Node rootNode = processNodesHierarchy(aiRootNode, null); Map<String, Animation> animations = processAnimations(aiScene, boneList, rootNode, rootTransfromation); AnimGameItem item = new AnimGameItem(meshes, animations); return item; }
Example #8
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
protected static void processVertices(AIMesh aiMesh, List<Float> vertices) { AIVector3D.Buffer aiVertices = aiMesh.mVertices(); while (aiVertices.remaining() > 0) { AIVector3D aiVertex = aiVertices.get(); vertices.add(aiVertex.x()); vertices.add(aiVertex.y()); vertices.add(aiVertex.z()); } }
Example #9
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
protected static void processTextCoords(AIMesh aiMesh, List<Float> textures) { AIVector3D.Buffer textCoords = aiMesh.mTextureCoords(0); int numTextCoords = textCoords != null ? textCoords.remaining() : 0; for (int i = 0; i < numTextCoords; i++) { AIVector3D textCoord = textCoords.get(); textures.add(textCoord.x()); textures.add(1 - textCoord.y()); } }
Example #10
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
protected static void processNormals(AIMesh aiMesh, List<Float> normals) { AIVector3D.Buffer aiNormals = aiMesh.mNormals(); while (aiNormals != null && aiNormals.remaining() > 0) { AIVector3D aiNormal = aiNormals.get(); normals.add(aiNormal.x()); normals.add(aiNormal.y()); normals.add(aiNormal.z()); } }
Example #11
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials) { List<Float> vertices = new ArrayList<>(); List<Float> textures = new ArrayList<>(); List<Float> normals = new ArrayList<>(); List<Integer> indices = new ArrayList<>(); processVertices(aiMesh, vertices); processNormals(aiMesh, normals); processTextCoords(aiMesh, textures); processIndices(aiMesh, indices); // Texture coordinates may not have been populated. We need at least the empty slots if ( textures.size() == 0) { int numElements = (vertices.size() / 3) * 2; for (int i=0; i<numElements; i++) { textures.add(0.0f); } } Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures), Utils.listToArray(normals), Utils.listIntToArray(indices)); Material material; int materialIdx = aiMesh.mMaterialIndex(); if (materialIdx >= 0 && materialIdx < materials.size()) { material = materials.get(materialIdx); } else { material = new Material(); } mesh.setMaterial(material); return mesh; }
Example #12
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
protected static void processIndices(AIMesh aiMesh, List<Integer> indices) { int numFaces = aiMesh.mNumFaces(); AIFace.Buffer aiFaces = aiMesh.mFaces(); for (int i = 0; i < numFaces; i++) { AIFace aiFace = aiFaces.get(i); IntBuffer buffer = aiFace.mIndices(); while (buffer.remaining() > 0) { indices.add(buffer.get()); } } }
Example #13
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static void processIndices(AIMesh aiMesh, List<Integer> indices) { int numFaces = aiMesh.mNumFaces(); AIFace.Buffer aiFaces = aiMesh.mFaces(); for (int i = 0; i < numFaces; i++) { AIFace aiFace = aiFaces.get(i); IntBuffer buffer = aiFace.mIndices(); while (buffer.remaining() > 0) { indices.add(buffer.get()); } } }
Example #14
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static void processTextCoords(AIMesh aiMesh, List<Float> textures) { AIVector3D.Buffer textCoords = aiMesh.mTextureCoords(0); int numTextCoords = textCoords != null ? textCoords.remaining() : 0; for (int i = 0; i < numTextCoords; i++) { AIVector3D textCoord = textCoords.get(); textures.add(textCoord.x()); textures.add(1 - textCoord.y()); } }
Example #15
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static void processNormals(AIMesh aiMesh, List<Float> normals) { AIVector3D.Buffer aiNormals = aiMesh.mNormals(); while (aiNormals != null && aiNormals.remaining() > 0) { AIVector3D aiNormal = aiNormals.get(); normals.add(aiNormal.x()); normals.add(aiNormal.y()); normals.add(aiNormal.z()); } }
Example #16
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static void processVertices(AIMesh aiMesh, List<Float> vertices) { AIVector3D.Buffer aiVertices = aiMesh.mVertices(); while (aiVertices.remaining() > 0) { AIVector3D aiVertex = aiVertices.get(); vertices.add(aiVertex.x()); vertices.add(aiVertex.y()); vertices.add(aiVertex.z()); } }
Example #17
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials) { List<Float> vertices = new ArrayList<>(); List<Float> textures = new ArrayList<>(); List<Float> normals = new ArrayList<>(); List<Integer> indices = new ArrayList<>(); processVertices(aiMesh, vertices); processNormals(aiMesh, normals); processTextCoords(aiMesh, textures); processIndices(aiMesh, indices); // Texture coordinates may not have been populated. We need at least the empty slots if ( textures.size() == 0) { int numElements = (vertices.size() / 3) * 2; for (int i=0; i<numElements; i++) { textures.add(0.0f); } } Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures), Utils.listToArray(normals), Utils.listIntToArray(indices) ); Material material; int materialIdx = aiMesh.mMaterialIndex(); if (materialIdx >= 0 && materialIdx < materials.size()) { material = materials.get(materialIdx); } else { material = new Material(); } mesh.setMaterial(material); return mesh; }
Example #18
Source File: AnimMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials, List<Bone> boneList) { List<Float> vertices = new ArrayList<>(); List<Float> textures = new ArrayList<>(); List<Float> normals = new ArrayList<>(); List<Integer> indices = new ArrayList<>(); List<Integer> boneIds = new ArrayList<>(); List<Float> weights = new ArrayList<>(); processVertices(aiMesh, vertices); processNormals(aiMesh, normals); processTextCoords(aiMesh, textures); processIndices(aiMesh, indices); processBones(aiMesh, boneList, boneIds, weights); // Texture coordinates may not have been populated. We need at least the empty slots if ( textures.size() == 0) { int numElements = (vertices.size() / 3) * 2; for (int i=0; i<numElements; i++) { textures.add(0.0f); } } Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures), Utils.listToArray(normals), Utils.listIntToArray(indices), Utils.listIntToArray(boneIds), Utils.listToArray(weights)); Material material; int materialIdx = aiMesh.mMaterialIndex(); if (materialIdx >= 0 && materialIdx < materials.size()) { material = materials.get(materialIdx); } else { material = new Material(); } mesh.setMaterial(material); return mesh; }
Example #19
Source File: AnimMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
public static AnimGameItem loadAnimGameItem(String resourcePath, String texturesDir, int flags) throws Exception { AIScene aiScene = aiImportFile(resourcePath, flags); if (aiScene == null) { throw new Exception("Error loading model"); } int numMaterials = aiScene.mNumMaterials(); PointerBuffer aiMaterials = aiScene.mMaterials(); List<Material> materials = new ArrayList<>(); for (int i = 0; i < numMaterials; i++) { AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i)); processMaterial(aiMaterial, materials, texturesDir); } List<Bone> boneList = new ArrayList<>(); int numMeshes = aiScene.mNumMeshes(); PointerBuffer aiMeshes = aiScene.mMeshes(); Mesh[] meshes = new Mesh[numMeshes]; for (int i = 0; i < numMeshes; i++) { AIMesh aiMesh = AIMesh.create(aiMeshes.get(i)); Mesh mesh = processMesh(aiMesh, materials, boneList); meshes[i] = mesh; } AINode aiRootNode = aiScene.mRootNode(); Matrix4f rootTransfromation = AnimMeshesLoader.toMatrix(aiRootNode.mTransformation()); Node rootNode = processNodesHierarchy(aiRootNode, null); Map<String, Animation> animations = processAnimations(aiScene, boneList, rootNode, rootTransfromation); AnimGameItem item = new AnimGameItem(meshes, animations); return item; }
Example #20
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
protected static void processVertices(AIMesh aiMesh, List<Float> vertices) { AIVector3D.Buffer aiVertices = aiMesh.mVertices(); while (aiVertices.remaining() > 0) { AIVector3D aiVertex = aiVertices.get(); vertices.add(aiVertex.x()); vertices.add(aiVertex.y()); vertices.add(aiVertex.z()); } }
Example #21
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
protected static void processTextCoords(AIMesh aiMesh, List<Float> textures) { AIVector3D.Buffer textCoords = aiMesh.mTextureCoords(0); int numTextCoords = textCoords != null ? textCoords.remaining() : 0; for (int i = 0; i < numTextCoords; i++) { AIVector3D textCoord = textCoords.get(); textures.add(textCoord.x()); textures.add(1 - textCoord.y()); } }
Example #22
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
protected static void processNormals(AIMesh aiMesh, List<Float> normals) { AIVector3D.Buffer aiNormals = aiMesh.mNormals(); while (aiNormals != null && aiNormals.remaining() > 0) { AIVector3D aiNormal = aiNormals.get(); normals.add(aiNormal.x()); normals.add(aiNormal.y()); normals.add(aiNormal.z()); } }
Example #23
Source File: StaticMeshesLoader.java From lwjglbook with Apache License 2.0 | 5 votes |
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials) { List<Float> vertices = new ArrayList<>(); List<Float> textures = new ArrayList<>(); List<Float> normals = new ArrayList<>(); List<Integer> indices = new ArrayList<>(); processVertices(aiMesh, vertices); processNormals(aiMesh, normals); processTextCoords(aiMesh, textures); processIndices(aiMesh, indices); // Texture coordinates may not have been populated. We need at least the empty slots if ( textures.size() == 0) { int numElements = (vertices.size() / 3) * 2; for (int i=0; i<numElements; i++) { textures.add(0.0f); } } Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures), Utils.listToArray(normals), Utils.listIntToArray(indices)); Material material; int materialIdx = aiMesh.mMaterialIndex(); if (materialIdx >= 0 && materialIdx < materials.size()) { material = materials.get(materialIdx); } else { material = new Material(); } mesh.setMaterial(material); return mesh; }
Example #24
Source File: AssimpAPI.java From WraithEngine with Apache License 2.0 | 4 votes |
@Override public IAssimpMesh getMesh(int index) { return new AssimpMesh(AIMesh.create(scene.mMeshes() .get(index))); }
Example #25
Source File: AssimpAPI.java From WraithEngine with Apache License 2.0 | 4 votes |
private AssimpMesh(AIMesh mesh) { this.mesh = mesh; }
Example #26
Source File: AssimpAPI.java From WraithEngine with Apache License 2.0 | 4 votes |
@Override public IAssimpMesh getMesh(int index) { return new AssimpMesh(AIMesh.create(scene.mMeshes() .get(index))); }
Example #27
Source File: AssimpAPI.java From WraithEngine with Apache License 2.0 | 4 votes |
private AssimpMesh(AIMesh mesh) { this.mesh = mesh; }