Skip to content

Commit

Permalink
feat: fire event while render mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
steel1990 committed Dec 23, 2024
1 parent 7249aa3 commit 85923a7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions build/Hilo3d.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/Hilo3d.single.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/math.single.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hilo3d",
"version": "1.19.0",
"version": "1.19.1",
"description": "Hilo3d, a WebGL 3d engine.",
"main": "build/Hilo3d.js",
"types": "types/index.d.ts",
Expand Down
17 changes: 15 additions & 2 deletions src/renderer/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,20 +882,30 @@ const WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */ {
* 渲染一个mesh
* @param {Mesh} mesh
*/
renderMesh(mesh) {
renderMesh(mesh, silent = false) {
if (!silent) {
mesh.fire('beforeRender', mesh);
}
const vao = this.setupMesh(mesh, false).vao;
vao.draw();
this.addRenderInfo(vao.vertexCount / 3, 1);
if (!silent) {
mesh.fire('afterRender', mesh);
}
},
/**
*
* 渲染一组 instanced mesh
* @param {Mesh[]} meshes
*/
renderInstancedMeshes(meshes) {
renderInstancedMeshes(meshes, silent = false) {
const mesh = meshes[0];
if (!mesh) {
return;
}
if (!silent) {
meshes.forEach(m => m.fire('beforeRender', mesh));
}
const material = this.forceMaterial || mesh.material;
const {
vao,
Expand All @@ -915,6 +925,9 @@ const WebGLRenderer = Class.create(/** @lends WebGLRenderer.prototype */ {
});
vao.drawInstance(meshes.length);
this.addRenderInfo(vao.vertexCount / 3 * meshes.length, 1);
if (!silent) {
meshes.forEach(m => m.fire('afterRender', mesh));
}
},
/**
* 渲染一组普通mesh
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3117,12 +3117,12 @@ class WebGLRenderer implements EventMixin {
* 渲染一个mesh
* @param mesh
*/
renderMesh(mesh: Mesh): void;
renderMesh(mesh: Mesh, silent = false): void;
/**
* 渲染一组 instanced mesh
* @param meshes
*/
renderInstancedMeshes(meshes: Mesh[]): void;
renderInstancedMeshes(meshes: Mesh[], silent = false): void;
/**
* 渲染一组普通mesh
* @param meshes
Expand Down

0 comments on commit 85923a7

Please sign in to comment.