未验证 提交 8b71831e 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #17968 from Mugen87/dev29

Material: Introduce version property.
......@@ -186,8 +186,7 @@
<h3>[property:Boolean needsUpdate]</h3>
<p>
Specifies that the material needs to be recompiled.<br />
This property is automatically set to *true* when instancing a new material.
Specifies that the material needs to be recompiled.
</p>
<h3>[property:Float opacity]</h3>
......@@ -296,6 +295,11 @@
This gets automatically assigned, so this shouldn't be edited.
</p>
<h3>[property:Integer version]</h3>
<p>
This starts at *0* and counts how many times [property:Boolean needsUpdate] is set to *true*.
</p>
<h3>[property:Integer vertexColors]</h3>
<p>
Defines whether vertex coloring is used.
......
......@@ -163,8 +163,7 @@ Which stencil operation to perform when the comparison function returns true and
<p>对象的可选名称(不必是唯一的)。默认值为空字符串。</p>
<h3>[property:Boolean needsUpdate]</h3>
<p>指定需要重新编译材质。<br/>
实例化新材质时,此属性自动设置为true。
<p>指定需要重新编译材质。
</p>
<h3>[property:Float opacity]</h3>
......@@ -255,6 +254,11 @@ Defines whether this material is tone mapped according to the renderer's [page:W
<p> 此材质实例的[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID],会自动分配,不应该被更改。
</p>
<h3>[property:Integer version]</h3>
<p>
This starts at *0* and counts how many times [property:Boolean needsUpdate] is set to *true*.
</p>
<h3>[property:Integer vertexColors]</h3>
<p> 是否使用顶点着色。默认值为[page:Materials THREE.NoColors]。
其他选项有[page:Materials THREE.VertexColors] 和 [page:Materials THREE.FaceColors]。
......
......@@ -30,7 +30,9 @@ function NodeMaterial( vertex, fragment ) {
this.onBeforeCompile = function ( shader, renderer ) {
if ( this.needsUpdate ) {
var materialProperties = renderer.properties.get( this );
if ( this.version !== materialProperties.__version ) {
this.build( { renderer: renderer } );
......@@ -74,6 +76,7 @@ Object.defineProperties( NodeMaterial.prototype, {
set: function ( value ) {
if ( value === true ) this.version ++;
this.needsCompile = value;
},
......@@ -120,8 +123,6 @@ NodeMaterial.prototype.build = function ( params ) {
this.transparent = builder.requires.transparent || this.blending > NormalBlending;
this.needsUpdate = false;
return this;
};
......
......@@ -293,6 +293,11 @@ export class Material extends EventDispatcher {
*/
userData: any;
/**
* This starts at 0 and counts how many times .needsUpdate is set to true.
*/
version: number;
/**
* Return a new material with the same parameters as this material.
*/
......
......@@ -74,7 +74,7 @@ function Material() {
this.userData = {};
this.needsUpdate = true;
this.version = 0;
}
......@@ -422,5 +422,14 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
} );
Object.defineProperty( Material.prototype, 'needsUpdate', {
set: function ( value ) {
if ( value === true ) this.version ++;
}
} );
export { Material };
......@@ -1675,7 +1675,7 @@ function WebGLRenderer( parameters ) {
}
if ( material.needsUpdate === false ) {
if ( material.version === materialProperties.__version ) {
if ( materialProperties.program === undefined ) {
......@@ -1699,10 +1699,10 @@ function WebGLRenderer( parameters ) {
}
if ( material.needsUpdate ) {
if ( material.version !== materialProperties.__version ) {
initMaterial( material, fog, object );
material.needsUpdate = false;
materialProperties.__version = material.version;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册