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

升级tiny_gltf.h到 2.9.3,纹理无法显示 #325

Open
eurekao opened this issue Nov 17, 2024 · 2 comments
Open

升级tiny_gltf.h到 2.9.3,纹理无法显示 #325

eurekao opened this issue Nov 17, 2024 · 2 comments

Comments

@eurekao
Copy link

eurekao commented Nov 17, 2024

适配最新版 tiny_gltf.h,只做了以下改动,转换后发现纹理没有了。

tinygltf::Material make_color_material_osgb(double r, double g, double b) {
     tinygltf::Material material;
     material.name = "default";
@@ -458,10 +536,10 @@ tinygltf::Material make_color_material_osgb(double r, double g, double b) {
     material.values["baseColorFactor"] = baseColorFactor;
 
     tinygltf::Parameter metallicFactor;
-    metallicFactor.number_value = 0;
+    metallicFactor.number_value = new double(0);
     material.values["metallicFactor"] = metallicFactor;
     tinygltf::Parameter roughnessFactor;
-    roughnessFactor.number_value = 1;
+    roughnessFactor.number_value = new double(1);
     material.values["roughnessFactor"] = roughnessFactor;
     //
     return material;
@@ -909,20 +987,19 @@ bool osgb2glb_buf(std::string path, std::string& glb_buff, MeshInfo& mesh_info,
         sample.wrapT = TINYGLTF_TEXTURE_WRAP_REPEAT;
         model.samplers = { sample };
     }
-
     // use KHR_materials_unlit
     model.extensionsRequired = { "KHR_materials_unlit" };
     model.extensionsUsed = { "KHR_materials_unlit" };
-    for (int i = 0; i < infoVisitor.texture_array.size(); i++)
+    for (int i = 0 ; i < infoVisitor.texture_array.size(); i++)
     {
         tinygltf::Material mat = make_color_material_osgb(1.0, 1.0, 1.0);
+        mat.b_unlit = true; // use KHR_materials_unlit
         tinygltf::Parameter baseColorTexture;
-        baseColorTexture.json_double_value = { std::pair<string,int>("index",i) };
+        baseColorTexture.json_int_value = { std::pair<string,int>("index",i) };
         mat.values["baseColorTexture"] = baseColorTexture;
         model.materials.push_back(mat);
     }
     model.asset.generator = "fanvanzh";
 
-    std::ostringstream oss;
-
-    if (gltf.WriteGltfSceneToStream(&model, oss, false, true)) {
-        glb_buff = oss.str();
-        return true;
-    }
-    return false;
+    glb_buff = gltf.Serialize(&model);
+    return true;
 }

test.osgb转换出来时这样的:
屏幕截图 2024-11-17 225115

@fanvanzh
Copy link
Owner

不清楚哎,是 mat.b_unlit 原因吗

@eurekao
Copy link
Author

eurekao commented Nov 18, 2024

不清楚哎,是 mat.b_unlit 原因吗

新版tinyGltf没有这个参数了

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

No branches or pull requests

2 participants