fix particle coordinate system bug (#4373)

This commit is contained in:
zxg0622
2019-05-06 12:59:47 +08:00
committed by Weiliang Wang
parent cbeec544be
commit dd5df2bdfa
4 changed files with 46 additions and 31 deletions
@@ -161,6 +161,7 @@ export class ParticleSystemComponent extends Component {
if (val !== this._simulationSpace) {
this._simulationSpace = val;
(this.renderer as any)._updateMaterialParams();
(this.renderer as any)._updateTrailMaterial();
}
}
@@ -230,6 +230,7 @@ export default class ParticleSystemRenderer extends RenderableComponent {
this._model.enabled = this.enabledInHierarchy;
this._updateMaterialParams();
this._updateModel();
this._updateTrailMaterial();
}
public onDisable () {
@@ -389,15 +390,10 @@ export default class ParticleSystemRenderer extends RenderableComponent {
public _onMaterialModified (index: number, material: Material) {
if (index === 0) {
this._updateMaterialParams();
this._updateModel();
} else {
if (this.particleSystem.trailModule.enable) {
this.particleSystem.trailModule._updateMaterial();
const mat = this.getMaterial(1, CC_EDITOR)!;
mat!.recompileShaders(this._trailDefines);
}
this._updateTrailMaterial();
}
this._updateModel();
}
public _onRebuildPSO (index: number, material: Material) {
@@ -467,6 +463,22 @@ export default class ParticleSystemRenderer extends RenderableComponent {
} else {
mat!.setProperty('frameTile_velLenScale', this.frameTile_velLenScale);
}
if (this._model) {
this._model.setSubModelMaterial(0, this.sharedMaterial || this._defaultMat);
}
}
private _updateTrailMaterial () {
if (this.particleSystem.trailModule.enable) {
if (this.particleSystem._simulationSpace === Space.World) {
this._trailDefines[CC_USE_WORLD_SPACE] = true;
} else {
this._trailDefines[CC_USE_WORLD_SPACE] = false;
}
const mat = this.getMaterial(1, CC_EDITOR)!;
mat!.recompileShaders(this._trailDefines);
this.particleSystem.trailModule._updateMaterial();
}
}
private _updateModel () {
@@ -474,7 +486,6 @@ export default class ParticleSystemRenderer extends RenderableComponent {
return;
}
this._model.setVertexAttributes(this._renderMode === RenderMode.Mesh ? this._mesh : null, this._vertAttrs);
this._model.setSubModelMaterial(0, this.sharedMaterial || this._defaultMat);
// if (Object.getPrototypeOf(this).constructor.name === 'ParticleSystemGpuRenderer') {
// return;
// }
+26 -22
View File
@@ -137,18 +137,19 @@ export default class TrailModule {
}
public set enable (val) {
this._enable = val;
if (this._enable) {
if (val && !this._trailModel) {
this._createModel();
}
if (val && !this._enable) {
this._updateMaterial();
}
this._enable = val;
if (this._trailModel) {
this._trailModel.enabled = val;
}
}
@property({
displayOrder: 1,
})
@property
public _enable = false;
/**
@@ -156,7 +157,7 @@ export default class TrailModule {
*/
@property({
type: TrailMode,
displayOrder: 2,
displayOrder: 1,
})
public mode = TrailMode.Particles;
@@ -164,7 +165,7 @@ export default class TrailModule {
* 设定粒子中生成轨迹的比例
*/
@property({
displayOrder: 3,
displayOrder: 2,
})
public ratio = 1;
@@ -173,13 +174,16 @@ export default class TrailModule {
*/
@property({
type: CurveRange,
displayOrder: 4,
displayOrder: 3,
})
public lifeTime = new CurveRange();
/**
* 每个轨迹粒子之间的最小间距
*/
@property({
displayOrder: 5,
})
public get minParticleDistance () {
return this._minParticleDistance;
}
@@ -189,19 +193,17 @@ export default class TrailModule {
this._minSquaredDistance = val * val;
}
@property({
displayOrder: 5,
})
@property
public _minParticleDistance = 0.1;
/**
* 轨迹设定时的坐标系
*/
@property({
type: Space,
displayOrder: 6,
})
public space = Space.World;
// /**
// * 轨迹设定时的坐标系
// */
// @property({
// type: Space,
// displayOrder: 6,
// })
// public space = Space.World;
/**
* 粒子本身是否存在
@@ -353,9 +355,11 @@ export default class TrailModule {
}
public _updateMaterial () {
const mat = this._particleSystem.renderer.getMaterial(1, CC_EDITOR)!;
if (mat) {
this._trailModel!.setSubModelMaterial(0, mat);
if (this._particleSystem) {
const mat = this._particleSystem.renderer.getMaterial(1, CC_EDITOR)!;
if (mat) {
this._trailModel!.setSubModelMaterial(0, mat);
}
}
}
-1
View File
@@ -72,7 +72,6 @@ export class SubModel {
}
if (this._inputAssembler) {
this._inputAssembler.initialize(iaInfo);
this.updateCommandBuffer();
} else {
this._inputAssembler = (cc.director.root.device as GFXDevice).createInputAssembler(iaInfo);
}