Assimp Material Loading in Java

Started by DanielUnleashed, February 26, 2017, 12:35:53

Previous topic - Next topic

DanielUnleashed

So, the name explains it very well:
I've been struggling with Assimp because I cannot get the properties of a material, and well, I'm searching for help or maybe a link where I can find information.
So far, this is what I got.
int numMaterials = scene.mNumMaterials();
		int[] materialRemap = new int[numMaterials];
		for(int i = 0; i < numMaterials; i++){
			AIMaterial material = new AIMaterial(scene.mMaterials().getByteBuffer(1288));
			for(int j = 0; j < material.mNumProperties(); j++){
				AIMaterialProperty prop = new AIMaterialProperty(material.mProperties().getByteBuffer(1288));
                                // What now?
			}
			material.close();
		}

Any help will be well received, thank you!

spasi

That is not the correct way to iterate the scene materials. Also, AIMaterialProperty structs are not usually accessed by the user directly, the more convenient aiGetMaterial<property> functions are used instead. Example code:

PointerBuffer materials = scene.mMaterials(); // array of pointers to AIMaterial structs
for ( int i = 0; i < materials.remaining(); i++ ) {
	AIMaterial material = AIMaterial.create(materials.get(i)); // wrap raw pointer in AIMaterial instance

	// Method 1: use aiGetMaterial<property> functions, e.g.
	int texCount = aiGetMaterialTextureCount(material, aiTextureType_DIFFUSE);

	// Method 2: Parse material properties manually
	PointerBuffer properties = material.mProperties(); // array of pointers to AIMaterialProperty structs
	for ( int j = 0; j < properties.remaining(); j++ ) {
		AIMaterialProperty prop = AIMaterialProperty.create(properties.get(j));
		// parse property
	}
}


Finally, material.close() or material.free() should not be called. The memory backing the materials is allocated by Assimp and is part of the AIScene object, it will be deallocated when you call aiReleaseImport(scene).

DanielUnleashed

Thank you sir, it worked as a charm!
But one final question, how do we parse the information of a AIMaterialProperties; I mean, how would I do, if I want to know all the name properties of the material?
And also, any sort of wiki or javadoc where I can found more info about Assimp?

spasi

The Assimp documentation is here. I don't think there's any information on how to parse material properties and I'm not sure why one would want to do it manually instead of using the aiGetMaterial* functions.

DanielUnleashed

Well, still huge thanks for the help :)

DanielUnleashed

One final question, how could I get a float from Assimp. I mean, getting for example de Index of Refracion, what method should I use?
aiGetMaterialFloatArray() maybe?  ???