org.lwjgl.assimp.Assimp Java Examples

The following examples show how to use org.lwjgl.assimp.Assimp. 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 vote down vote up
@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: AssimpAPI.java    From WraithEngine with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: AssimpAPI.java    From WraithEngine with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose()
{
    if (isDisposed())
        return;

    disposed = true;
    Assimp.aiReleaseImport(scene);
}
 
Example #4
Source File: VkAssimpModelLoader.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
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 #5
Source File: GLAssimpModelLoader.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
private static Material processMaterial(AIMaterial aiMaterial, String texturesDir) {

		// diffuse Texture
	    AIString diffPath = AIString.calloc();
	    Assimp.aiGetMaterialTexture(aiMaterial, Assimp.aiTextureType_DIFFUSE, 0, diffPath, (IntBuffer) null, null, null, null, null, null);
	    String diffTexPath = diffPath.dataString();
	    
	    GLTexture diffuseTexture = null;
	    if (diffTexPath != null && diffTexPath.length() > 0) {
	    	diffuseTexture = new TextureImage2D(texturesDir + "/" + diffTexPath, SamplerFilter.Trilinear);
	    }
	    
	    // normal Texture
	    AIString normalPath = AIString.calloc();
	    Assimp.aiGetMaterialTexture(aiMaterial, Assimp.aiTextureType_NORMALS, 0, normalPath, (IntBuffer) null, null, null, null, null, null);
	    String normalTexPath = normalPath.dataString();
	    
	    GLTexture normalTexture = null;
	    if (normalTexPath != null && normalTexPath.length() > 0) {
	    	normalTexture = new TextureImage2D(texturesDir + "/" + normalTexPath, SamplerFilter.Trilinear);
	    }

	    AIColor4D color = AIColor4D.create();
	    
	    Vec3f diffuseColor = null;
	    int result = Assimp.aiGetMaterialColor(aiMaterial, Assimp.AI_MATKEY_COLOR_AMBIENT, Assimp.aiTextureType_NONE, 0, color);
	    if (result == 0) {
	    	diffuseColor = new Vec3f(color.r(), color.g(), color.b());
	    }

	    Material material = new Material();
	    material.setDiffusemap(diffuseTexture);
	    material.setNormalmap(normalTexture);
	    material.setColor(diffuseColor);
	    
	    return material;
	}
 
Example #6
Source File: AssimpAPI.java    From WraithEngine with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose()
{
    if (isDisposed())
        return;

    disposed = true;
    Assimp.aiReleaseImport(scene);
}