From 831d3bb3f23a6728414df508bf25d4cd09399f51 Mon Sep 17 00:00:00 2001 From: Jone <350791117@qq.com> Date: Tue, 29 Jan 2019 21:38:03 +0800 Subject: [PATCH] commit ttf --- cocos/2d/renderer/utils/label/ttf.js | 4 +- cocos/3d/ui/assembler/label/ttf.ts | 23 +++-- cocos/3d/ui/assembler/sprite/bar-filled.ts | 3 +- cocos/3d/ui/components/label-component.ts | 40 +++++--- cocos/3d/ui/components/sprite-component.ts | 4 +- playground/files.js | 2 +- playground/ui-render.html | 112 +++++++++++++++++++++ 7 files changed, 159 insertions(+), 29 deletions(-) create mode 100644 playground/ui-render.html diff --git a/cocos/2d/renderer/utils/label/ttf.js b/cocos/2d/renderer/utils/label/ttf.js index 2adb5d0709..40c2826a2f 100644 --- a/cocos/2d/renderer/utils/label/ttf.js +++ b/cocos/2d/renderer/utils/label/ttf.js @@ -127,7 +127,7 @@ export default { comp._actualFontSize = _fontSize; comp.node.setContentSize(_canvasSize); - this._updateVerts(comp); + this.updateVerts(comp); comp._renderData.vertDirty = comp._renderData.uvDirty = false; @@ -136,7 +136,7 @@ export default { _texture = null; }, - _updateVerts() { + updateVerts() { }, _updateFontFamly(comp) { diff --git a/cocos/3d/ui/assembler/label/ttf.ts b/cocos/3d/ui/assembler/label/ttf.ts index edd7a7a8a4..90b1e1800b 100644 --- a/cocos/3d/ui/assembler/label/ttf.ts +++ b/cocos/3d/ui/assembler/label/ttf.ts @@ -26,12 +26,14 @@ import ttfUtls from '../../../../2d/renderer/utils/label/ttf'; import * as js from '../../../../core/utils/js'; import { RenderData } from '../../../../renderer/ui/renderData'; -import { UI } from '../../../../renderer/ui/ui'; +import { UI, IUIRenderData } from '../../../../renderer/ui/ui'; import { LabelComponent } from '../../components/label-component'; import { IAssembler} from '../assembler'; import { fillMeshVertices3D } from '../utils'; +import { MeshBuffer } from '../../mesh-buffer'; +import { color4 } from '../../../../core/vmath'; -const WHITE = cc.color(255, 255, 255, 255); +const WHITE = color4.create(); export const ttf: IAssembler = { useModel: false, @@ -55,8 +57,19 @@ export const ttf: IAssembler = { return renderData as RenderData; }, - fillBuffers (comp: LabelComponent, /*renderer*/buffer: UI) { - fillMeshVertices3D(comp.node, /*renderer._quadBuffer3D*/buffer, comp.renderData, WHITE); + fillBuffers (comp: LabelComponent, renderer: UI) { + const buffer: MeshBuffer = renderer.createBuffer( + comp.renderData!.vertexCount, + comp.renderData!.indiceCount, + ); + const commitBuffer: IUIRenderData = renderer.createUIRenderData(); + fillMeshVertices3D(comp.node, buffer, comp.renderData, WHITE); + + commitBuffer.meshBuffer = buffer; + commitBuffer.material = comp.material!; + commitBuffer.texture = comp.texture!; + commitBuffer.priority = comp.priority; + renderer.addToQueue(commitBuffer); }, updateVerts (comp: LabelComponent) { @@ -78,8 +91,6 @@ export const ttf: IAssembler = { datas[3].x = width - appx; datas[3].y = height - appy; }, - - updateRenderData (comp: LabelComponent) {}, }; js.addon(ttf, ttfUtls); diff --git a/cocos/3d/ui/assembler/sprite/bar-filled.ts b/cocos/3d/ui/assembler/sprite/bar-filled.ts index 9ffae1be79..251b5479c8 100644 --- a/cocos/3d/ui/assembler/sprite/bar-filled.ts +++ b/cocos/3d/ui/assembler/sprite/bar-filled.ts @@ -237,8 +237,7 @@ export const barFilled: IAssembler = { const node = sprite.node; const datas = sprite.renderData!.datas; - // node._updateWorldMatrix(); - // const matrix = node._worldMatrix; + node.getWorldMatrix(matrix); for (let i = 0; i < 4; i++) { const local = datas[i + 4]; const world = datas[i]; diff --git a/cocos/3d/ui/components/label-component.ts b/cocos/3d/ui/components/label-component.ts index 79b96d186c..db87a8d3e9 100644 --- a/cocos/3d/ui/components/label-component.ts +++ b/cocos/3d/ui/components/label-component.ts @@ -39,6 +39,7 @@ import macro from '../../../core/platform/CCMacro'; import { Enum } from '../../../core/value-types'; import { MeshBuffer } from '../mesh-buffer'; import { UIRenderComponent } from './ui-render-component'; +import { SpriteFrame } from '../../../assets/CCSpriteFrame'; // import { value } from '../../../core/utils/js'; /** @@ -465,6 +466,10 @@ export class LabelComponent extends UIRenderComponent { this._isUnderline = value; } + get texture(){ + return this._texture; + } + public static HorizontalAlign = HorizontalAlign; public static VerticalAlign = VerticalAlign; public static Overflow = Overflow; @@ -506,8 +511,8 @@ export class LabelComponent extends UIRenderComponent { public _isUnderline: boolean = false; // don't need serialize - private _texture: Texture2D | null = null; - private _ttfTexture: Texture2D | null = null; + private _texture: SpriteFrame | null = null; + private _ttfTexture: SpriteFrame | null = null; private _userDefinedFont: Font | null = null; private _assemblerData: object|null = null; @@ -597,30 +602,33 @@ export class LabelComponent extends UIRenderComponent { } } - public _activateMaterial (force: boolean) { + private _activateMaterial (force: boolean) { let material = this.material; - if (material && !force) { - return; - } + // if (material && !force) { + // return; + // } - if (!material) { - // material = new SpriteMaterial(); - this.material = cc.builtinResMgr.get('sprite-material'); - material = this.material; - } + // if (!material) { + // // material = new SpriteMaterial(); + // this.material = cc.builtinResMgr.get('sprite-material'); + // material = this.material; + // } // Setup blend function for premultiplied ttf label texture if (this._texture === this._ttfTexture) { this._srcBlendFactor = cc.macro.BlendFactor.ONE; } else { this._srcBlendFactor = cc.macro.BlendFactor.SRC_ALPHA; } - material!.setProperty('u_texSampler', this._texture); + + if (material) { + material.setProperty('u_texSampler', this._texture); + } // For batch rendering, do not use uniform color. // material!.useColor = false; // this._updateMaterial(material); } - public _applyFontTexture (force: boolean) { + private _applyFontTexture (force: boolean) { const font = this._font; if (font instanceof cc.BitmapFont) { const spriteFrame = font.spriteFrame; @@ -655,7 +663,7 @@ export class LabelComponent extends UIRenderComponent { // this._ttfTexture.setPremultiplyAlpha(true); } this._assemblerData = this._assembler._getAssemblerData(); - this._ttfTexture.image = new ImageAsset(this._assemblerData.canvas); + this._ttfTexture!.image = new ImageAsset(this._assemblerData.canvas); // this._ttfTexture.initWithElement(this._assemblerData.canvas); } this._texture = this._ttfTexture; @@ -667,7 +675,7 @@ export class LabelComponent extends UIRenderComponent { } } - public _updateColor () { + private _updateColor () { const font = this.font; if (font instanceof cc.BitmapFont) { // this._super(); @@ -677,7 +685,7 @@ export class LabelComponent extends UIRenderComponent { } } - public _updateRenderData (force: boolean = false) { + private _updateRenderData (force: boolean = false) { const renderData = this._renderData; if (renderData) { renderData.vertDirty = true; diff --git a/cocos/3d/ui/components/sprite-component.ts b/cocos/3d/ui/components/sprite-component.ts index 8981335291..6b85f816f3 100644 --- a/cocos/3d/ui/components/sprite-component.ts +++ b/cocos/3d/ui/components/sprite-component.ts @@ -58,7 +58,7 @@ enum SpriteType { // * !#zh 平铺类型 // * @property {Number} TILED // */ - TILED = 2, + // TILED = 2, /** * !#en The filled type. * !#zh 填充类型 @@ -98,7 +98,7 @@ enum FillType { // * !#zh 径向填充 // * @property {Number} RADIAL // */ - RADIAL = 2, + // RADIAL = 2, }; ccenum(FillType); diff --git a/playground/files.js b/playground/files.js index 9964bb6342..e20c98d812 100644 --- a/playground/files.js +++ b/playground/files.js @@ -1,7 +1,7 @@ window.files = { "aa": [ "simple", - "ui" + "ui-render" ], // "animation": [ // "spec-skeleton" diff --git a/playground/ui-render.html b/playground/ui-render.html new file mode 100644 index 0000000000..73035deb3b --- /dev/null +++ b/playground/ui-render.html @@ -0,0 +1,112 @@ + + + +
+