mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
bd3c30fd4c
* VB cache add(only simple) * sliced add * after rebase * Extract BufferAccessor from MeshBuffer * Refactor for linear buffer accessor * Support simple sprite * Fix initialization issues * Fix simple sprite rendering * Rough adaptation * tweaks * Fix LinearBufferAccessor's appendBuffers * Cleanup mesh buffer codes * Reorganize ia allocation * Middleware adaptation & Particle 2d adaptation (#31) * Middleware adaptation * particle-2d adaptation * Initial implementation of static vb accessor * Complete static vb accessor * Improve static vb accessor * Ensure MeshBuffer.byteOffset * Fix record batch process in static vb accessor * Fix vb reset * simple & simple label add (#32) * Meshbuffer static length (#33) * set ib only first time * Meshbuffer static length * Some name refactor * remove RenderData.vData * Improve buffer update logics * Use appendIndices in fillBuffers * The quickest version(simple & label can render) (#34) * Revert "Use appendIndices in fillBuffers" This reverts commit 0600e26f7eee277c820c3097b1f48f79fcf60890. * the quickest version * pass renderScene * batch * change batcher update Co-authored-by: pandamicro <lphuabin@gmail.com> * Move ia record logic from accessor to batcher * Make vertexFormat sourced from render data * sliced & bar-filled (#35) * radial-filled & tiled & label (#36) * radial-filled & tiled * bmfont & char label * function change * name change * Remove uvDirty fixes Fix uv update for sprite * Reduce mesh buffer setDirty * uv fix * Format label * Refactor color and cascade opacity mechanism * Fix empty render data or chunk absent issue * fix some uv (#37) * Fix non stop allocation issue in static vb accessor * fix bmfont richText & remove uiComponent (#38) * fix bmfont uv * fix richText & remove ui Component * Fix mesh render data batching * Small fix * Update for spine * Formatting jsb spine and editor * middle ware & particle 2d (#39) * motion-streak * dragon Bones add * tiled map unsafe change * particle-2d add * function name change * some function change (#40) * Fix RenderData pool usage * Fix merge issue * fix misc bug (#41) * Native adaptation for spine and dragonbones with MeshRenderData * misc fix (#42) * Improvements * Fix ci and improvements Co-authored-by: ChiaNing <sun.cloud.mo@gmail.com>
89 lines
3.4 KiB
TypeScript
89 lines
3.4 KiB
TypeScript
/*
|
|
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
|
|
|
|
https://www.cocos.com/
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated engine source code (the "Software"), a limited,
|
|
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
|
to use Cocos Creator solely to develop games on your target platforms. You shall
|
|
not use Cocos Creator software for developing other software or tools that's
|
|
used for developing games. You are not granted to publish, distribute,
|
|
sublicense, and/or sell copies of Cocos Creator.
|
|
|
|
The software or tools in this License Agreement are licensed, not sold.
|
|
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
|
|
/**
|
|
* @packageDocumentation
|
|
* @hidden
|
|
*/
|
|
|
|
import { Color, Mat4, Vec3 } from '../../core/math';
|
|
import { RenderData } from '../renderer/render-data';
|
|
import { IBatcher } from '../renderer/i-batcher';
|
|
import { Node } from '../../core/scene-graph/node';
|
|
import { assertIsTrue } from '../../core/data/utils/asserts';
|
|
import { vfmtPosColor, vfmtPosUvColor } from '../renderer/vertex-format';
|
|
|
|
const vec3_temp = new Vec3();
|
|
const _worldMatrix = new Mat4();
|
|
|
|
export function fillMeshVertices3D (node: Node, renderer: IBatcher, renderData: RenderData, color: Color) {
|
|
const chunk = renderData.chunk;
|
|
const dataList = renderData.data;
|
|
const vData = chunk.vb;
|
|
const vertexCount = renderData.vertexCount;
|
|
|
|
node.getWorldMatrix(_worldMatrix);
|
|
|
|
let vertexOffset = 0;
|
|
for (let i = 0; i < vertexCount; i++) {
|
|
const vert = dataList[i];
|
|
Vec3.set(vec3_temp, vert.x, vert.y, 0);
|
|
Vec3.transformMat4(vec3_temp, vec3_temp, _worldMatrix);
|
|
vData[vertexOffset++] = vec3_temp.x;
|
|
vData[vertexOffset++] = vec3_temp.y;
|
|
vData[vertexOffset++] = vec3_temp.z;
|
|
Color.toArray(vData, color, vertexOffset + 2);
|
|
vertexOffset += 6;
|
|
}
|
|
|
|
// fill index data
|
|
const bid = chunk.bufferId;
|
|
const vid = chunk.vertexOffset;
|
|
const meshBuffer = chunk.vertexAccessor.getMeshBuffer(chunk.bufferId);
|
|
const ib = chunk.vertexAccessor.getIndexBuffer(bid);
|
|
let indexOffset = meshBuffer.indexOffset;
|
|
for (let i = 0, count = vertexCount / 4; i < count; i++) {
|
|
const start = vid + i * 4;
|
|
ib[indexOffset++] = start;
|
|
ib[indexOffset++] = start + 1;
|
|
ib[indexOffset++] = start + 2;
|
|
ib[indexOffset++] = start + 1;
|
|
ib[indexOffset++] = start + 3;
|
|
ib[indexOffset++] = start + 2;
|
|
}
|
|
meshBuffer.indexOffset += renderData.indexCount;
|
|
meshBuffer.setDirty();
|
|
}
|
|
|
|
export function updateOpacity (renderData: RenderData, opacity: number) {
|
|
const vfmt = renderData.vertexFormat;
|
|
assertIsTrue(vfmt && (vfmt === vfmtPosColor || vfmt === vfmtPosUvColor));
|
|
const vb = renderData.chunk.vb;
|
|
const floatStride = renderData.floatStride;
|
|
for (let offset = floatStride - 1; offset < vb.length; offset += floatStride) {
|
|
vb[offset] = opacity;
|
|
}
|
|
}
|