【发布时间】:2015-08-28 04:23:26
【问题描述】:
我在我的场景中添加了一个带有MeshPhongMaterial 的对象。我想窥探三号在物体上设置的制服。我以为它会像obj.uniforms.uniformName 一样简单,但实际上并不存在。有没有简单的方法来获取运行时制服Three is setting?
我追求的是统一的名称和它们的值。
我想出的方法需要一个双循环。我可以在运行材料上看到的唯一有用的是material.uniformsList,它是WebGLUniformLocations 和值的列表,但没有名称。还有material.program.uniforms,它是WebGLUniformLocations 名称的键值存储。似乎可以将两者压缩在一起以获得统一列表,但有更好的方法吗?
let builtUniforms = {};
// For every uniform in the array, look for its location in the program
// uniforms to get the name
for( x = 0; uniform = object.material.uniformsList[ x++ ]; ) {
// uniform is [ { type, value }, WebGLUniformLocation ] but no name :(
for( uniformName in object.material.program.uniforms ) {
// If the WebGLUniformLocations match up, we've found the name
if( object.material.program.uniforms[ uniformName ] === uniform[ 1 ] ) {
builtUniforms[ uniformName ] = {
value: uniform[ 0 ].value,
name: uniformName
};
break;
}
}
}
- 有没有更直接的方法从 Three.Material 中获取统一的名称和值?
-
uniformsList或program.uniforms会改变吗?我是否需要在每个渲染循环中构建一次此对象,或者我可以构建一次并重新使用它?
【问题讨论】: