1
好的,我已經用JSON加載程序導入了多材質對象,並且試圖在運行時訪問每種材質。
基本上我喜歡修改進口材料的顏色。Three.js - 在運行時更改JSON材質
任何人都可以指導我如何實現它,或者它可能嗎?
謝謝。
JSON
{
"vertices": [-0.889175,-0.389516,-0.407662,-0.889175,0.521047,-0.407662,-0.889175,-0.389516,-1.31822,-0.889175,0.521046,-1.31822,0.021387,-0.389516,-0.407662,0.021387,0.521047,-0.407662,0.021387,-0.389516,-1.31822,0.021387,0.521046,-1.31822],
"normals": [-0.577349,-0.577349,-0.577349,-0.577349,-0.577349,0.577349,-0.577349,0.577349,0.577349,-0.577349,0.577349,-0.577349,0.577349,0.577349,-0.577349,0.577349,-0.577349,-0.577349,0.577349,0.577349,0.577349,0.577349,-0.577349,0.577349],
"faces": [35,2,0,1,3,0,0,1,2,3,35,3,7,6,2,1,3,4,5,0,35,7,5,4,6,0,4,6,7,5,35,0,4,5,1,1,1,7,6,2,35,0,2,6,4,1,1,0,5,7,35,5,7,3,1,1,6,4,3,2],
"name": "CubeGeometry.2",
"uvs": [],
"colors": [],
"metadata": {
"version": 3,
"normals": 8,
"faces": 6,
"uvs": 0,
"colors": 0,
"materials": 2,
"vertices": 8,
"generator": "io_three",
"type": "Geometry"
},
"materials": [{
"specularCoef": 50,
"DbgIndex": 1,
"wireframe": false,
"opacity": 1,
"visible": true,
"DbgName": "material2",
"depthTest": true,
"blending": "NormalBlending",
"transparent": false,
"shading": "phong",
"colorEmissive": [0,0,0],
"colorDiffuse": [0.64,0.64,0.64],
"DbgColor": 15597568,
"depthWrite": true,
"colorSpecular": [0.5,0.5,0.5],
"vertexColors": false,
"colorAmbient": [0.64,0.64,0.64]
},{
"specularCoef": 50,
"DbgIndex": 0,
"wireframe": false,
"opacity": 1,
"visible": true,
"DbgName": "material1",
"depthTest": true,
"blending": "NormalBlending",
"transparent": false,
"shading": "phong",
"colorEmissive": [0,0,0],
"colorDiffuse": [0.64,0.64,0.64],
"DbgColor": 15658734,
"depthWrite": true,
"colorSpecular": [0.5,0.5,0.5],
"vertexColors": false,
"colorAmbient": [0.64,0.64,0.64]
}]
}
JSON裝載機,並添加到現場
var loader = new THREE.JSONLoader();
loader.load("test.js", function(geometry, materials){
var mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
scene.add(mesh);
});