mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 02:02:41 +08:00
fix mask in new model structure (#5801)
This commit is contained in:
@@ -29,8 +29,6 @@
|
||||
|
||||
import {
|
||||
ccclass,
|
||||
executeInEditMode,
|
||||
executionOrder,
|
||||
property,
|
||||
} from '../../../core/data/class-decorator';
|
||||
import { SystemEventType } from '../../../core/platform/event-manager/event-enum';
|
||||
@@ -43,8 +41,8 @@ import { Material } from '../../assets';
|
||||
import { RenderableComponent } from '../../../core/3d/framework/renderable-component';
|
||||
import { IAssembler, IAssemblerManager } from '../../renderer/ui/base';
|
||||
import { UIComponent } from './ui-component';
|
||||
import { UITransformComponent } from './ui-transfrom-component';
|
||||
import { TransformBit } from '../../scene-graph/node-enum';
|
||||
import { INode } from '../../utils/interfaces';
|
||||
|
||||
// hack
|
||||
ccenum(GFXBlendFactor);
|
||||
@@ -203,8 +201,8 @@ export class UIRenderComponent extends UIComponent {
|
||||
}
|
||||
|
||||
// Render data can be submitted even if it is not on the node tree
|
||||
set simulate (value) {
|
||||
this._simulate = value;
|
||||
set delegateSrc (value: INode) {
|
||||
this._delegateSrc = value;
|
||||
}
|
||||
|
||||
public static BlendState = GFXBlendFactor;
|
||||
@@ -225,8 +223,8 @@ export class UIRenderComponent extends UIComponent {
|
||||
protected _renderData: RenderData | null = null;
|
||||
protected _renderDataFlag = true;
|
||||
protected _renderFlag = true;
|
||||
// 特殊渲染标记,在可渲染情况下,因为自身某个原因不给予渲染
|
||||
// protected _renderPermit = true;
|
||||
// 特殊渲染节点,给一些不在节点树上的组件做依赖渲染(例如 mask 组件内置两个 graphics 来渲染)
|
||||
protected _delegateSrc: INode | null = null;
|
||||
protected _material: Material | null = null;
|
||||
protected _instanceMaterialType = InstanceMaterialType.ADDCOLORANDTEXTURE;
|
||||
protected _blendTemplate = {
|
||||
@@ -241,7 +239,6 @@ export class UIRenderComponent extends UIComponent {
|
||||
depthStencilState: {},
|
||||
rasterizerState: {},
|
||||
};
|
||||
protected _simulate = false;
|
||||
|
||||
public __preload (){
|
||||
super.__preload();
|
||||
@@ -351,7 +348,7 @@ export class UIRenderComponent extends UIComponent {
|
||||
}
|
||||
|
||||
protected _canRender () {
|
||||
return this.material !== null && this.enabled && (this._simulate? true: this.enabledInHierarchy);
|
||||
return this.material !== null && this.enabled && (this._delegateSrc ? this._delegateSrc.activeInHierarchy : this.enabledInHierarchy);
|
||||
}
|
||||
|
||||
protected _postCanRender(){}
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Component } from './component';
|
||||
import { EventHandler } from './component-event-handler';
|
||||
import { ccclass, property, menu, executionOrder } from '../data/class-decorator';
|
||||
import { Node } from '../scene-graph';
|
||||
import { convertUtils } from '../utils';
|
||||
import { CameraComponent } from '../3d';
|
||||
import { Vec3 } from '../math';
|
||||
import { Component } from '../components/component';
|
||||
import { EventHandler } from './component-event-handler';
|
||||
|
||||
/**
|
||||
* @zh 3D 节点映射 UI 节点组件
|
||||
|
||||
@@ -200,6 +200,7 @@ export class Model {
|
||||
this._matPSORecord.clear();
|
||||
this._matRefCount.clear();
|
||||
this._inited = false;
|
||||
this._transformUpdated = true;
|
||||
}
|
||||
|
||||
public attachToScene (scene: RenderScene) {
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
import { Color, Vec3 } from '../../../../core/math';
|
||||
import { GFXPrimitiveMode } from '../../../../core/gfx';
|
||||
import { Model } from '../../../../core/renderer';
|
||||
import { RenderScene } from '../../../../core/renderer/scene/render-scene';
|
||||
import { MeshRenderData } from '../../../../core/renderer/ui/render-data';
|
||||
import { UI } from '../../../../core/renderer/ui/ui';
|
||||
import { createMesh } from '../../../../core/3d/misc/utils';
|
||||
@@ -40,7 +39,8 @@ import { IAssembler } from '../../../../core/renderer/ui/base';
|
||||
import { LineCap, LineJoin, PointFlags } from '../types';
|
||||
import { earcut as Earcut } from './earcut';
|
||||
import { Impl, Point } from './impl';
|
||||
import { director } from '../../../../core/director';
|
||||
import { director } from '../../../../core';
|
||||
import { RenderScene } from '../../../../core/renderer/scene/render-scene';
|
||||
|
||||
const MAX_VERTEX = 65535;
|
||||
const MAX_INDICE = MAX_VERTEX * 2;
|
||||
@@ -175,13 +175,10 @@ export const graphicsAssembler: IAssembler = {
|
||||
this.end(graphics);
|
||||
},
|
||||
|
||||
end (graphics: GraphicsComponent){
|
||||
end(graphics: GraphicsComponent) {
|
||||
if (graphics.model) {
|
||||
graphics.model.destroy();
|
||||
} else {
|
||||
graphics.model = new Model();
|
||||
}
|
||||
|
||||
const impl = graphics.impl;
|
||||
const primitiveMode = GFXPrimitiveMode.TRIANGLE_LIST;
|
||||
const renderDatas = impl && impl.getRenderDatas();
|
||||
|
||||
@@ -212,14 +212,14 @@ export class GraphicsComponent extends UIRenderComponent {
|
||||
this.impl = this._assembler && (this._assembler as IAssembler).createImpl!(this);
|
||||
}
|
||||
|
||||
public onLoad (){
|
||||
this._sceneGetter = director.root!.ui.getRenderSceneGetter();
|
||||
public onLoad() {
|
||||
this._sceneGetter = director.root!.ui.getRenderSceneGetter();
|
||||
if (!this.model) {
|
||||
this.model = new Model();
|
||||
this.model = director.root!.createModel(Model);
|
||||
}
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
public onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
this._attachToScene();
|
||||
@@ -237,6 +237,7 @@ export class GraphicsComponent extends UIRenderComponent {
|
||||
this._sceneGetter = null;
|
||||
if (this.model) {
|
||||
this.model.destroy();
|
||||
director.root!.destroyModel(this.model);
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
@@ -248,23 +249,6 @@ export class GraphicsComponent extends UIRenderComponent {
|
||||
this.impl = null;
|
||||
}
|
||||
|
||||
protected _attachToScene(){
|
||||
const scene = director.root!.ui.renderScene;
|
||||
if (!this.model) {
|
||||
return;
|
||||
}
|
||||
if (this.model!.scene != null) {
|
||||
this._detachFromScene();
|
||||
}
|
||||
scene.addModel(this.model!);
|
||||
}
|
||||
|
||||
protected _detachFromScene() {
|
||||
if (this.model && this.model.scene) {
|
||||
this.model.scene.removeModel(this.model);
|
||||
}
|
||||
}
|
||||
|
||||
public _activateMaterial () {
|
||||
if (!this._material) {
|
||||
return;
|
||||
@@ -451,7 +435,6 @@ export class GraphicsComponent extends UIRenderComponent {
|
||||
|
||||
this.impl.clear(clean);
|
||||
if (this.model) {
|
||||
this._detachFromScene();
|
||||
this.model.destroy();
|
||||
}
|
||||
|
||||
@@ -528,7 +511,24 @@ export class GraphicsComponent extends UIRenderComponent {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.model ? true : false;
|
||||
return !!this.model && this.model.inited;
|
||||
}
|
||||
|
||||
protected _attachToScene() {
|
||||
const scene = director.root!.ui.renderScene;
|
||||
if (!this.model) {
|
||||
return;
|
||||
}
|
||||
if (this.model!.scene != null) {
|
||||
this._detachFromScene();
|
||||
}
|
||||
scene.addModel(this.model!);
|
||||
}
|
||||
|
||||
protected _detachFromScene() {
|
||||
if (this.model && this.model.scene) {
|
||||
this.model.scene.removeModel(this.model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ import { UI } from '../../core/renderer/ui/ui';
|
||||
import { Node } from '../../core/scene-graph';
|
||||
import { ccenum } from '../../core/value-types/enum';
|
||||
import { GraphicsComponent } from './graphics-component';
|
||||
import { UITransformComponent, CanvasComponent } from '../../core';
|
||||
import { INode } from '../../core/utils/interfaces';
|
||||
import { TransformBit } from '../../core/scene-graph/node-enum';
|
||||
|
||||
const _worldMatrix = new Mat4();
|
||||
@@ -283,6 +281,13 @@ export class MaskComponent extends UIRenderComponent {
|
||||
|
||||
public onLoad () {
|
||||
this._createGraphics();
|
||||
if (this._clearGraphics) {
|
||||
this._clearGraphics.onLoad();
|
||||
}
|
||||
|
||||
if (this._graphics) {
|
||||
this._graphics.onLoad();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,13 +316,10 @@ export class MaskComponent extends UIRenderComponent {
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
if (this._clearGraphics) {
|
||||
this._clearGraphics.onEnable();
|
||||
}
|
||||
this._updateGraphics();
|
||||
this._enableGraphics();
|
||||
// }
|
||||
|
||||
this._activateMaterial();
|
||||
// this._activateMaterial();
|
||||
|
||||
this.node.on(SystemEventType.TRANSFORM_CHANGED, this._nodeStateChange, this);
|
||||
view.on('design-resolution-changed', this._updateClearGraphics, this);
|
||||
@@ -469,14 +471,12 @@ export class MaskComponent extends UIRenderComponent {
|
||||
if (!this._clearGraphics) {
|
||||
const node = new Node('clear-graphics');
|
||||
const clearGraphics = this._clearGraphics = node.addComponent(GraphicsComponent)!;
|
||||
clearGraphics.delegateSrc = this.node;
|
||||
clearGraphics.helpInstanceMaterial();
|
||||
clearGraphics._activateMaterial();
|
||||
clearGraphics.lineWidth = 0;
|
||||
const color = Color.WHITE.clone();
|
||||
color.a = 0;
|
||||
clearGraphics.fillColor = color;
|
||||
clearGraphics.simulate = true;
|
||||
this._updateClearGraphics();
|
||||
}
|
||||
|
||||
if (!this._graphics) {
|
||||
@@ -539,6 +539,18 @@ export class MaskComponent extends UIRenderComponent {
|
||||
graphics.fill();
|
||||
}
|
||||
|
||||
private _enableGraphics() {
|
||||
if (this._clearGraphics) {
|
||||
this._clearGraphics.onEnable();
|
||||
this._updateClearGraphics();
|
||||
}
|
||||
|
||||
if (this._graphics) {
|
||||
this._graphics.onEnable();
|
||||
this._updateGraphics();
|
||||
}
|
||||
}
|
||||
|
||||
private _disableGraphics () {
|
||||
if (this._graphics) {
|
||||
this._graphics.onDisable();
|
||||
|
||||
Reference in New Issue
Block a user