From c761b408dc858040aa686880256090d9bea6ecaf Mon Sep 17 00:00:00 2001 From: zheng han Date: Fri, 1 Nov 2019 10:43:18 +0800 Subject: [PATCH 1/9] add editorExtends for node and component (#5659) * add editorExtends for node and component * remove CC_TEST --- @types/editor-extends.d.ts | 8 ++--- cocos/core/components/component.ts | 5 --- cocos/core/scene-graph/base-node.ts | 50 +++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/@types/editor-extends.d.ts b/@types/editor-extends.d.ts index 330e0b3362..fb88d13c04 100644 --- a/@types/editor-extends.d.ts +++ b/@types/editor-extends.d.ts @@ -21,13 +21,13 @@ interface EditorAssetInfo { interface EditorExtendsScript { add(uuid: string, ctor: any): any; - delete(uuid: string, ctor: any): any; + remove(uuid: string, ctor: any): any; getCtors(uuid: string): { [uuid: string]: any } } interface EditorExtendsNode { add(uuid: string, node: any): any; - delete(uuid: string): any; + remove(uuid: string): any; clear(): any; getNode(uuid: string): any; getNodes(): {[uuid: string]: any}; @@ -35,10 +35,10 @@ interface EditorExtendsNode { interface EditorExtendsComponent { addMenu(component: Function, path: string, priority?: number); - deleteMenu(component: Function); + removeMenu(component: Function); getMenus(): { [uuid: string]: Object }; add(uuid: string, component: any): any; - delete(uuid: string): any; + remove(uuid: string): any; clear(): any; getComponent(uuid: string): any; getComponents(): {[uuid: string]: any}; diff --git a/cocos/core/components/component.ts b/cocos/core/components/component.ts index fd2cb400fb..5f79629c37 100644 --- a/cocos/core/components/component.ts +++ b/cocos/core/components/component.ts @@ -98,11 +98,6 @@ class Component extends CCObject { visible: false, }) get uuid () { - // @ts-ignore - if (CC_EDITOR) { - EditorExtends.Component.add(this._id, this); - } - return this._id; } diff --git a/cocos/core/scene-graph/base-node.ts b/cocos/core/scene-graph/base-node.ts index ade09ecf04..6e9bad465d 100644 --- a/cocos/core/scene-graph/base-node.ts +++ b/cocos/core/scene-graph/base-node.ts @@ -386,12 +386,6 @@ export class BaseNode extends CCObject implements IBaseNode, ISchedulable { constructor (name?: string) { super(name); this._name = name !== undefined ? name : 'New Node'; - - // @ts-ignore - if (CC_EDITOR) { - // @ts-ignore - EditorExtends.Node.add(this._id, this); - } } /** @@ -1041,8 +1035,11 @@ export class BaseNode extends CCObject implements IBaseNode, ISchedulable { const component = new constructor(); component.node = this; this._components.push(component); - if ((CC_EDITOR || CC_TEST) && cc.engine && (this._id in cc.engine.attachedObjsForEditor)) { - cc.engine.attachedObjsForEditor[component._id] = component; + if (CC_EDITOR && EditorExtends.Node && EditorExtends.Component) { + let node = EditorExtends.Node.getNode(this._id); + if (node) { + EditorExtends.Component.add(component._id, component); + } } if (this._activeInHierarchy) { cc.director._nodeActivator.activateComp(component); @@ -1147,8 +1144,8 @@ export class BaseNode extends CCObject implements IBaseNode, ISchedulable { const i = this._components.indexOf(component); if (i !== -1) { this._components.splice(i, 1); - if ((CC_EDITOR || CC_TEST) && cc.engine) { - delete cc.engine.attachedObjsForEditor[component._id]; + if (CC_EDITOR && EditorExtends.Component) { + EditorExtends.Component.remove(component._id); } } // @ts-ignore @@ -1231,7 +1228,7 @@ export class BaseNode extends CCObject implements IBaseNode, ISchedulable { } } - if (CC_EDITOR || CC_TEST) { + if (CC_EDITOR) { const scene = cc.director.getScene() as this | null; const inCurrentSceneBefore = oldParent && oldParent.isChildOf(scene); const inCurrentSceneNow = newParent && newParent.isChildOf(scene); @@ -1282,7 +1279,7 @@ export class BaseNode extends CCObject implements IBaseNode, ISchedulable { // detach self and children from editor const parent = this._parent; const destroyByParent: boolean = (parent !== null) && ((parent._objFlags & Destroying) !== 0); - if (!destroyByParent && (CC_EDITOR || CC_TEST)) { + if (!destroyByParent && CC_EDITOR) { this._registerIfAttached!(false); } @@ -1350,9 +1347,34 @@ export class BaseNode extends CCObject implements IBaseNode, ISchedulable { } } - protected _onSiblingIndexChanged? (siblingIndex: number): void; + protected _registerIfAttached = !CC_EDITOR ? undefined : function (this: BaseNode, register) { + if (EditorExtends.Node && EditorExtends.Component) { + if (register) { + EditorExtends.Node.add(this._id, this); - protected _registerIfAttached? (attached: boolean): void; + for (let i = 0; i < this._components.length; i++) { + let comp = this._components[i]; + EditorExtends.Component.add(comp._id, comp); + } + } + else { + EditorExtends.Node.remove(this._id); + + for (let i = 0; i < this._components.length; i++) { + let comp = this._components[i]; + EditorExtends.Component.remove(comp._id); + } + } + } + + var children = this._children; + for (let i = 0, len = children.length; i < len; ++i) { + var child = children[i]; + child._registerIfAttached!(register); + } + }; + + protected _onSiblingIndexChanged? (siblingIndex: number): void; protected _checkMultipleComp? (constructor: Function): boolean; } From c8dcceefe404a46eb01ef3a5238401dc3193b178 Mon Sep 17 00:00:00 2001 From: zheng han Date: Fri, 8 Nov 2019 15:03:08 +0800 Subject: [PATCH 2/9] public InEditor Function (#5708) --- cocos/core/components/component.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/core/components/component.ts b/cocos/core/components/component.ts index 5f79629c37..32fc6712bd 100644 --- a/cocos/core/components/component.ts +++ b/cocos/core/components/component.ts @@ -585,16 +585,16 @@ class Component extends CCObject { */ protected onDestroy? (): void; - protected onFocusInEditor? (): void; + public onFocusInEditor? (): void; - protected onLostFocusInEditor? (): void; + public onLostFocusInEditor? (): void; /** * @en Called to initialize the component or node’s properties when adding the component the first time or when the Reset command is used. * This function is only called in editor.
* @zh 用来初始化组件或节点的一些属性,当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。这个回调只会在编辑器下调用。 */ - protected resetInEditor? (): void; + public resetInEditor? (): void; // VIRTUAL From 4638caecb09c4c66c1b7ba07099402b512a97a61 Mon Sep 17 00:00:00 2001 From: JoneLau <32630749+JoneLau@users.noreply.github.com> Date: Wed, 13 Nov 2019 15:50:44 +0800 Subject: [PATCH 3/9] fix name err (#5726) --- cocos/core/components/ui-base/canvas-component.ts | 2 +- cocos/core/components/ui-base/index.ts | 2 +- cocos/core/components/ui-base/ui-render-component.ts | 2 +- ...i-transfrom-component.ts => ui-transform-component.ts} | 8 ++++---- cocos/core/platform/SubContextView.ts | 2 +- cocos/core/utils/coordinates-converts-utils.ts | 2 +- cocos/ui/components/editbox/edit-box-component.ts | 2 +- cocos/ui/components/layout-component.ts | 2 +- cocos/ui/components/rich-text-component.ts | 2 +- cocos/ui/components/widget-component.ts | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) rename cocos/core/components/ui-base/{ui-transfrom-component.ts => ui-transform-component.ts} (98%) diff --git a/cocos/core/components/ui-base/canvas-component.ts b/cocos/core/components/ui-base/canvas-component.ts index 2fe71911fe..9f2af1dc8d 100644 --- a/cocos/core/components/ui-base/canvas-component.ts +++ b/cocos/core/components/ui-base/canvas-component.ts @@ -33,7 +33,7 @@ import { ccclass, disallowMultiple, executeInEditMode, executionOrder, menu, pro import { Vec3, Color } from '../../math'; import { GFXClearFlag } from '../../gfx/define'; import { Camera } from '../../renderer'; -import { UITransformComponent } from './ui-transfrom-component'; +import { UITransformComponent } from './ui-transform-component'; import { Node } from '../../scene-graph/node'; import { RenderTexture } from '../../assets/render-texture'; import { GFXWindow } from '../../gfx/window'; diff --git a/cocos/core/components/ui-base/index.ts b/cocos/core/components/ui-base/index.ts index 162d09790c..f55f5f316e 100644 --- a/cocos/core/components/ui-base/index.ts +++ b/cocos/core/components/ui-base/index.ts @@ -30,6 +30,6 @@ export * from './canvas-component'; export * from './ui-component'; export * from './ui-render-component'; -export * from './ui-transfrom-component'; +export * from './ui-transform-component'; import './deprecated'; diff --git a/cocos/core/components/ui-base/ui-render-component.ts b/cocos/core/components/ui-base/ui-render-component.ts index 49f2f5fa24..4cda352f75 100644 --- a/cocos/core/components/ui-base/ui-render-component.ts +++ b/cocos/core/components/ui-base/ui-render-component.ts @@ -44,7 +44,7 @@ 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 { UITransformComponent } from './ui-transform-component'; import { director } from '../../director'; // hack diff --git a/cocos/core/components/ui-base/ui-transfrom-component.ts b/cocos/core/components/ui-base/ui-transform-component.ts similarity index 98% rename from cocos/core/components/ui-base/ui-transfrom-component.ts rename to cocos/core/components/ui-base/ui-transform-component.ts index bb3153eb3c..dc9d706414 100644 --- a/cocos/core/components/ui-base/ui-transfrom-component.ts +++ b/cocos/core/components/ui-base/ui-transform-component.ts @@ -28,10 +28,10 @@ */ import { Component } from '../component'; -import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../../core/data/class-decorator'; -import { SystemEventType } from '../../../core/platform/event-manager/event-enum'; -import { EventListener, ILinstenerMask } from '../../../core/platform/event-manager/event-listener'; -import { Mat4, Rect, Size, Vec2, Vec3 } from '../../../core/math'; +import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../data/class-decorator'; +import { SystemEventType } from '../../platform/event-manager/event-enum'; +import { EventListener, ILinstenerMask } from '../../platform/event-manager/event-listener'; +import { Mat4, Rect, Size, Vec2, Vec3 } from '../../math'; import { aabb } from '../../geom-utils'; import { CanvasComponent } from './canvas-component'; import { director } from '../../director'; diff --git a/cocos/core/platform/SubContextView.ts b/cocos/core/platform/SubContextView.ts index 0af0599a30..ccb2e97128 100644 --- a/cocos/core/platform/SubContextView.ts +++ b/cocos/core/platform/SubContextView.ts @@ -4,7 +4,7 @@ import { property, ccclass, menu, executionOrder } from '../data/class-decorator import { view } from './view'; import { SpriteComponent } from '../../ui/components/sprite-component'; import { Node } from '../scene-graph'; -import { UITransformComponent } from '../components/ui-base/ui-transfrom-component'; +import { UITransformComponent } from '../components/ui-base/ui-transform-component'; import { SpriteFrame, ImageAsset } from '../assets'; import { Rect } from '../math'; diff --git a/cocos/core/utils/coordinates-converts-utils.ts b/cocos/core/utils/coordinates-converts-utils.ts index 47a997cc69..caa5cd6db8 100644 --- a/cocos/core/utils/coordinates-converts-utils.ts +++ b/cocos/core/utils/coordinates-converts-utils.ts @@ -2,7 +2,7 @@ * @category pipeline */ -import { UITransformComponent } from '../components/ui-base/ui-transfrom-component'; +import { UITransformComponent } from '../components/ui-base/ui-transform-component'; import { CameraComponent } from '../3d/framework'; import { Vec3 } from '../math'; import { Node } from '../scene-graph'; diff --git a/cocos/ui/components/editbox/edit-box-component.ts b/cocos/ui/components/editbox/edit-box-component.ts index 394a0af5c7..bfaa9f7b3c 100644 --- a/cocos/ui/components/editbox/edit-box-component.ts +++ b/cocos/ui/components/editbox/edit-box-component.ts @@ -38,7 +38,7 @@ import { Color, Size } from '../../../core/math'; import { LabelComponent, VerticalTextAlignment } from '../label-component'; import { SpriteComponent } from '../sprite-component'; import { UIRenderComponent } from '../../../core/components/ui-base/ui-render-component'; -import { UITransformComponent } from '../../../core/components/ui-base/ui-transfrom-component'; +import { UITransformComponent } from '../../../core/components/ui-base/ui-transform-component'; import { EditBoxImpl } from './edit-box-impl'; import { InputFlag, InputMode, KeyboardReturnType } from './types'; import { INode } from '../../../core/utils/interfaces'; diff --git a/cocos/ui/components/layout-component.ts b/cocos/ui/components/layout-component.ts index d5a47ab875..fd6f5801e8 100644 --- a/cocos/ui/components/layout-component.ts +++ b/cocos/ui/components/layout-component.ts @@ -32,7 +32,7 @@ import { Component } from '../../core/components/component'; import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator'; import { Rect, Size, Vec2, Vec3 } from '../../core/math'; import { ccenum } from '../../core/value-types/enum'; -import { UITransformComponent } from '../../core/components/ui-base/ui-transfrom-component'; +import { UITransformComponent } from '../../core/components/ui-base/ui-transform-component'; import { SystemEventType } from '../../core/platform/event-manager/event-enum'; import { INode } from '../../core/utils/interfaces'; import { director, Director } from '../../core/director'; diff --git a/cocos/ui/components/rich-text-component.ts b/cocos/ui/components/rich-text-component.ts index 1cf134d428..5d8785526a 100644 --- a/cocos/ui/components/rich-text-component.ts +++ b/cocos/ui/components/rich-text-component.ts @@ -40,7 +40,7 @@ import { LabelOutlineComponent } from './label-outline-component'; import { SpriteComponent } from './sprite-component'; import { UIComponent } from '../../core/components/ui-base/ui-component'; import { UIRenderComponent } from '../../core/components/ui-base/ui-render-component'; -import { UITransformComponent } from '../../core/components/ui-base/ui-transfrom-component'; +import { UITransformComponent } from '../../core/components/ui-base/ui-transform-component'; import { INode } from '../../core/utils/interfaces'; import { assert, warnID } from '../../core/platform/debug'; import { loader } from '../../core/load-pipeline'; diff --git a/cocos/ui/components/widget-component.ts b/cocos/ui/components/widget-component.ts index 18b6d6c691..5ec9689a9c 100644 --- a/cocos/ui/components/widget-component.ts +++ b/cocos/ui/components/widget-component.ts @@ -29,7 +29,7 @@ */ import { Component} from '../../core/components'; -import { UITransformComponent } from '../../core/components/ui-base/ui-transfrom-component'; +import { UITransformComponent } from '../../core/components/ui-base/ui-transform-component'; import { ccclass, executeInEditMode, executionOrder, menu, property, requireComponent } from '../../core/data/class-decorator'; import { Size, Vec3 } from '../../core/math'; import { errorID } from '../../core/platform/debug'; From c482c137d4f66686b2ae9414287bdf938b8f58ee Mon Sep 17 00:00:00 2001 From: Myway Date: Tue, 19 Nov 2019 14:44:51 +0800 Subject: [PATCH 4/9] Refactor terrain with resource (#5690) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 资源化地形 * 新增导出默认资源 * 修改资源导出的bug --- cocos/terrain/index.ts | 3 +- cocos/terrain/terrain-asset.ts | 347 ++++++++++++++++++++++++ cocos/terrain/terrain.ts | 466 ++++++++++++++++++++++----------- 3 files changed, 668 insertions(+), 148 deletions(-) create mode 100644 cocos/terrain/terrain-asset.ts diff --git a/cocos/terrain/index.ts b/cocos/terrain/index.ts index 31c5626a38..bf2aecccbe 100644 --- a/cocos/terrain/index.ts +++ b/cocos/terrain/index.ts @@ -3,4 +3,5 @@ */ export * from './height-field'; -export * from './terrain'; \ No newline at end of file +export * from './terrain'; +export * from './terrain-asset'; \ No newline at end of file diff --git a/cocos/terrain/terrain-asset.ts b/cocos/terrain/terrain-asset.ts new file mode 100644 index 0000000000..e793ff7e37 --- /dev/null +++ b/cocos/terrain/terrain-asset.ts @@ -0,0 +1,347 @@ +/** + * @category terrain + */ +import { Asset } from "../core/assets"; +import { ccclass } from "../core/data/class-decorator"; + +export const TERRAIN_DATA_VERSION = 0x01010001; +export const TERRAIN_DATA_VERSION2 = 0x01010002; +export const TERRAIN_DATA_VERSION_DEFAULT = 0x01010111; + + +export class TerrainBuffer { + public Length: number = 0; + public Buffer: Uint8Array = new Uint8Array(2048); + private _dview: DataView = new DataView(this.Buffer.buffer); + private _seekPos: number = 0; + + public Reserve (size: number) { + if (this.Buffer.byteLength > size) { + return; + } + + let capacity = this.Buffer.byteLength; + while (capacity < size) { + capacity += capacity; + } + + let temp = new Uint8Array(capacity); + for (let i = 0; i < this.Length; ++i) { + temp[i] = this.Buffer[i]; + } + + this.Buffer = temp; + this._dview = new DataView(this.Buffer.buffer); + } + + public Assign (buff: Uint8Array) { + this.Buffer = buff; + this.Length = buff.length; + this._seekPos = buff.byteOffset; + this._dview = new DataView(buff.buffer); + } + + public WriteInt8 (value: number) { + this.Reserve(this.Length + 1); + + this._dview.setInt8(this.Length, value); + this.Length += 1; + } + + public WriteInt16 (value: number) { + this.Reserve(this.Length + 2); + + this._dview.setInt16(this.Length, value, true); + this.Length += 2; + } + + public WriteInt32 (value: number) { + this.Reserve(this.Length + 4); + + this._dview.setInt32(this.Length, value, true); + this.Length += 4; + } + + public WriteIntArray (value: number[]) { + this.Reserve(this.Length + 4 * value.length); + + for (let i = 0; i < value.length; ++i) { + this._dview.setInt32(this.Length + i * 4, value[i], true); + } + this.Length += 4 * value.length; + } + + public WriteFloat (value: number) { + this.Reserve(this.Length + 4); + + this._dview.setFloat32(this.Length, value, true); + this.Length += 4; + } + + public WriteFloatArray (value: number[]) { + this.Reserve(this.Length + 4 * value.length); + + for (let i = 0; i < value.length; ++i) { + this._dview.setFloat32(this.Length + i * 4, value[i], true); + } + this.Length += 4 * value.length; + } + + public WriteString (value: string) { + this.Reserve(this.Length + value.length + 4); + + this._dview.setInt32(this.Length, value.length, true); + for (let i = 0; i < value.length; ++i) { + this._dview.setInt8(this.Length + 4 + i, value.charCodeAt(i)); + } + this.Length += value.length + 4; + } + + public ReadInt8 () { + let value = this._dview.getInt8(this._seekPos); + this._seekPos += 1; + return value; + } + + public ReadInt16 () { + let value = this._dview.getInt16(this._seekPos, true); + this._seekPos += 2; + return value; + } + + public ReadInt () { + let value = this._dview.getInt32(this._seekPos, true); + this._seekPos += 4; + return value; + } + + public ReadIntArray (value: number[]) { + for (let i = 0; i < value.length; ++i) { + value[i] = this._dview.getInt32(this._seekPos + i * 4, true); + } + this._seekPos += 4 * value.length; + return value; + } + + public ReadFloat () { + let value = this._dview.getFloat32(this._seekPos, true); + this._seekPos += 4; + return value; + } + + public ReadFloatArray (value: number[]) { + for (let i = 0; i < value.length; ++i) { + value[i] = this._dview.getFloat32(this._seekPos + i * 4, true); + } + this._seekPos += 4 * value.length; + return value; + } + + public ReadString () { + let length = this.ReadInt(); + + let value = ""; + for (let i = 0; i < length; ++i) { + value += String.fromCharCode(this.ReadInt8()); + } + + return value; + } +} + +@ccclass('cc.TerrainAsset') +export class TerrainAsset extends Asset +{ + protected _data: Uint8Array|null = null; + protected _tileSize: number = 1; + protected _blockCount: number[] = [1, 1]; + protected _weightMapSize: number = 128; + protected _lightMapSize: number = 128; + protected _heights: Uint16Array = new Uint16Array; + protected _weights: Uint8Array = new Uint8Array; + protected _layerBuffer: number[] = [-1, -1, -1, -1]; + + constructor () { + super(); + this.loaded = false; + } + + get _nativeAsset (): ArrayBuffer { + return this._data!.buffer; + } + + set _nativeAsset (value: ArrayBuffer) { + if (this._data && this._data.byteLength === value.byteLength) { + this._data.set(new Uint8Array(value)); + if (cc.loader._cache[this.nativeUrl]) { + cc.loader._cache[this.nativeUrl].content = this._data.buffer; + } + } + else { + this._data = new Uint8Array(value); + } + + this._loadNativeData(this._data); + this.loaded = true; + this.emit('load'); + } + + set tileSize (value: number) { + this._tileSize = value; + } + + get tileSize () { + return this._tileSize; + } + + set blockCount (value: number[]) { + this._blockCount = value; + } + + get blockCount () { + return this._blockCount; + } + + set lightMapSize (value: number) { + this._lightMapSize = value; + } + + get lightMapSize () { + return this._lightMapSize; + } + + set weightMapSize (value: number) { + this._weightMapSize = value; + } + + get weightMapSize () { + return this._weightMapSize; + } + + set heights (value: Uint16Array) { + this._heights = value; + } + + get heights () { + return this._heights; + } + + set weights (value: Uint8Array) { + this._weights = value; + } + + get weights () { + return this._weights; + } + + set layerBuffer(value: number[]) { + this._layerBuffer = value; + } + + get layerBuffer() { + return this._layerBuffer; + } + + public getLayer (xblock: number, yblock: number, layerId: number) { + let blockId = yblock * this.blockCount[0] + xblock; + let index = blockId * 4 + layerId; + + if (xblock < this.blockCount[0] && yblock < this.blockCount[1] && index < this._layerBuffer.length) { + return this._layerBuffer[index]; + } + + return -1; + } + + public _setNativeData(_nativeData: Uint8Array) { + this._data = _nativeData; + } + + public _loadNativeData (_nativeData: Uint8Array) { + let stream = new TerrainBuffer(); + stream.Assign(_nativeData); + + // version + let version = stream.ReadInt(); + if (version == TERRAIN_DATA_VERSION_DEFAULT) { + return true; + } + if (version != TERRAIN_DATA_VERSION && + version != TERRAIN_DATA_VERSION2) { + return false; + } + + // geometry info + this.tileSize = stream.ReadFloat(); + stream.ReadIntArray(this._blockCount); + this.weightMapSize = stream.ReadInt16(); + this.lightMapSize = stream.ReadInt16(); + + // heights + let heightBufferSize = stream.ReadInt(); + this.heights = new Uint16Array(heightBufferSize); + for (let i = 0; i < this.heights.length; ++i) { + this.heights[i] = stream.ReadInt16(); + } + + // weights + let WeightBufferSize = stream.ReadInt(); + this.weights = new Uint8Array(WeightBufferSize); + for (let i = 0; i < this.weights.length; ++i) { + this.weights[i] = stream.ReadInt8(); + } + + // layer buffer + if (version != TERRAIN_DATA_VERSION2) { + let layerBufferSize = stream.ReadInt(); + this.layerBuffer = new Array(layerBufferSize); + for (let i = 0; i < this.weights.length; ++i) { + this.layerBuffer[i] = stream.ReadInt16(); + } + } + + return true; + } + + public _exportNativeData() : Uint8Array { + let stream = new TerrainBuffer(); + + // version + stream.WriteInt32(TERRAIN_DATA_VERSION2); + + // geometry info + stream.WriteFloat(this.tileSize); + stream.WriteIntArray(this._blockCount); + stream.WriteInt16(this.weightMapSize); + stream.WriteInt16(this.lightMapSize); + + // heights + stream.WriteInt32(this.heights.length); + for (let i = 0; i < this.heights.length; ++i) { + stream.WriteInt16(this.heights[i]); + } + + // weights + stream.WriteInt32(this.weights.length); + for (let i = 0; i < this.weights.length; ++i) { + stream.WriteInt8(this.weights[i]); + } + + // layer buffer + stream.WriteInt32(this.layerBuffer.length); + for (let i = 0; i < this.layerBuffer.length; ++i) { + stream.WriteInt16(this.layerBuffer[i]); + } + + return stream.Buffer; + } + + public _exportDefaultNativeData() : Uint8Array { + let stream = new TerrainBuffer(); + + stream.WriteInt32(TERRAIN_DATA_VERSION_DEFAULT); + + return stream.Buffer; + + } + } \ No newline at end of file diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index 47586cfb0f..85559d14c2 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -19,7 +19,9 @@ import { Model } from '../core/renderer/scene/model'; import { PrivateNode } from '../core/scene-graph/private-node'; import { IDefineMap } from '../core/renderer/core/pass'; import { HeightField } from './height-field'; +import { TerrainAsset } from './terrain-asset'; import { director } from '../core/director'; +import { validateMethodWithProps } from '../core/data/utils/preprocess-class'; export const TERRAIN_MAX_LEVELS = 4; export const TERRAIN_MAX_BLEND_LAYERS = 4; @@ -31,6 +33,8 @@ export const TERRAIN_NORTH_INDEX = 0; export const TERRAIN_SOUTH_INDEX = 1; export const TERRAIN_WEST_INDEX = 2; export const TERRAIN_EAST_INDEX = 3; +export const TERRAIN_HEIGHT_BASE = 32768; +export const TERRAIN_HEIGHT_FACTORY = 1.0 / 512.0; /** * 地形信息。 @@ -39,40 +43,35 @@ export const TERRAIN_EAST_INDEX = 3; export class TerrainInfo { @property public tileSize: number = 1; - @property public blockCount: number[] = [1, 1]; - @property public weightMapSize: number = 128; - @property public lightMapSize: number = 128; - // - protected _tileCount: number[] = [0, 0]; - protected _vertexCount: number[] = [0, 0]; - protected _size: Size = new Size(0, 0); + public get size () { + let sz = new Size(0, 0); + sz.width = this.blockCount[0] * TERRAIN_BLOCK_TILE_COMPLEXITY * this.tileSize; + sz.height = this.blockCount[1] * TERRAIN_BLOCK_TILE_COMPLEXITY * this.tileSize; - public initialize () { - this._tileCount[0] = this.blockCount[0] * TERRAIN_BLOCK_TILE_COMPLEXITY; - this._tileCount[1] = this.blockCount[1] * TERRAIN_BLOCK_TILE_COMPLEXITY; - this._vertexCount[0] = this._tileCount[0] + 1; - this._vertexCount[1] = this._tileCount[1] + 1; - this._size.width = this._tileCount[0] * this.tileSize; - this._size.height = this._tileCount[1] * this.tileSize; + return sz; } public get tileCount () { - return this._tileCount; + let _tileCount = [0, 0]; + _tileCount[0] = this.blockCount[0] * TERRAIN_BLOCK_TILE_COMPLEXITY; + _tileCount[1] = this.blockCount[1] * TERRAIN_BLOCK_TILE_COMPLEXITY; + + return _tileCount; } public get vertexCount () { - return this._vertexCount; - } + let _vertexCount = this.tileCount; + _vertexCount[0] += 1; + _vertexCount[1] += 1; - public get size () { - return this._size; + return _vertexCount; } } @@ -131,7 +130,7 @@ export class TerrainRenderable extends RenderableComponent { this._currentMaterial = new Material(); this._currentMaterial.initialize({ - effectAsset: EffectAsset.get('builtin-terrain'), + effectAsset: cc.EffectAsset.get('builtin-terrain'), defines: block._getMaterialDefines(nlayers), }); @@ -181,6 +180,11 @@ export class TerrainRenderable extends RenderableComponent { export class TerrainBlockInfo { @property public layers: number[] = [-1, -1, -1, -1]; + public lightMap: Texture2D|null = null; + public lightMapUOff: number = 0; + public lightMapVOff: number = 0; + public lightMapUScale: number = 0; + public lightMapVScale: number = 0; } export class TerrainBlock { @@ -303,7 +307,7 @@ export class TerrainBlock { mtl.setProperty('detailMap0', l0 != null ? l0.detailMap : null); } else { - mtl.setProperty('detailMap0', builtinResMgr.get('default-texture')); + mtl.setProperty('detailMap0', cc.builtinResMgr.get('default-texture')); } } else if (nlayers === 1) { @@ -368,6 +372,11 @@ export class TerrainBlock { } mtl.setProperty('UVScale', uvScale); + + if (this.lightmap != null) { + mtl.setProperty('lightMap', this.lightmap); + mtl.setProperty('lightMapUVParam', this.lightmapUVParam); + } } } @@ -382,6 +391,14 @@ export class TerrainBlock { return this._info.layers; } + get lightmap () { + return this._info.lightMap; + } + + get lightmapUVParam () { + return new Vec4(this._info.lightMapUOff, this._info.lightMapVOff, this._info.lightMapUScale, this._info.lightMapVScale); + } + public getTerrain () { return this._terrain; } @@ -428,17 +445,33 @@ export class TerrainBlock { } public _getMaterialDefines (nlayers: number): IDefineMap { - if (nlayers === 0) { - return { LAYERS: 1 }; + if (this.lightmap != null) { + if (nlayers === 0) { + return { LAYERS: 1, LIGHT_MAP: 1}; + } + else if (nlayers === 1) { + return { LAYERS: 2, LIGHT_MAP: 1 }; + } + else if (nlayers === 2) { + return { LAYERS: 3, LIGHT_MAP: 1 }; + } + else if (nlayers === 3) { + return { LAYERS: 4, LIGHT_MAP: 1 }; + } } - else if (nlayers === 1) { - return { LAYERS: 2 }; - } - else if (nlayers === 2) { - return { LAYERS: 3 }; - } - else if (nlayers === 3) { - return { LAYERS: 4 }; + else { + if (nlayers === 0) { + return { LAYERS: 1 }; + } + else if (nlayers === 1) { + return { LAYERS: 2 }; + } + else if (nlayers === 2) { + return { LAYERS: 3 }; + } + else if (nlayers === 3) { + return { LAYERS: 4 }; + } } return { LAYERS: 0 }; @@ -497,18 +530,18 @@ export class TerrainBlock { else { if (this._weightMap == null) { this._weightMap = new Texture2D(); - this._weightMap.create(this._terrain.info.weightMapSize, this._terrain.info.weightMapSize, PixelFormat.RGBA8888); + this._weightMap.create(this._terrain.weightMapSize, this._terrain.weightMapSize, PixelFormat.RGBA8888); this._weightMap.setFilters(Filter.LINEAR, Filter.LINEAR); this._weightMap.setWrapMode(WrapMode.CLAMP_TO_EDGE, WrapMode.CLAMP_TO_EDGE); } } - const weightData = new Uint8Array(this._terrain.info.weightMapSize * this._terrain.info.weightMapSize * 4); + const weightData = new Uint8Array(this._terrain.weightMapSize * this._terrain.weightMapSize * 4); let weightIndex = 0; - for (let j = 0; j < this._terrain.info.weightMapSize; ++j) { - for (let i = 0; i < this._terrain.info.weightMapSize; ++i) { - const x = this._index[0] * this._terrain.info.weightMapSize + i; - const y = this._index[1] * this._terrain.info.weightMapSize + j; + for (let j = 0; j < this._terrain.weightMapSize; ++j) { + for (let i = 0; i < this._terrain.weightMapSize; ++i) { + const x = this._index[0] * this._terrain.weightMapSize + i; + const y = this._index[1] * this._terrain.weightMapSize + j; const w = this._terrain.getWeight(x, y); weightData[weightIndex * 4 + 0] = Math.floor(w.x * 255); @@ -521,6 +554,15 @@ export class TerrainBlock { } this._weightMap.uploadData(weightData.buffer); } + + public _updateLightmap(tex: Texture2D|null, uoff: number, voff: number, uscale: number, vscale: number) { + this._info.lightMap = tex; + this._info.lightMapUOff = uoff; + this._info.lightMapVOff = voff; + this._info.lightMapUScale = uscale; + this._info.lightMapVScale = vscale; + this._invalidMaterial(); + } } @ccclass('cc.Terrain') @@ -528,32 +570,28 @@ export class TerrainBlock { @executeInEditMode export class Terrain extends Component { @property({ - type: TerrainInfo, - visible: true, + type: TerrainAsset, + visible: false, }) - protected _info: TerrainInfo = new TerrainInfo(); - + protected __asset: TerrainAsset|null = null; + @property({ type: TerrainLayer, visible: true, }) protected _layers: Array = []; - @property({ - visible: false, - }) - protected _heights: number[] = []; - - @property({ - visible: false, - }) - protected _weights: Uint8Array = new Uint8Array(); - @property({ visible: false, }) protected _blockInfos: TerrainBlockInfo[] = []; + protected _tileSize: number = 1; + protected _blockCount: number[] = [1, 1]; + protected _weightMapSize: number = 128; + protected _lightMapSize: number = 128; + protected _heights: Uint16Array = new Uint16Array; + protected _weights: Uint8Array = new Uint8Array; protected _normals: number[] = []; protected _blocks: TerrainBlock[] = []; protected _sharedIndexBuffer: GFXBuffer|null = null; @@ -567,36 +605,119 @@ export class Terrain extends Component { } } + @property({ + type: TerrainAsset, + visible: true, + serializable: false, + }) + public set _asset(value: TerrainAsset|null) { + if (this.__asset != value) { + this.__asset = value; + if (this.__asset != null && this.valid) { + // rebuild + for (const block of this._blocks) { + block.destroy(); + } + this._blocks = []; + this._blockInfos = []; + this._buildImp(); + } + } + } + + public get _asset() { + return this.__asset; + } + + public get size () { + let sz = new Size(0, 0); + sz.width = this.blockCount[0] * TERRAIN_BLOCK_TILE_COMPLEXITY * this.tileSize; + sz.height = this.blockCount[1] * TERRAIN_BLOCK_TILE_COMPLEXITY * this.tileSize; + return sz; + } + + get tileSize () { + return this._tileSize; + } + + public get tileCount () { + let _tileCount = [0, 0]; + _tileCount[0] = this.blockCount[0] * TERRAIN_BLOCK_TILE_COMPLEXITY; + _tileCount[1] = this.blockCount[1] * TERRAIN_BLOCK_TILE_COMPLEXITY; + + return _tileCount; + } + + public get vertexCount () { + let _vertexCount = this.tileCount; + _vertexCount[0] += 1; + _vertexCount[1] += 1; + + return _vertexCount; + } + + get blockCount () { + return this._blockCount; + } + + get lightMapSize () { + return this._lightMapSize; + } + + get weightMapSize () { + return this._weightMapSize; + } + + get heights () { + return this._heights; + } + + get weights () { + return this._weights; + } + + get valid () { + return this._blocks.length > 0; + } + + @property({ + type: TerrainInfo, + visible: true, + }) public get info () { - return this._info; + let ti = new TerrainInfo; + ti.tileSize = this.tileSize; + ti.blockCount[0] = this.blockCount[0]; + ti.blockCount[1] = this.blockCount[1]; + ti.weightMapSize = this.weightMapSize; + ti.lightMapSize = this.lightMapSize; + + return ti; } public build (info: TerrainInfo) { - this._info.tileSize = info.tileSize; - this._info.blockCount[0] = info.blockCount[0]; - this._info.blockCount[1] = info.blockCount[1]; - this._info.weightMapSize = info.weightMapSize; - this._info.lightMapSize = info.lightMapSize; - this._info.initialize(); + this._tileSize = info.tileSize; + this._blockCount[0] = info.blockCount[0]; + this._blockCount[1] = info.blockCount[1]; + this._weightMapSize = info.weightMapSize; + this._lightMapSize = info.lightMapSize; return this._buildImp(); } public rebuild (info: TerrainInfo) { - info.initialize(); - // build block info const blockInfos: TerrainBlockInfo[] = []; for (let i = 0; i < info.blockCount[0] * info.blockCount[1]; ++i) { blockInfos.push(new TerrainBlockInfo()); } - const w = Math.min(this.info.blockCount[0], info.blockCount[0]); - const h = Math.min(this.info.blockCount[1], info.blockCount[1]); + const w = Math.min(this._blockCount[0], info.blockCount[0]); + const h = Math.min(this._blockCount[1], info.blockCount[1]); for (let j = 0; j < h; ++j) { for (let i = 0; i < w; ++i) { const index0 = j * info.vertexCount[0] + i; - const index1 = j * this.info.vertexCount[0] + i; + const index1 = j * this.vertexCount[0] + i; blockInfos[index0] = this._blockInfos[index1]; } @@ -616,18 +737,17 @@ export class Terrain extends Component { this._rebuildWeights(info); // update info - this._info.tileSize = info.tileSize; - this._info.blockCount[0] = info.blockCount[0]; - this._info.blockCount[1] = info.blockCount[1]; - this._info.weightMapSize = info.weightMapSize; - this._info.lightMapSize = info.lightMapSize; - this._info.initialize(); + this._tileSize = info.tileSize; + this._blockCount[0] = info.blockCount[0]; + this._blockCount[1] = info.blockCount[1]; + this._weightMapSize = info.weightMapSize; + this._lightMapSize = info.lightMapSize; // build blocks this._buildNormals(); - for (let j = 0; j < this._info.blockCount[1]; ++j) { - for (let i = 0; i < this._info.blockCount[0]; ++i) { + for (let j = 0; j < this._blockCount[1]; ++j) { + for (let i = 0; i < this._blockCount[0]; ++i) { this._blocks.push(new TerrainBlock(this, i, j)); } } @@ -639,10 +759,10 @@ export class Terrain extends Component { public importHeightField (hf: HeightField, heightScale: number) { let index = 0; - for (let j = 0; j < this._info.vertexCount[1]; ++j) { - for (let i = 0; i < this._info.vertexCount[0]; ++i) { - const u = i / this._info.tileCount[0]; - const v = j / this._info.tileCount[1]; + for (let j = 0; j < this.vertexCount[1]; ++j) { + for (let i = 0; i < this.vertexCount[0]; ++i) { + const u = i / this.tileCount[0]; + const v = j / this.tileCount[1]; const h = hf.getAt(u * hf.w, v * hf.h) * heightScale; @@ -665,8 +785,8 @@ export class Terrain extends Component { const u = i / (hf.w - 1); const v = j / (hf.h - 1); - const x = u * this._info.size.width; - const y = v * this._info.size.height; + const x = u * this.size.width; + const y = v * this.size.height; const h = this.getHeightAt(x, y); if (h != null) { @@ -676,8 +796,31 @@ export class Terrain extends Component { } } + public exportAsset() { + let asset = this._asset; + if (asset == null) { + asset = new TerrainAsset; + } + + asset.tileSize = this.tileSize; + asset.blockCount = this.blockCount; + asset.lightMapSize = this.lightMapSize; + asset.weightMapSize = this.weightMapSize; + asset.heights = this.heights; + asset.weights = this.weights; + asset.layerBuffer = new Array(this._blocks.length * 4); + for (let i = 0; i < this._blocks.length; ++i) { + asset.layerBuffer[i * 4 + 0] + this._blocks[i].layers[0]; + asset.layerBuffer[i * 4 + 1] + this._blocks[i].layers[1]; + asset.layerBuffer[i * 4 + 2] + this._blocks[i].layers[2]; + asset.layerBuffer[i * 4 + 3] + this._blocks[i].layers[3]; + } + + return asset; + } + public onLoad () { - const gfxDevice = director.root!.device as GFXDevice; + const gfxDevice = cc.director.root.device as GFXDevice; // initialize shared index buffer const indexData = new Uint16Array(TERRAIN_BLOCK_TILE_COMPLEXITY * TERRAIN_BLOCK_TILE_COMPLEXITY * 6); @@ -770,31 +913,35 @@ export class Terrain extends Component { } public getPosition (i: number, j: number) { - const x = i * this._info.tileSize; - const z = j * this._info.tileSize; + const x = i * this._tileSize; + const z = j * this._tileSize; const y = this.getHeight(i, j); return new Vec3(x, y, z); } + public getHeightField () { + return this._heights; + } + public setHeight (i: number, j: number, h: number) { - this._heights[j * this._info.vertexCount[0] + i] = h; + this._heights[j * this.vertexCount[0] + i] = TERRAIN_HEIGHT_BASE + h / TERRAIN_HEIGHT_FACTORY; } public getHeight (i: number, j: number) { - return this._heights[j * this._info.vertexCount[0] + i]; + return (this._heights[j * this.vertexCount[0] + i] - TERRAIN_HEIGHT_BASE) * TERRAIN_HEIGHT_FACTORY; } public getHeightClamp (i: number, j: number) { - i = clamp(i, 0, this._info.vertexCount[0] - 1); - j = clamp(j, 0, this._info.vertexCount[1] - 1); + i = clamp(i, 0, this.vertexCount[0] - 1); + j = clamp(j, 0, this.vertexCount[1] - 1); return this.getHeight(i, j); } public getHeightAt (x: number, y: number) { - const fx = x / this._info.vertexCount[0]; - const fy = y / this._info.vertexCount[1]; + const fx = x / this.vertexCount[0]; + const fy = y / this.vertexCount[1]; let ix0 = Math.floor(fx); let iz0 = Math.floor(fy); @@ -803,14 +950,14 @@ export class Terrain extends Component { const dx = fx - ix0; const dz = fy - iz0; - if (ix0 < 0 || ix0 > this._info.vertexCount[0] - 1 || iz0 < 0 || iz0 > this._info.vertexCount[1] - 1) { + if (ix0 < 0 || ix0 > this.vertexCount[0] - 1 || iz0 < 0 || iz0 > this.vertexCount[1] - 1) { return null; } - ix0 = clamp(ix0, 0, this._info.vertexCount[0] - 1); - iz0 = clamp(iz0, 0, this._info.vertexCount[1] - 1); - ix1 = clamp(ix1, 0, this._info.vertexCount[0] - 1); - iz1 = clamp(iz1, 0, this._info.vertexCount[1] - 1); + ix0 = clamp(ix0, 0, this.vertexCount[0] - 1); + iz0 = clamp(iz0, 0, this.vertexCount[1] - 1); + ix1 = clamp(ix1, 0, this.vertexCount[0] - 1); + iz1 = clamp(iz1, 0, this.vertexCount[1] - 1); let a = this.getHeight(ix0, iz0); const b = this.getHeight(ix1, iz0); @@ -834,7 +981,7 @@ export class Terrain extends Component { } public _setNormal (i: number, j: number, n: Vec3) { - const index = j * this._info.vertexCount[0] + i; + const index = j * this.vertexCount[0] + i; this._normals[index * 3 + 0] = n.x; this._normals[index * 3 + 1] = n.y; @@ -842,7 +989,7 @@ export class Terrain extends Component { } public getNormal (i: number, j: number) { - const index = j * this._info.vertexCount[0] + i; + const index = j * this.vertexCount[0] + i; const n = new Vec3(); n.x = this._normals[index * 3 + 0]; @@ -853,8 +1000,8 @@ export class Terrain extends Component { } public getNormalAt (x: number, y: number) { - const fx = x / this._info.vertexCount[0]; - const fy = y / this._info.vertexCount[1]; + const fx = x / this.vertexCount[0]; + const fy = y / this.vertexCount[1]; let ix0 = Math.floor(fx); let iz0 = Math.floor(fy); @@ -863,14 +1010,14 @@ export class Terrain extends Component { const dx = fx - ix0; const dz = fy - iz0; - if (ix0 < 0 || ix0 > this._info.vertexCount[0] - 1 || iz0 < 0 || iz0 > this._info.vertexCount[1] - 1) { + if (ix0 < 0 || ix0 > this.vertexCount[0] - 1 || iz0 < 0 || iz0 > this.vertexCount[1] - 1) { return null; } - ix0 = clamp(ix0, 0, this._info.vertexCount[0] - 1); - iz0 = clamp(iz0, 0, this._info.vertexCount[1] - 1); - ix1 = clamp(ix1, 0, this._info.vertexCount[0] - 1); - iz1 = clamp(iz1, 0, this._info.vertexCount[1] - 1); + ix0 = clamp(ix0, 0, this.vertexCount[0] - 1); + iz0 = clamp(iz0, 0, this.vertexCount[1] - 1); + ix1 = clamp(ix1, 0, this.vertexCount[0] - 1); + iz1 = clamp(iz1, 0, this.vertexCount[1] - 1); const a = this.getNormal(ix0, iz0); const b = this.getNormal(ix1, iz0); @@ -903,7 +1050,7 @@ export class Terrain extends Component { } public setWeight (i: number, j: number, w: Vec4) { - const index = j * this.info.weightMapSize * this.info.blockCount[0] + i; + const index = j * this._weightMapSize * this._blockCount[0] + i; this._weights[index * 4 + 0] = w.x * 255; this._weights[index * 4 + 1] = w.y * 255; @@ -912,7 +1059,7 @@ export class Terrain extends Component { } public getWeight (i: number, j: number) { - const index = j * this.info.weightMapSize * this.info.blockCount[0] + i; + const index = j * this._weightMapSize * this._blockCount[0] + i; const w = new Vec4(); w.x = this._weights[index * 4 + 0] / 255.0; @@ -924,8 +1071,8 @@ export class Terrain extends Component { } public getWeightAt (x: number, y: number) { - const fx = x / this._info.vertexCount[0]; - const fy = y / this._info.vertexCount[1]; + const fx = x / this.vertexCount[0]; + const fy = y / this.vertexCount[1]; let ix0 = Math.floor(fx); let iz0 = Math.floor(fy); @@ -934,14 +1081,14 @@ export class Terrain extends Component { const dx = fx - ix0; const dz = fy - iz0; - if (ix0 < 0 || ix0 > this._info.vertexCount[0] - 1 || iz0 < 0 || iz0 > this._info.vertexCount[1] - 1) { + if (ix0 < 0 || ix0 > this.vertexCount[0] - 1 || iz0 < 0 || iz0 > this.vertexCount[1] - 1) { return null; } - ix0 = clamp(ix0, 0, this._info.vertexCount[0] - 1); - iz0 = clamp(iz0, 0, this._info.vertexCount[1] - 1); - ix1 = clamp(ix1, 0, this._info.vertexCount[0] - 1); - iz1 = clamp(iz1, 0, this._info.vertexCount[1] - 1); + ix0 = clamp(ix0, 0, this.vertexCount[0] - 1); + iz0 = clamp(iz0, 0, this.vertexCount[1] - 1); + ix1 = clamp(ix1, 0, this.vertexCount[0] - 1); + iz1 = clamp(iz1, 0, this.vertexCount[1] - 1); let a = this.getWeight(ix0, iz0); const b = this.getWeight(ix1, iz0); @@ -970,11 +1117,11 @@ export class Terrain extends Component { } public getBlockInfo (i: number, j: number) { - return this._blockInfos[j * this._info.blockCount[0] + i]; + return this._blockInfos[j * this._blockCount[0] + i]; } public getBlock (i: number, j: number) { - return this._blocks[j * this._info.blockCount[0] + i]; + return this._blocks[j * this._blockCount[0] + i]; } public getBlocks () { @@ -1009,6 +1156,16 @@ export class Terrain extends Component { } } else { + // 优先大步进查找 + while (i++ < MAX_COUNT) { + const y = this.getHeightAt(trace.x, trace.z); + if (y != null && trace.y <= y) { + break; + } + + trace.add(dir); + } + // 穷举法 while (i++ < MAX_COUNT) { const y = this.getHeightAt(trace.x, trace.z); @@ -1030,7 +1187,7 @@ export class Terrain extends Component { let right: Vec3; let up: Vec3; - if (x < this._info.vertexCount[0] - 1) { + if (x < this.vertexCount[0] - 1) { right = this.getPosition(x + 1, z); } else { @@ -1038,7 +1195,7 @@ export class Terrain extends Component { right = this.getPosition(x - 1, z); } - if (z < this._info.vertexCount[1] - 1) { + if (z < this.vertexCount[1] - 1) { up = this.getPosition(x, z + 1); } else { @@ -1060,8 +1217,8 @@ export class Terrain extends Component { public _buildNormals () { let index = 0; - for (let y = 0; y < this._info.vertexCount[1]; ++y) { - for (let x = 0; x < this._info.vertexCount[0]; ++x) { + for (let y = 0; y < this.vertexCount[1]; ++y) { + for (let x = 0; x < this.vertexCount[0]; ++x) { const n = this._calcuNormal(x, y); this._normals[index * 3 + 0] = n.x; @@ -1073,24 +1230,31 @@ export class Terrain extends Component { } private _buildImp () { - if (this._blocks.length > 0) { + if (this.valid) { return true; } - this._info.initialize(); + if (this.__asset != null) { + this._tileSize = this.__asset.tileSize; + this._blockCount = this.__asset.blockCount; + this._weightMapSize = this.__asset.weightMapSize; + this._lightMapSize = this.__asset.lightMapSize; + this._heights = this.__asset.heights; + this._weights = this.__asset.weights; + } - if (this._info.blockCount[0] === 0 || this._info.blockCount[1] === 0) { + if (this._blockCount[0] === 0 || this._blockCount[1] === 0) { return false; } // build heights & normals - const vcount = this._info.vertexCount[0] * this._info.vertexCount[1]; + const vcount = this.vertexCount[0] * this.vertexCount[1]; if (this._heights.length !== vcount) { - this._heights = new Array(vcount); + this._heights = new Uint16Array(vcount); this._normals = new Array(vcount * 3); for (let i = 0; i < vcount; ++i) { - this._heights[i] = 0; + this._heights[i] = TERRAIN_HEIGHT_BASE; this._normals[i * 3 + 0] = 0; this._normals[i * 3 + 1] = 1; this._normals[i * 3 + 2] = 0; @@ -1102,8 +1266,8 @@ export class Terrain extends Component { } // initialize weights - const weightMapComplexityU = this.info.weightMapSize * this.info.blockCount[0]; - const weightMapComplexityV = this.info.weightMapSize * this.info.blockCount[1]; + const weightMapComplexityU = this._weightMapSize * this._blockCount[0]; + const weightMapComplexityV = this._weightMapSize * this._blockCount[1]; if (this._weights.length !== weightMapComplexityU * weightMapComplexityV * 4) { this._weights = new Uint8Array(weightMapComplexityU * weightMapComplexityV * 4); for (let i = 0; i < weightMapComplexityU * weightMapComplexityV; ++i) { @@ -1115,17 +1279,25 @@ export class Terrain extends Component { } // build blocks - if (this._blockInfos.length !== this.info.blockCount[0] * this.info.blockCount[1]) { + if (this._blockInfos.length !== this._blockCount[0] * this._blockCount[1]) { this._blockInfos = []; - for (let j = 0; j < this.info.blockCount[1]; ++j) { - for (let i = 0; i < this.info.blockCount[0]; ++i) { - this._blockInfos.push(new TerrainBlockInfo()); + for (let j = 0; j < this._blockCount[1]; ++j) { + for (let i = 0; i < this._blockCount[0]; ++i) { + let info = new TerrainBlockInfo(); + if (this._asset != null) { + info.layers[0] = this._asset.getLayer(i, j, 0); + info.layers[1] = this._asset.getLayer(i, j, 1); + info.layers[2] = this._asset.getLayer(i, j, 2); + info.layers[3] = this._asset.getLayer(i, j, 3); + } + + this._blockInfos.push(info); } } } - for (let j = 0; j < this.info.blockCount[1]; ++j) { - for (let i = 0; i < this.info.blockCount[0]; ++i) { + for (let j = 0; j < this._blockCount[1]; ++j) { + for (let i = 0; i < this._blockCount[0]; ++i) { this._blocks.push(new TerrainBlock(this, i, j)); } } @@ -1136,23 +1308,23 @@ export class Terrain extends Component { } private _rebuildHeights (info: TerrainInfo) { - if (this.info.vertexCount[0] === info.vertexCount[0] && - this.info.vertexCount[1] === info.vertexCount[1]) { + if (this.vertexCount[0] === info.vertexCount[0] && + this.vertexCount[1] === info.vertexCount[1]) { return false; } - const heights = new Array(info.vertexCount[0] * info.vertexCount[1]); + const heights = new Uint16Array(info.vertexCount[0] * info.vertexCount[1]); for (let i = 0; i < heights.length; ++i) { - heights[i] = 0; + heights[i] = TERRAIN_HEIGHT_BASE; } - const w = Math.min(this.info.vertexCount[0], info.vertexCount[0]); - const h = Math.min(this.info.vertexCount[1], info.vertexCount[1]); + const w = Math.min(this.vertexCount[0], info.vertexCount[0]); + const h = Math.min(this.vertexCount[1], info.vertexCount[1]); for (let j = 0; j < h; ++j) { for (let i = 0; i < w; ++i) { const index0 = j * info.vertexCount[0] + i; - const index1 = j * this.info.vertexCount[0] + i; + const index1 = j * this.vertexCount[0] + i; heights[index0] = this._heights[index1]; } @@ -1164,9 +1336,9 @@ export class Terrain extends Component { } private _rebuildWeights (info: TerrainInfo) { - const oldWeightMapSize = this.info.weightMapSize; - const oldWeightMapComplexityU = this.info.weightMapSize * this.info.blockCount[0]; - const oldWeightMapComplexityV = this.info.weightMapSize * this.info.blockCount[1]; + const oldWeightMapSize = this._weightMapSize; + const oldWeightMapComplexityU = this._weightMapSize * this._blockCount[0]; + const oldWeightMapComplexityV = this._weightMapSize * this._blockCount[1]; const weightMapComplexityU = info.weightMapSize * info.blockCount[0]; const weightMapComplexityV = info.weightMapSize * info.blockCount[1]; @@ -1185,8 +1357,8 @@ export class Terrain extends Component { weights[i * 4 + 3] = 0; } - const w = Math.min(info.blockCount[0], this.info.blockCount[0]); - const h = Math.min(info.blockCount[1], this.info.blockCount[1]); + const w = Math.min(info.blockCount[0], this._blockCount[0]); + const h = Math.min(info.blockCount[1], this._blockCount[1]); // get weight const getOldWeight = (_i: number, _j: number, _weights: Uint8Array) => { @@ -1244,20 +1416,20 @@ export class Terrain extends Component { const uoff = i * oldWeightMapSize; const voff = j * oldWeightMapSize; - for (let v = 0; v < this.info.weightMapSize; ++v) { - for (let u = 0; u < this.info.weightMapSize; ++u) { + for (let v = 0; v < this._weightMapSize; ++v) { + for (let u = 0; u < this._weightMapSize; ++u) { let w: Vec4; if (info.weightMapSize == oldWeightMapSize) { w = getOldWeight(u + uoff, v + voff, this._weights); } else { - const x = u / (this.info.weightMapSize - 1) * (oldWeightMapSize - 1); - const y = v / (this.info.weightMapSize - 1) * (oldWeightMapSize - 1); + const x = u / (this._weightMapSize - 1) * (oldWeightMapSize - 1); + const y = v / (this._weightMapSize - 1) * (oldWeightMapSize - 1); w = sampleOldWeight(x, y, uoff, voff, this._weights); } - const du = i * this.info.weightMapSize + u; - const dv = j * this.info.weightMapSize + v; + const du = i * this._weightMapSize + u; + const dv = j * this._weightMapSize + v; const index = dv * weightMapComplexityU + du; weights[index * 4 + 0] = w.x * 255; From a8607620538a4631a33e2d3cbf2c8bfd74434266 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 19 Nov 2019 18:37:36 +0800 Subject: [PATCH 5/9] Fix ci --- cocos/core/components/ui-base/ui-transform-component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/core/components/ui-base/ui-transform-component.ts b/cocos/core/components/ui-base/ui-transform-component.ts index 68b9b9fe4f..e541b15c96 100644 --- a/cocos/core/components/ui-base/ui-transform-component.ts +++ b/cocos/core/components/ui-base/ui-transform-component.ts @@ -30,7 +30,7 @@ import { Component } from '../component'; import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../data/class-decorator'; import { SystemEventType } from '../../platform/event-manager/event-enum'; -import { EventListener, ILinstenerMask } from '../../platform/event-manager/event-listener'; +import { EventListener, IListenerMask } from '../../platform/event-manager/event-listener'; import { Mat4, Rect, Size, Vec2, Vec3 } from '../../math'; import { aabb } from '../../geom-utils'; import { CanvasComponent } from './canvas-component'; From fd10ade041077012d5769d4c26f7ab93f4ff630b Mon Sep 17 00:00:00 2001 From: zxg0622 <247274249@qq.com> Date: Fri, 22 Nov 2019 12:07:23 +0800 Subject: [PATCH 6/9] renderpipeline asset (#5755) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add renderpipeline asset * Rndppl (#3) * 编辑器联调 renderpipeline * 加载 renderpipeline * 1 * change init flow * add renderpipeline load failed process * fix interface * fix ci error * fix forward ubo binding error * fix null value & array iterate * fix for of & game.ts line end --- cocos/core/assets/index.ts | 3 +- cocos/core/assets/render-pipeline-asset.ts | 13 + cocos/core/data/class.ts | 29 + cocos/core/game.ts | 10 + cocos/core/pipeline/forward/enum.ts | 18 + cocos/core/pipeline/forward/forward-flow.ts | 46 +- .../core/pipeline/forward/forward-pipeline.ts | 127 ++-- cocos/core/pipeline/forward/forward-stage.ts | 158 ++-- cocos/core/pipeline/index.ts | 10 + cocos/core/pipeline/pipeline-serialization.ts | 125 ++++ cocos/core/pipeline/ppfx/tonemap-flow.ts | 42 +- cocos/core/pipeline/ppfx/tonemap-stage.ts | 62 +- cocos/core/pipeline/render-flow.ts | 136 ++-- cocos/core/pipeline/render-pipeline.ts | 703 ++++++------------ cocos/core/pipeline/render-stage.ts | 174 ++++- cocos/core/pipeline/render-view.ts | 2 +- cocos/core/pipeline/ui/ui-flow.ts | 31 +- cocos/core/pipeline/ui/ui-stage.ts | 68 +- cocos/core/root.ts | 27 +- 19 files changed, 905 insertions(+), 879 deletions(-) create mode 100644 cocos/core/assets/render-pipeline-asset.ts create mode 100644 cocos/core/pipeline/forward/enum.ts create mode 100644 cocos/core/pipeline/pipeline-serialization.ts diff --git a/cocos/core/assets/index.ts b/cocos/core/assets/index.ts index d7c8781883..e8bc233aa2 100644 --- a/cocos/core/assets/index.ts +++ b/cocos/core/assets/index.ts @@ -40,7 +40,7 @@ export {default as JsonAsset} from './json-asset'; export {default as AssetLibrary} from './asset-library'; export { ImageAsset } from './image-asset'; export { Texture2D } from './texture-2d'; -export { TextureCube } from './texture-cube' +export { TextureCube } from './texture-cube'; export { TTFFont } from './ttf-font'; export { LabelAtlas } from './label-atlas'; export { BitmapFont } from './bitmap-font'; @@ -53,4 +53,5 @@ export { Material } from './material'; export { Mesh } from './mesh'; export { Skeleton } from './skeleton'; export { RenderTexture } from './render-texture'; +export { default as RenderPipelineAsset } from './render-pipeline-asset'; diff --git a/cocos/core/assets/render-pipeline-asset.ts b/cocos/core/assets/render-pipeline-asset.ts new file mode 100644 index 0000000000..2f01bf3220 --- /dev/null +++ b/cocos/core/assets/render-pipeline-asset.ts @@ -0,0 +1,13 @@ +import { ccclass, property } from '../data/class-decorator'; +import { RenderPipeline } from '../pipeline/render-pipeline'; +import { Asset } from './asset'; + +@ccclass('cc.RenderPipelineAsset') +export default class RenderPipelineAsset extends Asset { + @property({ + type: RenderPipeline, + }) + public renderPipeline: RenderPipeline | null = null; +} + +cc.RenderPipelineAsset = RenderPipelineAsset; diff --git a/cocos/core/data/class.ts b/cocos/core/data/class.ts index bd57635501..bca09e03df 100644 --- a/cocos/core/data/class.ts +++ b/cocos/core/data/class.ts @@ -375,7 +375,36 @@ function define (className, baseClass, mixins, options) { const cls = doDefine(className, baseClass, mixins, options); + // for RenderPipeline, RenderFlow, RenderStage + const isRenderPipeline = js.isChildClassOf(baseClass, cc.RenderPipeline); + const isRenderFlow = js.isChildClassOf(baseClass, cc.RenderFlow); + const isRenderStage = js.isChildClassOf(baseClass, cc.RenderStage); + + const isRender = isRenderPipeline || isRenderFlow || isRenderStage || false; + + if (isRender) { + let renderName = ''; + if (isRenderPipeline) { + renderName = 'render_pipeline'; + } else if (isRenderFlow) { + renderName = 'render_flow'; + } else if (isRenderStage) { + renderName = 'render_stage'; + } + + if (renderName) { + js._setClassId(className, cls); + if (CC_EDITOR) { + // 增加了 hidden: 开头标识,使它最终不会显示在 Editor inspector 的添加组件列表里 + // @ts-ignore + // tslint:disable-next-line:no-unused-expression + window.EditorExtends && window.EditorExtends.Component.addMenu(cls, `hidden:${renderName}/${className}`, -1); + } + } + } + if (frame) { + // 基础的 ts, js 脚本组件 if (js.isChildClassOf(baseClass, Component)) { const uuid = frame.uuid; if (uuid) { diff --git a/cocos/core/game.ts b/cocos/core/game.ts index 036f811c91..03b434704a 100644 --- a/cocos/core/game.ts +++ b/cocos/core/game.ts @@ -32,6 +32,7 @@ import { WebGLGFXDevice } from './gfx/webgl/webgl-device'; import { WebGL2GFXDevice } from './gfx/webgl2/webgl2-device'; import * as debug from './platform/debug'; import { SplashScreen } from './splash-image'; +import { ForwardPipeline } from './pipeline'; /** * @en * The current game configuration, including:
@@ -978,6 +979,15 @@ export class Game extends EventTarget { cc.game.resume(); }); } + + private setRenderPipeline (rppl) { + // cc.director.root.setRenderPipeline(rppl.renderPipeline); + if (!rppl) { + rppl = new ForwardPipeline(); + rppl.initialize(ForwardPipeline.initInfo); + } + cc.director.root.setRenderPipeline(rppl); + } } cc.Game = Game; diff --git a/cocos/core/pipeline/forward/enum.ts b/cocos/core/pipeline/forward/enum.ts new file mode 100644 index 0000000000..382befb906 --- /dev/null +++ b/cocos/core/pipeline/forward/enum.ts @@ -0,0 +1,18 @@ + +/** + * @zh + * 前向阶段优先级。 + */ +export enum ForwardStagePriority { + FORWARD = 0, +} + + +/** + * @zh + * 前向渲染流程优先级。 + */ +export enum ForwardFlowPriority { + FORWARD = 0, + UI = 10, +} \ No newline at end of file diff --git a/cocos/core/pipeline/forward/forward-flow.ts b/cocos/core/pipeline/forward/forward-flow.ts index 75f1981703..c3eadbca95 100644 --- a/cocos/core/pipeline/forward/forward-flow.ts +++ b/cocos/core/pipeline/forward/forward-flow.ts @@ -2,51 +2,37 @@ * @category pipeline.forward */ +import { ccclass } from '../../data/class-decorator'; import { IRenderFlowInfo, RenderFlow } from '../render-flow'; -import { RenderPipeline } from '../render-pipeline'; import { ForwardStage } from './forward-stage'; - -/** - * @zh - * 前向阶段优先级。 - */ -export enum ForwardStagePriority { - FORWARD = 0, -} +import { PIPELINE_FLOW_FORWARD } from '../define'; +import { ForwardFlowPriority } from "./enum"; /** * @zh * 前向渲染流程。 */ +@ccclass('ForwardFlow') export class ForwardFlow extends RenderFlow { + public static initInfo: IRenderFlowInfo = { + name: PIPELINE_FLOW_FORWARD, + priority: ForwardFlowPriority.FORWARD, + }; + /** * 构造函数。 * @param pipeline 渲染管线。 */ - constructor (pipeline: RenderPipeline) { - super(pipeline); + constructor () { + super(); } - /** - * @zh - * 初始化函数。 - * @param info 渲染流程描述信息。 - */ - public initialize (info: IRenderFlowInfo): boolean { - - if (info.name !== undefined) { - this._name = info.name; - } - - this._priority = info.priority; - - this.createStage(ForwardStage, { - name: 'ForwardStage', - priority: ForwardStagePriority.FORWARD, - }); - - return true; + public initialize(info: IRenderFlowInfo) { + super.initialize(info); + const forwardStage = new ForwardStage(); + forwardStage.initialize(ForwardStage.initInfo); + this._stages.push(forwardStage); } /** diff --git a/cocos/core/pipeline/forward/forward-pipeline.ts b/cocos/core/pipeline/forward/forward-pipeline.ts index 74ccdf2687..6cf3d17d4d 100644 --- a/cocos/core/pipeline/forward/forward-pipeline.ts +++ b/cocos/core/pipeline/forward/forward-pipeline.ts @@ -3,6 +3,7 @@ */ import { intersect, sphere } from '../../geom-utils'; +import { ccclass } from '../../data/class-decorator'; import { GFXBuffer } from '../../gfx/buffer'; import { GFXBindingType, GFXBufferUsageBit, GFXMemoryUsageBit } from '../../gfx/define'; import { GFXRenderPass } from '../../gfx/render-pass'; @@ -15,20 +16,12 @@ import { SpotLight } from '../../renderer/scene/spot-light'; import { Root } from '../../root'; import { cullDirectionalLight, cullSphereLight, cullSpotLight } from '../culling'; import { PIPELINE_FLOW_FORWARD, PIPELINE_FLOW_TONEMAP, RenderPassStage, UBOForwardLight } from '../define'; -import { ToneMapFlow } from '../ppfx/tonemap-flow'; -import { IRenderPipelineInfo, RenderPipeline } from '../render-pipeline'; +import { RenderPipeline, IRenderPipelineInfo, IRenderPipelineDesc } from '../render-pipeline'; import { RenderView } from '../render-view'; import { UIFlow } from '../ui/ui-flow'; import { ForwardFlow } from './forward-flow'; - -/** - * @zh - * 前向渲染流程优先级。 - */ -export enum ForwardFlowPriority { - FORWARD = 0, - UI = 10, -} +import { ToneMapFlow } from '../ppfx/tonemap-flow'; +import { ForwardFlowPriority } from './enum'; const _vec4Array = new Float32Array(4); const _sphere = sphere.create(0, 0, 0, 1); @@ -40,8 +33,12 @@ const _tempVec3 = new Vec3(); * @zh * 前向渲染管线。 */ +@ccclass('ForwardPipeline') export class ForwardPipeline extends RenderPipeline { + public static initInfo: IRenderPipelineInfo = { + }; + /** * @zh * 全部光源的UBO结构描述。 @@ -72,7 +69,7 @@ export class ForwardPipeline extends RenderPipeline { */ private _lightIndices: number[]; - public get lightsUBO (): GFXBuffer { + public get lightsUBO(): GFXBuffer { return this._lightsUBO!; } @@ -80,26 +77,45 @@ export class ForwardPipeline extends RenderPipeline { * 构造函数。 * @param root Root类实例。 */ - constructor (root: Root) { - super(root); + constructor() { + super(); this._validLights = []; this._lightIndexOffset = []; this._lightIndices = []; } - /** - * @zh - * 初始化函数。 - * @param info 渲染管线描述信息。 - */ - public initialize (info: IRenderPipelineInfo): boolean { + public initialize(info: IRenderPipelineInfo) { + super.initialize(info); + const forwardFlow = new ForwardFlow(); + forwardFlow.initialize(ForwardFlow.initInfo); + this._flows.push(forwardFlow); + } - if (!this._initialize(info)) { - return false; + public activate(root: Root) { + super.activate(root); + this.getFlow(PIPELINE_FLOW_FORWARD)!.activate(this); + + if (this._usePostProcess) { + if (this._useSMAA) { + /* + this.createFlow(SMAAEdgeFlow, { + name: PIPELINE_FLOW_SMAA, + priority: 0, + }); + */ + } + this.getFlow(PIPELINE_FLOW_TONEMAP)!.activate(this); } - this._name = 'ForwardPipeline'; + const uiFlow = new UIFlow(); + uiFlow.initialize(UIFlow.initInfo); + this._flows.push(uiFlow); + uiFlow.activate(this); + return true; + } + + protected createUBOs(): boolean { if (!this._globalBindings.get(UBOForwardLight.BLOCK.name)) { const lightsUBO = this._root.device.createBuffer({ usage: GFXBufferUsageBit.UNIFORM | GFXBufferUsageBit.TRANSFER_DST, @@ -117,55 +133,14 @@ export class ForwardPipeline extends RenderPipeline { buffer: lightsUBO, }); } - - const mainWindow = this._root.mainWindow; - let windowPass: GFXRenderPass | null = null; - - if (mainWindow) { - windowPass = mainWindow.renderPass; - } - - if (!windowPass) { - console.error('RenderPass of main window is null.'); - return false; - } - - this.addRenderPass(RenderPassStage.DEFAULT, windowPass); - - // create flows - this.createFlow(ForwardFlow, { - name: PIPELINE_FLOW_FORWARD, - priority: ForwardFlowPriority.FORWARD, - }); - - if (this._usePostProcess) { - if (this._useSMAA) { - /* - this.createFlow(SMAAEdgeFlow, { - name: PIPELINE_FLOW_SMAA, - priority: 0, - }); - */ - } - this.createFlow(ToneMapFlow, { - name: PIPELINE_FLOW_TONEMAP, - priority: 0, - }); - } - - this.createFlow(UIFlow, { - name: 'UIFlow', - priority: ForwardFlowPriority.UI, - }); - - return true; + return super.createUBOs(); } /** * @zh * 销毁函数。 */ - public destroy () { + public destroy() { const lightsUBO = this._globalBindings.get(UBOForwardLight.BLOCK.name); if (lightsUBO) { lightsUBO.buffer!.destroy(); @@ -179,10 +154,10 @@ export class ForwardPipeline extends RenderPipeline { * @zh * 重构函数。 */ - public rebuild () { + public rebuild() { super.rebuild(); - for (const flow of this._flows) { - flow.rebuild(); + for (let i = 0; i < this._flows.length; i++) { + this._flows[i].rebuild(); } } @@ -190,7 +165,7 @@ export class ForwardPipeline extends RenderPipeline { * @zh * 更新UBO。 */ - protected updateUBOs (view: RenderView) { + protected updateUBOs(view: RenderView) { super.updateUBOs(view); const exposure = view.camera.exposure; @@ -283,10 +258,11 @@ export class ForwardPipeline extends RenderPipeline { * 场景裁剪。 * @param view 渲染视图。 */ - protected sceneCulling (view: RenderView) { + protected sceneCulling(view: RenderView) { super.sceneCulling(view); this._validLights.splice(0); - for (const light of view.camera.scene.sphereLights) { + for (let i = 0; i < view.camera.scene.sphereLights.length; i++) { + const light = view.camera.scene.sphereLights[i]; if (light.enabled) { light.update(); sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range); @@ -295,7 +271,8 @@ export class ForwardPipeline extends RenderPipeline { } } } - for (const light of view.camera.scene.spotLights) { + for (let i = 0; i < view.camera.scene.spotLights.length; i++) { + const light = view.camera.scene.spotLights[i]; if (light.enabled) { light.update(); sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range); @@ -320,7 +297,7 @@ export class ForwardPipeline extends RenderPipeline { * 对每个模型裁剪光源。 * @param model 模型。 */ - private cullLightPerModel (model: Model) { + private cullLightPerModel(model: Model) { _tempLightIndex.splice(0); for (let i = 0; i < this._validLights.length; i++) { let isCulled = false; @@ -348,7 +325,7 @@ export class ForwardPipeline extends RenderPipeline { this._lightIndices.push(..._tempLightIndex); } - private sortLight (a, b) { + private sortLight(a, b) { return _tempLightDist[a] - _tempLightDist[b]; } } diff --git a/cocos/core/pipeline/forward/forward-stage.ts b/cocos/core/pipeline/forward/forward-stage.ts index 9e5d0822db..1218225922 100644 --- a/cocos/core/pipeline/forward/forward-stage.ts +++ b/cocos/core/pipeline/forward/forward-stage.ts @@ -2,16 +2,17 @@ * @category pipeline.forward */ +import { ccclass } from '../../data/class-decorator'; import { GFXCommandBuffer } from '../../gfx/command-buffer'; import { GFXClearFlag, GFXCommandBufferType, GFXFilter, IGFXColor } from '../../gfx/define'; import { Layers } from '../../scene-graph'; -import { getPhaseID } from '../pass-phase'; import { SRGBToLinear } from '../pipeline-funcs'; import { RenderBatchedQueue } from '../render-batched-queue'; -import { RenderFlow } from '../render-flow'; -import { opaqueCompareFn, RenderQueue, transparentCompareFn } from '../render-queue'; -import { IRenderStageInfo, RenderStage } from '../render-stage'; +import { RenderQueue } from '../render-queue'; +import { IRenderStageInfo, RenderStage, RenderQueueSortMode } from '../render-stage'; import { RenderView } from '../render-view'; +import { ForwardStagePriority } from './enum'; +import { RenderFlow } from '../render-flow'; const colors: IGFXColor[] = [ { r: 0, g: 0, b: 0, a: 1 } ]; const bufs: GFXCommandBuffer[] = []; @@ -20,51 +21,40 @@ const bufs: GFXCommandBuffer[] = []; * @zh * 前向渲染阶段。 */ +@ccclass('ForwardStage') export class ForwardStage extends RenderStage { - private _opaqueQueue: RenderQueue; - private _transparentQueue: RenderQueue; + public static initInfo: IRenderStageInfo = { + name: 'ForwardStage', + priority: ForwardStagePriority.FORWARD, + renderQueues: [ + { + isTransparent: false, + sortMode: RenderQueueSortMode.FRONT_TO_BACK, + stages: ['default'], + }, + { + isTransparent: true, + sortMode: RenderQueueSortMode.BACK_TO_FRONT, + stages: ['default', 'planarShadow'], + } + ] + }; + private _opaqueBatchedQueue: RenderBatchedQueue; /** * 构造函数。 * @param flow 渲染阶段。 */ - constructor (flow: RenderFlow) { - super(flow); - - this._opaqueQueue = new RenderQueue({ - isTransparent: false, - phases: getPhaseID('default'), - sortFunc: opaqueCompareFn, - }); - this._transparentQueue = new RenderQueue({ - isTransparent: true, - phases: getPhaseID('default') | getPhaseID('planarShadow'), - sortFunc: transparentCompareFn, - }); + constructor () { + super(); this._opaqueBatchedQueue = new RenderBatchedQueue(); } - /** - * @zh - * 初始化函数。 - * @param info 渲染阶段描述信息。 - */ - public initialize (info: IRenderStageInfo): boolean { - - if (info.name !== undefined) { - this._name = info.name; - } - - this._priority = info.priority; - - this._cmdBuff = this._device.createCommandBuffer({ - allocator: this._device.commandAllocator, - type: GFXCommandBufferType.PRIMARY, - }); - - return true; + public activate (flow: RenderFlow) { + super.activate(flow); + this._createCmdBuffer(); } /** @@ -102,8 +92,7 @@ export class ForwardStage extends RenderStage { public render (view: RenderView) { this._opaqueBatchedQueue.clear(); - this._opaqueQueue.clear(); - this._transparentQueue.clear(); + this._renderQueues.forEach(this.clearRenderQueue); const renderObjects = this._pipeline.renderObjects; for (let i = 0; i < renderObjects.length; ++i) { @@ -121,64 +110,32 @@ export class ForwardStage extends RenderStage { pass.batchedBuffer.merge(subModel, ro, pso); this._opaqueBatchedQueue.queue.add(pass.batchedBuffer); } else { - const hash = (0 << 30) | pass.priority << 16 | subModel.priority << 8 | p; - this._transparentQueue.queue.push({ - hash, - depth: ro.depth, - shaderId: pso.shader.id, - subModel, - cmdBuff: subModel.commandBuffers[p], - }); + this._renderQueues[1].insertRenderPass(ro, m, p); } } } } } else { - const subModels = ro.model.subModels; - for (let m = 0; m < subModels.length; ++m) { - const subModel = subModels[m]; - const passes = subModel.passes; - for (let p = 0; p < passes.length; ++p) { - const pass = subModel.passes[p]; - const pso = subModel.psos![p]; - const isTransparent = pso.blendState.targets[0].blend; - const hash = (0 << 30) | pass.priority << 16 | subModel.priority << 8 | p; - if (isTransparent) { - this._transparentQueue.queue.push({ - hash, - depth: ro.depth, - shaderId: pso.shader.id, - subModel, - cmdBuff: subModel.commandBuffers[p], - }); - } else { - this._opaqueQueue.queue.push({ - hash, - depth: ro.depth, - shaderId: pso.shader.id, - subModel, - cmdBuff: subModel.commandBuffers[p], - }); + for (let i = 0; i < ro.model.subModelNum; i++) { + for (let j = 0; j < ro.model.getSubModel(i).passes.length; j++) { + for (let k = 0; k < this._renderQueues.length; k++) { + this._renderQueues[k].insertRenderPass(ro, i, j); } - // this._opaqueQueue.insertRenderPass(ro, m, j); - // this._transparentQueue.insertRenderPass(ro, m, j); } } } } - - this._opaqueQueue.sort(); - this._transparentQueue.sort(); + this._renderQueues.forEach(this.sortRenderQueue); const camera = view.camera; const cmdBuff = this._cmdBuff!; const vp = camera.viewport; - this._renderArea.x = vp.x * camera.width; - this._renderArea.y = vp.y * camera.height; - this._renderArea.width = vp.width * camera.width * this.pipeline.shadingScale; - this._renderArea.height = vp.height * camera.height * this.pipeline.shadingScale; + this._renderArea!.x = vp.x * camera.width; + this._renderArea!.y = vp.y * camera.height; + this._renderArea!.width = vp.width * camera.width * this.pipeline!.shadingScale; + this._renderArea!.height = vp.height * camera.height * this.pipeline!.shadingScale; if (camera.clearFlag & GFXClearFlag.COLOR) { if (this._pipeline.isHDR) { @@ -196,9 +153,9 @@ export class ForwardStage extends RenderStage { if (this._pipeline.usePostProcess) { if (!this._pipeline.useMSAA) { - this._framebuffer = this._pipeline.curShadingFBO; + this._framebuffer = this._pipeline.getFrameBuffer(this._pipeline!.currShading)!; } else { - this._framebuffer = this._pipeline.msaaShadingFBO; + this._framebuffer = this._pipeline.getFrameBuffer('msaa')!; } } else { this._framebuffer = view.window!.framebuffer; @@ -207,31 +164,46 @@ export class ForwardStage extends RenderStage { const planarShadow = camera.scene.planarShadows; cmdBuff.begin(); - cmdBuff.beginRenderPass(this._framebuffer!, this._renderArea, + cmdBuff.beginRenderPass(this._framebuffer!, this._renderArea!, camera.clearFlag, colors, camera.clearDepth, camera.clearStencil); - cmdBuff.execute(this._opaqueQueue.cmdBuffs.array, this._opaqueQueue.cmdBuffCount); + cmdBuff.execute(this._renderQueues[0].cmdBuffs.array, this._renderQueues[0].cmdBuffCount); this._opaqueBatchedQueue.recordCommandBuffer(cmdBuff); if (camera.visibility & Layers.BitMask.DEFAULT) { cmdBuff.execute(planarShadow.cmdBuffs.array, planarShadow.cmdBuffCount); } - cmdBuff.execute(this._transparentQueue.cmdBuffs.array, this._transparentQueue.cmdBuffCount); + cmdBuff.execute(this._renderQueues[1].cmdBuffs.array, this._renderQueues[1].cmdBuffCount); cmdBuff.endRenderPass(); cmdBuff.end(); bufs[0] = cmdBuff; - this._device.queue.submit(bufs); + this._device!.queue.submit(bufs); if (this._pipeline.useMSAA) { - this._device.blitFramebuffer( - this._framebuffer, - this._pipeline.curShadingFBO, - this._renderArea, - this._renderArea, + this._device!.blitFramebuffer( + this._framebuffer!, + this._pipeline.getFrameBuffer(this._pipeline.currShading)!, + this._renderArea!, + this._renderArea!, GFXFilter.POINT); } } + + private _createCmdBuffer () { + this._cmdBuff = this._device!.createCommandBuffer({ + allocator: this._device!.commandAllocator, + type: GFXCommandBufferType.PRIMARY, + }); + } + + private clearRenderQueue (rq: RenderQueue) { + rq.clear(); + } + + private sortRenderQueue (rq: RenderQueue) { + rq.sort(); + } } diff --git a/cocos/core/pipeline/index.ts b/cocos/core/pipeline/index.ts index 97fda13592..c11f682022 100644 --- a/cocos/core/pipeline/index.ts +++ b/cocos/core/pipeline/index.ts @@ -5,4 +5,14 @@ import { RenderPassStage } from './define'; import './render-view'; +export { RenderPipeline } from './render-pipeline'; +export { RenderFlow } from './render-flow'; +export { RenderStage } from './render-stage'; + +export { ForwardPipeline } from './forward/forward-pipeline'; +export { ForwardFlow } from './forward/forward-flow'; +export { ForwardStage } from './forward/forward-stage'; +export { ToneMapFlow } from './ppfx/tonemap-flow'; +export { ToneMapStage } from './ppfx/tonemap-stage'; + cc.RenderPassStage = RenderPassStage; export { RenderPassStage }; diff --git a/cocos/core/pipeline/pipeline-serialization.ts b/cocos/core/pipeline/pipeline-serialization.ts new file mode 100644 index 0000000000..f4bc218377 --- /dev/null +++ b/cocos/core/pipeline/pipeline-serialization.ts @@ -0,0 +1,125 @@ + +import { ccclass, property } from '../data/class-decorator'; +import { ccenum } from '../value-types/enum'; +import { GFXFormat, GFXLoadOp, GFXStoreOp, GFXTextureLayout, GFXTextureType, GFXTextureUsageBit, GFXTextureViewType} from '../gfx/define'; + +ccenum(GFXTextureType); +ccenum(GFXTextureViewType); +ccenum(GFXTextureUsageBit); +ccenum(GFXStoreOp); +ccenum(GFXLoadOp); +ccenum(GFXTextureLayout); + +@ccclass('RenderTextureDesc') +export class RenderTextureDesc { + @property + public name: string = ''; + @property({ + type: GFXTextureType, + }) + public type: GFXTextureType = GFXTextureType.TEX2D; + @property({ + type: GFXTextureViewType, + }) + public viewType: GFXTextureViewType = GFXTextureViewType.TV2D; + @property({ + type: GFXTextureUsageBit, + }) + public usage: GFXTextureUsageBit = GFXTextureUsageBit.COLOR_ATTACHMENT; + @property({ + type: GFXFormat, + }) + public format: GFXFormat = GFXFormat.UNKNOWN; + @property + public width: number = -1; + @property + public height: number = -1; +} + +@ccclass('FrameBufferDesc') +export class FrameBufferDesc { + @property + public name: string = ''; + @property + public renderPass: number = 0; + @property({ + type: [String], + }) + public colorViews = []; + @property + public depthStencilView: string = ''; +} + +@ccclass('ColorDesc') +export class ColorDesc { + @property({ + type: GFXFormat, + }) + public format: GFXFormat = GFXFormat.UNKNOWN; + @property({ + type: GFXLoadOp, + }) + public loadOp: GFXLoadOp = GFXLoadOp.CLEAR; + @property({ + type: GFXStoreOp, + }) + public storeOp: GFXStoreOp = GFXStoreOp.STORE; + @property + public sampleCount: number = 1; + @property({ + type: GFXTextureLayout, + }) + public beginLayout: GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL; + @property({ + type: GFXTextureLayout, + }) + public endLayout: GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL; +} + +@ccclass('DepthStencilDesc') +export class DepthStencilDesc { + @property({ + type: GFXFormat, + }) + public format: GFXFormat = GFXFormat.UNKNOWN; + @property({ + type: GFXLoadOp, + }) + public depthLoadOp: GFXLoadOp = GFXLoadOp.CLEAR; + @property({ + type: GFXStoreOp, + }) + public depthStoreOp: GFXStoreOp = GFXStoreOp.STORE; + @property({ + type: GFXLoadOp, + }) + public stencilLoadOp: GFXLoadOp = GFXLoadOp.CLEAR; + @property({ + type: GFXStoreOp, + }) + public stencilStoreOp: GFXStoreOp = GFXStoreOp.STORE; + @property + public sampleCount: number = 1; + @property({ + type: GFXTextureLayout, + }) + public beginLayout: GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL; + @property({ + type: GFXTextureLayout, + }) + public endLayout: GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL; +} + +@ccclass('RenderPassDesc') +export class RenderPassDesc { + @property + public index: number = -1; + @property({ + type: [ColorDesc], + }) + public colorAttachments = []; + @property({ + type: DepthStencilDesc, + }) + public depthStencilAttachment: DepthStencilDesc = new DepthStencilDesc(); +} diff --git a/cocos/core/pipeline/ppfx/tonemap-flow.ts b/cocos/core/pipeline/ppfx/tonemap-flow.ts index 808fd36334..313f4e52c9 100644 --- a/cocos/core/pipeline/ppfx/tonemap-flow.ts +++ b/cocos/core/pipeline/ppfx/tonemap-flow.ts @@ -2,41 +2,39 @@ * @category pipeline.ppfx */ +import { ccclass } from '../../data/class-decorator'; import { IRenderFlowInfo, RenderFlow } from '../render-flow'; -import { RenderPipeline } from '../render-pipeline'; import { ToneMapStage } from './tonemap-stage'; +import { PIPELINE_FLOW_TONEMAP } from '../define'; +import { ForwardFlowPriority } from '../forward/enum'; /** * @zh * 色调映射渲染流程。 */ +@ccclass('ToneMapFlow') export class ToneMapFlow extends RenderFlow { - constructor (pipeline: RenderPipeline) { - super(pipeline); + public static initInfo: IRenderFlowInfo = { + name: PIPELINE_FLOW_TONEMAP, + priority: ForwardFlowPriority.FORWARD + 1, + }; + + constructor () { + super(); } public initialize (info: IRenderFlowInfo): boolean { - - if (info.name !== undefined) { - this._name = info.name; - } - - this._priority = info.priority; + super.initialize(info); const material = this._material; - material.initialize({ - effectName: 'pipeline/tonemap', - defines: { CC_USE_SMAA: this._pipeline.useSMAA }, + material!.recompileShaders({ + CC_USE_SMAA: this._pipeline!.useSMAA }); - const framebuffer = this._pipeline.root.mainWindow!.framebuffer!; - - this.createStage(ToneMapStage, { - name: 'ToneMapStage', - priority: 0, - framebuffer, - }); + const toneStage = new ToneMapStage(); + toneStage.initialize(ToneMapStage.initInfo); + this._stages.push(toneStage); return true; } @@ -50,10 +48,8 @@ export class ToneMapFlow extends RenderFlow { public rebuild () { if (this._material) { - this._material.destroy(); - this._material.initialize({ - effectName: 'pipeline/tonemap', - defines: { CC_USE_SMAA: this._pipeline.useSMAA }, + this._material.recompileShaders({ + CC_USE_SMAA: this._pipeline!.useSMAA }); } diff --git a/cocos/core/pipeline/ppfx/tonemap-stage.ts b/cocos/core/pipeline/ppfx/tonemap-stage.ts index fa41ab09dd..cb28c895ba 100644 --- a/cocos/core/pipeline/ppfx/tonemap-stage.ts +++ b/cocos/core/pipeline/ppfx/tonemap-stage.ts @@ -2,13 +2,14 @@ * @category pipeline.ppfx */ +import { ccclass } from '../../data/class-decorator'; import { GFXBindingLayout } from '../../gfx/binding-layout'; import { GFXCommandBuffer } from '../../gfx/command-buffer'; import { GFXClearFlag, GFXCommandBufferType, IGFXColor } from '../../gfx/define'; import { UBOGlobal } from '../define'; -import { RenderFlow } from '../render-flow'; import { IRenderStageInfo, RenderStage } from '../render-stage'; import { RenderView } from '../render-view'; +import { RenderFlow } from '../render-flow'; const colors: IGFXColor[] = [ { r: 0, g: 0, b: 0, a: 1 } ]; const bufs: GFXCommandBuffer[] = []; @@ -18,36 +19,37 @@ const bufs: GFXCommandBuffer[] = []; * 色调映射渲染阶段。 * */ +@ccclass('ToneMapStage') export class ToneMapStage extends RenderStage { + public static initInfo: IRenderStageInfo = { + name: 'ToneMapStage', + priority: 0, + framebuffer: 'window' + } + private _hTexSampler: number = 0; private _hBlendTexSampler: number = 0; private _bindingLayout: GFXBindingLayout | null = null; - constructor (flow: RenderFlow) { - super(flow); + constructor () { + super(); } - public initialize (info: IRenderStageInfo): boolean { + public activate (flow: RenderFlow) { - if (info.name !== undefined) { - this._name = info.name; - } + super.activate(flow); - this._priority = info.priority; - - if (info.framebuffer !== undefined) { - this._framebuffer = info.framebuffer ; - } - - this._cmdBuff = this._device.createCommandBuffer({ - allocator: this._device.commandAllocator, - type: GFXCommandBufferType.PRIMARY, - }); + this._createCmdBuffer(); this.rebuild(); + } - return true; + private _createCmdBuffer () { + this._cmdBuff = this._device!.createCommandBuffer({ + allocator: this._device!.commandAllocator, + type: GFXCommandBufferType.PRIMARY, + }); } public destroy () { @@ -61,20 +63,20 @@ export class ToneMapStage extends RenderStage { } public rebuild () { - this._pass = this._flow.material.passes[0]; + this._pass = this._flow!.material!.passes[0]; this._hTexSampler = this._pass.getBinding('u_texSampler')!; - const globalUBO = this._pipeline.globalBindings.get(UBOGlobal.BLOCK.name); + const globalUBO = this._pipeline!.globalBindings.get(UBOGlobal.BLOCK.name); this._pso = this._pass.createPipelineState(); this._bindingLayout = this._pso!.pipelineLayout.layouts[0]; this._pass.bindBuffer(UBOGlobal.BLOCK.binding, globalUBO!.buffer!); - this._pass.bindTextureView(this._hTexSampler, this._pipeline.curShadingTexView); + this._pass.bindTextureView(this._hTexSampler, this._pipeline!.getTextureView(this._pipeline!.currShading)!); - if (this._pipeline.useSMAA) { + if (this._pipeline!.useSMAA) { this._hBlendTexSampler = this._pass.getBinding('u_blendTexSampler')!; - this._pass.bindTextureView(this._hBlendTexSampler, this._pipeline.smaaBlendTexView); + this._pass.bindTextureView(this._hBlendTexSampler, this._pipeline!.getTextureView('smaaBlend')!); } this._pass.update(); @@ -87,23 +89,23 @@ export class ToneMapStage extends RenderStage { if (this._cmdBuff) { - this._renderArea.width = camera.width; - this._renderArea.height = camera.height; + this._renderArea!.width = camera.width; + this._renderArea!.height = camera.height; const framebuffer = view.window!.framebuffer; this._cmdBuff.begin(); - this._cmdBuff.beginRenderPass(framebuffer, this._renderArea, - GFXClearFlag.ALL, colors, 1.0, 0); + this._cmdBuff.beginRenderPass(framebuffer, this._renderArea!, + GFXClearFlag.ALL, [{ r: 0.0, g: 0.0, b: 0.0, a: 1.0 }], 1.0, 0); this._cmdBuff.bindPipelineState(this._pso!); this._cmdBuff.bindBindingLayout(this._pso!.pipelineLayout.layouts[0]); - this._cmdBuff.bindInputAssembler(this._pipeline.quadIA); - this._cmdBuff.draw(this._pipeline.quadIA); + this._cmdBuff.bindInputAssembler(this._pipeline!.quadIA); + this._cmdBuff.draw(this._pipeline!.quadIA); this._cmdBuff.endRenderPass(); this._cmdBuff.end(); } bufs[0] = this._cmdBuff!; - this._device.queue.submit(bufs); + this._device!.queue.submit(bufs); // this._pipeline.swapFBOs(); } diff --git a/cocos/core/pipeline/render-flow.ts b/cocos/core/pipeline/render-flow.ts index 4cbe1cf5d2..45ab57ba20 100644 --- a/cocos/core/pipeline/render-flow.ts +++ b/cocos/core/pipeline/render-flow.ts @@ -3,9 +3,10 @@ */ import { Material } from '../assets/material'; +import { ccclass, property } from '../data/class-decorator'; import { GFXDevice } from '../gfx/device'; import { RenderPipeline } from './render-pipeline'; -import { IRenderStageInfo, RenderStage } from './render-stage'; +import { RenderStage } from './render-stage'; import { RenderView } from './render-view'; /** @@ -15,35 +16,37 @@ import { RenderView } from './render-view'; export interface IRenderFlowInfo { name?: string; priority: number; + material?: Material; } /** * @zh * 渲染流程。 */ +@ccclass('RenderFlow') export abstract class RenderFlow { - public get device (): GFXDevice { - return this._device; + public get device(): GFXDevice { + return this._device!; } - public get pipeline (): RenderPipeline { + public get pipeline(): RenderPipeline { return this._pipeline; } - public get name (): string { + public get name(): string { return this._name; } - public get priority (): number { + public get priority(): number { return this._priority; } - public get stages (): RenderStage[] { + public get stages(): RenderStage[] { return this._stages!; } - public get material (): Material { + public get material(): Material | null { return this._material; } @@ -51,45 +54,61 @@ export abstract class RenderFlow { * @zh * GFX设备。 */ - protected _device: GFXDevice; + protected _device: GFXDevice | null = null; /** * @zh * 渲染管线。 */ - protected _pipeline: RenderPipeline; + protected _pipeline: RenderPipeline = null!; /** * @zh * 名称。 */ + @property({ + displayOrder: 0, + visible: true + }) protected _name: string = ''; /** * @zh * 优先级。 */ + @property({ + displayOrder: 1, + visible: true + }) protected _priority: number = 0; - /** - * @zh - * 渲染阶段数组。 - */ - protected _stages: RenderStage[] = []; - /** * @zh * 材质。 */ - protected _material: Material = new Material(); + @property({ + type: cc.Material, + displayOrder: 2, + visible: true + }) + protected _material: Material | null = null; + + /** + * @zh + * 渲染阶段数组。 + */ + @property({ + type: [RenderStage], + displayOrder: 3, + visible: true + }) + protected _stages: RenderStage[] = []; /** * 构造函数。 * @param pipeline 渲染管线。 */ - constructor (pipeline: RenderPipeline) { - this._device = pipeline.device; - this._pipeline = pipeline; + constructor() { } /** @@ -97,19 +116,47 @@ export abstract class RenderFlow { * 初始化函数。 * @param info 渲染流程描述信息。 */ - public abstract initialize (info: IRenderFlowInfo): boolean; + public initialize(info: IRenderFlowInfo) { + if (info.name !== undefined) { + this._name = info.name; + } + + this._priority = info.priority; + + if (info.material) + this._material = info.material; + } + + /** + * 把序列化数据转换成运行时数据 + */ + public activate(pipeline: RenderPipeline) { + this._device = pipeline.device; + this._pipeline = pipeline; + (pipeline as any).activateFlow(this); + this._activateStages(); + } + + protected _activateStages() { + for (let i = 0; i < this._stages.length; i++) { + this._stages[i].activate(this); + } + this._stages.sort((a, b) => { + return a.priority - b.priority; + }) + } /** * @zh * 销毁函数。 */ - public abstract destroy (); + public abstract destroy(); /** * @zh * 重构函数。 */ - public abstract rebuild (); + public abstract rebuild(); /** * @zh @@ -117,9 +164,9 @@ export abstract class RenderFlow { * @param width 屏幕宽度。 * @param height 屏幕高度。 */ - public resize (width: number, height: number) { - for (const stage of this._stages) { - stage.resize(width, height); + public resize(width: number, height: number) { + for (let i = 0; i < this._stages.length; i++) { + this._stages[i].resize(width, height); } } @@ -128,32 +175,9 @@ export abstract class RenderFlow { * 渲染函数。 * @param view 渲染视图。 */ - public render (view: RenderView) { - for (const stage of this._stages) { - stage.render(view); - } - } - - /** - * @zh - * 创建渲染阶段。 - * @param clazz 渲染阶段类。 - * @param info 渲染阶段描述信息。 - */ - public createStage ( - clazz: new(flow: RenderFlow) => T, - info: IRenderStageInfo): RenderStage | null { - - const stage: RenderStage = new clazz(this); - if (stage.initialize(info)) { - this._stages.push(stage); - this._stages.sort((a, b) => { - return a.priority - b.priority; - }); - - return stage; - } else { - return null; + public render(view: RenderView) { + for (let i = 0; i < this._stages.length; i++) { + this._stages[i].render(view); } } @@ -161,10 +185,12 @@ export abstract class RenderFlow { * @zh * 销毁全部渲染阶段。 */ - public destroyStages () { - for (const stage of this._stages) { - stage.destroy(); + public destroyStages() { + for (let i = 0; i < this._stages.length; i++) { + this._stages[i].destroy(); } this._stages = []; } } + +cc.RenderFlow = RenderFlow; diff --git a/cocos/core/pipeline/render-pipeline.ts b/cocos/core/pipeline/render-pipeline.ts index 100ff1aa2a..e0c04fe5e1 100644 --- a/cocos/core/pipeline/render-pipeline.ts +++ b/cocos/core/pipeline/render-pipeline.ts @@ -3,9 +3,15 @@ */ import { intersect } from '../geom-utils'; +import { ccclass, property } from '../data/class-decorator'; import { GFXBuffer } from '../gfx/buffer'; -import { GFXBindingType, GFXBufferUsageBit, GFXFormat, GFXFormatInfos, GFXLoadOp, GFXMemoryUsageBit, - GFXStoreOp, GFXTextureLayout, GFXTextureType, GFXTextureUsageBit, GFXTextureViewType } from '../gfx/define'; +import { + GFXBindingType, + GFXBufferUsageBit, + GFXFormat, + GFXFormatInfos, + GFXMemoryUsageBit, + GFXTextureUsageBit } from '../gfx/define'; import { GFXDevice, GFXFeature } from '../gfx/device'; import { GFXFramebuffer } from '../gfx/framebuffer'; import { GFXInputAssembler, IGFXAttribute } from '../gfx/input-assembler'; @@ -19,10 +25,12 @@ import { programLib } from '../renderer/core/program-lib'; import { SKYBOX_FLAG } from '../renderer/scene/camera'; import { Root } from '../root'; import { Layers } from '../scene-graph'; -import { IRenderObject, UBOGlobal, UBOShadow, UNIFORM_ENVIRONMENT } from './define'; +import { IRenderObject, UBOGlobal, UBOShadow, UNIFORM_ENVIRONMENT, RenderPassStage } from './define'; import { IInternalBindingInst } from './define'; +import { FrameBufferDesc, RenderPassDesc, RenderTextureDesc } from './pipeline-serialization'; import { IRenderFlowInfo, RenderFlow } from './render-flow'; import { RenderView } from './render-view'; +import { Asset } from '../assets'; const _vec4Array = new Float32Array(4); const _v3tmp = new Vec3(); @@ -38,12 +46,20 @@ export interface IRenderPipelineInfo { enableMSAA?: boolean; enableSMAA?: boolean; enableIBL?: boolean; + renderTextures?: RenderTextureDesc[]; + framebuffers?: FrameBufferDesc[]; + renderPasses?: RenderPassDesc[]; +} + +export interface IRenderPipelineDesc { + root: Root; } /** * @zh * 渲染流程。 */ +@ccclass('RenderPipeline') export abstract class RenderPipeline { /** @@ -67,7 +83,7 @@ export abstract class RenderPipeline { * 名称。 */ public get name (): string { - return this._name; + return this.constructor.name; } /** @@ -86,6 +102,10 @@ export abstract class RenderPipeline { return this._flows; } + public get activeFlows (): RenderFlow[] { + return this._activeFlows; + } + /** * @zh * 启用后期处理。 @@ -130,54 +150,6 @@ export abstract class RenderPipeline { return this._lightMeterScale; } - /** - * @zh - * 深度模板纹理视图。 - */ - public get depthStencilTexView (): GFXTextureView { - return this._depthStencilTexView!; - } - - /** - * @zh - * 着色纹理视图数组的当前帧缓冲索引。 - */ - public get curShadingTexView (): GFXTextureView { - return this._shadingTexViews[this._curIdx]; - } - - /** - * @zh - * 着色纹理视图数组的上一帧缓冲索引。 - */ - public get prevShadingTexView (): GFXTextureView { - return this._shadingTexViews[this._prevIdx]; - } - - /** - * @zh - * 着色帧缓冲数组的当前帧缓冲索引。 - */ - public get curShadingFBO (): GFXFramebuffer { - return this._shadingFBOs[this._curIdx]; - } - - /** - * @zh - * 着色帧缓冲数组的上一帧缓冲索引。 - */ - public get prevShadingFBO (): GFXFramebuffer { - return this._shadingFBOs[this._prevIdx]; - } - - /** - * @zh - * MSAA着色帧缓冲。 - */ - public get msaaShadingFBO (): GFXFramebuffer { - return this._msaaShadingFBO!; - } - /** * @zh * 启用MSAA。 @@ -194,38 +166,6 @@ export abstract class RenderPipeline { return this._useSMAA; } - /** - * @zh - * SMAA边缘纹理视图。 - */ - public get smaaEdgeTexView (): GFXTextureView { - return this._smaaEdgeTexView!; - } - - /** - * @zh - * SMAA边缘帧缓冲。 - */ - public get smaaEdgeFBO (): GFXFramebuffer { - return this._smaaEdgeFBO!; - } - - /** - * @zh - * SMAA混合纹理视图。 - */ - public get smaaBlendTexView (): GFXTextureView { - return this._smaaBlendTexView!; - } - - /** - * @zh - * SMAA混合帧缓冲。 - */ - public get smaaBlendFBO (): GFXFramebuffer { - return this._smaaBlendFBO!; - } - /** * @zh * 四边形输入汇集器。 @@ -282,6 +222,14 @@ export abstract class RenderPipeline { return this._uboGlobal!.view; } + get currShading () { + return this._curIdx; + } + + get prevShading () { + return this._prevIdx; + } + /** * @zh * 启用动态合批。 @@ -290,44 +238,32 @@ export abstract class RenderPipeline { return this._useDynamicBatching; } - protected _root: Root; - protected _device: GFXDevice; - protected _name: string = 'BasePipeline'; + protected _root: Root = null!; + protected _device: GFXDevice = null!; protected _renderObjects: IRenderObject[] = []; - protected _renderPasses: Map = new Map(); + + @property({ + type: [RenderFlow], + visible: true + }) protected _flows: RenderFlow[] = []; + + protected _activeFlows: RenderFlow[] = []; + protected _isHDRSupported: boolean = false; protected _isHDR: boolean = false; protected _lightMeterScale: number = 10000.0; - protected _shadingPass: GFXRenderPass | null = null; protected _fboCount: number = 0; - protected _msaaShadingTex: GFXTexture | null = null; - protected _msaaShadingTexView: GFXTextureView | null = null; - protected _msaaDepthStencilTex: GFXTexture | null = null; - protected _msaaDepthStencilTexView: GFXTextureView | null = null; - protected _msaaShadingFBO: GFXFramebuffer | null = null; protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN; protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN; - protected _shadingTextures: GFXTexture[] = []; - protected _shadingTexViews: GFXTextureView[] = []; - protected _depthStencilTex: GFXTexture | null = null; - protected _depthStencilTexView: GFXTextureView | null = null; - protected _shadingFBOs: GFXFramebuffer[] = []; protected _shadingWidth: number = 0.0; protected _shadingHeight: number = 0.0; protected _shadingScale: number = 1.0; - protected _curIdx: number = 0; - protected _prevIdx: number = 1; + protected _curIdx: string = 'shading'; + protected _prevIdx: string = 'shading1'; protected _usePostProcess: boolean = false; protected _useMSAA: boolean = false; protected _useSMAA: boolean = false; - protected _smaaPass: GFXRenderPass | null = null; - protected _smaaEdgeFBO: GFXFramebuffer | null = null; - protected _smaaEdgeTex: GFXTexture | null = null; - protected _smaaEdgeTexView: GFXTextureView | null = null; - protected _smaaBlendFBO: GFXFramebuffer | null = null; - protected _smaaBlendTex: GFXTexture | null = null; - protected _smaaBlendTexView: GFXTextureView | null = null; protected _quadVB: GFXBuffer | null = null; protected _quadIB: GFXBuffer | null = null; protected _quadIA: GFXInputAssembler | null = null; @@ -340,21 +276,93 @@ export abstract class RenderPipeline { protected _macros: IDefineMap = {}; protected _useDynamicBatching = false; + @property({ + type: [RenderTextureDesc], + }) + protected renderTextures: RenderTextureDesc[] = []; + @property({ + type: [FrameBufferDesc], + }) + protected framebuffers: FrameBufferDesc[] = []; + @property({ + type: [RenderPassDesc], + }) + protected renderPasses: RenderPassDesc[] = []; + protected _renderTextures: Map = new Map(); + protected _textureViews: Map = new Map(); + protected _frameBuffers: Map = new Map(); + protected _renderPasses: Map = new Map(); + /** * 构造函数。 * @param root Root类实例。 */ - constructor (root: Root) { - this._root = root; - this._device = root.device; + constructor () { + } + + public getTextureView (name: string) { + return this._textureViews.get(name); + } + + public getRenderTexture (name: string) { + return this._renderTextures.get(name); + } + + public getFrameBuffer (name: string) { + return this._frameBuffers.get(name); } /** * @zh - * 初始化函数。 + * 初始化函数,用于不从资源加载RenderPipeline的情况。 * @param info 渲染管线描述信息。 */ - public abstract initialize (info: IRenderPipelineInfo): boolean; + public initialize (info: IRenderPipelineInfo) { + + if (info.enablePostProcess !== undefined) { + this._usePostProcess = info.enablePostProcess; + } else { + // We disable post process now, post process will be enabled in furture. + this._usePostProcess = false; + } + + this._isHDR = (info.enableHDR !== undefined ? info.enableHDR : false); + + // Config Anti-Aliasing + this._useSMAA = info.enableSMAA !== undefined ? info.enableSMAA : false; + this._useMSAA = info.enableMSAA !== undefined ? info.enableMSAA : false; + + if (info.renderTextures) + this.renderTextures = info.renderTextures; + if (info.framebuffers) + this.framebuffers = info.framebuffers; + if (info.renderPasses) + this.renderPasses = info.renderPasses; + } + + /** + * 当RenderPipeline资源加载完成后,启用相应的flow + * @param desc + */ + public activate (root: Root) { + this._root = root; + this._device = root.device; + + if (!this._initRenderResource()) { + console.error('RenderPipeline:' + this.name + ' startup failed!'); + } + } + + /** + * 激活一个RenderFlow,将其添加到可执行的RenderFlow数组中 + * @param flow 运行时会执行的RenderFlow + */ + private activateFlow (flow: RenderFlow) { + this._activeFlows.push(flow); + this._activeFlows.sort((a: RenderFlow, b: RenderFlow) => { + return a.priority - b.priority; + }); + } /** * @zh @@ -375,8 +383,8 @@ export abstract class RenderPipeline { this.updateUBOs(view); - for (const flow of view.flows) { - flow.render(view); + for (let i = 0; i < view.flows.length; i++) { + view.flows[i].render(view); } } @@ -405,8 +413,8 @@ export abstract class RenderPipeline { this.resizeFBOs(w, h); } - for (const flow of this._flows) { - flow.resize(width, height); + for (let i = 0; i < this._flows.length; i++) { + this._flows[i].resize(width, height); } } @@ -463,33 +471,13 @@ export abstract class RenderPipeline { this._renderPasses.clear(); } - /** - * @zh - * 创建渲染流程。 - */ - public createFlow ( - clazz: new (pipeline: RenderPipeline) => T, - info: IRenderFlowInfo): RenderFlow | null { - const flow: RenderFlow = new clazz(this); - if (flow.initialize(info)) { - this._flows.push(flow); - this._flows.sort((a: RenderFlow, b: RenderFlow) => { - return a.priority - b.priority; - }); - - return flow; - } else { - return null; - } - } - /** * @zh * 销毁全部渲染流程。 */ public destroyFlows () { - for (const flow of this._flows) { - flow.destroy(); + for (let i = 0; i < this._flows.length; i++) { + this._flows[i].destroy(); } this._flows = []; } @@ -500,9 +488,9 @@ export abstract class RenderPipeline { * @param name 名称。 */ public getFlow (name: string): RenderFlow | null { - for (const flow of this._flows) { - if (flow.name === name) { - return flow; + for (let i = 0; i < this._flows.length; i++) { + if (this._flows[i].name === name) { + return this._flows[i]; } } @@ -516,24 +504,12 @@ export abstract class RenderPipeline { public updateMacros () { programLib.destroyShaderByDefines(this._macros); this._macros.CC_USE_HDR = (this._isHDR); - for (const scene of this._root.scenes) { - scene.onPipelineChange(); + for (let i = 0; i < this._root.scenes.length; i++) { + this._root.scenes[i].onPipelineChange(); } } - /** - * @zh - * 内部初始化函数。 - * @param info 渲染流程描述信息。 - */ - protected _initialize (info: IRenderPipelineInfo): boolean { - - if (info.enablePostProcess !== undefined) { - this._usePostProcess = info.enablePostProcess; - } else { - // We disable post process now, post process will be enabled in furture. - this._usePostProcess = false; - } + protected _initRenderResource () { if (this._usePostProcess) { if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F) || @@ -544,15 +520,7 @@ export abstract class RenderPipeline { // this._isHDRSupported = false; this._fboCount = 1; - this._shadingTextures = new Array(this._fboCount); - this._shadingTexViews = new Array(this._fboCount); - this._shadingFBOs = new Array(this._fboCount); - this._isHDR = (info.enableHDR !== undefined ? info.enableHDR : true); - - // Config Anti-Aliasing - this._useSMAA = info.enableSMAA !== undefined ? info.enableSMAA : false; - this._useMSAA = info.enableMSAA !== undefined ? info.enableMSAA : false; if (this._useMSAA) { this._useMSAA = this.device.hasFeature(GFXFeature.MSAA); } @@ -569,8 +537,8 @@ export abstract class RenderPipeline { this._colorFmt = GFXFormat.RGBA16F; this._isHDR = true; } - } else if (this._device.hasFeature(GFXFeature.COLOR_FLOAT) && - this._device.hasFeature(GFXFeature.TEXTURE_FLOAT_LINEAR)) { + } else if (this._device!.hasFeature(GFXFeature.COLOR_FLOAT) && + this._device!.hasFeature(GFXFeature.TEXTURE_FLOAT_LINEAR)) { if (this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) { this._colorFmt = GFXFormat.RGBA32F; this._isHDR = true; @@ -586,9 +554,9 @@ export abstract class RenderPipeline { if (this._device.depthBits === 24) { if (this._device.stencilBits === 8) { - this._depthStencilFmt = GFXFormat.D24S8; + this._depthStencilFmt = GFXFormat.D24S8; } else { - this._depthStencilFmt = GFXFormat.D24; + this._depthStencilFmt = GFXFormat.D24; } } else { this._depthStencilFmt = GFXFormat.D16; @@ -614,151 +582,38 @@ export abstract class RenderPipeline { console.info('SHADING_COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name); console.info('SHADING_DEPTH_FORMAT: ' + GFXFormatInfos[this._depthStencilFmt].name); - this._shadingPass = this._device.createRenderPass({ - colorAttachments: [{ - format: this._colorFmt, - loadOp: GFXLoadOp.CLEAR, - storeOp: GFXStoreOp.STORE, - sampleCount: 1, - beginLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL, - endLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL, - }], - depthStencilAttachment: { - format : this._depthStencilFmt, - depthLoadOp : GFXLoadOp.CLEAR, - depthStoreOp : GFXStoreOp.STORE, - stencilLoadOp : GFXLoadOp.CLEAR, - stencilStoreOp : GFXStoreOp.STORE, - sampleCount : 1, - beginLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - endLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - }, - }); - - if (this._useMSAA) { - this._msaaShadingTex = this._device.createTexture({ - type: GFXTextureType.TEX2D, - usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED, - format: this._colorFmt, - width: this._shadingWidth, - height: this._shadingHeight, - }); - this._msaaShadingTexView = this._device.createTextureView({ - texture : this._msaaShadingTex, - type : GFXTextureViewType.TV2D, - format : this._colorFmt, - }); - this._msaaDepthStencilTex = this._device.createTexture({ - type : GFXTextureType.TEX2D, - usage : GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT | GFXTextureUsageBit.SAMPLED, - format : this._depthStencilFmt, - width : this._shadingWidth, - height : this._shadingHeight, - }); - this._msaaDepthStencilTexView = this._device.createTextureView({ - texture : this._msaaDepthStencilTex, - type : GFXTextureViewType.TV2D, - format : this._depthStencilFmt, - }); - this._msaaShadingFBO = this._device.createFramebuffer({ - renderPass: this._shadingPass, - colorViews: [ this._msaaShadingTexView ], - depthStencilView: this._msaaDepthStencilTexView!, - }); + for (let i = 0; i < this.renderTextures.length; i++) { + const rtd = this.renderTextures[i]; + this._renderTextures.set(rtd.name, this._device.createTexture({ + type: rtd.type, + usage: rtd.usage, + format: this._getTextureFormat(rtd.format, rtd.usage), + width: rtd.width === -1 ? this._shadingWidth : rtd.width, + height: rtd.height === -1 ? this._shadingHeight : rtd.height, + })); + this._textureViews.set(rtd.name, this._device.createTextureView({ + texture: this._renderTextures.get(rtd.name)!, + type: rtd.viewType, + format: this._getTextureFormat(rtd.format, rtd.usage), + })); + } + for (let i = 0; i < this.renderPasses.length; i++) { + const rpd = this.renderPasses[i]; + this._renderPasses.set(rpd.index, this._device.createRenderPass({ + colorAttachments: rpd.colorAttachments, + depthStencilAttachment: rpd.depthStencilAttachment, + })); } - if (this._fboCount > 0) { - this._depthStencilTex = this._device.createTexture({ - type : GFXTextureType.TEX2D, - usage : GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT | GFXTextureUsageBit.SAMPLED, - format : this._depthStencilFmt, - width : this._shadingWidth, - height : this._shadingHeight, - }); - - this._depthStencilTexView = this._device.createTextureView({ - texture : this._depthStencilTex, - type : GFXTextureViewType.TV2D, - format : this._depthStencilFmt, - }); - - for (let i = 0; i < this._fboCount; ++i) { - this._shadingTextures[i] = this._device.createTexture({ - type: GFXTextureType.TEX2D, - usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED, - format: this._colorFmt, - width: this._shadingWidth, - height: this._shadingHeight, - }); - - this._shadingTexViews[i] = this._device.createTextureView({ - texture : this._shadingTextures[i], - type : GFXTextureViewType.TV2D, - format : this._colorFmt, - }); - - this._shadingFBOs[i] = this._device.createFramebuffer({ - renderPass: this._shadingPass, - colorViews: [ this._shadingTexViews[i] ], - depthStencilView: this._depthStencilTexView!, - }); - } - } - - // create smaa framebuffer - if (this._useSMAA) { - const smaaColorFmt = GFXFormat.RGBA8; - - this._smaaPass = this._device.createRenderPass({ - colorAttachments: [{ - format: smaaColorFmt, - loadOp: GFXLoadOp.CLEAR, - storeOp: GFXStoreOp.STORE, - sampleCount: 1, - beginLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL, - endLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL, - }], - }); - - this._smaaEdgeTex = this._device.createTexture({ - type: GFXTextureType.TEX2D, - usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED, - format: smaaColorFmt, - width: this._shadingWidth, - height: this._shadingHeight, - }); - - this._smaaEdgeTexView = this._device.createTextureView({ - texture : this._smaaEdgeTex, - type : GFXTextureViewType.TV2D, - format : smaaColorFmt, - }); - - this._smaaEdgeFBO = this._device.createFramebuffer({ - renderPass: this._smaaPass, - colorViews: [ this._smaaEdgeTexView ], - depthStencilView: null, - }); - - this._smaaBlendTex = this._device.createTexture({ - type: GFXTextureType.TEX2D, - usage: GFXTextureUsageBit.COLOR_ATTACHMENT | GFXTextureUsageBit.SAMPLED, - format: smaaColorFmt, - width: this._shadingWidth, - height: this._shadingHeight, - }); - - this._smaaBlendTexView = this._device.createTextureView({ - texture : this._smaaBlendTex, - type : GFXTextureViewType.TV2D, - format : smaaColorFmt, - }); - - this._smaaBlendFBO = this._device.createFramebuffer({ - renderPass: this._smaaPass, - colorViews: [ this._smaaBlendTexView ], - depthStencilView: null, - }); + for (let i = 0; i < this.framebuffers.length; i++) { + const fbd = this.framebuffers[i]; + this._frameBuffers.set(fbd.name, this._device.createFramebuffer({ + renderPass: this._renderPasses.get(fbd.renderPass)!, + colorViews: fbd.colorViews.map((value) => { + return this._textureViews.get(value)!; + }, this), + depthStencilView: this._textureViews.get(fbd.depthStencilView)!, + })); } if (!this.createQuadInputAssembler()) { @@ -769,6 +624,20 @@ export abstract class RenderPipeline { return false; } + const mainWindow = this._root.mainWindow; + let windowPass: GFXRenderPass | null = null; + + if (mainWindow) { + windowPass = mainWindow.renderPass; + } + + if (!windowPass) { + console.error('RenderPass of main window is null.'); + return false; + } + + this.addRenderPass(RenderPassStage.DEFAULT, windowPass); + return true; } @@ -783,87 +652,32 @@ export abstract class RenderPipeline { this.destroyQuadInputAssembler(); this.destroyUBOs(); - if (this._smaaEdgeTexView) { - this._smaaEdgeTexView.destroy(); - this._smaaEdgeTexView = null; + let rtIter = this._renderTextures.values(); + let rtRes = rtIter.next(); + while (!rtRes.done) { + rtRes.value.destroy(); + rtRes = rtIter.next(); } - if (this._smaaEdgeTex) { - this._smaaEdgeTex.destroy(); - this._smaaEdgeTex = null; + let tvIter = this._textureViews.values(); + let tvRes = tvIter.next(); + while (!tvRes.done) { + tvRes.value.destroy(); + tvRes = tvIter.next(); } - if (this._smaaEdgeFBO) { - this._smaaEdgeFBO.destroy(); - this._smaaEdgeFBO = null; + let rpIter = this._renderPasses.values(); + let rpRes = rpIter.next(); + while (!rpRes.done) { + rpRes.value.destroy(); + rpRes = rpIter.next(); } - if (this._smaaBlendTexView) { - this._smaaBlendTexView.destroy(); - this._smaaBlendTexView = null; - } - - if (this._smaaBlendTex) { - this._smaaBlendTex.destroy(); - this._smaaBlendTex = null; - } - - if (this._smaaBlendFBO) { - this._smaaBlendFBO.destroy(); - this._smaaBlendFBO = null; - } - - if (this._msaaShadingTexView) { - this._msaaShadingTexView.destroy(); - this._msaaShadingTexView = null; - } - if (this._msaaShadingTex) { - this._msaaShadingTex.destroy(); - this._msaaShadingTex = null; - } - if (this._msaaDepthStencilTexView) { - this._msaaDepthStencilTexView.destroy(); - this._msaaDepthStencilTexView = null; - } - if (this._msaaDepthStencilTex) { - this._msaaDepthStencilTex.destroy(); - this._msaaDepthStencilTex = null; - } - if (this._msaaShadingFBO) { - this._msaaShadingFBO.destroy(); - this._msaaShadingFBO = null; - } - - for (let i = 0; i < this._shadingTexViews.length; ++i) { - if (this._shadingTexViews[i]) { - this._shadingTexViews[i].destroy(); - } - - if (this._shadingTextures[i]) { - this._shadingTextures[i].destroy(); - } - - if (this._shadingFBOs[i]) { - this._shadingFBOs[i].destroy(); - } - } - - this._shadingTexViews.splice(0); - this._shadingTextures.splice(0); - this._shadingFBOs.splice(0); - - if (this._depthStencilTexView) { - this._depthStencilTexView.destroy(); - this._depthStencilTexView = null; - } - if (this._depthStencilTex) { - this._depthStencilTex.destroy(); - this._depthStencilTex = null; - } - - if (this._shadingPass) { - this._shadingPass.destroy(); - this._shadingPass = null; + let fbIter = this._frameBuffers.values(); + let fbRes = fbIter.next(); + while (!fbRes.done) { + fbRes.value.destroy(); + fbRes = fbIter.next(); } } @@ -878,85 +692,31 @@ export abstract class RenderPipeline { this._shadingWidth = width; this._shadingHeight = height; - if (this._depthStencilTex) { - this._depthStencilTex.resize(width, height); - this._depthStencilTexView!.destroy(); - this._depthStencilTexView!.initialize({ - texture : this._depthStencilTex, - type : GFXTextureViewType.TV2D, - format : this._depthStencilFmt, + let rtIter = this.renderTextures.values(); + let rtRes = rtIter.next(); + while (!rtRes.done) { + this._renderTextures.get(rtRes.value.name)!.resize(width, height); + this._textureViews.get(rtRes.value.name)!.destroy(); + this._textureViews.get(rtRes.value.name)!.initialize({ + texture: this._renderTextures.get(rtRes.value.name)!, + type: rtRes.value.viewType, + format: this._getTextureFormat(rtRes.value.format, rtRes.value.usage), }); + rtRes = rtIter.next(); } - for (let i = 0; i < this._fboCount; ++i) { - this._shadingTextures[i].resize(width, height); - this._shadingTexViews[i].destroy(); - this._shadingTexViews[i].initialize({ - texture : this._shadingTextures[i], - type : GFXTextureViewType.TV2D, - format : this._colorFmt, - }); - - this._shadingFBOs[i].destroy(); - this._shadingFBOs[i].initialize({ - renderPass: this._shadingPass!, - colorViews: [ this._shadingTexViews[i] ], - depthStencilView: this._depthStencilTexView!, - }); - } - - if (this._useMSAA) { - this._msaaShadingTex!.resize(width, height); - this._msaaShadingTexView!.destroy(); - this._msaaShadingTexView!.initialize({ - texture : this._msaaShadingTex!, - type : GFXTextureViewType.TV2D, - format : this._colorFmt, - }); - this._msaaDepthStencilTex!.resize(width, height); - this._msaaDepthStencilTexView!.destroy(); - this._msaaDepthStencilTexView!.initialize({ - texture : this._msaaDepthStencilTex!, - type : GFXTextureViewType.TV2D, - format : this._depthStencilFmt, - }); - this._msaaShadingFBO!.destroy(); - this._msaaShadingFBO!.initialize({ - renderPass: this._shadingPass!, - colorViews: [ this._msaaShadingTexView! ], - depthStencilView: this._msaaDepthStencilTexView!, - }); - } - - if (this._useSMAA) { - const smaaColorFmt = this._smaaEdgeTex!.format; - this._smaaEdgeTex!.resize(width, height); - this._smaaEdgeTexView!.destroy(); - this._smaaEdgeTexView!.initialize({ - texture : this._smaaEdgeTex!, - type : GFXTextureViewType.TV2D, - format : smaaColorFmt, - }); - - this._smaaEdgeFBO!.destroy(); - this._smaaEdgeFBO!.initialize({ - renderPass: this._smaaPass!, - colorViews: [ this._smaaEdgeTexView! ], - depthStencilView: null, - }); - this._smaaBlendTex!.resize(width, height); - this._smaaBlendTexView!.destroy(); - this._smaaBlendTexView!.initialize({ - texture : this._smaaBlendTex!, - type : GFXTextureViewType.TV2D, - format : smaaColorFmt, - }); - this._smaaBlendFBO!.destroy(); - this._smaaBlendFBO!.initialize({ - renderPass: this._smaaPass!, - colorViews: [ this._smaaBlendTexView! ], - depthStencilView: null, + let fbIter = this.framebuffers.values(); + let fbRes = fbIter.next(); + while (!fbRes.done) { + this._frameBuffers.get(fbRes.value.name)!.destroy(); + this._frameBuffers.get(fbRes.value.name)!.initialize({ + renderPass: this._renderPasses.get(fbRes.value.renderPass)!, + colorViews: fbRes.value.colorViews.map((value) => { + return this._textureViews.get(value)!; + }, this), + depthStencilView: this._textureViews.get(fbRes.value.depthStencilView)!, }); + fbRes = fbIter.next(); } console.info('Resizing shading fbos: ' + this._shadingWidth + 'x' + this._shadingHeight); @@ -1221,8 +981,8 @@ export abstract class RenderPipeline { this.addVisibleModel(scene.skybox, camera); } - for (const model of scene.models) { - + for (let i = 0; i < scene.models.length; i++) { + const model = scene.models[i]; model._resetUBOUpdateFlag(); // filter model by view visibility @@ -1275,4 +1035,19 @@ export abstract class RenderPipeline { depth, }); } + + private _getTextureFormat (format: GFXFormat, usage: GFXTextureUsageBit) { + if (format === GFXFormat.UNKNOWN) { + if (usage & GFXTextureUsageBit.COLOR_ATTACHMENT) { + return this._colorFmt; + } else if (usage & GFXTextureUsageBit.DEPTH_STENCIL_ATTACHMENT) { + return this._depthStencilFmt; + } else { + return GFXFormat.UNKNOWN; + } + } else { + return format; + } + } } +cc.RenderPipeline = RenderPipeline; diff --git a/cocos/core/pipeline/render-stage.ts b/cocos/core/pipeline/render-stage.ts index b2fad808f7..57e293e14e 100644 --- a/cocos/core/pipeline/render-stage.ts +++ b/cocos/core/pipeline/render-stage.ts @@ -2,16 +2,28 @@ * @category pipeline */ +import { ccclass, property } from '../data/class-decorator'; +import { ccenum } from '../value-types/enum'; import { GFXCommandBuffer } from '../gfx/command-buffer'; import { IGFXColor, IGFXRect } from '../gfx/define'; import { GFXDevice } from '../gfx/device'; import { GFXFramebuffer } from '../gfx/framebuffer'; import { GFXPipelineState } from '../gfx/pipeline-state'; import { Pass } from '../renderer'; +import { IRenderPass } from './define'; +import { getPhaseID } from './pass-phase'; import { RenderFlow } from './render-flow'; import { RenderPipeline } from './render-pipeline'; +import { opaqueCompareFn, RenderQueue, transparentCompareFn } from './render-queue'; import { RenderView } from './render-view'; +export enum RenderQueueSortMode { + FRONT_TO_BACK, + BACK_TO_FRONT, +} + +ccenum(RenderQueueSortMode); + /** * @zh * 渲染阶段描述信息。 @@ -19,20 +31,36 @@ import { RenderView } from './render-view'; export interface IRenderStageInfo { name?: string; priority: number; - framebuffer?: GFXFramebuffer; + renderQueues?: RenderQueueDesc[]; + framebuffer?: string; +} + +@ccclass('RenderQueueDesc') +class RenderQueueDesc { + @property + public isTransparent: boolean = false; + @property({ + type: RenderQueueSortMode, + }) + public sortMode: RenderQueueSortMode = RenderQueueSortMode.FRONT_TO_BACK; + @property({ + type: [String], + }) + public stages: string[] = []; } /** * @zh * 渲染阶段。 */ +@ccclass('RenderStage') export abstract class RenderStage { /** * @zh * 渲染流程。 */ - public get flow (): RenderFlow { + public get flow(): RenderFlow { return this._flow; } @@ -40,7 +68,7 @@ export abstract class RenderStage { * @zh * 渲染管线。 */ - public get pipeline (): RenderPipeline { + public get pipeline(): RenderPipeline { return this._pipeline; } @@ -60,36 +88,59 @@ export abstract class RenderStage { return this._framebuffer; } - /** - * @zh - * 渲染流程。 - */ - protected _flow: RenderFlow; - - /** - * @zh - * 渲染管线。 - */ - protected _pipeline: RenderPipeline; - - /** - * @zh - * GFX设备。 - */ - protected _device: GFXDevice; - /** * @zh * 名称。 */ + @property({ + displayOrder: 0, + visible: true + }) protected _name: string = ''; /** * @zh * 优先级。 */ + @property({ + displayOrder: 1, + visible: true + }) protected _priority: number = 0; + @property({ + displayOrder: 2, + visible: true + }) + protected frameBuffer: string = ''; + + @property({ + type: [RenderQueueDesc], + displayOrder: 3, + visible: true + }) + protected renderQueues: RenderQueueDesc[] = []; + + protected _renderQueues: RenderQueue[] = []; + + /** + * @zh + * 渲染流程。 + */ + protected _flow: RenderFlow = null!; + + /** + * @zh + * 渲染管线。 + */ + protected _pipeline: RenderPipeline = null!; + + /** + * @zh + * GFX设备。 + */ + protected _device: GFXDevice | null = null; + /** * @zh * 渲染流程。 @@ -106,7 +157,7 @@ export abstract class RenderStage { * @zh * 清空颜色数组。 */ - protected _clearColors: IGFXColor[]; + protected _clearColors: IGFXColor[] | null = null; /** * @zh @@ -124,7 +175,7 @@ export abstract class RenderStage { * @zh * 渲染区域。 */ - protected _renderArea: IGFXRect; + protected _renderArea: IGFXRect | null = null; /** * @zh @@ -142,7 +193,35 @@ export abstract class RenderStage { * 构造函数。 * @param flow 渲染流程。 */ - constructor (flow: RenderFlow) { + constructor () { + } + + /** + * @zh + * 初始化函数,用于不从资源加载RenderPipeline时使用。 + * @param info 渲染阶段描述信息。 + */ + public initialize (info: IRenderStageInfo): boolean { + if (info.name !== undefined) { + this._name = info.name; + } + + this._priority = info.priority; + + if(info.framebuffer) + this.frameBuffer = info.framebuffer; + + if (info.renderQueues) { + this.renderQueues = info.renderQueues; + } + + return true; + } + + /** + * 把序列化数据转换成运行时数据 + */ + public activate (flow: RenderFlow) { this._flow = flow; this._pipeline = flow.pipeline; this._device = flow.device; @@ -152,16 +231,37 @@ export abstract class RenderStage { } this._device = this._flow.pipeline.root.device; + this._clearColors = [{ r: 0.3, g: 0.6, b: 0.9, a: 1.0 }]; this._renderArea = { x: 0, y: 0, width: 0, height: 0 }; - } - /** - * @zh - * 初始化函数。 - * @param info 渲染阶段描述信息。 - */ - public abstract initialize (info: IRenderStageInfo): boolean; + for (let i = 0; i < this.renderQueues.length; i++) { + let phase = 0; + for (let j = 0; j < this.renderQueues[i].stages.length; j++) { + phase |= getPhaseID(this.renderQueues[i].stages[j]); + } + let sortFunc: (a: IRenderPass, b: IRenderPass) => number = opaqueCompareFn; + switch (this.renderQueues[i].sortMode) { + case RenderQueueSortMode.BACK_TO_FRONT: + sortFunc = transparentCompareFn; + break; + case RenderQueueSortMode.FRONT_TO_BACK: + sortFunc = opaqueCompareFn; + break; + } + this._renderQueues[i] = new RenderQueue({ + isTransparent: this.renderQueues[i].isTransparent, + phases: phase, + sortFunc, + }); + } + + if (this.frameBuffer === 'window') { + this._framebuffer = this._flow.pipeline.root.mainWindow!.framebuffer!; + } else { + this._framebuffer = this._flow.pipeline.getFrameBuffer(this.frameBuffer)!; + } + } /** * @zh @@ -195,10 +295,10 @@ export abstract class RenderStage { * 设置清空颜色。 */ public setClearColor (color: IGFXColor) { - if (this._clearColors.length > 0) { - this._clearColors[0] = color; + if (this._clearColors!.length > 0) { + this._clearColors![0] = color; } else { - this._clearColors.push(color); + this._clearColors!.push(color); } } @@ -231,7 +331,9 @@ export abstract class RenderStage { * 设置渲染区域。 */ public setRenderArea (width: number, height: number) { - this._renderArea.width = width; - this._renderArea.height = height; + this._renderArea!.width = width; + this._renderArea!.height = height; } } + +cc.RenderStage = RenderStage; diff --git a/cocos/core/pipeline/render-view.ts b/cocos/core/pipeline/render-view.ts index f80c646be3..2c9bfbb07c 100644 --- a/cocos/core/pipeline/render-view.ts +++ b/cocos/core/pipeline/render-view.ts @@ -208,7 +208,7 @@ export class RenderView { public setExecuteFlows (flows: string[]) { this.flows.length = 0; - const pipelineFlows = cc.director.root.pipeline.flows; + const pipelineFlows = cc.director.root.pipeline.activeFlows; for (const f of pipelineFlows) { if (flows.indexOf(f.name) !== -1) { this.flows.push(f); diff --git a/cocos/core/pipeline/ui/ui-flow.ts b/cocos/core/pipeline/ui/ui-flow.ts index c9c060ea8b..924c6bcf71 100644 --- a/cocos/core/pipeline/ui/ui-flow.ts +++ b/cocos/core/pipeline/ui/ui-flow.ts @@ -5,9 +5,10 @@ import { UBOGlobal } from '../define'; import { IRenderFlowInfo, RenderFlow } from '../render-flow'; -import { RenderPipeline } from '../render-pipeline'; import { RenderView } from '../render-view'; import { UIStage } from './ui-stage'; +import { RenderQueueSortMode } from '../render-stage'; +import { ForwardFlowPriority } from '../forward/enum'; /** * @zh @@ -15,28 +16,22 @@ import { UIStage } from './ui-stage'; */ export class UIFlow extends RenderFlow { - constructor (pipeline: RenderPipeline) { - super(pipeline); + public static initInfo: IRenderFlowInfo = { + name: 'UIFlow', + priority: ForwardFlowPriority.UI, + }; + + constructor () { + super(); } public initialize (info: IRenderFlowInfo): boolean { - if (info.name !== undefined) { - this._name = info.name; - } + super.initialize(info); - this._priority = info.priority; - - const mainWindow = this._pipeline.root.mainWindow; - if (!mainWindow || !mainWindow.framebuffer) { - return false; - } - - this.createStage(UIStage, { - name: 'UIStage', - priority: 0, - framebuffer: mainWindow.framebuffer, - }); + let uiStage = new UIStage(); + uiStage.initialize(UIStage.initInfo); + this._stages.push(uiStage); return true; } diff --git a/cocos/core/pipeline/ui/ui-stage.ts b/cocos/core/pipeline/ui/ui-stage.ts index a693bbf094..042f1af076 100644 --- a/cocos/core/pipeline/ui/ui-stage.ts +++ b/cocos/core/pipeline/ui/ui-stage.ts @@ -5,10 +5,10 @@ import { GFXCommandBuffer } from '../../gfx/command-buffer'; import { GFXCommandBufferType, IGFXColor } from '../../gfx/define'; import { getPhaseID } from '../pass-phase'; -import { RenderFlow } from '../render-flow'; import { RenderQueue, transparentCompareFn } from '../render-queue'; -import { IRenderStageInfo, RenderStage } from '../render-stage'; +import { IRenderStageInfo, RenderStage, RenderQueueSortMode } from '../render-stage'; import { RenderView } from '../render-view'; +import { RenderFlow } from '../render-flow'; const bufs: GFXCommandBuffer[] = []; const colors: IGFXColor[] = []; @@ -19,35 +19,27 @@ const colors: IGFXColor[] = []; */ export class UIStage extends RenderStage { - private _uiQueue: RenderQueue; - - constructor (flow: RenderFlow) { - super(flow); - this._uiQueue = new RenderQueue({ + public static initInfo: IRenderStageInfo = { + name: 'UIStage', + priority: 0, + renderQueues: [{ isTransparent: true, - phases: getPhaseID('default'), - sortFunc: transparentCompareFn, - }); + stages: ['default'], + sortMode: RenderQueueSortMode.BACK_TO_FRONT, + }], + framebuffer: 'window' + }; + + constructor () { + super(); } - public initialize (info: IRenderStageInfo): boolean { - - if (info.name !== undefined) { - this._name = info.name; - } - - this._priority = info.priority; - - if (info.framebuffer !== undefined) { - this._framebuffer = info.framebuffer; - } - - this._cmdBuff = this._device.createCommandBuffer({ - allocator: this._device.commandAllocator, + public activate(flow: RenderFlow) { + super.activate(flow); + this._cmdBuff = this._device!.createCommandBuffer({ + allocator: this._device!.commandAllocator, type: GFXCommandBufferType.PRIMARY, }); - - return true; } public destroy () { @@ -66,16 +58,16 @@ export class UIStage extends RenderStage { public render (view: RenderView) { - this._uiQueue.clear(); + this._renderQueues[0].clear(); - for (const ro of this._pipeline.renderObjects) { + for (const ro of this._pipeline!.renderObjects) { for (let i = 0; i < ro.model.subModelNum; i++) { for (let j = 0; j < ro.model.getSubModel(i).passes.length; j++) { - this._uiQueue.insertRenderPass(ro, i, j); + this._renderQueues[0].insertRenderPass(ro, i, j); } } } - this._uiQueue.sort(); + this._renderQueues[0].sort(); const framebuffer = view.window!.framebuffer; @@ -84,23 +76,23 @@ export class UIStage extends RenderStage { const camera = view.camera!; const vp = camera.viewport; - this._renderArea.x = vp.x * camera.width; - this._renderArea.y = vp.y * camera.height; - this._renderArea.width = vp.width * camera.width; - this._renderArea.height = vp.height * camera.height; + this._renderArea!.x = vp.x * camera.width; + this._renderArea!.y = vp.y * camera.height; + this._renderArea!.width = vp.width * camera.width; + this._renderArea!.height = vp.height * camera.height; colors[0] = camera.clearColor; cmdBuff.begin(); - cmdBuff.beginRenderPass(framebuffer, this._renderArea, - camera.clearFlag, colors, camera.clearDepth, camera.clearStencil); + cmdBuff.beginRenderPass(framebuffer, this._renderArea!, + camera.clearFlag, [camera.clearColor], camera.clearDepth, camera.clearStencil); - cmdBuff.execute(this._uiQueue.cmdBuffs.array, this._uiQueue.cmdBuffCount); + cmdBuff.execute(this._renderQueues[0].cmdBuffs.array, this._renderQueues[0].cmdBuffCount); cmdBuff.endRenderPass(); cmdBuff.end(); bufs[0] = cmdBuff; - this._device.queue.submit(bufs); + this._device!.queue.submit(bufs); } } diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 438ccd9b63..5769710c67 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -5,7 +5,6 @@ import { builtinResMgr } from './3d/builtin'; import { GFXDevice } from './gfx/device'; import { GFXWindow, IGFXWindowInfo } from './gfx/window'; -import { ForwardPipeline } from './pipeline/forward/forward-pipeline'; import { RenderPipeline } from './pipeline/render-pipeline'; import { IRenderViewInfo, RenderView } from './pipeline/render-view'; import { DataPoolManager } from './renderer/data-pool-manager'; @@ -219,18 +218,6 @@ export class Root { builtinResMgr.initBuiltinRes(this._device); - this._pipeline = new ForwardPipeline(this); - if (!this._pipeline.initialize(info)) { - this.destroy(); - return false; - } - - this._ui = new UI(this); - if (!this._ui.initialize()) { - this.destroy(); - return false; - } - cc.view.on('design-resolution-changed', () => { const width = cc.game.canvas.width; const height = cc.game.canvas.height; @@ -290,6 +277,16 @@ export class Root { } } + public setRenderPipeline (rppl: RenderPipeline) { + this._pipeline = rppl; + this._pipeline.activate(this); + this._ui = new UI(this); + if (!this._ui.initialize()) { + this.destroy(); + return false; + } + } + /** * @zh * 激活指定窗口为当前窗口 @@ -343,8 +340,8 @@ export class Root { for (const view of this._views) { if (view.isEnable && (view.window && (view.window.isOffscreen || - (!view.window.isOffscreen && (view.window === this._curWindow))))) { - this._pipeline!.render(view); + (!view.window.isOffscreen && (view.window === this._curWindow)))) && this._pipeline) { + this._pipeline.render(view); } } From 3a246bd4dad592bfaa94465459d13d5280b5dab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=A3=AE=E6=96=8C?= Date: Fri, 29 Nov 2019 13:52:38 +0800 Subject: [PATCH 7/9] =?UTF-8?q?cc.game.run=20=E5=8C=85=E6=8B=AC=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=20renderpipeline=20(#5798)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/core/game.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cocos/core/game.ts b/cocos/core/game.ts index 03b434704a..8735ac2a13 100644 --- a/cocos/core/game.ts +++ b/cocos/core/game.ts @@ -492,13 +492,26 @@ export class Game extends EventTarget { this._initConfig(config); this._initRenderer(); - this.onStart = onStart; + // load renderpipeline + cc.loader.load({ uuid: config.renderpipeline }, (err, asset) => { + // failed load renderPipeline + if (err || !(asset instanceof cc.RenderPipeline)) { + console.error(`Failed load renderpipeline: ${config.renderpipeline}`); + console.error(err); - if (!CC_EDITOR && CC_WECHATGAME/* && !CC_PREVIEW*/) { - SplashScreen.instance.main(this._gfxDevice as any); - } + cc.game.setRenderPipeline(null); + } else { + cc.game.setRenderPipeline(asset); + } - this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game)); + this.onStart = onStart; + + if (!CC_EDITOR && CC_WECHATGAME/* && !CC_PREVIEW*/) { + SplashScreen.instance.main(this._gfxDevice as any); + } + + this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game)); + }); } // @ Persist root node section From 096c9498079e537ba1c64851dc5756b529b610c2 Mon Sep 17 00:00:00 2001 From: zheng han Date: Mon, 2 Dec 2019 10:36:02 +0800 Subject: [PATCH 8/9] change animatable property from sharedMaterials to materials (#5789) --- cocos/core/3d/framework/renderable-component.ts | 6 ++++++ cocos/core/data/class.ts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cocos/core/3d/framework/renderable-component.ts b/cocos/core/3d/framework/renderable-component.ts index e0ad6ba24b..a7e3da091a 100644 --- a/cocos/core/3d/framework/renderable-component.ts +++ b/cocos/core/3d/framework/renderable-component.ts @@ -31,6 +31,7 @@ export class RenderableComponent extends Component { type: Material, displayName: 'Materials', tooltip: '源材质', + animatable: false, }) get sharedMaterials () { // if we don't create an array copy, the editor will modify the original array directly. @@ -56,6 +57,11 @@ export class RenderableComponent extends Component { * @zh 模型材质。 * @type {Material[]} */ + @property({ + type: Material, + visible: false, + animatable: true, + }) get materials () { for (let i = 0; i < this._materials.length; i++) { this._materials[i] = this.getMaterial(i)!; diff --git a/cocos/core/data/class.ts b/cocos/core/data/class.ts index bca09e03df..2807f1e908 100644 --- a/cocos/core/data/class.ts +++ b/cocos/core/data/class.ts @@ -1248,8 +1248,8 @@ function parseAttributes (constructor: Function, attributes: IAcceptableAttribut parseSimpleAttribute('formerlySerializedAs', 'string'); if (CC_EDITOR) { - if ('animatable' in attributes && !attributes.animatable) { - (attrsProto || getAttrsProto())[attrsProtoKey + 'animatable'] = false; + if ('animatable' in attributes) { + (attrsProto || getAttrsProto())[attrsProtoKey + 'animatable'] = attributes.animatable; } } From ff3bb5b332bfb7428281e3158d2d6f5f3540b508 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 3 Dec 2019 19:33:17 +0800 Subject: [PATCH 9/9] Fix ci --- cocos/core/components/ui-base/canvas-component.ts | 2 +- cocos/core/components/ui-base/ui-component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/core/components/ui-base/canvas-component.ts b/cocos/core/components/ui-base/canvas-component.ts index 28d671bc1a..b241754a14 100644 --- a/cocos/core/components/ui-base/canvas-component.ts +++ b/cocos/core/components/ui-base/canvas-component.ts @@ -43,7 +43,7 @@ import { Node } from '../../scene-graph/node'; import { INode } from '../../utils/interfaces'; import { Enum } from '../../value-types'; import { Component } from '../component'; -import { UITransformComponent } from './ui-transfrom-component'; +import { UITransformComponent } from './ui-transform-component'; const _worldPos = new Vec3(); diff --git a/cocos/core/components/ui-base/ui-component.ts b/cocos/core/components/ui-base/ui-component.ts index e94b9cc5a5..a225d1a0fc 100644 --- a/cocos/core/components/ui-base/ui-component.ts +++ b/cocos/core/components/ui-base/ui-component.ts @@ -31,7 +31,7 @@ import { ccclass, disallowMultiple, executeInEditMode, executionOrder, property, import { INode } from '../../../core/utils/interfaces'; import { UI } from '../../renderer/ui/ui'; import { Component } from '../component'; -import { UITransformComponent } from './ui-transfrom-component'; +import { UITransformComponent } from './ui-transform-component'; /** * @zh