diff --git a/cocos/3d/framework/particle/animator/curve-range.ts b/cocos/3d/framework/particle/animator/curve-range.ts index 0e47b42c6d..e2c15d3f42 100644 --- a/cocos/3d/framework/particle/animator/curve-range.ts +++ b/cocos/3d/framework/particle/animator/curve-range.ts @@ -4,7 +4,7 @@ import { AnimationCurve } from '../../../geom-utils'; import { CCClass } from '../../../../core/data'; import { property, ccclass } from '../../../../core/data/class-decorator'; -const Mode = Enum({ +export const Mode = Enum({ Constant: 0, Curve: 1, TwoCurves: 2, diff --git a/cocos/3d/framework/particle/animator/optimized-curve.ts b/cocos/3d/framework/particle/animator/optimized-curve.ts index fa812960f7..7e3ca3a578 100644 --- a/cocos/3d/framework/particle/animator/optimized-curve.ts +++ b/cocos/3d/framework/particle/animator/optimized-curve.ts @@ -1,6 +1,6 @@ import { OptimizedKey, evalOptCurve, AnimationCurve } from "../../../geom-utils/curve"; import { repeat } from "../../../../core/vmath"; -import CurveRange from "./curve-range"; +import CurveRange, { Mode } from "./curve-range"; // tslint:disable: max-line-length @@ -291,16 +291,16 @@ export class CurveUniform { public uploadUniform (device: any, name: number) { switch (this.mode) { - case 'constant': + case Mode.Constant: device.setUniform('u_' + name + '_curveMode', CURVE_MODE_CONSTANT); device.setUniform('u_' + name + '_minConstant', this.minConstant); break; - case 'twoConstants': + case Mode.TwoConstants: device.setUniform('u_' + name + '_curveMode', CURVE_MODE_RANDOM_CONSTANT); device.setUniform('u_' + name + '_minConstant', this.minConstant); device.setUniform('u_' + name + '_maxConstant', this.maxConstant); break; - case 'curve': + case Mode.Curve: if (this.minCurve != null) { device.setUniform('u_' + name + '_curveMode', CURVE_MODE_CURVE); device.setUniform('u_' + name + '_minKeyTime', this.minCurve.timeUniform); @@ -310,7 +310,7 @@ export class CurveUniform { } } break; - case 'twoCurves': + case Mode.TwoCurves: if (this.minCurve != null && this.maxCurve != null) { device.setUniform('u_' + name + '_curveMode', CURVE_MODE_RANDOM_CURVE); device.setUniform('u_' + name + '_minKeyTime', this.minCurve.timeUniform); diff --git a/cocos/3d/framework/particle/animator/texture-animation.ts b/cocos/3d/framework/particle/animator/texture-animation.ts index 36ca742e5e..9f53738296 100644 --- a/cocos/3d/framework/particle/animator/texture-animation.ts +++ b/cocos/3d/framework/particle/animator/texture-animation.ts @@ -32,7 +32,7 @@ export default class TextureAnimationModule { set enable (val) { this._enable = val; - this.ps!.renderer!._updateMaterialParams(); + (this.ps!.getComponent(cc.ParticleSystemRenderer) as any)._updateMaterialParams(); } @property({ diff --git a/cocos/3d/framework/particle/emitter/shape-module.ts b/cocos/3d/framework/particle/emitter/shape-module.ts index 21ed1e1bfc..7da1634f90 100644 --- a/cocos/3d/framework/particle/emitter/shape-module.ts +++ b/cocos/3d/framework/particle/emitter/shape-module.ts @@ -147,7 +147,7 @@ export default class ShapeModule { private mat: mat4; private quat: quat; - private particleSystem: ParticleSystemComponent | null; + private particleSystem: any; private lastTime: number; private totalAngle: number; @@ -162,7 +162,7 @@ export default class ShapeModule { public onInit (ps: ParticleSystemComponent) { this.constructMat(); this.particleSystem = ps; - this.lastTime = ps._time; + this.lastTime = this.particleSystem._time; this.totalAngle = 0; } diff --git a/cocos/3d/framework/particle/particle-system-component.ts b/cocos/3d/framework/particle/particle-system-component.ts index ac21332a54..f945afbc0c 100644 --- a/cocos/3d/framework/particle/particle-system-component.ts +++ b/cocos/3d/framework/particle/particle-system-component.ts @@ -96,7 +96,7 @@ export class ParticleSystemComponent extends Component { set simulationSpace (val) { if (val !== this._simulationSpace) { this._simulationSpace = val; - this.renderer!._updateMaterialParams(); + (this.renderer as any)._updateMaterialParams(); } } diff --git a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts index 4333d7c8a5..5b202e8263 100644 --- a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts +++ b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts @@ -99,7 +99,7 @@ export default class ParticleSystemRenderer extends RenderableComponent { private attrs: any[]; private _vertAttrs: IGFXInputAttribute[]; private particleSystem: any; - private _particles: RecyclePool; + private _particles: RecyclePool | null = null; private _defaultMat: Material | null = null; constructor () { @@ -155,14 +155,14 @@ export default class ParticleSystemRenderer extends RenderableComponent { } public clear () { - this._particles.reset(); + this._particles!.reset(); } public _getFreeParticle (): Particle | null { - if (this._particles.length >= this.particleSystem.capacity) { + if (this._particles!.length >= this.particleSystem.capacity) { return null; } - return this._particles.add(); + return this._particles!.add(); } public _setNewParticle (p: Particle) { @@ -177,13 +177,13 @@ export default class ParticleSystemRenderer extends RenderableComponent { if (this.particleSystem.forceOvertimeModule.enable) { this.particleSystem.forceOvertimeModule.update(this.particleSystem._simulationSpace, _tempWorldTrans); } - for (let i = 0; i < this._particles.length; ++i) { - const p = this._particles.data[i]; + for (let i = 0; i < this._particles!.length; ++i) { + const p = this._particles!.data[i]; p.remainingLifetime -= dt; vec3.set(p.animatedVelocity, 0, 0, 0); if (p.remainingLifetime < 0.0) { - this._particles.removeAt(i); + this._particles!.removeAt(i); --i; continue; } @@ -221,8 +221,8 @@ export default class ParticleSystemRenderer extends RenderableComponent { // update vertex buffer let idx = 0; const uploadVel = this._renderMode === RenderMode.StrecthedBillboard; - for (let i = 0; i < this._particles.length; ++i) { - const p = this._particles.data[i]; + for (let i = 0; i < this._particles!.length; ++i) { + const p = this._particles!.data[i]; let fi = 0; if (this.particleSystem.textureAnimationModule.enable) { fi = p.frameIndex; @@ -250,7 +250,7 @@ export default class ParticleSystemRenderer extends RenderableComponent { } // because we use index buffer, per particle index count = 6. - this._model!.updateIA(this._particles.length * 6); + this._model!.updateIA(this._particles!.length * 6); } public updateShaderUniform () { @@ -258,7 +258,7 @@ export default class ParticleSystemRenderer extends RenderableComponent { } public getParticleCount (): number { - return this._particles.length; + return this._particles!.length; } public _onMaterialModified (index: number, material: Material) { diff --git a/cocos/3d/memop/pool.ts b/cocos/3d/memop/pool.ts index f3813bbfa6..f252f71607 100644 --- a/cocos/3d/memop/pool.ts +++ b/cocos/3d/memop/pool.ts @@ -37,7 +37,7 @@ export default class Pool { } const ret = this._frees[this._idx]; - this._frees[this._idx] = null; + this._frees.splice(this._idx); --this._idx; return ret; diff --git a/cocos/renderer/models/particle-batch-model.ts b/cocos/renderer/models/particle-batch-model.ts index f194ddd904..3d26a8e3fa 100644 --- a/cocos/renderer/models/particle-batch-model.ts +++ b/cocos/renderer/models/particle-batch-model.ts @@ -23,7 +23,7 @@ export default class ParticleBatchModel extends Model { private _iaInfoBuffer: GFXBuffer; private _subMeshData: IRenderingSubmesh | null; - constructor (scene: RenderScene, node: Node) { + constructor (scene: RenderScene, node: Node | null) { super(scene, node); this._type = 'particle-batch'; diff --git a/cocos/renderer/scene/model.ts b/cocos/renderer/scene/model.ts index d7ab7fb7fc..054df30e0d 100644 --- a/cocos/renderer/scene/model.ts +++ b/cocos/renderer/scene/model.ts @@ -258,7 +258,7 @@ export class Model { this.allocatePSO(mat); } } - this._subModels[idx]._psos = mat ? this._matPSORecord.get(mat)! : null; + (this._subModels[idx] as any)._psos = mat ? this._matPSORecord.get(mat)! : null; this._subModels[idx].material = mat; } @@ -304,17 +304,19 @@ export class Model { } } - protected initLocalBindings (mat: Material) { - if (this._localBindings.size === 0) { - this.onSetLocalBindings(mat); - } - for (const localBinding of this._localBindings.values()) { - if (!localBinding.buffer) { - localBinding.buffer = this._device.createBuffer({ - usage: GFXBufferUsageBit.UNIFORM | GFXBufferUsageBit.TRANSFER_DST, - memUsage: GFXMemoryUsageBit.HOST | GFXMemoryUsageBit.DEVICE, - size: getUniformBlockSize(localBinding.blockInfo!), - }); + protected initLocalBindings (mat: Material|null) { + if (mat) { + if (this._localBindings.size === 0) { + this.onSetLocalBindings(mat); + } + for (const localBinding of this._localBindings.values()) { + if (!localBinding.buffer) { + localBinding.buffer = this._device.createBuffer({ + usage: GFXBufferUsageBit.UNIFORM | GFXBufferUsageBit.TRANSFER_DST, + memUsage: GFXMemoryUsageBit.HOST | GFXMemoryUsageBit.DEVICE, + size: getUniformBlockSize(localBinding.blockInfo!), + }); + } } } }