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/3d/framework/renderable-component.ts b/cocos/core/3d/framework/renderable-component.ts
index e14f70b9e4..1eb5b3f8c8 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/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/components/component.ts b/cocos/core/components/component.ts
index fd2cb400fb..32fc6712bd 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;
}
@@ -590,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
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/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-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
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 95b4164792..940acba175 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, IListenerMask } 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, 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';
import { director } from '../../director';
diff --git a/cocos/core/data/class.ts b/cocos/core/data/class.ts
index 1eb42be77f..cb75031be1 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) {
@@ -1223,8 +1252,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;
}
}
diff --git a/cocos/core/game.ts b/cocos/core/game.ts
index 7276be439b..cad715d855 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:
@@ -491,9 +492,25 @@ 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);
+ 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
@@ -953,6 +970,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 786ef702a0..2f5aa55cf3 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,10 @@ export class ForwardPipeline extends RenderPipeline {
* 场景裁剪。
* @param view 渲染视图。
*/
- protected sceneCulling (view: RenderView) {
+ protected sceneCulling(view: RenderView) {
super.sceneCulling(view);
this._validLights.length = 0;
- const sphereLights = view.camera.scene!.sphereLights;
+ const sphereLights = view.camera.scene.sphereLights;
for (let i = 0; i < sphereLights.length; i++) {
const light = sphereLights[i];
light.update();
@@ -295,7 +270,7 @@ export class ForwardPipeline extends RenderPipeline {
this._validLights.push(light);
}
}
- const spotLights = view.camera.scene!.spotLights;
+ const spotLights = view.camera.scene.spotLights;
for (let i = 0; i < spotLights.length; i++) {
const light = spotLights[i];
light.update();
@@ -348,7 +323,7 @@ export class ForwardPipeline extends RenderPipeline {
Array.prototype.push.apply(this._lightIndices, _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 a0db786855..6c61c4190c 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 6dde6844ff..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,33 +175,9 @@ export abstract class RenderFlow {
* 渲染函数。
* @param view 渲染视图。
*/
- public render (view: RenderView) {
+ public render(view: RenderView) {
for (let i = 0; i < this._stages.length; i++) {
- const stage = this._stages[i];
- 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;
+ this._stages[i].render(view);
}
}
@@ -162,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 cb29f9acb9..44ea58658f 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 v3_1 = new Vec3();
@@ -36,12 +44,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 {
/**
@@ -65,7 +81,7 @@ export abstract class RenderPipeline {
* 名称。
*/
public get name (): string {
- return this._name;
+ return this.constructor.name;
}
/**
@@ -84,6 +100,10 @@ export abstract class RenderPipeline {
return this._flows;
}
+ public get activeFlows (): RenderFlow[] {
+ return this._activeFlows;
+ }
+
/**
* @zh
* 启用后期处理。
@@ -128,54 +148,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。
@@ -192,38 +164,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
* 四边形输入汇集器。
@@ -280,6 +220,14 @@ export abstract class RenderPipeline {
return this._uboGlobal!.view;
}
+ get currShading () {
+ return this._curIdx;
+ }
+
+ get prevShading () {
+ return this._prevIdx;
+ }
+
/**
* @zh
* 启用动态合批。
@@ -288,44 +236,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;
@@ -338,21 +274,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
@@ -374,8 +382,7 @@ export abstract class RenderPipeline {
this.updateUBOs(view);
for (let i = 0; i < view.flows.length; i++) {
- const flow = view.flows[i];
- flow.render(view);
+ view.flows[i].render(view);
}
}
@@ -404,8 +411,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);
}
}
@@ -462,33 +469,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 = [];
}
@@ -499,9 +486,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];
}
}
@@ -515,24 +502,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) ||
@@ -543,15 +518,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);
}
@@ -568,8 +535,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;
@@ -585,9 +552,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;
@@ -613,151 +580,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()) {
@@ -768,6 +622,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;
}
@@ -782,87 +650,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.length = 0;
- this._shadingTextures.length = 0;
- this._shadingFBOs.length = 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();
}
}
@@ -877,85 +690,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);
@@ -1274,4 +1033,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/platform/SubContextView.ts b/cocos/core/platform/SubContextView.ts
index a049faab90..632f82465a 100644
--- a/cocos/core/platform/SubContextView.ts
+++ b/cocos/core/platform/SubContextView.ts
@@ -28,7 +28,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/root.ts b/cocos/core/root.ts
index 2d5f1a841f..fdf32d2afa 100644
--- a/cocos/core/root.ts
+++ b/cocos/core/root.ts
@@ -6,7 +6,6 @@ import { builtinResMgr } from './3d/builtin';
import { GFXDevice } from './gfx/device';
import { GFXWindow, IGFXWindowInfo } from './gfx/window';
import { Pool } from './memop';
-import { ForwardPipeline } from './pipeline/forward/forward-pipeline';
import { RenderPipeline } from './pipeline/render-pipeline';
import { IRenderViewInfo, RenderView } from './pipeline/render-view';
import { Camera, Light, Model } from './renderer';
@@ -233,18 +232,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;
@@ -304,6 +291,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
* 激活指定窗口为当前窗口
@@ -359,8 +356,8 @@ export class Root {
const view = views[i];
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);
}
}
diff --git a/cocos/core/scene-graph/base-node.ts b/cocos/core/scene-graph/base-node.ts
index bc04c50678..b69094ca40 100644
--- a/cocos/core/scene-graph/base-node.ts
+++ b/cocos/core/scene-graph/base-node.ts
@@ -395,12 +395,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);
- }
}
/**
@@ -1044,8 +1038,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);
@@ -1197,8 +1194,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
@@ -1283,7 +1280,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);
@@ -1334,7 +1331,7 @@ export class BaseNode extends CCObject implements IBaseNode, ISchedulable {
// detach self and children from editor
const parent = this._parent;
const destroyByParent: boolean = (!!parent) && ((parent._objFlags & Destroying) !== 0);
- if (!destroyByParent && (CC_EDITOR || CC_TEST)) {
+ if (!destroyByParent && CC_EDITOR) {
this._registerIfAttached!(false);
}
@@ -1403,12 +1400,35 @@ export class BaseNode extends CCObject implements IBaseNode, ISchedulable {
}
}
- // ABSTRACT INTERFACES
+ protected _registerIfAttached = !CC_EDITOR ? undefined : function (this: BaseNode, register) {
+ if (EditorExtends.Node && EditorExtends.Component) {
+ if (register) {
+ EditorExtends.Node.add(this._id, this);
+
+ 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 _registerIfAttached? (attached: boolean): void;
-
protected _checkMultipleComp? (constructor: Function): boolean;
}
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/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 35a498a59b..016d2c8b95 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;
/**
* 地形信息。
@@ -41,46 +45,35 @@ export class TerrainInfo {
tooltip:'地形Tile的大小',
})
public tileSize: number = 1;
-
- @property({
- tooltip:'地形块在两个维度上的数量',
- })
+ @property
public blockCount: number[] = [1, 1];
-
- @property({
- tooltip:'权重图大小',
- })
+ @property
public weightMapSize: number = 128;
-
- @property({
- tooltip:'光照贴图大小',
- })
+ @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;
}
}
@@ -143,7 +136,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),
});
@@ -193,6 +186,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 {
@@ -315,7 +313,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) {
@@ -380,6 +378,11 @@ export class TerrainBlock {
}
mtl.setProperty('UVScale', uvScale);
+
+ if (this.lightmap != null) {
+ mtl.setProperty('lightMap', this.lightmap);
+ mtl.setProperty('lightMapUVParam', this.lightmapUVParam);
+ }
}
}
@@ -394,6 +397,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;
}
@@ -440,17 +451,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 };
@@ -509,18 +536,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);
@@ -533,6 +560,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')
@@ -540,32 +576,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;
@@ -579,36 +611,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];
}
@@ -628,18 +743,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));
}
}
@@ -651,10 +765,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;
@@ -677,8 +791,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) {
@@ -688,8 +802,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);
@@ -782,31 +919,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);
@@ -815,14 +956,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);
@@ -846,7 +987,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;
@@ -854,7 +995,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];
@@ -865,8 +1006,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);
@@ -875,14 +1016,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);
@@ -915,7 +1056,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;
@@ -924,7 +1065,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;
@@ -936,8 +1077,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);
@@ -946,14 +1087,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);
@@ -982,11 +1123,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 () {
@@ -1021,6 +1162,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);
@@ -1042,7 +1193,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 {
@@ -1050,7 +1201,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 {
@@ -1072,8 +1223,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;
@@ -1085,24 +1236,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;
@@ -1114,8 +1272,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) {
@@ -1127,17 +1285,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));
}
}
@@ -1148,23 +1314,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];
}
@@ -1176,9 +1342,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];
@@ -1197,8 +1363,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) => {
@@ -1256,20 +1422,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;
diff --git a/cocos/ui/components/editbox/edit-box-component.ts b/cocos/ui/components/editbox/edit-box-component.ts
index c5304ba905..0fc9d3582f 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 2d074193c0..278448b72a 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 80b25446c6..18ee59fc71 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 80d1f5f95c..a685645ec7 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';