mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
reorganize rendering components
This commit is contained in:
@@ -33,7 +33,7 @@ import { IAssembler} from '../assembler';
|
||||
import { fillMeshVertices3D } from '../utils';
|
||||
import { ttfUtils } from './ttfUtils';
|
||||
|
||||
const WHITE = new Color();
|
||||
const WHITE = Color.WHITE;
|
||||
|
||||
export const ttf: IAssembler = {
|
||||
useModel: false,
|
||||
|
||||
@@ -32,7 +32,7 @@ import { Color, Size } from '../../../../core/value-types';
|
||||
import { LabelComponent } from '../../components/label-component';
|
||||
|
||||
const Overflow = LabelComponent.Overflow;
|
||||
const WHITE = cc.Color.WHITE;
|
||||
const WHITE = Color.WHITE;
|
||||
const OUTLINE_SUPPORTED = cc.js.isChildClassOf(LabelOutline, Component);
|
||||
|
||||
let _context: CanvasRenderingContext2D | null = null;
|
||||
@@ -136,7 +136,7 @@ export const ttfUtils = {
|
||||
this._calculateTextBaseline();
|
||||
this._updateTexture();
|
||||
|
||||
comp._actualFontSize = _fontSize;
|
||||
// comp._actualFontSize = _fontSize;
|
||||
comp.node.setContentSize(_canvasSize);
|
||||
|
||||
this.updateVerts(comp);
|
||||
@@ -184,18 +184,18 @@ export const ttfUtils = {
|
||||
_texture = comp.texture;
|
||||
|
||||
_string = comp.string.toString();
|
||||
_fontSize = comp._fontSize;
|
||||
_fontSize = comp.fontSize;
|
||||
_drawFontsize = _fontSize;
|
||||
_overflow = comp.overflow;
|
||||
_canvasSize.width = comp.node.width!;
|
||||
_canvasSize.height = comp.node.height!;
|
||||
_lineHeight = comp._lineHeight;
|
||||
_lineHeight = comp.lineHeight;
|
||||
_hAlign = comp.horizontalAlign;
|
||||
_vAlign = comp.verticalAlign;
|
||||
_color = comp.color;
|
||||
_isBold = comp._isBold;
|
||||
_isItalic = comp._isItalic;
|
||||
_isUnderline = comp._isUnderline;
|
||||
_isBold = comp.isBold;
|
||||
_isItalic = comp.isItalic;
|
||||
_isUnderline = comp.isUnderline;
|
||||
|
||||
if (_overflow === Overflow.NONE) {
|
||||
_isWrapText = false;
|
||||
@@ -290,8 +290,7 @@ export const ttfUtils = {
|
||||
}
|
||||
|
||||
// _texture.handleLoadedTexture();
|
||||
// hack
|
||||
if (_texture && _texture.image && _texture.image!.width !== 0 && _texture.image!.height !== 0) {
|
||||
if (_texture) {
|
||||
_texture.mipmaps = [_texture.image!];
|
||||
}
|
||||
},
|
||||
@@ -408,6 +407,10 @@ export const ttfUtils = {
|
||||
fontDesc = 'bold ' + fontDesc;
|
||||
}
|
||||
|
||||
if (_isItalic) {
|
||||
fontDesc = 'italic ' + fontDesc;
|
||||
}
|
||||
|
||||
return fontDesc;
|
||||
},
|
||||
|
||||
|
||||
@@ -28,15 +28,15 @@ import { SpriteFrame } from '../../../assets/CCSpriteFrame';
|
||||
import ComponentEventHandler from '../../../components/CCComponentEventHandler';
|
||||
import { Component} from '../../../components/component';
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator';
|
||||
import { EventTouch, EventMouse } from '../../../core/platform/event-manager';
|
||||
import { EventMouse, EventTouch } from '../../../core/platform/event-manager';
|
||||
import { lerp } from '../../../core/utils/misc';
|
||||
import { Color, Vec3 } from '../../../core/value-types/index';
|
||||
import { ccenum } from '../../../core/value-types/enum';
|
||||
import { Color, Vec3 } from '../../../core/value-types/index';
|
||||
import * as math from '../../../core/vmath/index';
|
||||
import { Node } from '../../../scene-graph';
|
||||
import { EventType } from '../../../scene-graph/node-event-enum';
|
||||
import { SpriteComponent } from './sprite-component';
|
||||
import { UIRenderComponent } from './ui-render-component';
|
||||
import { EventType } from '../../../scene-graph/node-event-enum';
|
||||
|
||||
/**
|
||||
* !#en Enum for transition type.
|
||||
@@ -79,7 +79,7 @@ enum State {
|
||||
HOVER = 'hover',
|
||||
PRESSED = 'pressed',
|
||||
DISABLED = 'disabled',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* !#en
|
||||
@@ -348,7 +348,7 @@ export class ButtonComponent extends Component {
|
||||
|
||||
this._normalSprite = value;
|
||||
const sprite = this.node.getComponent(SpriteComponent);
|
||||
if(sprite){
|
||||
if (sprite){
|
||||
sprite.spriteFrame = value;
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ export class ButtonComponent extends Component {
|
||||
* @property {Node} target
|
||||
*/
|
||||
@property({
|
||||
type: Node
|
||||
type: Node,
|
||||
})
|
||||
get target () {
|
||||
return this._target;
|
||||
@@ -521,21 +521,6 @@ export class ButtonComponent extends Component {
|
||||
this._updateState();
|
||||
}
|
||||
|
||||
private _resetState () {
|
||||
this._pressed = false;
|
||||
this._hovered = false;
|
||||
// Restore button status
|
||||
const target = this._target;
|
||||
const renderComp = target.getComponent(UIRenderComponent);
|
||||
const transition = this._transition;
|
||||
if (transition === Transition.COLOR && this._interactable) {
|
||||
renderComp.color = this._normalColor;
|
||||
} else if (transition === Transition.SCALE) {
|
||||
target.scale = this._originalScale;
|
||||
}
|
||||
this._transitionFinished = true;
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
// check sprite frames
|
||||
if (this._normalSprite) {
|
||||
@@ -581,7 +566,7 @@ export class ButtonComponent extends Component {
|
||||
}
|
||||
|
||||
public update (dt: number) {
|
||||
const target = this._target? this._target: this.node;;
|
||||
const target = this._target ? this._target : this.node;
|
||||
if (this._transitionFinished) {
|
||||
return;
|
||||
}
|
||||
@@ -612,6 +597,27 @@ export class ButtonComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
protected _resizeNodeToTargetNode () {
|
||||
if (CC_EDITOR && this._target) {
|
||||
this.node.setContentSize(this.target.getContentSize());
|
||||
}
|
||||
}
|
||||
|
||||
private _resetState () {
|
||||
this._pressed = false;
|
||||
this._hovered = false;
|
||||
// Restore button status
|
||||
const target = this._target;
|
||||
const renderComp = target.getComponent(UIRenderComponent);
|
||||
const transition = this._transition;
|
||||
if (transition === Transition.COLOR && this._interactable) {
|
||||
renderComp.color = this._normalColor;
|
||||
} else if (transition === Transition.SCALE) {
|
||||
target.scale = this._originalScale;
|
||||
}
|
||||
this._transitionFinished = true;
|
||||
}
|
||||
|
||||
private _registerEvent () {
|
||||
this.node.on(EventType.TOUCH_START, this._onTouchBegan, this);
|
||||
this.node.on(EventType.TOUCH_MOVE, this._onTouchMove, this);
|
||||
@@ -638,17 +644,17 @@ export class ButtonComponent extends Component {
|
||||
}
|
||||
|
||||
// touch event handler
|
||||
private _onTouchBegan(event?: EventTouch) {
|
||||
private _onTouchBegan (event?: EventTouch) {
|
||||
if (!this._interactable || !this.enabledInHierarchy) { return; }
|
||||
|
||||
this._pressed = true;
|
||||
this._updateState();
|
||||
if(event){
|
||||
event.propagationStopped = true
|
||||
};
|
||||
if (event){
|
||||
event.propagationStopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
private _onTouchMove(event?: EventTouch) {
|
||||
private _onTouchMove (event?: EventTouch) {
|
||||
if (!this._interactable || !this.enabledInHierarchy || !this._pressed) { return; }
|
||||
// mobile phone will not emit _onMouseMoveOut,
|
||||
// so we have to do hit test when touch moving
|
||||
@@ -671,7 +677,7 @@ export class ButtonComponent extends Component {
|
||||
} else {
|
||||
this._time = 0;
|
||||
this._transitionFinished = true;
|
||||
if(this._target){
|
||||
if (this._target){
|
||||
this._target!.setScale(this._originalScale);
|
||||
}
|
||||
}
|
||||
@@ -686,11 +692,11 @@ export class ButtonComponent extends Component {
|
||||
}
|
||||
|
||||
if (event) {
|
||||
event.propagationStopped = true
|
||||
event.propagationStopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
private _onTouchEnded(event?: EventTouch) {
|
||||
private _onTouchEnded (event?: EventTouch) {
|
||||
if (!this._interactable || !this.enabledInHierarchy) {
|
||||
return;
|
||||
}
|
||||
@@ -703,11 +709,11 @@ export class ButtonComponent extends Component {
|
||||
this._updateState();
|
||||
|
||||
if (event) {
|
||||
event.propagationStopped = true
|
||||
};
|
||||
event.propagationStopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
private _onTouchCancel(event?: EventTouch) {
|
||||
private _onTouchCancel (event?: EventTouch) {
|
||||
if (!this._interactable || !this.enabledInHierarchy) { return; }
|
||||
|
||||
this._pressed = false;
|
||||
@@ -724,7 +730,7 @@ export class ButtonComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
private _onMouseMoveOut(event?: EventMouse) {
|
||||
private _onMouseMoveOut (event?: EventMouse) {
|
||||
if (this._hovered) {
|
||||
this._hovered = false;
|
||||
this._updateState();
|
||||
@@ -753,7 +759,7 @@ export class ButtonComponent extends Component {
|
||||
private _updateColorTransition (state: string) {
|
||||
const color = this[state + 'Color'];
|
||||
const target = this._target;
|
||||
if(!target){
|
||||
if (!target){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -780,7 +786,7 @@ export class ButtonComponent extends Component {
|
||||
}
|
||||
|
||||
private _updateScaleTransition (state: string) {
|
||||
if(!this._interactable){
|
||||
if (!this._interactable){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -816,12 +822,6 @@ export class ButtonComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
protected _resizeNodeToTargetNode () {
|
||||
if (CC_EDITOR && this._target) {
|
||||
this.node.setContentSize(this.target.getContentSize());
|
||||
}
|
||||
}
|
||||
|
||||
// _updateDisabledState() {
|
||||
// if (this._sprite) {
|
||||
// if (this.enableAutoGrayEffect) {
|
||||
|
||||
@@ -214,6 +214,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
@property({
|
||||
readonly: true,
|
||||
displayName: 'Actual Font Size',
|
||||
visible: false,
|
||||
})
|
||||
get actualFontSize () {
|
||||
return this._actualFontSize;
|
||||
@@ -301,7 +302,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
* !#zh 是否自动换行。
|
||||
* @property {Boolean} enableWrapText
|
||||
*/
|
||||
@property
|
||||
@property()
|
||||
get enableWrapText () {
|
||||
return this._enableWrapText;
|
||||
}
|
||||
@@ -402,7 +403,6 @@ export class LabelComponent extends UIRenderComponent {
|
||||
|
||||
}
|
||||
|
||||
@property
|
||||
get spacingX () {
|
||||
return this._spacingX;
|
||||
}
|
||||
@@ -421,7 +421,9 @@ export class LabelComponent extends UIRenderComponent {
|
||||
* !#zh 字体是否加粗。
|
||||
* @property {Boolean} isBold
|
||||
*/
|
||||
@property
|
||||
@property({
|
||||
// visible: false,
|
||||
})
|
||||
get isBold () {
|
||||
return this._isBold;
|
||||
}
|
||||
@@ -432,6 +434,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
|
||||
this._isBold = value;
|
||||
this.updateRenderData();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -439,7 +442,9 @@ export class LabelComponent extends UIRenderComponent {
|
||||
* !#zh 字体是否倾斜。
|
||||
* @property {Boolean} isItalic
|
||||
*/
|
||||
@property
|
||||
@property({
|
||||
// visible: false,
|
||||
})
|
||||
get isItalic () {
|
||||
return this._isItalic;
|
||||
}
|
||||
@@ -450,6 +455,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
|
||||
this._isItalic = value;
|
||||
this.updateRenderData();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -457,7 +463,9 @@ export class LabelComponent extends UIRenderComponent {
|
||||
* !#zh 字体是否加下划线。
|
||||
* @property {Boolean} isUnderline
|
||||
*/
|
||||
@property
|
||||
@property({
|
||||
// visible: false,
|
||||
})
|
||||
get isUnderline () {
|
||||
return this._isUnderline;
|
||||
}
|
||||
@@ -468,6 +476,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
|
||||
this._isUnderline = value;
|
||||
this.updateRenderData();
|
||||
}
|
||||
|
||||
get texture (){
|
||||
@@ -517,7 +526,6 @@ export class LabelComponent extends UIRenderComponent {
|
||||
private _isSystemFontUsed = true;
|
||||
@property
|
||||
private _bmFontOriginalSize = -1;
|
||||
@property
|
||||
private _spacingX = 0;
|
||||
@property
|
||||
private _isItalic = false;
|
||||
@@ -543,7 +551,6 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
// this._super();
|
||||
super.onEnable();
|
||||
|
||||
// TODO: Hack for barbarians
|
||||
@@ -557,13 +564,10 @@ export class LabelComponent extends UIRenderComponent {
|
||||
|
||||
this._checkStringEmpty();
|
||||
this.updateRenderData(true);
|
||||
// this._updateAssembler();
|
||||
// this._activateMaterial();
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
super.onDisable();
|
||||
// this._super();
|
||||
}
|
||||
|
||||
public onDestroy () {
|
||||
@@ -576,7 +580,8 @@ export class LabelComponent extends UIRenderComponent {
|
||||
this._ttfTexture.destroy();
|
||||
this._ttfTexture = null;
|
||||
}
|
||||
// this._super();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public updateRenderData (force = false) {
|
||||
@@ -584,7 +589,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
if (renderData) {
|
||||
renderData.vertDirty = true;
|
||||
renderData.uvDirty = true;
|
||||
// this.markForUpdateRenderData(true);
|
||||
this.markForUpdateRenderData(true);
|
||||
}
|
||||
|
||||
if (force) {
|
||||
@@ -594,53 +599,31 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
|
||||
protected _updateColor () {
|
||||
const font = this.font;
|
||||
if (font instanceof cc.BitmapFont) {
|
||||
// this._super();
|
||||
if (this._font instanceof BitmapFont) {
|
||||
super._updateColor();
|
||||
} else {
|
||||
this.updateRenderData(false);
|
||||
// this.node._renderFlag &= ~RenderFlow.FLAG_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
protected _canRender () {
|
||||
// let result = this._super();
|
||||
// TODO: use renderFlag
|
||||
let result = super._canRender();
|
||||
// if (result) {
|
||||
// const font = this._font;
|
||||
// if (font && font instanceof cc.BitmapFont) {
|
||||
// const spriteFrame = font.spriteFrame;
|
||||
// // cannot be activated if texture not loaded yet
|
||||
// if (!spriteFrame || !spriteFrame.textureLoaded()) {
|
||||
// result = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (result) {
|
||||
result = this._string.length > 0 ? true : false;
|
||||
const font = this._font;
|
||||
if (font && font instanceof BitmapFont) {
|
||||
const spriteFrame = font.spriteFrame;
|
||||
// cannot be activated if texture not loaded yet
|
||||
if (!spriteFrame || !spriteFrame.textureLoaded()) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// private _canRender () {
|
||||
// // let result = this._super();
|
||||
// let result = this._enabled;
|
||||
// const font = this.font;
|
||||
// if (font instanceof cc.BitmapFont) {
|
||||
// const spriteFrame = font.spriteFrame;
|
||||
// // cannot be activated if texture not loaded yet
|
||||
// if (!spriteFrame || !spriteFrame.textureLoaded()) {
|
||||
// result = false;
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
private _checkStringEmpty () {
|
||||
// this.markForRender(!!this.string);
|
||||
this._renderPermit = !!this.string;
|
||||
}
|
||||
|
||||
private _flushAssembler () {
|
||||
@@ -659,30 +642,20 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private _activateMaterial (force) {
|
||||
private _flushMaterial () {
|
||||
const material = this._material;
|
||||
// if (material && !force) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 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;
|
||||
this._srcBlendFactor = macro.BlendFactor.ONE;
|
||||
} else {
|
||||
this._srcBlendFactor = cc.macro.BlendFactor.SRC_ALPHA;
|
||||
this._srcBlendFactor = macro.BlendFactor.SRC_ALPHA;
|
||||
}
|
||||
|
||||
if (material) {
|
||||
material.setProperty('mainTexture', this._texture);
|
||||
}
|
||||
// For batch rendering, do not use uniform color.
|
||||
// material!.useColor = false;
|
||||
// this._updateMaterial(material);
|
||||
|
||||
this._updateMaterial(material);
|
||||
}
|
||||
|
||||
private _applyFontTexture (force) {
|
||||
@@ -693,7 +666,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
const onBMFontTextureLoaded = () => {
|
||||
// TODO: old texture in material have been released by loader
|
||||
self._texture = spriteFrame;
|
||||
self._activateMaterial(force);
|
||||
self._flushMaterial();
|
||||
|
||||
if (force && self._assembler && self._assembler.updateRenderData) {
|
||||
self._assembler.updateRenderData(self);
|
||||
@@ -712,7 +685,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
}
|
||||
} else {
|
||||
if (!this._ttfTexture) {
|
||||
this._ttfTexture = new cc.SpriteFrame();
|
||||
this._ttfTexture = new SpriteFrame();
|
||||
// this._ttfTexture.setFilters(cc.Texture2D.Filter.LINEAR, cc.Texture2D.Filter.LINEAR);
|
||||
// this._ttfTexture.setWrapMode(cc.Texture2D.WrapMode.CLAMP_TO_EDGE, cc.Texture2D.WrapMode.CLAMP_TO_EDGE);
|
||||
// TTF texture in web will blend with canvas or body background color
|
||||
@@ -730,7 +703,7 @@ export class LabelComponent extends UIRenderComponent {
|
||||
// this._ttfTexture.initWithElement(this._assemblerData.canvas);
|
||||
}
|
||||
this._texture = this._ttfTexture;
|
||||
this._activateMaterial(force);
|
||||
this._flushMaterial();
|
||||
|
||||
if (force && this._assembler && this._assembler.updateRenderData) {
|
||||
this._assembler.updateRenderData(this);
|
||||
|
||||
@@ -216,17 +216,19 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
return this._fillType;
|
||||
}
|
||||
set fillType (value: FillType) {
|
||||
if (value !== this._fillType) {
|
||||
// if (value === FillType.RADIAL || this._fillType === FillType.RADIAL) {
|
||||
// // this.destroyRenderData(/*this._renderData*/);
|
||||
// this._renderData = null;
|
||||
// } else
|
||||
if (this._renderData) {
|
||||
this.markForUpdateRenderData(true);
|
||||
if (this._fillType !== value) {
|
||||
if (value === FillType.RADIAL || this._fillType === FillType.RADIAL) {
|
||||
this.destroyRenderData();
|
||||
this._renderData = null;
|
||||
} else {
|
||||
if (this._renderData) {
|
||||
this.markForUpdateRenderData(true);
|
||||
}
|
||||
}
|
||||
this._fillType = value;
|
||||
this._flushAssembler();
|
||||
}
|
||||
|
||||
this._fillType = value;
|
||||
this._flushAssembler();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,31 +429,20 @@ export class SpriteComponent extends UIRenderComponent {
|
||||
}
|
||||
}
|
||||
|
||||
// public onDisable () {
|
||||
// // this._super();
|
||||
// super.onDisable();
|
||||
// }
|
||||
public markForUpdateRenderData (enable: boolean = true) {
|
||||
if (enable && this._canRender()) {
|
||||
const renderData = this._renderData;
|
||||
if (renderData) {
|
||||
renderData.uvDirty = true;
|
||||
renderData.vertDirty = true;
|
||||
}
|
||||
|
||||
public _onNodeSizeDirty () {
|
||||
if (!this._renderData) { return; }
|
||||
this.markForUpdateRenderData();
|
||||
this._renderDataDirty = enable;
|
||||
} else if (!enable) {
|
||||
this._renderDataDirty = enable;
|
||||
}
|
||||
}
|
||||
|
||||
// public markForUpdateRenderData (enable: boolean) {
|
||||
// if (enable /*&& this._canRender()*/) {
|
||||
// // this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
|
||||
// const renderData = this._renderData;
|
||||
// if (renderData) {
|
||||
// renderData.uvDirty = true;
|
||||
// renderData.vertDirty = true;
|
||||
// }
|
||||
// }
|
||||
// // else if (!enable) {
|
||||
// // this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
// // }
|
||||
// }
|
||||
|
||||
public _applySpriteSize () {
|
||||
if (this._spriteFrame) {
|
||||
if (SizeMode.RAW === this._sizeMode) {
|
||||
|
||||
@@ -166,12 +166,12 @@ export class UIRenderComponent extends Component {
|
||||
return this._material;
|
||||
}
|
||||
|
||||
set material (value) {
|
||||
set material (value: Material | null) {
|
||||
if (this._material === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._material = value;
|
||||
this._updateMaterial(value);
|
||||
}
|
||||
|
||||
public static Assembler: IAssemblerManager | null = null;
|
||||
@@ -186,14 +186,18 @@ export class UIRenderComponent extends Component {
|
||||
protected _priority = 0;
|
||||
@property
|
||||
protected _material: Material | null = null;
|
||||
@property
|
||||
protected _sharedMaterial: Material | null = null;
|
||||
|
||||
protected _assembler: IAssembler | null = null;
|
||||
protected _postAssembler: IAssembler | null = null;
|
||||
protected _renderDataPoolID = -1;
|
||||
protected _visibility = -1;
|
||||
protected _renderData: RenderData | null = null;
|
||||
@property
|
||||
private _sharedMaterial: Material | null = null;
|
||||
protected _renderDataDirty = false;
|
||||
// 特殊渲染标记,在可渲染情况下,因为自身某个原因不给予渲染
|
||||
protected _renderPermit = true;
|
||||
|
||||
// _allocedDatas = [];
|
||||
// _vertexFormat = null;
|
||||
// _toPostHandle = false;
|
||||
@@ -210,6 +214,7 @@ export class UIRenderComponent extends Component {
|
||||
|
||||
public onEnable () {
|
||||
let parent = this.node;
|
||||
// 获取被渲染相机的 visibility
|
||||
while (parent) {
|
||||
if (parent) {
|
||||
const canvasComp = parent.getComponent(CanvasComponent);
|
||||
@@ -223,23 +228,24 @@ export class UIRenderComponent extends Component {
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
||||
this.node.on(EventType.ANCHOR_CHANGED, this._stateChange, this);
|
||||
this.node.on(EventType.TRANSFORM_CHANGED, this._stateChange, this);
|
||||
this.node.on(EventType.SIZE_CHANGED, this._stateChange, this);
|
||||
this.node.on(EventType.ANCHOR_CHANGED, this._nodeStateChange, this);
|
||||
this.node.on(EventType.TRANSFORM_CHANGED, this._nodeStateChange, this);
|
||||
this.node.on(EventType.SIZE_CHANGED, this._nodeStateChange, this);
|
||||
// if (this.node._renderComponent) {
|
||||
// this.node._renderComponent.enabled = false;
|
||||
// }
|
||||
// this.node._renderComponent = this;
|
||||
// this.node._renderFlag |= RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_COLOR;
|
||||
this._renderDataDirty = true;
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
this._visibility = -1;
|
||||
// this.node._renderComponent = null;
|
||||
// this.disableRender();
|
||||
this.node.off(EventType.ANCHOR_CHANGED, this._stateChange, this);
|
||||
this.node.off(EventType.TRANSFORM_CHANGED, this._stateChange, this);
|
||||
this.node.off(EventType.SIZE_CHANGED, this._stateChange, this);
|
||||
this.node.off(EventType.ANCHOR_CHANGED, this._nodeStateChange, this);
|
||||
this.node.off(EventType.TRANSFORM_CHANGED, this._nodeStateChange, this);
|
||||
this.node.off(EventType.SIZE_CHANGED, this._nodeStateChange, this);
|
||||
}
|
||||
|
||||
public onDestroy () {
|
||||
@@ -253,50 +259,23 @@ export class UIRenderComponent extends Component {
|
||||
}
|
||||
|
||||
public markForUpdateRenderData (enable: boolean = true) {
|
||||
// if (enable && this._canRender()) {
|
||||
// this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
// }
|
||||
// else if (!enable) {
|
||||
// this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
// }
|
||||
|
||||
// if (enable /*&& this._canRender()*/) {
|
||||
// this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
|
||||
const renderData = this._renderData;
|
||||
if (renderData) {
|
||||
renderData.uvDirty = enable;
|
||||
renderData.vertDirty = enable;
|
||||
for (const child of this.node.children) {
|
||||
const renderComp = child.getComponent(UIRenderComponent);
|
||||
if (renderComp){
|
||||
renderComp.markForUpdateRenderData();
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
// else if (!enable) {
|
||||
// this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
|
||||
// }
|
||||
if (enable && this._canRender()) {
|
||||
this._renderDataDirty = enable;
|
||||
}
|
||||
else if (!enable) {
|
||||
this._renderDataDirty = enable;
|
||||
}
|
||||
}
|
||||
|
||||
// markForRender(enable) {
|
||||
// // if (enable && this._canRender()) {
|
||||
// // this.node._renderFlag |= RenderFlow.FLAG_RENDER;
|
||||
// // }
|
||||
// // else if (!enable) {
|
||||
// // this.node._renderFlag &= ~RenderFlow.FLAG_RENDER;
|
||||
// // }
|
||||
// }
|
||||
|
||||
// markForCustomIARender(enable) {
|
||||
// // if (enable && this._canRender()) {
|
||||
// // this.node._renderFlag |= RenderFlow.FLAG_CUSTOM_IA_RENDER;
|
||||
// // }
|
||||
// // else if (!enable) {
|
||||
// // this.node._renderFlag &= ~RenderFlow.FLAG_CUSTOM_IA_RENDER;
|
||||
// // }
|
||||
// }
|
||||
// TODO:
|
||||
public markForCustomIARender (enable) {
|
||||
// if (enable && this._canRender()) {
|
||||
// this.node._renderFlag |= RenderFlow.FLAG_CUSTOM_IA_RENDER;
|
||||
// }
|
||||
// else if (!enable) {
|
||||
// this.node._renderFlag &= ~RenderFlow.FLAG_CUSTOM_IA_RENDER;
|
||||
// }
|
||||
}
|
||||
|
||||
// disableRender() {
|
||||
// // this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_CUSTOM_IA_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_COLOR);
|
||||
@@ -311,11 +290,6 @@ export class UIRenderComponent extends Component {
|
||||
}
|
||||
|
||||
public destroyRenderData () {
|
||||
// let index = this._allocedDatas.indexOf(data);
|
||||
// if (index !== -1) {
|
||||
// this._allocedDatas.splice(index, 1);
|
||||
// RenderData.free(data);
|
||||
// }
|
||||
if (this._renderDataPoolID === -1) {
|
||||
return;
|
||||
}
|
||||
@@ -329,23 +303,35 @@ export class UIRenderComponent extends Component {
|
||||
if (!this._canRender()) {
|
||||
return;
|
||||
}
|
||||
if (this._assembler!.updateRenderData) {
|
||||
this._assembler!.updateRenderData!(this);
|
||||
}
|
||||
|
||||
this._checkAndUpdateRenderData();
|
||||
this._assembler!.fillBuffers(this, render);
|
||||
}
|
||||
|
||||
public postUpdateAssembler () {
|
||||
if (!this._postAssembler) {
|
||||
return;
|
||||
}
|
||||
if (this._postAssembler.updateRenderData) {
|
||||
this._postAssembler.updateRenderData(this);
|
||||
// if (!this._canRender() || !this._postAssembler) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (this._renderDataDirty) {
|
||||
// this._postAssembler.updateRenderData(this);
|
||||
// this._renderDataDirty = false;
|
||||
// }
|
||||
}
|
||||
|
||||
public updateRenderData (force = false) {
|
||||
|
||||
}
|
||||
|
||||
protected _checkAndUpdateRenderData (){
|
||||
if (this._renderDataDirty) {
|
||||
this._assembler!.updateRenderData!(this);
|
||||
this._renderDataDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected _canRender () {
|
||||
return this._assembler !== null && this._material !== null;
|
||||
return this._material !== null && this._renderPermit;
|
||||
}
|
||||
|
||||
protected _updateColor () {
|
||||
@@ -356,12 +342,19 @@ export class UIRenderComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
private _updateBlendFunc (updateHash) {
|
||||
// if (!this.material) {
|
||||
// return;
|
||||
// }
|
||||
protected _updateMaterial (material: Material | null) {
|
||||
this._material = material;
|
||||
|
||||
this._updateBlendFunc();
|
||||
// material.updateHash();
|
||||
}
|
||||
|
||||
private _updateBlendFunc (updateHash: boolean = false) {
|
||||
if (!this._material) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// var pass = this.material._mainTech.passes[0];
|
||||
// pass.setBlend(
|
||||
// gfx.BLEND_FUNC_ADD,
|
||||
@@ -375,13 +368,22 @@ export class UIRenderComponent extends Component {
|
||||
// }
|
||||
}
|
||||
|
||||
private _stateChange (){
|
||||
this.markForUpdateRenderData();
|
||||
// pos, rot, scale changed
|
||||
private _nodeStateChange (){
|
||||
if (this._renderData) {
|
||||
this.markForUpdateRenderData();
|
||||
for (const child of this.node.children) {
|
||||
const renderComp = child.getComponent(UIRenderComponent);
|
||||
if (renderComp) {
|
||||
renderComp.updateRenderData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _instanceMaterial (){
|
||||
if (this._sharedMaterial) {
|
||||
this._material = Material.getInstantiatedMaterial(this._sharedMaterial, new RenderableComponent(), CC_EDITOR ? true : false);
|
||||
this.material = Material.getInstantiatedMaterial(this._sharedMaterial, new RenderableComponent(), CC_EDITOR ? true : false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export class Texture2D extends TextureBase {
|
||||
super(true);
|
||||
}
|
||||
|
||||
onLoaded () {
|
||||
public onLoaded () {
|
||||
super.onLoaded();
|
||||
this.mipmaps = this._mipmaps;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user