Skip to content

Commit

Permalink
Material: Add onBeforeRender() back. (#29043)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Aug 1, 2024
1 parent 93da17b commit cd600d7
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 7 deletions.
18 changes: 18 additions & 0 deletions docs/api/ar/materials/Material.html
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,24 @@ <h3>
على عكس الخصائص، لا يتم دعم رد الاتصال بواسطة [page:Material.clone .clone]()،
[page:Material.copy .copy]() و [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>
[method:undefined onBeforeRender]( [param:WebGLRenderer renderer], [param:Scene scene], [param:Camera camera], [param:BufferGeometry geometry], [param:Object3D object], [param:Group group] )
</h3>
<p>
An optional callback that is executed immediately before the material is used to
render a 3D object.
</p>
<p>
Unlike properties, the callback is not supported by [page:Material.clone .clone](),
[page:Material.copy .copy]() and [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>[method:String customProgramCacheKey]()</h3>
<p>
Expand Down
18 changes: 18 additions & 0 deletions docs/api/en/materials/Material.html
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,24 @@ <h3>
Unlike properties, the callback is not supported by [page:Material.clone .clone](),
[page:Material.copy .copy]() and [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>
[method:undefined onBeforeRender]( [param:WebGLRenderer renderer], [param:Scene scene], [param:Camera camera], [param:BufferGeometry geometry], [param:Object3D object], [param:Group group] )
</h3>
<p>
An optional callback that is executed immediately before the material is used to
render a 3D object.
</p>
<p>
Unlike properties, the callback is not supported by [page:Material.clone .clone](),
[page:Material.copy .copy]() and [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>[method:String customProgramCacheKey]()</h3>
<p>
Expand Down
18 changes: 18 additions & 0 deletions docs/api/fr/materials/Material.html
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ <h3>[method:undefined onBeforeCompile]( [param:Shader shader], [param:WebGLRende
<p>
Contrairement aux propriétés, le callback n'est pas pris en charge par [page:Material.clone .clone](), [page:Material.copy .copy]() et [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>
[method:undefined onBeforeRender]( [param:WebGLRenderer renderer], [param:Scene scene], [param:Camera camera], [param:BufferGeometry geometry], [param:Object3D object], [param:Group group] )
</h3>
<p>
An optional callback that is executed immediately before the material is used to
render a 3D object.
</p>
<p>
Unlike properties, the callback is not supported by [page:Material.clone .clone](),
[page:Material.copy .copy]() and [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>[method:String customProgramCacheKey]()</h3>
<p>
Expand Down
18 changes: 18 additions & 0 deletions docs/api/it/materials/Material.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,24 @@ <h3>[method:undefined onBeforeCompile]( [param:Shader shader], [param:WebGLRende
<p>
A differenza delle proprietà, la callback non è supportata da [page:Material.clone .clone](), [page:Material.copy .copy]() e [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>
[method:undefined onBeforeRender]( [param:WebGLRenderer renderer], [param:Scene scene], [param:Camera camera], [param:BufferGeometry geometry], [param:Object3D object], [param:Group group] )
</h3>
<p>
An optional callback that is executed immediately before the material is used to
render a 3D object.
</p>
<p>
Unlike properties, the callback is not supported by [page:Material.clone .clone](),
[page:Material.copy .copy]() and [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>[method:String customProgramCacheKey]()</h3>
<p>
Expand Down
18 changes: 18 additions & 0 deletions docs/api/zh/materials/Material.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,24 @@ <h3>[method:undefined onBeforeCompile]( [param:Shader shader], [param:WebGLRende
<p>
和其他属性不一样的是,这个回调在[page:Material.clone .clone](),[page:Material.copy .copy]() 和 [page:Material.toJSON .toJSON]() 中不支持。
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>
[method:undefined onBeforeRender]( [param:WebGLRenderer renderer], [param:Scene scene], [param:Camera camera], [param:BufferGeometry geometry], [param:Object3D object], [param:Group group] )
</h3>
<p>
An optional callback that is executed immediately before the material is used to
render a 3D object.
</p>
<p>
Unlike properties, the callback is not supported by [page:Material.clone .clone](),
[page:Material.copy .copy]() and [page:Material.toJSON .toJSON]().
</p>
<p>
This callback is only supported in `WebGLRenderer` (not `WebGPURenderer`).
</p>

<h3>[method:String customProgramCacheKey]()</h3>
<p>
Expand Down
11 changes: 4 additions & 7 deletions src/materials/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class Material extends EventDispatcher {

}

// onBeforeRender and onBeforeCompile only supported in WebGLRenderer

onBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {}

onBeforeCompile( /* shaderobject, renderer */ ) {}

customProgramCacheKey() {
Expand Down Expand Up @@ -522,13 +526,6 @@ class Material extends EventDispatcher {

}

onBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {

console.warn( 'Material: onBeforeRender() has been removed.' ); // @deprecated, r166

}


}

export { Material };
2 changes: 2 additions & 0 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,8 @@ class WebGLRenderer {
object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
object.normalMatrix.getNormalMatrix( object.modelViewMatrix );

material.onBeforeRender( _this, scene, camera, geometry, object, group );

if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {

material.side = BackSide;
Expand Down

0 comments on commit cd600d7

Please sign in to comment.