mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
adjust visibility to ui (#5312)
This commit is contained in:
@@ -74,8 +74,14 @@ export class RenderTexture extends TextureBase {
|
||||
if (info) {
|
||||
this._width = info.width;
|
||||
this._height = info.height;
|
||||
this._format = info.colorFormat;
|
||||
this._depthStencilFormat = info.depthStencilFormat;
|
||||
if(info.colorFormat){
|
||||
this._format = info.colorFormat;
|
||||
}
|
||||
|
||||
if(info.depthStencilFormat){
|
||||
this._depthStencilFormat = info.depthStencilFormat;
|
||||
}
|
||||
|
||||
this._tryResetWindow();
|
||||
this.emit('resize', this);
|
||||
}
|
||||
|
||||
@@ -71,71 +71,6 @@ const RenderMode = Enum({
|
||||
@executeInEditMode
|
||||
@disallowMultiple
|
||||
export class CanvasComponent extends Component {
|
||||
|
||||
// /**
|
||||
// * @zh
|
||||
// * 设计分辨率
|
||||
// *
|
||||
// * @param value - 设计分辨率尺寸。
|
||||
// */
|
||||
// @property({
|
||||
// type: Size,
|
||||
// displayOrder: 0,
|
||||
// })
|
||||
// get designResolution () {
|
||||
// return this._designResolution;
|
||||
// }
|
||||
|
||||
// set designResolution (value: Size) {
|
||||
// this._designResolution.width = value.width;
|
||||
// this._designResolution.height = value.height;
|
||||
// this.node.emit('design-resolution-changed', this._designResolution);
|
||||
// this.applySettings();
|
||||
// this.alignWithScreen();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @zh
|
||||
// * 是否优先将设计分辨率高度撑满视图高度。
|
||||
// *
|
||||
// * @param value - 是否撑满高度。
|
||||
// */
|
||||
// @property({
|
||||
// displayOrder: 1,
|
||||
// })
|
||||
// get fitHeight () {
|
||||
// return this._fitHeight;
|
||||
// }
|
||||
|
||||
// set fitHeight (value: boolean) {
|
||||
// if (this._fitHeight !== value) {
|
||||
// this._fitHeight = value;
|
||||
// this.applySettings();
|
||||
// this.alignWithScreen();
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @zh
|
||||
// * 是否优先将设计分辨率宽度撑满视图宽度。
|
||||
// *
|
||||
// * @param value - 是否撑满宽度。
|
||||
// */
|
||||
// @property({
|
||||
// displayOrder: 2,
|
||||
// })
|
||||
// get fitWidth () {
|
||||
// return this._fitWidth;
|
||||
// }
|
||||
|
||||
// set fitWidth (value: boolean) {
|
||||
// if (this._fitWidth !== value) {
|
||||
// this._fitWidth = value;
|
||||
// this.applySettings();
|
||||
// this.alignWithScreen();
|
||||
// }
|
||||
// }
|
||||
|
||||
@property({
|
||||
type: CanvasClearFlag,
|
||||
})
|
||||
|
||||
@@ -67,13 +67,23 @@ export class UIComponent extends Component {
|
||||
* 查找被渲染相机。
|
||||
*/
|
||||
get visibility () {
|
||||
return this._visibility;
|
||||
if(!this._screen){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return this._screen.visibility;
|
||||
// return this._visibility;
|
||||
}
|
||||
|
||||
get _screen (){
|
||||
return this._followScreen;
|
||||
}
|
||||
|
||||
@property
|
||||
protected _priority = 0;
|
||||
|
||||
protected _visibility = -1;
|
||||
// protected _visibility = -1;
|
||||
protected _followScreen: CanvasComponent | null = null;
|
||||
|
||||
private _lastParent: INode | null = null;
|
||||
public onEnable () {
|
||||
@@ -116,9 +126,16 @@ export class UIComponent extends Component {
|
||||
/**
|
||||
* @zh
|
||||
* 设置当前组件的可视编号。(我们不希望用户自行做处理,除非用户自己知道在做什么)
|
||||
*
|
||||
* @deprecated 会在 Cocos Creator 3D beta18 及之后的版本废除
|
||||
*/
|
||||
public setVisibility (value: number) {
|
||||
this._visibility = value;
|
||||
return;
|
||||
// this._visibility = value;
|
||||
}
|
||||
|
||||
public _setScreen(value: CanvasComponent){
|
||||
this._followScreen = value;
|
||||
}
|
||||
|
||||
protected _parentChanged (node: INode) {
|
||||
@@ -153,7 +170,7 @@ export class UIComponent extends Component {
|
||||
if (parent) {
|
||||
const canvasComp = parent.getComponent(CanvasComponent);
|
||||
if (canvasComp) {
|
||||
this._visibility = canvasComp.visibility;
|
||||
this._followScreen = canvasComp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -169,6 +186,6 @@ export class UIComponent extends Component {
|
||||
this._lastParent = null;
|
||||
}
|
||||
|
||||
this._visibility = -1;
|
||||
this._followScreen = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ export class UITransformComponent extends Component {
|
||||
|
||||
public __preload () {
|
||||
this.node.uiTransfromComp = this;
|
||||
this.node.layer |= cc.Layers.UI;
|
||||
this.node.layer = cc.Layers.UI2D;
|
||||
}
|
||||
|
||||
public onDestroy () {
|
||||
|
||||
@@ -31,6 +31,7 @@ import { IRenderObject, UBOGlobal, UBOShadow, UNIFORM_ENVIRONMENT } from './defi
|
||||
import { IInternalBindingInst } from './define';
|
||||
import { IRenderFlowInfo, RenderFlow } from './render-flow';
|
||||
import { RenderView } from './render-view';
|
||||
import { CameraVisFlags } from '../renderer/scene/camera';
|
||||
|
||||
const _vec4Array = new Float32Array(4);
|
||||
const _outMat = new Mat4();
|
||||
@@ -1463,18 +1464,29 @@ export abstract class RenderPipeline {
|
||||
model._resetUBOUpdateFlag();
|
||||
|
||||
// filter model by view visibility
|
||||
if (model.enabled &&
|
||||
((model.node && (view.visibility & model.node.layer)) ||
|
||||
(view.visibility & model.visFlags))) {
|
||||
model.updateTransform();
|
||||
if (model.enabled) {
|
||||
const vis = view.visibility & CameraVisFlags.UI2D;
|
||||
if (vis) {
|
||||
if ((model.node && (view.visibility === model.node.layer)) ||
|
||||
view.visibility === model.visFlags) {
|
||||
model.updateTransform();
|
||||
model.updateUBOs();
|
||||
this.addVisibleModel(model, camera);
|
||||
}
|
||||
}else{
|
||||
if ((model.node && (view.visibility & model.node.layer)) ||
|
||||
(view.visibility & model.visFlags)) {
|
||||
model.updateTransform();
|
||||
|
||||
// frustum culling
|
||||
if (model.worldBounds && !intersect.aabb_frustum(model.worldBounds, camera.frustum)) {
|
||||
continue;
|
||||
// frustum culling
|
||||
if (model.worldBounds && !intersect.aabb_frustum(model.worldBounds, camera.frustum)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
model.updateUBOs();
|
||||
this.addVisibleModel(model, camera);
|
||||
}
|
||||
}
|
||||
|
||||
model.updateUBOs();
|
||||
this.addVisibleModel(model, camera);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ export enum CameraVisFlags {
|
||||
GIZMOS = (1 << 21),
|
||||
EDITOR = (1 << 22),
|
||||
UI = (1 << 23),
|
||||
UI2D = (1 << 25),
|
||||
}
|
||||
|
||||
export class Camera {
|
||||
|
||||
@@ -37,6 +37,7 @@ export enum VisibilityFlags {
|
||||
GIZMOS = (1 << 21),
|
||||
EDITOR = (1 << 22),
|
||||
UI = (1 << 23),
|
||||
UI2D = (1 << 25),
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ import { GFXTextureView } from '../../gfx/texture-view';
|
||||
import { Pool, RecyclePool } from '../../memop';
|
||||
import { CachedArray } from '../../memop/cached-array';
|
||||
import { UniformBinding } from '../../pipeline/define';
|
||||
import { Camera } from '../../renderer/scene/camera';
|
||||
import { Camera, CameraVisFlags } from '../../renderer/scene/camera';
|
||||
import { Model, VisibilityFlags } from '../../renderer/scene/model';
|
||||
import { RenderScene } from '../../renderer/scene/render-scene';
|
||||
import { Root } from '../../root';
|
||||
@@ -101,20 +101,8 @@ export class UI {
|
||||
return this._currMeshBuffer;
|
||||
}
|
||||
|
||||
get debugScreen () {
|
||||
return this._debugScreen;
|
||||
}
|
||||
|
||||
set debugScreen (value){
|
||||
this._debugScreen = value;
|
||||
if (this._debugScreen && this._debugScreen.camera ) {
|
||||
this._debugScreen.camera.view.visibility = this._screens.length + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public device: GFXDevice;
|
||||
private _screens: CanvasComponent[] = [];
|
||||
private _debugScreen: CanvasComponent | null = null;
|
||||
private _bufferBatchPool: RecyclePool<MeshBuffer> = new RecyclePool(() => {
|
||||
return new MeshBuffer(this);
|
||||
}, 128);
|
||||
@@ -225,15 +213,12 @@ export class UI {
|
||||
*/
|
||||
public addScreen (comp: CanvasComponent) {
|
||||
this._screens.push(comp);
|
||||
|
||||
if (comp.camera) {
|
||||
comp.camera.view.visibility = this._screens.length;
|
||||
comp.camera.view.visibility = CameraVisFlags.UI2D | this._screens.length;
|
||||
this._canvasMaterials.set(comp.camera.view.visibility, new Map<number, number>());
|
||||
}
|
||||
|
||||
if (this._debugScreen && this._debugScreen.camera) {
|
||||
this._debugScreen.camera.view.visibility = this._screens.length + 1;
|
||||
}
|
||||
this._screens.sort(this._screenSort);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,10 +238,6 @@ export class UI {
|
||||
}
|
||||
}
|
||||
|
||||
if (this._debugScreen && this._debugScreen.camera && this._debugScreen.camera.view.visibility === visibility) {
|
||||
return this._debugScreen;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -281,15 +262,12 @@ export class UI {
|
||||
matHash = matHashInter.next();
|
||||
}
|
||||
}
|
||||
if (this._debugScreen && this._debugScreen.camera ) {
|
||||
this._debugScreen.camera.view.visibility = this._screens.length + 1;
|
||||
}
|
||||
|
||||
let camera: Camera | null;
|
||||
for (let i = idx; i < this._screens.length; i++) {
|
||||
camera = this._screens[i].camera;
|
||||
if (camera) {
|
||||
camera.view.visibility = i;
|
||||
camera.view.visibility = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,7 +306,9 @@ export class UI {
|
||||
|
||||
if (batch.model) {
|
||||
if (batch.camera) {
|
||||
batch.model.visFlags = batch.camera.view.visibility;
|
||||
const visFlags = batch.camera.view.visibility;
|
||||
batch.model.visFlags = visFlags;
|
||||
batch.model.node.layer = visFlags;
|
||||
}
|
||||
for (let j = 0; j < batch.model.subModelNum; j++) {
|
||||
batch.model.getSubModel(j).priority = batchPriority++;
|
||||
@@ -490,7 +470,6 @@ export class UI {
|
||||
const matIter = this._uiMaterials.values();
|
||||
let result = matIter.next();
|
||||
while (!result.done) {
|
||||
console.log('111111111');
|
||||
const uiMat = result.value;
|
||||
uiMat.destroy();
|
||||
result = matIter.next();
|
||||
@@ -524,10 +503,6 @@ export class UI {
|
||||
|
||||
this._recursiveScreenNode(screen.node);
|
||||
}
|
||||
|
||||
if (!CC_EDITOR && this._debugScreen && this._debugScreen.enabledInHierarchy) {
|
||||
this._recursiveScreenNode(this._debugScreen.node);
|
||||
}
|
||||
}
|
||||
|
||||
private _preprocess (c: INode) {
|
||||
@@ -586,4 +561,8 @@ export class UI {
|
||||
this._currMeshBuffer.request(arguments[0], arguments[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private _screenSort(a: CanvasComponent, b: CanvasComponent){
|
||||
return a.priority - b.priority;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,10 @@ export class Layers {
|
||||
public static IgnoreRaycast = (1 << 20);
|
||||
public static Gizmos = (1 << 21);
|
||||
public static Editor = (1 << 22);
|
||||
// 3D UI
|
||||
public static UI = (1 << 23);
|
||||
// 2D UI
|
||||
public static UI2D = (1 << 25);
|
||||
public static SceneGizmo = (1 << 24);
|
||||
|
||||
// masks
|
||||
|
||||
@@ -715,15 +715,6 @@ export class NodeEventProcessor {
|
||||
|
||||
if (!listeners.hasEventListener(type, callback, target)) {
|
||||
listeners.on(type, callback, target);
|
||||
|
||||
const targetImpl = target as ITargetImpl;
|
||||
if (target) {
|
||||
if (targetImpl.__eventTargets) {
|
||||
targetImpl.__eventTargets.push(this);
|
||||
} else if (targetImpl.node && targetImpl.node.__eventTargets) {
|
||||
targetImpl.node.__eventTargets.push(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return callback;
|
||||
@@ -747,15 +738,6 @@ export class NodeEventProcessor {
|
||||
const listeners = useCapture ? this.capturingTargets : this.bubblingTargets;
|
||||
if (listeners) {
|
||||
listeners.off(type, callback, target);
|
||||
|
||||
const targetImpl = target as ITargetImpl;
|
||||
if (target) {
|
||||
if (targetImpl.__eventTargets) {
|
||||
fastRemove(targetImpl.__eventTargets, this);
|
||||
} else if (targetImpl.node && targetImpl.node.__eventTargets) {
|
||||
fastRemove(targetImpl.node.__eventTargets, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -566,11 +566,11 @@ export class MaskComponent extends UIRenderComponent {
|
||||
|
||||
private _flushVisibility () {
|
||||
if (this._clearGraphics) {
|
||||
this._clearGraphics.setVisibility(this._visibility);
|
||||
this._clearGraphics._setScreen(this._screen);
|
||||
}
|
||||
|
||||
if (this._graphics) {
|
||||
this._graphics.setVisibility(this._visibility);
|
||||
this._graphics._setScreen(this._screen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user