diff --git a/cocos/3d/assets/mesh.ts b/cocos/3d/assets/mesh.ts index 5d31812c23..d83465b22d 100644 --- a/cocos/3d/assets/mesh.ts +++ b/cocos/3d/assets/mesh.ts @@ -536,6 +536,45 @@ export class Mesh extends Asset { return null; } + public copyAttribute (primitiveIndex: number, attributeName: GFXAttributeName, buffer: ArrayBuffer, stride: number, offset: number) { + if (!this._data || + primitiveIndex >= this._struct.primitives.length) { + return null; + } + const primitive = this._struct.primitives[primitiveIndex]; + for (const vertexBundleIndex of primitive.vertexBundelIndices) { + const vertexBundle = this._struct.vertexBundles[vertexBundleIndex]; + const iAttribute = vertexBundle.attributes.findIndex((a) => a.name === attributeName); + if (iAttribute < 0) { + continue; + } + const format = vertexBundle.attributes[iAttribute].format; + + const dataOffset = vertexBundle.view.offset + getOffset(vertexBundle.attributes, iAttribute); + const view = new DataView(this._data.buffer, dataOffset); + + const formatInfo = GFXFormatInfos[format]; + const storageConstructor = getStorageConstructor(format); + const reader = getReader(view, format); + if (!storageConstructor || !reader) { + return null; + } + const vertexCount = vertexBundle.view.count; + const componentCount = formatInfo.count; + const storage = new storageConstructor(buffer); + const componentStride = stride / storage.BYTES_PER_ELEMENT; + offset /= storage.BYTES_PER_ELEMENT; + const inputStride = vertexBundle.view.stride; + for (let iVertex = 0; iVertex < vertexCount; ++iVertex) { + for (let iComponent = 0; iComponent < componentCount; ++iComponent) { + storage[componentStride * iVertex + iComponent + offset] = reader(inputStride * iVertex + storage.BYTES_PER_ELEMENT * iComponent); + } + } + return storage; + } + return null; + } + public readIndices (primitiveIndex: number) { if (!this._data || primitiveIndex >= this._struct.primitives.length) { @@ -555,6 +594,23 @@ export class Mesh extends Asset { return storage; } + public copyIndices (primitiveIndex: number, typedArray: any) { + if (!this._data || + primitiveIndex >= this._struct.primitives.length) { + return null; + } + const primitive = this._struct.primitives[primitiveIndex]; + if (!primitive.indexView) { + return null; + } + const indexCount = primitive.indexView.count; + const indexFormat = primitive.indexView.stride === 1 ? GFXFormat.R8UI : (primitive.indexView.stride === 2 ? GFXFormat.R16UI : GFXFormat.R32UI); + const reader = getReader(new DataView(this._data.buffer), indexFormat)!; + for (let i = 0; i < indexCount; ++i) { + typedArray[i] = reader(primitive.indexView.offset + GFXFormatInfos[indexFormat].size * i); + } + } + private _init () { if (this._initialized) { return; diff --git a/cocos/3d/framework/particle/particle-system-component.ts b/cocos/3d/framework/particle/particle-system-component.ts index 3533658fa7..3715e53647 100644 --- a/cocos/3d/framework/particle/particle-system-component.ts +++ b/cocos/3d/framework/particle/particle-system-component.ts @@ -30,10 +30,22 @@ const _world_mat = mat4.create(); @executeInEditMode export class ParticleSystemComponent extends Component { + @property + private _capacity = 100; + @property({ displayOrder: 1, }) - public capacity = 2000; + public get capacity () { + return this._capacity; + } + + public set capacity (val) { + this._capacity = val; + if (this.renderer && this.renderer._model) { + this.renderer._model.setCapacity(this._capacity); + } + } @property({ type: GradientRange, @@ -194,9 +206,9 @@ export class ParticleSystemComponent extends Component { }) public textureAnimationModule = new TextureAnimationModule(); - // @property({ - // type: TrailModule, - // }) + @property({ + type: TrailModule, + }) public trailModule = new TrailModule(); // particle system renderer diff --git a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts index 1b5a4b4618..23ac847a36 100644 --- a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts +++ b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts @@ -11,6 +11,7 @@ import Particle from '../particle'; import { RenderableComponent } from '../../renderable-component'; import { Space } from '../particle-general-function'; import { builtinResMgr } from '../../../builtin'; +import { Mesh } from '../../../assets'; // import ParticleSystemComponent from '../particle-system-component'; // tslint:disable: max-line-length @@ -39,6 +40,32 @@ const CC_USE_BILLBOARD = 'CC_USE_BILLBOARD'; const CC_USE_STRETCHED_BILLBOARD = 'CC_USE_STRETCHED_BILLBOARD'; const CC_USE_HORIZONTAL_BILLBOARD = 'CC_USE_HORIZONTAL_BILLBOARD'; const CC_USE_VERTICAL_BILLBOARD = 'CC_USE_VERTICAL_BILLBOARD'; +const CC_USE_MESH = 'CC_USE_MESH'; + +const _vertex_attrs = [ + { name: GFXAttributeName.ATTR_POSITION, format: GFXFormat.RGB32F }, + { name: GFXAttributeName.ATTR_TEX_COORD, format: GFXFormat.RGB32F }, + { name: GFXAttributeName.ATTR_TEX_COORD1, format: GFXFormat.RG32F }, + { name: GFXAttributeName.ATTR_COLOR, format: GFXFormat.RGBA8, isNormalized: true }, +]; + +const _vertex_attrs_stretch = [ + { name: GFXAttributeName.ATTR_POSITION, format: GFXFormat.RGB32F }, + { name: GFXAttributeName.ATTR_TEX_COORD, format: GFXFormat.RGB32F }, + { name: GFXAttributeName.ATTR_TEX_COORD1, format: GFXFormat.RG32F }, + { name: GFXAttributeName.ATTR_COLOR, format: GFXFormat.RGBA8, isNormalized: true }, + { name: GFXAttributeName.ATTR_COLOR1, format: GFXFormat.RGB32F }, +]; + +const _vertex_attrs_mesh = [ + { name: GFXAttributeName.ATTR_POSITION, format: GFXFormat.RGB32F }, + { name: GFXAttributeName.ATTR_TEX_COORD, format: GFXFormat.RGB32F }, + { name: GFXAttributeName.ATTR_TEX_COORD1, format: GFXFormat.RG32F }, + { name: GFXAttributeName.ATTR_COLOR, format: GFXFormat.RGBA8, isNormalized: true }, + { name: GFXAttributeName.ATTR_TEX_COORD2, format: GFXFormat.RGB32F }, + { name: GFXAttributeName.ATTR_NORMAL, format: GFXFormat.RGB32F }, + { name: GFXAttributeName.ATTR_COLOR1, format: GFXFormat.RGBA8, isNormalized: true }, +]; @ccclass('cc.ParticleSystemRenderer') @executeInEditMode @@ -57,6 +84,7 @@ export default class ParticleSystemRenderer extends RenderableComponent { return; } this._renderMode = val; + this._setVertexAttrib(); this._updateMaterialParams(); this._updateModel(); } @@ -98,6 +126,23 @@ export default class ParticleSystemRenderer extends RenderableComponent { @property private _lengthScale = 1; + @property + private _mesh: Mesh | null = null; + + @property({ + type: Mesh, + }) + public get mesh () { + return this._mesh; + } + + public set mesh (val) { + this._mesh = val; + if (this._model) { + this._model.setVertexAttributes(this._renderMode === RenderMode.Mesh ? this._mesh : null, this._vertAttrs); + } + } + private _defines: { [index: string]: boolean }; private _trailDefines: { [index: string]: boolean }; private _model: ParticleBatchModel | null; @@ -114,12 +159,6 @@ export default class ParticleSystemRenderer extends RenderableComponent { this.frameTile_velLenScale = cc.v4(1, 1, 0, 0); this.attrs = new Array(5); - this._vertAttrs = [ - { name: GFXAttributeName.ATTR_POSITION, format: GFXFormat.RGB32F }, - { name: GFXAttributeName.ATTR_TEX_COORD, format: GFXFormat.RGB32F }, - { name: GFXAttributeName.ATTR_TEX_COORD1, format: GFXFormat.RG32F }, - { name: GFXAttributeName.ATTR_COLOR, format: GFXFormat.RGBA8, isNormalized: true }, - ]; this._defines = { CC_USE_WORLD_SPACE: true, CC_USE_BILLBOARD: true, @@ -137,6 +176,7 @@ export default class ParticleSystemRenderer extends RenderableComponent { this._particles = new RecyclePool(() => { return new Particle(this); }, 16); + this._setVertexAttrib(); this.onEnable(); } @@ -149,7 +189,6 @@ export default class ParticleSystemRenderer extends RenderableComponent { } if (!this._model.inited) { this._model.setCapacity(this.particleSystem.capacity); - this._model.setVertexAttributes(this._vertAttrs); this._model.node = this.node; } this._model.enabled = this.enabledInHierarchy; @@ -172,6 +211,19 @@ export default class ParticleSystemRenderer extends RenderableComponent { this._particles!.reset(); } + private _setVertexAttrib () { + switch (this._renderMode) { + case RenderMode.StrecthedBillboard: + this._vertAttrs = _vertex_attrs_stretch.slice(); + break; + case RenderMode.Mesh: + this._vertAttrs = _vertex_attrs_mesh.slice(); + break; + default: + this._vertAttrs = _vertex_attrs.slice(); + } + } + public _getFreeParticle (): Particle | null { if (this._particles!.length >= this.particleSystem.capacity) { return null; @@ -252,28 +304,40 @@ export default class ParticleSystemRenderer extends RenderableComponent { } idx = i * 4; let attrNum = 0; - for (let j = 0; j < 4; ++j) { // four verts per particle. + if (this._renderMode !== RenderMode.Mesh) { + for (let j = 0; j < 4; ++j) { // four verts per particle. + attrNum = 0; + this.attrs[attrNum++] = p.position; + _tempAttribUV.x = _uvs[2 * j]; + _tempAttribUV.y = _uvs[2 * j + 1]; + _tempAttribUV.z = fi; + this.attrs[attrNum++] = _tempAttribUV; + _tempAttribUV0.x = p.size.x; + _tempAttribUV0.y = p.rotation.x; + this.attrs[attrNum++] = _tempAttribUV0; + this.attrs[attrNum++] = p.color._val; + + if (uploadVel) { + this.attrs[attrNum++] = p.ultimateVelocity; + } + + this._model!.addParticleVertexData(idx++, this.attrs); + } + } else { attrNum = 0; this.attrs[attrNum++] = p.position; - _tempAttribUV.x = _uvs[2 * j]; - _tempAttribUV.y = _uvs[2 * j + 1]; _tempAttribUV.z = fi; this.attrs[attrNum++] = _tempAttribUV; _tempAttribUV0.x = p.size.x; _tempAttribUV0.y = p.rotation.x; this.attrs[attrNum++] = _tempAttribUV0; this.attrs[attrNum++] = p.color._val; - - if (uploadVel) { - this.attrs[attrNum++] = p.ultimateVelocity; - } - - this._model!.addParticleVertexData(idx++, this.attrs); + this._model!.addParticleVertexData(i, this.attrs); } } // because we use index buffer, per particle index count = 6. - this._model!.updateIA(this._particles!.length * 6); + this._model!.updateIA(this._particles!.length); } public updateShaderUniform () { @@ -319,11 +383,13 @@ export default class ParticleSystemRenderer extends RenderableComponent { this._defines[CC_USE_STRETCHED_BILLBOARD] = false; this._defines[CC_USE_HORIZONTAL_BILLBOARD] = false; this._defines[CC_USE_VERTICAL_BILLBOARD] = false; + this._defines[CC_USE_MESH] = false; } else if (this._renderMode === RenderMode.StrecthedBillboard) { this._defines[CC_USE_BILLBOARD] = false; this._defines[CC_USE_STRETCHED_BILLBOARD] = true; this._defines[CC_USE_HORIZONTAL_BILLBOARD] = false; this._defines[CC_USE_VERTICAL_BILLBOARD] = false; + this._defines[CC_USE_MESH] = false; this.frameTile_velLenScale.z = this._velocityScale; this.frameTile_velLenScale.w = this._lengthScale; } else if (this._renderMode === RenderMode.HorizontalBillboard) { @@ -331,11 +397,19 @@ export default class ParticleSystemRenderer extends RenderableComponent { this._defines[CC_USE_STRETCHED_BILLBOARD] = false; this._defines[CC_USE_HORIZONTAL_BILLBOARD] = true; this._defines[CC_USE_VERTICAL_BILLBOARD] = false; + this._defines[CC_USE_MESH] = false; } else if (this._renderMode === RenderMode.VerticalBillboard) { this._defines[CC_USE_BILLBOARD] = false; this._defines[CC_USE_STRETCHED_BILLBOARD] = false; this._defines[CC_USE_HORIZONTAL_BILLBOARD] = false; this._defines[CC_USE_VERTICAL_BILLBOARD] = true; + this._defines[CC_USE_MESH] = false; + } else if (this._renderMode === RenderMode.Mesh) { + this._defines[CC_USE_BILLBOARD] = false; + this._defines[CC_USE_STRETCHED_BILLBOARD] = false; + this._defines[CC_USE_HORIZONTAL_BILLBOARD] = false; + this._defines[CC_USE_VERTICAL_BILLBOARD] = false; + this._defines[CC_USE_MESH] = true; } else { console.warn(`particle system renderMode ${this._renderMode} not support.`); } @@ -354,15 +428,11 @@ export default class ParticleSystemRenderer extends RenderableComponent { } private _updateModel () { - if (!this.particleSystem) { + if (!this._model) { return; } - if (this._renderMode === RenderMode.StrecthedBillboard) { - this._model!.enableStretchedBillboard(); - } else { - this._model!.disableStretchedBillboard(); - } - this._model!.setSubModelMaterial(0, this.sharedMaterial || this._defaultMat); + 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; // } diff --git a/cocos/3d/framework/particle/renderer/trail.ts b/cocos/3d/framework/particle/renderer/trail.ts index d16912a92b..84bc8b118b 100644 --- a/cocos/3d/framework/particle/renderer/trail.ts +++ b/cocos/3d/framework/particle/renderer/trail.ts @@ -220,8 +220,10 @@ export default class TrailModule { this._particleSystem = ps; this.lifeTime.constant = 1; this._trailNum = ps.startLifetime.getMax() * this.lifeTime.getMax() * 60 * ps.rateOverTime.getMax() * ps.duration; - this._trailSegments = new Pool(() => new TrailSegment(ps.startLifetime.getMax() * this.lifeTime.getMax() * 60), ps.rateOverTime.getMax() * ps.duration); - this._updateMaterial(); + this._trailSegments = new Pool(() => new TrailSegment(ps.startLifetime.getMax() * this.lifeTime.getMax() * 60), Math.ceil(ps.rateOverTime.getMax() * ps.duration)); + if (this._enable) { + this._updateMaterial(); + } } private _createModel () { diff --git a/cocos/renderer/models/particle-batch-model.ts b/cocos/renderer/models/particle-batch-model.ts index cbe75983e4..0e389dbe8b 100644 --- a/cocos/renderer/models/particle-batch-model.ts +++ b/cocos/renderer/models/particle-batch-model.ts @@ -1,7 +1,7 @@ // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. import { Material } from '../../3d/assets/material'; -import { IRenderingSubmesh } from '../../3d/assets/mesh'; +import { IRenderingSubmesh, Mesh } from '../../3d/assets/mesh'; import { GFX_DRAW_INFO_SIZE, GFXBuffer, IGFXIndirectBuffer } from '../../gfx/buffer'; import { GFXAttributeName, GFXBufferUsageBit, GFXFormat, GFXFormatInfos, GFXMemoryUsageBit, GFXPrimitiveMode } from '../../gfx/define'; @@ -22,6 +22,9 @@ export default class ParticleBatchModel extends Model { private _iaInfo: IGFXIndirectBuffer; private _iaInfoBuffer: GFXBuffer; private _subMeshData: IRenderingSubmesh | null; + private _mesh: Mesh | null; + private _vertCount: number = 0; + private _indexCount: number = 0; constructor (scene: RenderScene, node: Node) { super(scene, node); @@ -52,21 +55,30 @@ export default class ParticleBatchModel extends Model { stride: 1, }); this._subMeshData = null; + this._mesh = null; } public setCapacity (capacity: number) { this._capacity = capacity; + if (this._inited) { + this.setVertexAttributes(this._mesh, this._vertAttrs!); + } } - public setVertexAttributes (attrs: IGFXAttribute[]) { + public setVertexAttributes (mesh: Mesh | null, attrs: IGFXAttribute[]) { + if (this._mesh === mesh && this._vertAttrs === attrs) { + return; + } + this._mesh = mesh; this._vertAttrs = attrs; this._vertSize = 0; for (const a of this._vertAttrs) { + (a as any).offset = this._vertSize; this._vertSize += GFXFormatInfos[a.format].size; } + this._vertAttrsFloatCount = this._vertSize / 4; // number of float // rebuid this._vBuffer = this._createSubMeshData(); - this._vertAttrsFloatCount = this._vertSize / 4; // number of float this._vdataF32 = new Float32Array(this._vBuffer); this._vdataUint32 = new Uint32Array(this._vBuffer); this._inited = true; @@ -76,38 +88,73 @@ export default class ParticleBatchModel extends Model { if (this._subMeshData) { this.destroySubMeshData(); } + this._vertCount = 4; + this._indexCount = 6; + if (this._mesh) { + this._vertCount = this._mesh.struct.vertexBundles[this._mesh.struct.primitives[0].vertexBundelIndices[0]].view.count; + this._indexCount = this._mesh.struct.primitives[0].indexView!.count; + } const vertexBuffer = this._device.createBuffer({ usage: GFXBufferUsageBit.VERTEX | GFXBufferUsageBit.TRANSFER_DST, memUsage: GFXMemoryUsageBit.HOST | GFXMemoryUsageBit.DEVICE, - size: this._vertSize * this._capacity * 4, + size: this._vertSize * this._capacity * this._vertCount, stride: this._vertSize, }); - const vBuffer: ArrayBuffer = new ArrayBuffer(this._vertSize * this._capacity * 4); + const vBuffer: ArrayBuffer = new ArrayBuffer(this._vertSize * this._capacity * this._vertCount); + if (this._mesh) { + let vIdx = this._vertAttrs!.findIndex((val) => val.name === GFXAttributeName.ATTR_TEX_COORD2); + let vOffset = (this._vertAttrs![vIdx++] as any).offset; + this._mesh.copyAttribute(0, GFXAttributeName.ATTR_POSITION, vBuffer, this._vertSize, vOffset); + vOffset = (this._vertAttrs![vIdx++] as any).offset; + this._mesh.copyAttribute(0, GFXAttributeName.ATTR_NORMAL, vBuffer, this._vertSize, vOffset); + vOffset = (this._vertAttrs![this._vertAttrs!.findIndex((val) => val.name === GFXAttributeName.ATTR_TEX_COORD)] as any).offset; + this._mesh.copyAttribute(0, GFXAttributeName.ATTR_TEX_COORD, vBuffer, this._vertSize, vOffset); + vOffset = (this._vertAttrs![vIdx++] as any).offset; + if (!this._mesh.copyAttribute(0, GFXAttributeName.ATTR_COLOR, vBuffer, this._vertSize, vOffset)) { + const vb = new Uint32Array(vBuffer); + for (let iVertex = 0; iVertex < this._vertCount; ++iVertex) { + vb[iVertex * this._vertAttrsFloatCount + vOffset / 4] = cc.Color.WHITE._val; + } + } + const vbFloatArray = new Float32Array(vBuffer); + for (let i = 1; i < this._capacity; i++) { + vbFloatArray.copyWithin(i * this._vertSize * this._vertCount / 4, 0, this._vertSize * this._vertCount / 4); + } + } vertexBuffer.update(vBuffer); - const indices: Uint16Array = new Uint16Array(this._capacity * 6); - let dst = 0; - for (let i = 0; i < this._capacity; ++i) { - const baseIdx = 4 * i; - indices[dst++] = baseIdx; - indices[dst++] = baseIdx + 1; - indices[dst++] = baseIdx + 2; - indices[dst++] = baseIdx + 3; - indices[dst++] = baseIdx + 2; - indices[dst++] = baseIdx + 1; + const indices: Uint16Array = new Uint16Array(this._capacity * this._indexCount); + if (this._mesh) { + this._mesh.copyIndices(0, indices); + for (let i = 1; i < this._capacity; i++) { + for (let j = 0; j < this._indexCount; j++) { + indices[i * this._indexCount + j] = indices[j] + i * this._vertCount; + } + } + } else { + let dst = 0; + for (let i = 0; i < this._capacity; ++i) { + const baseIdx = 4 * i; + indices[dst++] = baseIdx; + indices[dst++] = baseIdx + 1; + indices[dst++] = baseIdx + 2; + indices[dst++] = baseIdx + 3; + indices[dst++] = baseIdx + 2; + indices[dst++] = baseIdx + 1; + } } const indexBuffer = this._device.createBuffer({ usage: GFXBufferUsageBit.INDEX | GFXBufferUsageBit.TRANSFER_DST, memUsage: GFXMemoryUsageBit.HOST | GFXMemoryUsageBit.DEVICE, - size: this._capacity * 6 * Uint16Array.BYTES_PER_ELEMENT, + size: this._capacity * this._indexCount * Uint16Array.BYTES_PER_ELEMENT, stride: Uint16Array.BYTES_PER_ELEMENT, }); indexBuffer.update(indices); - this._iaInfo.drawInfos[0].vertexCount = this._capacity * 4; - this._iaInfo.drawInfos[0].indexCount = this._capacity * 6; + this._iaInfo.drawInfos[0].vertexCount = this._capacity * this._vertCount; + this._iaInfo.drawInfos[0].indexCount = this._capacity * this._indexCount; this._iaInfoBuffer.update(this._iaInfo); this._subMeshData = { @@ -126,51 +173,38 @@ export default class ParticleBatchModel extends Model { super.setSubModelMaterial(idx, mat); } - public enableStretchedBillboard () { - if (this._vertAttrs!.find((attr) => attr.name === GFXAttributeName.ATTR_COLOR1) === undefined) { - this._vertAttrs!.push({ name: GFXAttributeName.ATTR_COLOR1, format: GFXFormat.RGB32F }); - this.setVertexAttributes(this._vertAttrs!); - } - } - - public disableStretchedBillboard () { - if (this._vertAttrs!.find((attr) => attr.name === GFXAttributeName.ATTR_COLOR1) !== undefined) { - this._vertAttrs!.pop(); - this.setVertexAttributes(this._vertAttrs!); - } - } - public addParticleVertexData (index: number, pvdata: any[]) { - // if (pvdata.length !== this._vertAttrs.length) { - // console.error('particle vertex stream data not match.'); - // } - let offset: number = index * this._vertAttrsFloatCount; - for (let i = 0; i < this._vertAttrs!.length; ++i) { - const curAttr: IGFXAttribute = this._vertAttrs![i]; - if (curAttr.format === GFXFormat.R32F) { - this._vdataF32![offset] = pvdata[i]; // if not a single float? - offset++; - } else if (curAttr.format === GFXFormat.RG32F) { - this._vdataF32![offset] = pvdata[i].x; - this._vdataF32![offset + 1] = pvdata[i].y; + if (!this._mesh) { + let offset: number = index * this._vertAttrsFloatCount; + this._vdataF32![offset++] = pvdata[0].x; // if not a single float? + this._vdataF32![offset++] = pvdata[0].y; + this._vdataF32![offset++] = pvdata[0].z; + this._vdataF32![offset++] = pvdata[1].x; + this._vdataF32![offset++] = pvdata[1].y; + this._vdataF32![offset++] = pvdata[1].z; + this._vdataF32![offset++] = pvdata[2].x; + this._vdataF32![offset++] = pvdata[2].y; + this._vdataUint32![offset++] = pvdata[3]; + } else { + for (let i = 0; i < this._vertCount; i++) { + let offset: number = (index * this._vertCount + i) * this._vertAttrsFloatCount; + this._vdataF32![offset++] = pvdata[0].x; // if not a single float? + this._vdataF32![offset++] = pvdata[0].y; + this._vdataF32![offset++] = pvdata[0].z; offset += 2; - } else if (curAttr.format === GFXFormat.RGB32F) { - this._vdataF32![offset] = pvdata[i].x; - this._vdataF32![offset + 2] = pvdata[i].z; - this._vdataF32![offset + 1] = pvdata[i].y; - offset += 3; - } else if (curAttr.format === GFXFormat.RGBA8) { - this._vdataUint32![offset] = pvdata[i]; - offset += 1; - } else { - console.error('particle vertex attribute format not support'); + // this._vdataF32![offset++] = index; + // this._vdataF32![offset++] = pvdata[1].y; + this._vdataF32![offset++] = index; + this._vdataF32![offset++] = pvdata[2].x; + this._vdataF32![offset++] = pvdata[2].y; + this._vdataUint32![offset++] = pvdata[3]; } } } public updateIA (count: number) { this.getSubModel(0).inputAssembler!.vertexBuffers[0].update(this._vdataF32!); - this.getSubModel(0).inputAssembler!.indexCount = count; + this.getSubModel(0).inputAssembler!.indexCount = this._indexCount * count; this.getSubModel(0).inputAssembler!.extractDrawInfo(this._iaInfo.drawInfos[0]); this._iaInfoBuffer.update(this._iaInfo); } diff --git a/cocos/renderer/scene/submodel.ts b/cocos/renderer/scene/submodel.ts index c3e8e116c1..cf14a3a632 100644 --- a/cocos/renderer/scene/submodel.ts +++ b/cocos/renderer/scene/submodel.ts @@ -71,6 +71,7 @@ export class SubModel { } if (this._inputAssembler) { this._inputAssembler.initialize(iaInfo); + this.updateCommandBuffer(); } else { this._inputAssembler = (cc.director.root.device as GFXDevice).createInputAssembler(iaInfo); }