[英]JSON images url instead of base64
I'm using Three.js to save and load objects in a database. 我正在使用Three.js在数据库中保存和加载对象。 I'm inserting my objects as JSON.
我将对象插入为JSON。
The problem is that JSON.stringify or toJSON() transform the image url (textures) in base64, and I wanted to keep the http url. 问题是JSON.stringify或toJSON()在base64中转换了图像URL(纹理),而我想保留http URL。
This is the originial JSON: 这是原始的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": {
[...]
}
}
And the desired kind of JSON would be this : 所需的JSON类型是:
{
"metadata": {
[...]
},
"geometries": [
{
[...]
}],
"materials": [
{
[...]
}],
"textures": [
{
[...]
}],
"images": [
{
"uuid": "4ED9CE3E-7C8A-4EB7-8CF8-D90B3527DF5F",
"url": "http://www.domain.com/picture/path.png"
}],
"object": {
[...]
}
}
Is there a solution to do this ? 有解决方案吗?
After studying the JSON file and getting my texture path, I did the following: 研究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
And now it did the trick ! 现在它成功了! :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.