好吧,我已经使用 JSON 加载器导入了一个多 Material 对象,我正在尝试在运行时访问每种 Material 。
基本上我喜欢修改导入 Material 的颜色。
任何人都可以指导我如何完成它,或者根本不可能吗?
谢谢。
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);
});
最佳答案
如果您使用的是 MultiMaterial
(以前称为 MeshFaceMaterial
),您可以像这样访问和更改 Material 颜色:
mesh.material.materials[ 0 ].color.set( 0xff0000 );
mesh.material.materials[ 1 ].color.setRGB( 1, 0, 0 );
研究 THREE.Color()
的文档以查看其他可接受的格式。
three.js r.73
关于javascript - Three.js - 在运行时更改 JSON Material ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33851010/