ThreeJS获得运行材料的统一值

时间:2015-08-27 04:20:52

标签: three.js webgl shader

我在场景中添加了一个带有MeshPhongMaterial的对象。我想监视Three正在设置物体的制服。我认为它会像obj.uniforms.uniformName一样简单,但实际上并不存在。有没有一种简单的方法来获取运行时制服Three is setting

我所追求的是统一的名字及其价值。

我提出的方法需要双循环。我唯一能看到的有用的运行材料是material.uniformsList,它是WebGLUniformLocation和值的列表,但没有名称。还有material.program.uniforms,它是WebGLUniformLocation s的名称的键值存储。看起来你可以将两者拼接在一起以获得统一的列表,但是有更好的方法吗?

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;

        }
    }
}
  1. 是否有更简单的方法从Three.Material获取统一的名称和值?
  2. uniformsListprogram.uniforms会改变吗?我是否需要在每个渲染循环中构建一次此对象,或者我可以构建它一次并重新使用它吗?

0 个答案:

没有答案
相关问题