org.lwjgl.assimp.AIScene Java Examples
The following examples show how to use
org.lwjgl.assimp.AIScene.
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: AssimpAPI.java From WraithEngine with Apache License 2.0 | 7 votes |
@Override public IAssimpScene loadScene(File file) { AIPropertyStore settings = Assimp.aiCreatePropertyStore(); Assimp.aiSetImportPropertyInteger(settings, Assimp.AI_CONFIG_PP_SLM_VERTEX_LIMIT, 65535); AIScene scene = Assimp.aiImportFile(file.toString(), Assimp.aiProcess_Triangulate | Assimp.aiProcess_GenSmoothNormals | Assimp.aiProcess_FlipUVs | Assimp.aiProcess_CalcTangentSpace | Assimp.aiProcess_LimitBoneWeights | Assimp.aiProcess_SplitLargeMeshes | Assimp.aiProcess_OptimizeMeshes | Assimp.aiProcess_JoinIdenticalVertices); Assimp.aiReleasePropertyStore(settings); if (scene == null) return null; return new AssimpScene(scene); }
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 [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 #3
Source File: AnimMeshesLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
private static Map<String, Animation> processAnimations(AIScene aiScene, List<Bone> boneList, Node rootNode, Matrix4f rootTransformation) { Map<String, Animation> animations = new HashMap<>(); // Process all animations int numAnimations = aiScene.mNumAnimations(); PointerBuffer aiAnimations = aiScene.mAnimations(); for (int i = 0; i < numAnimations; i++) { AIAnimation aiAnimation = AIAnimation.create(aiAnimations.get(i)); // Calculate transformation matrices for each node int numChanels = aiAnimation.mNumChannels(); PointerBuffer aiChannels = aiAnimation.mChannels(); for (int j = 0; j < numChanels; j++) { AINodeAnim aiNodeAnim = AINodeAnim.create(aiChannels.get(j)); String nodeName = aiNodeAnim.mNodeName().dataString(); Node node = rootNode.findByName(nodeName); buildTransFormationMatrices(aiNodeAnim, node); } List<AnimatedFrame> frames = buildAnimationFrames(boneList, rootNode, rootTransformation); Animation animation = new Animation(aiAnimation.mName().dataString(), frames, aiAnimation.mDuration()); animations.put(animation.getName(), animation); } return animations; }
Example #4
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 #5
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 #6
Source File: AnimMeshesLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
private static Map<String, Animation> processAnimations(AIScene aiScene, List<Bone> boneList, Node rootNode, Matrix4f rootTransformation) { Map<String, Animation> animations = new HashMap<>(); // Process all animations int numAnimations = aiScene.mNumAnimations(); PointerBuffer aiAnimations = aiScene.mAnimations(); for (int i = 0; i < numAnimations; i++) { AIAnimation aiAnimation = AIAnimation.create(aiAnimations.get(i)); // Calculate transformation matrices for each node int numChanels = aiAnimation.mNumChannels(); PointerBuffer aiChannels = aiAnimation.mChannels(); for (int j = 0; j < numChanels; j++) { AINodeAnim aiNodeAnim = AINodeAnim.create(aiChannels.get(j)); String nodeName = aiNodeAnim.mNodeName().dataString(); Node node = rootNode.findByName(nodeName); buildTransFormationMatrices(aiNodeAnim, node); } List<AnimatedFrame> frames = buildAnimationFrames(boneList, rootNode, rootTransformation); Animation animation = new Animation(aiAnimation.mName().dataString(), frames, aiAnimation.mDuration()); animations.put(animation.getName(), animation); } return animations; }
Example #7
Source File: AssimpAPI.java From WraithEngine with Apache License 2.0 | 6 votes |
@Override public IAssimpScene loadScene(File file) { AIPropertyStore settings = Assimp.aiCreatePropertyStore(); Assimp.aiSetImportPropertyInteger(settings, Assimp.AI_CONFIG_PP_SLM_VERTEX_LIMIT, 65535); AIScene scene = Assimp.aiImportFile(file.toString(), Assimp.aiProcess_Triangulate | Assimp.aiProcess_GenSmoothNormals | Assimp.aiProcess_FlipUVs | Assimp.aiProcess_CalcTangentSpace | Assimp.aiProcess_LimitBoneWeights | Assimp.aiProcess_SplitLargeMeshes | Assimp.aiProcess_OptimizeMeshes | Assimp.aiProcess_JoinIdenticalVertices); Assimp.aiReleasePropertyStore(settings); if (scene == null) return null; return new AssimpScene(scene); }
Example #8
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 #9
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 #10
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 #11
Source File: AssimpAPI.java From WraithEngine with Apache License 2.0 | 4 votes |
private AssimpScene(AIScene scene) { this.scene = scene; }
Example #12
Source File: AssimpAPI.java From WraithEngine with Apache License 2.0 | 4 votes |
private AssimpScene(AIScene scene) { this.scene = scene; }