fanvanzh / 3dtiles

The fastest tools for 3dtiles convert in the world!
Apache License 2.0
1.98k stars 594 forks source link

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

Open eurekao opened 6 days ago

eurekao commented 6 days ago

适配最新版 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 commented 6 days ago

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

eurekao commented 5 days ago

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

新版tinyGltf没有这个参数了