[英]How can I assign a constant value to attributes in Three.js
Basically what I am looking for is the Three.js equivalent to vertexAttrib
. 基本上,我正在寻找的是相当于
vertexAttrib
。 I intend to assign a constant value to my shader attribute. 我打算为我的着色器属性分配一个常量值。
You can do this by defining Material.defaultAttributeValues
. 您可以通过定义
Material.defaultAttributeValues
。 It's an object where the key
is the attribute name and the value
is the constant attribute value. 这是一个对象,其中
key
是属性名称,而value
是恒定属性值。 For example if you want to define a constant vertex color, you can do this: 例如,如果要定义恒定的顶点颜色,可以执行以下操作:
var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.VertexColors } );
material.defaultAttributeValues = {
color: [ 0, 0, 1 ] // blue
};
When doing so, it's important to avoid a buffer attribute definition with the same name. 这样做时,重要的是要避免使用相同名称的缓冲区属性定义。 Otherwise the geometry data are used and not the values from
defaultAttributeValues
. 否则,将使用几何数据,而不使用
defaultAttributeValues
的值。
In any event, consider to use uniforms if a property is equal for all vertices. 无论如何,如果所有顶点的属性均相等,请考虑使用制服。 The better alternative for the above example is to define
Material.color
. 上面示例的更好替代方法是定义
Material.color
。
three.js R106
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.