[英]JSON images url instead of base64
我正在使用Three.js在數據庫中保存和加載對象。 我將對象插入為JSON。
問題是JSON.stringify或toJSON()在base64中轉換了圖像URL(紋理),而我想保留http URL。
這是原始的JSON:
{
"metadata": {
[...]
},
"geometries": [
{
[...]
}],
"materials": [
{
[...]
}],
"textures": [
{
[...]
}],
"images": [
{
"uuid": "4ED9CE3E-7C8A-4EB7-8CF8-D90B3527DF5F",
"url": "data:image/png;base64,iVBORw0KGgoATyuRZGZVREd0FAERRRBAEBEFwAYEyKqP/Rfozx+5fDYjvpeT/akv+n/J+/7eMjX9Ke8uojP4JVAYAyuj/Ld3Por7fPQ9i8d7vvr8LKNzLg/dn1u1hvQf3q/v92vRX0X/ [...]"
}],
"object": {
[...]
}
}
所需的JSON類型是:
{
"metadata": {
[...]
},
"geometries": [
{
[...]
}],
"materials": [
{
[...]
}],
"textures": [
{
[...]
}],
"images": [
{
"uuid": "4ED9CE3E-7C8A-4EB7-8CF8-D90B3527DF5F",
"url": "http://www.domain.com/picture/path.png"
}],
"object": {
[...]
}
}
有解決方案嗎?
研究JSON文件並獲取我的紋理路徑后,我執行了以下操作:
var objectParsed = SELECTED.toJSON(); //transform the selected object in JSON
textureBase64 = objectParsed.images[0].url; //get the value of the base64 encoded image
objectParsed.images[0].url = texMap; // replace the base64 encoded image with the http texture path
objectParsed = JSON.stringify( objectParsed, null, '\t' );
objectParsed = objectParsed.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' ); // make the JSON readable
現在它成功了! :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.