LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: Assimp Material Loading in Java  (Read 351 times)

DanielUnleashed

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
Assimp Material Loading in Java
« on: February 26, 2017, 12:35:53 »

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.
Code: [Select]
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!
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1762
Re: Assimp Material Loading in Java
« Reply #1 on: February 26, 2017, 15:40:37 »

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:

Code: [Select]
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).
Logged

DanielUnleashed

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
Re: Assimp Material Loading in Java
« Reply #2 on: February 27, 2017, 15:48:56 »

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?
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1762
Re: Assimp Material Loading in Java
« Reply #3 on: February 27, 2017, 18:15:41 »

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.
Logged

DanielUnleashed

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
Re: Assimp Material Loading in Java
« Reply #4 on: February 28, 2017, 19:04:57 »

Well, still huge thanks for the help :)
Logged

DanielUnleashed

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
Re: Assimp Material Loading in Java
« Reply #5 on: March 04, 2017, 11:24:35 »

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?  ???
Logged