Skip to content

Commit

Permalink
modify some statements
Browse files Browse the repository at this point in the history
  • Loading branch information
zxx43 committed Aug 7, 2023
1 parent 8ae777e commit 687829c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 47 deletions.
14 changes: 5 additions & 9 deletions cocos/particle/particle-culler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ export class ParticleCuller {
Mat4.fromTranslation(_pos_mat, _node_pos);
Mat4.fromQuat(_rol_mat, _node_rol);
Mat4.fromScaling(_scale_mat, _node_scale);
Mat4.multiply(_rol_scale_mat, _rol_mat, _scale_mat);
Mat4.multiply(_trans_mat, _pos_mat, _rol_scale_mat);
Mat4.fromRTS(_rol_scale_mat, _node_rol, Vec3.ZERO, _node_scale);
Mat4.fromRTS(_trans_mat, _node_rol, _node_pos, _node_scale);
}

for (let i = 0; i < count; ++i) {
Expand Down Expand Up @@ -222,19 +222,15 @@ export class ParticleCuller {
Mat4.fromTranslation(_pos_mat, _node_pos);
Mat4.fromQuat(_rol_mat, _node_rol);
Mat4.fromScaling(_scale_mat, _node_scale);
Mat4.multiply(_rol_scale_mat, _rol_mat, _scale_mat);
Mat4.multiply(_trans_mat, _pos_mat, _rol_scale_mat);
Mat4.fromRTS(_rol_scale_mat, _node_rol, Vec3.ZERO, _node_scale);
Mat4.fromRTS(_trans_mat, _node_rol, _node_pos, _node_scale);

this._updateList.forEach((value: IParticleModule, key: string) => {
value.update(ps.simulationSpace, _trans_mat);
});

if (ps.simulationSpace === Space.Local) {
Mat4.invert(this._localMat, _trans_mat);
this._localMat.m12 = 0;
this._localMat.m13 = 0;
this._localMat.m14 = 0;
this._localMat.m15 = 1;
Mat4.transpose(this._localMat, _rol_scale_mat);
}

for (let i = 0; i < particleLst.length; ++i) {
Expand Down
57 changes: 19 additions & 38 deletions cocos/particle/renderer/particle-system-renderer-cpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,54 +345,35 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas
}
}

private doScale (pass) {
Mat4.fromScaling(this._scale_local_trans, this._node_scale);
this._particleSystem.node.getWorldRotation(this._world_rot);
Quat.normalize(this._world_rot, this._world_rot);
Mat4.multiply(this._scale_local_trans, Mat4.fromQuat(_rot_mat, this._world_rot), this._scale_local_trans);
this._particleSystem.node.getWorldPosition(this._node_pos);
Mat4.fromTranslation(this._pos_mat, this._node_pos);
Mat4.multiply(this._scale_local_trans, this._pos_mat, this._scale_local_trans);
Mat4.copy(_tempWorldTrans, this._scale_local_trans);

pass.setUniform(this._uTransformHandle, _tempWorldTrans);
if (this._trailMat) {
this._trailMat.passes[0].setUniform(this._uTransTrailHandle, _tempWorldTrans);
}
}

private doUpdateScale (pass) {
switch (this._particleSystem.scaleSpace) {
case Space.Local:
this._particleSystem.node.getScale(this._node_scale);
Mat4.fromScaling(this._scale_local_trans, this._node_scale);
this._particleSystem.node.getWorldRotation(this._world_rot);
Quat.normalize(this._world_rot, this._world_rot);
Mat4.multiply(this._scale_local_trans, Mat4.fromQuat(_rot_mat, this._world_rot), this._scale_local_trans);
this._particleSystem.node.getWorldPosition(this._node_pos);
Mat4.fromTranslation(this._pos_mat, this._node_pos);
Mat4.multiply(this._scale_local_trans, this._pos_mat, this._scale_local_trans);
Mat4.copy(_tempWorldTrans, this._scale_local_trans);
pass.setUniform(this._uTransformHandle, _tempWorldTrans);
if (this._trailMat) {
this._trailMat.passes[0].setUniform(this._uTransTrailHandle, _tempWorldTrans);
}
this.doScale(pass);
break;
case Space.World:
this._particleSystem.node.getWorldScale(this._node_scale);
Mat4.fromScaling(this._scale_local_trans, this._node_scale);
this._particleSystem.node.getWorldRotation(this._world_rot);
Quat.normalize(this._world_rot, this._world_rot);
Mat4.multiply(this._scale_local_trans, Mat4.fromQuat(_rot_mat, this._world_rot), this._scale_local_trans);
this._particleSystem.node.getWorldPosition(this._node_pos);
Mat4.fromTranslation(this._pos_mat, this._node_pos);
Mat4.multiply(this._scale_local_trans, this._pos_mat, this._scale_local_trans);
Mat4.copy(_tempWorldTrans, this._scale_local_trans);

pass.setUniform(this._uTransformHandle, _tempWorldTrans);
if (this._trailMat) {
this._trailMat.passes[0].setUniform(this._uTransTrailHandle, _tempWorldTrans);
}
this.doScale(pass);
break;
default:
this._particleSystem.node.getScale(this._node_scale);
Mat4.fromScaling(this._scale_local_trans, this._node_scale);
this._particleSystem.node.getWorldRotation(this._world_rot);
Quat.normalize(this._world_rot, this._world_rot);
Mat4.multiply(this._scale_local_trans, Mat4.fromQuat(_rot_mat, this._world_rot), this._scale_local_trans);
this._particleSystem.node.getWorldPosition(this._node_pos);
Mat4.fromTranslation(this._pos_mat, this._node_pos);
Mat4.multiply(this._scale_local_trans, this._pos_mat, this._scale_local_trans);
Mat4.copy(_tempWorldTrans, this._scale_local_trans);

pass.setUniform(this._uTransformHandle, _tempWorldTrans);
if (this._trailMat) {
this._trailMat.passes[0].setUniform(this._uTransTrailHandle, _tempWorldTrans);
}
this.doScale(pass);
break;
}
pass.setUniform(this._uScaleHandle, this._node_scale);
Expand Down

0 comments on commit 687829c

Please sign in to comment.