toJSON()
方法将 MeshGeometry
对象转换为 JSON 格式。
meshGeometryInstance.toJSON();
返回一个 JSON 格式的对象,包含 MeshGeometry
对象的数据。
var meshGeometry = new Yuka.MeshGeometry();
meshGeometry.fromBufferGeometry(new THREE.BoxBufferGeometry( 0.5, 0.5, 0.5 ));
var json = meshGeometry.toJSON();
console.log( json );
返回的 JSON 代码示例:
{
"indices": [0,1,2, 2,3,0],
"vertices": [0.25,-0.25,-0.25, 0.25,0.25,-0.25, -0.25,0.25,-0.25, -0.25,-0.25,-0.25, 0.25,-0.25,0.25, 0.25,0.25,0.25, -0.25,0.25,0.25, -0.25,-0.25,0.25],
"normals": [0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, 0,0,1, 0,0,1, 0,0,1, 0,0,1],
"uvs": [],
"name": "",
"type": "MeshGeometry"
}
返回的 JSON 对象具有以下属性:
indices
(Array): 一个包含索引数据的数组。vertices
(Array): 包含顶点数据的数组。normals
(Array): 包含法向量数据的数组。uvs
(Array): 包含纹理坐标数据的数组。name
(String): MeshGeometry
对象的名称。type
(String): 返回的对象类型,值为 MeshGeometry
。