Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I import Blender specular value via glTF Assimp import? #909

Open
wedesoft opened this issue Aug 9, 2023 · 1 comment
Open

How can I import Blender specular value via glTF Assimp import? #909

wedesoft opened this issue Aug 9, 2023 · 1 comment

Comments

@wedesoft
Copy link

wedesoft commented Aug 9, 2023

Question

I created a textured sample cube in Blender and exported it as glTF. I am using Assimp from LWJGL 3.3.2 and it is working quite well and I managed to access faces, vertices, normals, as well as texture coordinates and the texture itself. However I am struggling to understand the material properties interface.
I managed to access the roughness and metallic factor but I can't see a way to access the specular value.

(import '[org.lwjgl.assimp Assimp AIMaterial AIMaterialProperty])
(import '[org.lwjgl PointerBuffer])

(def scene (Assimp/aiImportFile "etc/cube.gltf" Assimp/aiProcess_Triangulate))

(.mNumMaterials scene)
; 2
(def material (AIMaterial/create ^long (.get (.mMaterials scene) 0)))

(def properties (map #(AIMaterialProperty/create (.get (.mProperties material) %)) (range (.mNumProperties material))))

(map (fn [prop] (.dataString (.mKey prop))) properties)
; ("?mat.name" "$clr.diffuse" "$clr.base" "$tex.file" "$tex.uvwsrc" "$tex.mappingname" "$tex.mappingid" "$tex.mapmodeu"
; "$tex.mapmodev" "$tex.mappingfiltermag" "$tex.mappingfiltermin" "$tex.file" "$tex.uvwsrc" "$tex.mappingname"
; "$tex.mappingid" "$tex.mapmodeu" "$tex.mapmodev" "$tex.mappingfiltermag" "$tex.mappingfiltermin" 
; "$mat.metallicFactor" "$mat.roughnessFactor" "$mat.shininess" "$clr.emissive" "$mat.twosided" "$mat.opacity" 
; "$mat.gltf.alphaMode" "$mat.gltf.alphaCutoff" "$mat.shadingm")

(def p (PointerBuffer/allocateDirect 1))
(Assimp/aiGetMaterialProperty material Assimp/AI_MATKEY_ROUGHNESS_FACTOR 0 0 p)
; 0
(.getFloat (.mData (AIMaterialProperty/create ^long (.get p 0))))
; 0.3

(def p (PointerBuffer/allocateDirect 1))
(Assimp/aiGetMaterialProperty material Assimp/AI_MATKEY_METALLIC_FACTOR 0 0 p)
; 0
(.getFloat (.mData (AIMaterialProperty/create ^long (.get p 0))))
; 0.1

(def p (PointerBuffer/allocateDirect 1))
(Assimp/aiGetMaterialProperty material Assimp/AI_MATKEY_SPECULAR_FACTOR 0 0 p)
; -1

(def color (AIColor4D/create))
(Assimp/aiGetMaterialColor material Assimp/AI_MATKEY_COLOR_DIFFUSE Assimp/aiTextureType_NONE 0 color)
; 0
(Assimp/aiGetMaterialColor material Assimp/AI_MATKEY_COLOR_SPECULAR Assimp/aiTextureType_NONE 0 color)
; -1

In Blender the specular value is 0.2 and I can see the value 0.4 under "specularColorFactor" in the glTF file:

{
  "asset":{
    "generator":"Khronos glTF Blender I/O v3.6.27",
    "version":"2.0"
  },
  "extensionsUsed":[
    "KHR_materials_specular"
  ],
  "scene":0,
  "scenes":[
    {
      "name":"Scene",
      "nodes":[
        0
      ]
    }
  ],
  "nodes":[
    {
      "mesh":0,
      "name":"Cube"
    }
  ],
  "materials":[
    {
      "doubleSided":true,
      "extensions":{
        "KHR_materials_specular":{
          "specularColorFactor":[
            0.4000000059604644,
            0.4000000059604644,
            0.4000000059604644
          ]
        }
      },
      "name":"Material.002",
      "pbrMetallicRoughness":{
        "baseColorTexture":{
          "index":0
        },
        "metallicFactor":0.10000000149011612,
        "roughnessFactor":0.30000001192092896
      }
    }
  ],
  ...
}

I have tried to import the Blender file instead but that doesn't seem to expose texture coordinates and normal vectors (and maybe other entries).

@wedesoft
Copy link
Author

Looks like it was reported at assimp/assimp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant