尝试更改json (gltf)并将其保存为php



我正在尝试用php改变gltf的纹理;

$jsonString = file_get_contents('jsonFile.gltf');
$data = json_decode($jsonString, true);
foreach ($data as $key => $entry) {
if ($entry['uri'] == 'textures/CARA_A_baseColor.jpeg') {
$data[$key]['uri'] = "textures/Another_baseColor.jpeg";
}
}
$newJsonString = json_encode($data);
file_put_contents('jsonFile.gltf', $newJsonString);
echo "bitti";

这里是我想修改的代码;

"images": [
{
"uri": "textures/CARA_A_baseColor.jpeg"
},
{
"uri": "textures/CARA_B_baseColor.jpeg"
},
{
"uri": "textures/GLASS_normal.jpeg"
}
],

我想用新值(textures/Another_baseColor.jpeg)改变第一个子(textures/CARA_A_baseColor.jpeg)并再次保存它。有谁能帮我理解一下,我怎么才能选择"images"然后改变它。Ty。

$jsonString = file_get_contents('jsonFile.gltf');
$data = json_decode($jsonString, true);
$data['images'][0]['uri'] = "textures/Another_baseColor.jpeg";
$newJsonString = json_encode($data);
file_put_contents('jsonFile.gltf', $newJsonString);
echo "bitti";
我用上面的代码解决了我的问题,谢谢你

最新更新