mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix particle hemisphere emitter bug & opt model updateUBO (#4885)
This commit is contained in:
@@ -52,7 +52,7 @@ export default class ShapeModule {
|
||||
* @zh 粒子发射器位置。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 12,
|
||||
displayOrder: 13,
|
||||
})
|
||||
get position () {
|
||||
return this._position;
|
||||
@@ -69,7 +69,7 @@ export default class ShapeModule {
|
||||
* @zh 粒子发射器旋转角度。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 13,
|
||||
displayOrder: 14,
|
||||
})
|
||||
get rotation () {
|
||||
return this._rotation;
|
||||
@@ -86,7 +86,7 @@ export default class ShapeModule {
|
||||
* @zh 粒子发射器缩放比例。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 14,
|
||||
displayOrder: 15,
|
||||
})
|
||||
get scale () {
|
||||
return this._scale;
|
||||
@@ -100,7 +100,7 @@ export default class ShapeModule {
|
||||
* @zh 根据粒子的初始方向决定粒子的移动方向。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 15,
|
||||
displayOrder: 16,
|
||||
})
|
||||
public alignToDirection = false;
|
||||
|
||||
@@ -108,7 +108,7 @@ export default class ShapeModule {
|
||||
* @zh 粒子生成方向随机设定。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 16,
|
||||
displayOrder: 17,
|
||||
})
|
||||
public randomDirectionAmount = 0;
|
||||
|
||||
@@ -116,7 +116,7 @@ export default class ShapeModule {
|
||||
* @zh 表示当前发射方向与当前位置到结点中心连线方向的插值。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 17,
|
||||
displayOrder: 18,
|
||||
})
|
||||
public sphericalDirectionAmount = 0;
|
||||
|
||||
@@ -124,7 +124,7 @@ export default class ShapeModule {
|
||||
* @zh 粒子生成位置随机设定(设定此值为非 0 会使粒子生成位置超出生成器大小范围)。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 18,
|
||||
displayOrder: 19,
|
||||
})
|
||||
public randomPositionAmount = 0;
|
||||
|
||||
@@ -177,7 +177,7 @@ export default class ShapeModule {
|
||||
* @zh 控制可能产生粒子的弧周围的离散间隔。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 0,
|
||||
displayOrder: 9,
|
||||
})
|
||||
public arcSpread = 8;
|
||||
|
||||
@@ -186,7 +186,7 @@ export default class ShapeModule {
|
||||
*/
|
||||
@property({
|
||||
type: CurveRange,
|
||||
displayOrder: 9,
|
||||
displayOrder: 10,
|
||||
})
|
||||
public arcSpeed = new CurveRange();
|
||||
|
||||
@@ -213,7 +213,7 @@ export default class ShapeModule {
|
||||
* 决定圆锥发射器的高度。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 10,
|
||||
displayOrder: 11,
|
||||
})
|
||||
public length = 0;
|
||||
|
||||
@@ -221,7 +221,7 @@ export default class ShapeModule {
|
||||
* @zh 粒子发射器发射位置(针对 Box 类型的粒子发射器)。
|
||||
*/
|
||||
@property({
|
||||
displayOrder: 11,
|
||||
displayOrder: 12,
|
||||
})
|
||||
public boxThickness = new Vec3(0, 0, 0);
|
||||
|
||||
@@ -333,7 +333,7 @@ function hemisphereEmit (emitFrom, radius, radiusThickness, pos, dir) {
|
||||
case EmitLocation.Shell:
|
||||
randomUnitVector(pos);
|
||||
vec3.scale(pos, pos, radius);
|
||||
if (pos.z < 0) {
|
||||
if (pos.z > 0) {
|
||||
pos.z *= -1;
|
||||
}
|
||||
vec3.copy(dir, pos);
|
||||
|
||||
@@ -158,6 +158,7 @@ export class Model {
|
||||
protected _inited: boolean = false;
|
||||
protected _uboUpdated: boolean = false;
|
||||
protected _castShadow: boolean = false;
|
||||
private _transformUpdated: boolean = true;
|
||||
|
||||
/**
|
||||
* Setup a default empty model
|
||||
@@ -208,6 +209,7 @@ export class Model {
|
||||
// @ts-ignore
|
||||
if (!node.hasChanged && !node._dirty) { return; }
|
||||
node.updateWorldTransformFull();
|
||||
this._transformUpdated = this._transformUpdated || this.node.hasChanged;
|
||||
if (!this._modelBounds || !this._worldBounds) { return; }
|
||||
// @ts-ignore
|
||||
this._modelBounds.transform(node._mat, node._pos, node._rot, node._scale, this._worldBounds);
|
||||
@@ -223,24 +225,20 @@ export class Model {
|
||||
}
|
||||
this._uboUpdated = true;
|
||||
// @ts-ignore
|
||||
const worldMatrix = this._transform._mat; const rot = this._transform._rot;
|
||||
mat4.array(this._uboLocal.view, worldMatrix, UBOLocal.MAT_WORLD_OFFSET);
|
||||
mat4.fromQuat(m4_1, rot);
|
||||
mat4.array(this._uboLocal.view, m4_1, UBOLocal.MAT_WORLD_IT_OFFSET);
|
||||
if (this._transformUpdated) {
|
||||
const worldMatrix = this._transform._mat; const rot = this._transform._rot;
|
||||
mat4.array(this._uboLocal.view, worldMatrix, UBOLocal.MAT_WORLD_OFFSET);
|
||||
mat4.fromQuat(m4_1, rot);
|
||||
mat4.array(this._uboLocal.view, m4_1, UBOLocal.MAT_WORLD_IT_OFFSET);
|
||||
|
||||
const commonLocal = this._localBindings.get(UBOLocal.BLOCK.name);
|
||||
if (commonLocal && commonLocal.buffer) {
|
||||
commonLocal.buffer!.update(this._uboLocal.view);
|
||||
const commonLocal = this._localBindings.get(UBOLocal.BLOCK.name);
|
||||
if (commonLocal && commonLocal.buffer) {
|
||||
commonLocal.buffer!.update(this._uboLocal.view);
|
||||
}
|
||||
this._transformUpdated = false;
|
||||
}
|
||||
|
||||
for (const mat of this._matPSORecord.keys()) {
|
||||
for (const pass of mat.passes) {
|
||||
pass.update();
|
||||
}
|
||||
for (const pso of this._matPSORecord.get(mat)!) {
|
||||
pso.pipelineLayout.layouts[0].update();
|
||||
}
|
||||
}
|
||||
this._matPSORecord.forEach(this._updatePass, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -367,7 +365,7 @@ export class Model {
|
||||
}
|
||||
}
|
||||
|
||||
protected initLocalBindings (mat: Material|null) {
|
||||
protected initLocalBindings (mat: Material | null) {
|
||||
if (mat) {
|
||||
this.onSetLocalBindings(mat);
|
||||
const lbIter = this._localBindings.values();
|
||||
@@ -386,6 +384,15 @@ export class Model {
|
||||
}
|
||||
}
|
||||
|
||||
private _updatePass (psos: GFXPipelineState[], mat: Material) {
|
||||
for (let i = 0; i < mat.passes.length; i++) {
|
||||
mat.passes[i].update();
|
||||
}
|
||||
for (let i = 0; i < psos.length; i++) {
|
||||
psos[i].pipelineLayout.layouts[0].update();
|
||||
}
|
||||
}
|
||||
|
||||
private allocatePSO (mat: Material) {
|
||||
if (this._matRefCount.get(mat) == null) {
|
||||
this._matRefCount.set(mat, 1);
|
||||
|
||||
Reference in New Issue
Block a user