From 69c3363d05211f366e03304925b4fc2c59e84edc Mon Sep 17 00:00:00 2001 From: Leslie Leigh Date: Wed, 24 Apr 2019 16:40:50 +0800 Subject: [PATCH 1/4] remove WrapMode from cc, instead make it as a member of AnimationClip (#4292) * remove WrapMode from cc, instead make it as a member of AnimationClip * fix bug in getChildByPath --- cocos/animation/animation-clip.ts | 8 +++++--- cocos/animation/types.ts | 1 - cocos/scene-graph/base-node.ts | 12 +++--------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/cocos/animation/animation-clip.ts b/cocos/animation/animation-clip.ts index 6e638db8b5..822ee6f1e5 100644 --- a/cocos/animation/animation-clip.ts +++ b/cocos/animation/animation-clip.ts @@ -10,7 +10,7 @@ import { CurveValue, DynamicAnimCurve, EasingMethodName, ICurveTarget, RatioSamp import { AnimationState } from './animation-state'; import * as blending from './blending'; import { MotionPath, sampleMotionPaths } from './motion-path-helper'; -import { ILerpable, isLerpable, WrapMode } from './types'; +import { ILerpable, isLerpable, WrapMode as AnimationWrapMode } from './types'; interface IAnimationEvent { frame: number; @@ -43,6 +43,7 @@ interface ICurveData { @ccclass('cc.AnimationClip') export class AnimationClip extends Asset { + public static WrapMode = AnimationWrapMode; /** * !#en Duration of this animation. @@ -114,7 +115,7 @@ export class AnimationClip extends Asset { * !#zh 动画的循环模式。 */ @property - public wrapMode = WrapMode.Normal; + public wrapMode = AnimationWrapMode.Normal; /** * !#en Curve data. @@ -259,8 +260,9 @@ export class AnimationClip extends Asset { (key) => key / this._duration))); const curves: DynamicAnimCurve[] = []; for (const path of Object.keys(this.curveDatas)) { - const target = find(path, root); + const target = root.getChildByPath(path); if (!target) { + console.warn(`Target animation node referenced by path ${path} is not found(from ${root.name}).`); continue; } const curveData = this.curveDatas[path]; diff --git a/cocos/animation/types.ts b/cocos/animation/types.ts index e0f594e5c6..7036a8809b 100644 --- a/cocos/animation/types.ts +++ b/cocos/animation/types.ts @@ -61,7 +61,6 @@ export enum WrapMode { } ccenum(WrapMode); -cc.WrapMode = WrapMode; /** * For internal diff --git a/cocos/scene-graph/base-node.ts b/cocos/scene-graph/base-node.ts index 88f6a32fff..a773b579a7 100644 --- a/cocos/scene-graph/base-node.ts +++ b/cocos/scene-graph/base-node.ts @@ -494,18 +494,12 @@ export class BaseNode extends CCObject { * var child = node.getChildByPath("Test Node"); */ public getChildByPath (path: string) { - if (path.length === 0) { - return this; - } const segments = path.split('/'); - - // Starts with / - if (segments.length !== 0 && segments[0].length === 0) { - segments.shift(); - } - let lastNode: this = this; for (const segment of segments) { + if (segment.length === 0) { + continue; + } const next = lastNode.children.find((childNode) => childNode.name === segment); if (!next) { return null; From ee806e9938e0c678fda8be7faeee14f67ace2136 Mon Sep 17 00:00:00 2001 From: JoneLau <32630749+JoneLau@users.noreply.github.com> Date: Wed, 24 Apr 2019 17:45:31 +0800 Subject: [PATCH 2/4] fix render-twice (#4294) --- cocos/3d/ui/components/canvas-component.ts | 2 +- .../ui/components/debug-canvas-component.ts | 39 +++++++++++++++++-- cocos/core/utils/profiler/profiler.ts | 1 - cocos/renderer/ui/ui.ts | 14 +++++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/cocos/3d/ui/components/canvas-component.ts b/cocos/3d/ui/components/canvas-component.ts index dcf160e800..8993d7d531 100644 --- a/cocos/3d/ui/components/canvas-component.ts +++ b/cocos/3d/ui/components/canvas-component.ts @@ -43,7 +43,7 @@ const _worldPos = new Vec3(); * @extends Component */ @ccclass('cc.CanvasComponent') -@executionOrder(100) +@executionOrder(110) @requireComponent(UITransformComponent) @menu('UI/Canvas') @executeInEditMode diff --git a/cocos/3d/ui/components/debug-canvas-component.ts b/cocos/3d/ui/components/debug-canvas-component.ts index 274d6b9a33..1c4a8202a2 100644 --- a/cocos/3d/ui/components/debug-canvas-component.ts +++ b/cocos/3d/ui/components/debug-canvas-component.ts @@ -1,4 +1,6 @@ import { Vec3 } from '../../../core/value-types'; +import { GFXClearFlag } from '../../../gfx/define'; +import { CameraComponent } from '../../framework'; import { CanvasComponent } from './canvas-component'; const _worldPos = new Vec3(); @@ -7,6 +9,34 @@ export class DebugCanvasComponent extends CanvasComponent{ super(); this._thisOnResized = this.alignWithScreen.bind(this); } + public __preload (){ + const cameraNode = new cc.Node('UICamera'); + cameraNode.setPosition(0, 0, 1000); + + this._camera = cc.director.root.ui.renderScene.createCamera({ + name: 'ui', + node: cameraNode, + projection: CameraComponent.ProjectionType.ORTHO, + targetDisplay: 0, + priority: this._priority, + isUI: true, + flows: ['UIFlow'], + }); + + this._camera!.fov = 45; + this._camera!.clearFlag = GFXClearFlag.COLOR | GFXClearFlag.DEPTH | GFXClearFlag.STENCIL; + + const device = cc.director.root.device; + this._camera!.resize(device.width, device.height); + + cc.view.on('design-resolution-changed', this._thisOnResized); + + this.alignWithScreen(); + + if (cc.director.root && cc.director.root.ui) { + cc.director.root.ui.debugScreen = this; + } + } // don't remove public onEnable (){ @@ -16,12 +46,15 @@ export class DebugCanvasComponent extends CanvasComponent{ public onDisable (){ } - public onDestroy (){ - if (CC_EDITOR) { - cc.director.off(cc.Director.EVENT_AFTER_UPDATE, this.alignWithScreen, this); + public onDestroy () { + if (this._camera) { + this._getRenderScene().destroyCamera(this._camera); } cc.view.off('design-resolution-changed', this._thisOnResized); + if (cc.director.root && cc.director.root.ui) { + cc.director.root.ui.debugScreen = null; + } } public alignWithScreen (){ diff --git a/cocos/core/utils/profiler/profiler.ts b/cocos/core/utils/profiler/profiler.ts index efad7c8819..e6024a1cc6 100644 --- a/cocos/core/utils/profiler/profiler.ts +++ b/cocos/core/utils/profiler/profiler.ts @@ -172,7 +172,6 @@ function generateNode () { _rootNode = new Node('PROFILER-NODE'); _rootNode.addComponent(UITransformComponent); const screen = _rootNode.addComponent(DebugCanvasComponent); - cc.director.root.ui.debugScreen = screen; cc.game.addPersistRootNode(_rootNode); // const camera = cc.director.root. diff --git a/cocos/renderer/ui/ui.ts b/cocos/renderer/ui/ui.ts index 1c7f54d53b..b204f4ca90 100644 --- a/cocos/renderer/ui/ui.ts +++ b/cocos/renderer/ui/ui.ts @@ -80,6 +80,9 @@ export class UI { set debugScreen (value){ this._debugScreen = value; + if (this._debugScreen && this._debugScreen.camera ) { + this._debugScreen.camera.view.visibility = this._screens.length + 1; + } } public device: GFXDevice; @@ -186,6 +189,10 @@ export class UI { comp.camera.view.visibility = this._screens.length; } + if (this._debugScreen && this._debugScreen.camera) { + this._debugScreen.camera.view.visibility = this._screens.length + 1; + } + } public getScreen (visibility: number) { @@ -197,6 +204,10 @@ export class UI { } } + if (this._debugScreen && this._debugScreen.camera && this._debugScreen.camera.visibility === visibility) { + return this._debugScreen; + } + return null; } @@ -207,6 +218,9 @@ export class UI { } this._screens.splice(idx, 1); + if (this._debugScreen && this._debugScreen.camera ) { + this._debugScreen.camera.view.visibility = this._screens.length + 1; + } let camera: Camera | null; for (let i = idx; i < this._screens.length;) { From efa0d249da62eac6d7025bb9bc45edb773a5ec54 Mon Sep 17 00:00:00 2001 From: JoneLau <32630749+JoneLau@users.noreply.github.com> Date: Thu, 25 Apr 2019 10:11:28 +0800 Subject: [PATCH 3/4] fix bug (#4297) --- cocos/3d/ui/components/canvas-component.ts | 15 +++++---------- cocos/3d/ui/components/widget-manager.ts | 4 ++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/cocos/3d/ui/components/canvas-component.ts b/cocos/3d/ui/components/canvas-component.ts index 8993d7d531..be3bd43757 100644 --- a/cocos/3d/ui/components/canvas-component.ts +++ b/cocos/3d/ui/components/canvas-component.ts @@ -28,11 +28,11 @@ import { CameraComponent } from '../../../3d/framework/camera-component'; import { Component } from '../../../components/component'; import { ccclass, executeInEditMode, executionOrder, menu, property, requireComponent } from '../../../core/data/class-decorator'; import { Size, Vec3 } from '../../../core/value-types'; +import { vec3 } from '../../../core/vmath'; import { GFXClearFlag } from '../../../gfx/define'; import { Camera } from '../../../renderer/scene/camera'; import { UITransformComponent } from './ui-transfrom-component'; -const _tempPos = new Vec3(); const _worldPos = new Vec3(); /** @@ -223,10 +223,7 @@ export class CanvasComponent extends Component { if (CC_EDITOR) { // nodeSize = designSize = cc.engine.getDesignResolutionSize(); nodeSize = designSize = this._designResolution; - _tempPos.x = designSize.width * 0.5; - _tempPos.y = designSize.height * 0.5; - _tempPos.z = 0; - + vec3.set(_worldPos, designSize.width * 0.5, designSize.height * 0.5, 1); } else { const canvasSize = cc.visibleRect; @@ -241,13 +238,11 @@ export class CanvasComponent extends Component { offsetY = (designSize.height - canvasSize.height) * 0.5; } - _tempPos.x = canvasSize.width * 0.5 + offsetX; - _tempPos.y = canvasSize.height * 0.5 + offsetY; - _tempPos.z = 0; + vec3.set(_worldPos, canvasSize.width * 0.5 + offsetX, canvasSize.height * 0.5 + offsetY, 1); } - if (this._pos.equals(_tempPos)) { - this.node.setPosition(_tempPos); + if (!this._pos.equals(_worldPos)){ + this.node.setPosition(_worldPos); } if (this.node.width !== nodeSize.width) { diff --git a/cocos/3d/ui/components/widget-manager.ts b/cocos/3d/ui/components/widget-manager.ts index 0e2090238c..55604849f3 100644 --- a/cocos/3d/ui/components/widget-manager.ts +++ b/cocos/3d/ui/components/widget-manager.ts @@ -558,7 +558,7 @@ export const widgetManager = cc._widgetManager = { l += zero.x; l *= one.x; temp = pos.x - myAP.x * widgetNode.width! * widgetNodeScale.x - l; - if (widget.isAbsoluteLeft) { + if (!widget.isAbsoluteLeft) { temp /= matchSize.width; } @@ -570,7 +570,7 @@ export const widgetManager = cc._widgetManager = { let r = (1 - parentAP.x) * matchSize.width; r += zero.x; temp = (r *= one.x) - (pos.x + (1 - myAP.x) * widgetNode.width! * widgetNodeScale.x); - if (widget.isAbsoluteRight) { + if (!widget.isAbsoluteRight) { temp /= matchSize.width; } From 9dc687bfde46cae312318b5e44f5fcb780a3e10d Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Thu, 25 Apr 2019 11:43:59 +0800 Subject: [PATCH 4/4] Extract enum to avoid circular reference (#4298) --- cocos/3d/physics/cannon-impl.ts | 15 +-- cocos/assets/asset-enum.ts | 113 +++++++++++++++++++++++ cocos/assets/image-asset.ts | 7 +- cocos/assets/texture-base.ts | 116 +----------------------- cocos/renderer/models/skinning-model.ts | 2 +- 5 files changed, 125 insertions(+), 128 deletions(-) create mode 100644 cocos/assets/asset-enum.ts diff --git a/cocos/3d/physics/cannon-impl.ts b/cocos/3d/physics/cannon-impl.ts index 5d43afecf8..f85db9f276 100644 --- a/cocos/3d/physics/cannon-impl.ts +++ b/cocos/3d/physics/cannon-impl.ts @@ -12,7 +12,7 @@ import { IRaycastOptions, LockConstraintBase, PhysicsWorldBase, PointToPointConstraintBase, RigidBodyBase, ShapeBase, SphereShapeBase, } from './api'; -import { ERigidBodyType } from './physic-enum'; +import { ERigidBodyType, ETransformSource } from './physic-enum'; import { RaycastResult } from './raycast-result'; import { stringfyQuat, stringfyVec3 } from './util'; @@ -166,11 +166,6 @@ function fillRaycastResult (result: RaycastResult, cannonResult: CANNON.RaycastR ); } -enum ETransformSource { - Scene, - Physics, -} - export class CannonRigidBody implements RigidBodyBase { get impl (): CANNON.Body { @@ -185,7 +180,7 @@ export class CannonRigidBody implements RigidBodyBase { private _onWorldPostStepListener: (event: CANNON.ICollisionEvent) => any; private _collisionCallbacks: ICollisionCallback[] = []; private _shapes: CannonShape[] = []; - private _transformSource: ETransformSource = ETransformSource.Scene; + private _transformSource: ETransformSource = ETransformSource.SCENE; private _userData: any; private _world: CannonWorld | null = null; private _name: string; @@ -377,7 +372,7 @@ export class CannonRigidBody implements RigidBodyBase { } public isPhysicsManagedTransform (): boolean { - return this._transformSource === ETransformSource.Physics; + return this._transformSource === ETransformSource.PHYSIC; } public getPosition (out: Vec3) { @@ -443,9 +438,9 @@ export class CannonRigidBody implements RigidBodyBase { private _onBodyTypeUpdated () { if (this._cannonBody) { if (this._cannonBody.type === CANNON.Body.STATIC) { - this._transformSource = ETransformSource.Scene; + this._transformSource = ETransformSource.SCENE; } else { - this._transformSource = ETransformSource.Physics; + this._transformSource = ETransformSource.PHYSIC; } } } diff --git a/cocos/assets/asset-enum.ts b/cocos/assets/asset-enum.ts new file mode 100644 index 0000000000..e2b5cfc00e --- /dev/null +++ b/cocos/assets/asset-enum.ts @@ -0,0 +1,113 @@ +import { GFXAddress, GFXFilter, GFXFormat } from '../gfx/define'; + +/** + * The texture pixel format, default value is RGBA8888, + * you should note that textures loaded by normal image files (png, jpg) can only support RGBA8888 format, + * other formats are supported by compressed file types or raw data. + * @enum {number} + */ +export enum PixelFormat { + /** + * 16-bit texture without Alpha channel + */ + RGB565 = GFXFormat.R5G6B5, + /** + * 16-bit textures: RGB5A1 + */ + RGB5A1 = GFXFormat.RGB5A1, + /** + * 16-bit textures: RGBA4444 + */ + RGBA4444 = GFXFormat.RGBA4, + /** + * 24-bit texture: RGB888 + */ + RGB888 = GFXFormat.RGB8, + /** + * 32-bit texture: RGBA8888 + */ + RGBA8888 = GFXFormat.RGBA8, + /** + * 32-bit float texture: RGBA32F + */ + RGBA32F = GFXFormat.RGBA32F, + /** + * 8-bit textures used as masks + */ + A8 = GFXFormat.A8, + /** + * 8-bit intensity texture + */ + I8 = GFXFormat.L8, + /** + * 16-bit textures used as masks + */ + AI8 = GFXFormat.LA8, + /** + * rgb 2 bpp pvrtc + */ + RGB_PVRTC_2BPPV1 = GFXFormat.PVRTC_RGB2, + /** + * rgba 2 bpp pvrtc + */ + RGBA_PVRTC_2BPPV1 = GFXFormat.PVRTC_RGBA2, + /** + * rgb 4 bpp pvrtc + */ + RGB_PVRTC_4BPPV1 = GFXFormat.PVRTC_RGB4, + /** + * rgba 4 bpp pvrtc + */ + RGBA_PVRTC_4BPPV1 = GFXFormat.PVRTC_RGBA4, + /** + * rgb etc1 + */ + RGB_ETC1 = GFXFormat.ETC_RGB8, + /** + * rgb etc2 + */ + RGB_ETC2 = GFXFormat.ETC2_RGB8, + /** + * rgba etc2 + */ + RGBA_ETC2 = GFXFormat.ETC2_RGBA8, +} + +/** + * The texture wrap mode. + * @enum {number} + */ +export enum WrapMode { + /** + * Specifies that the repeat warp mode will be used. + */ + REPEAT = GFXAddress.WRAP, + /** + * Specifies that the clamp to edge warp mode will be used. + */ + CLAMP_TO_EDGE = GFXAddress.CLAMP, + /** + * Specifies that the mirrored repeat warp mode will be used. + */ + MIRRORED_REPEAT = GFXAddress.MIRROR, + /** + * Specifies that the clamp to border wrap mode will be used. + */ + CLAMP_TO_BORDER = GFXAddress.BORDER, +} + +/** + * The texture filter mode + * @enum {number} + */ +export enum Filter { + NONE = GFXFilter.NONE, + /** + * Specifies linear filtering. + */ + LINEAR = GFXFilter.LINEAR, + /** + * Specifies nearest filtering. + */ + NEAREST = GFXFilter.POINT, +} diff --git a/cocos/assets/image-asset.ts b/cocos/assets/image-asset.ts index db05145171..a96b162156 100644 --- a/cocos/assets/image-asset.ts +++ b/cocos/assets/image-asset.ts @@ -24,10 +24,11 @@ ****************************************************************************/ // @ts-check import {ccclass, property} from '../core/data/class-decorator'; -// import {addon} from '../core/utils/js'; -import { Asset } from './asset'; import { EventTargetFactory } from '../core/event/event-target-factory'; import { GFXDevice, GFXFeature } from '../gfx/device'; +// import {addon} from '../core/utils/js'; +import { Asset } from './asset'; +import { PixelFormat } from './asset-enum'; export interface IMemoryImageSource { _data: ArrayBufferView | null; @@ -187,7 +188,7 @@ export class ImageAsset extends EventTargetFactory(Asset) { let format = this._format; let ext = ''; const SupportTextureFormats = cc.macro.SUPPORT_TEXTURE_FORMATS as string[]; - const PixelFormat = cc.TextureBase.PixelFormat; + // const PixelFormat = cc.TextureBase.PixelFormat; for (const extensionID of extensionIDs) { const extFormat = extensionID.split('@'); diff --git a/cocos/assets/texture-base.ts b/cocos/assets/texture-base.ts index 10821ed1a8..5f39c0cc09 100644 --- a/cocos/assets/texture-base.ts +++ b/cocos/assets/texture-base.ts @@ -27,131 +27,19 @@ import {ccclass, property} from '../core/data/class-decorator'; import { EventTargetFactory } from '../core/event/event-target-factory'; import IDGenerator from '../core/utils/id-generator'; -import { GFXAddress, GFXBufferTextureCopy, GFXFilter, GFXFormat, - GFXTextureFlagBit, GFXTextureType, GFXTextureUsageBit, GFXTextureViewType } from '../gfx/define'; +import { GFXBufferTextureCopy, GFXTextureFlagBit, GFXTextureType, GFXTextureUsageBit, GFXTextureViewType } from '../gfx/define'; import { GFXDevice } from '../gfx/device'; import { GFXTexture, IGFXTextureInfo } from '../gfx/texture'; import { GFXTextureView, IGFXTextureViewInfo } from '../gfx/texture-view'; import { SamplerInfoIndex } from '../renderer/core/sampler-lib'; import { Asset } from './asset'; +import { Filter, PixelFormat, WrapMode } from './asset-enum'; import { ImageAsset } from './image-asset'; const CHAR_CODE_1 = 49; // '1' const idGenerator = new IDGenerator('Tex'); -/** - * The texture pixel format, default value is RGBA8888, - * you should note that textures loaded by normal image files (png, jpg) can only support RGBA8888 format, - * other formats are supported by compressed file types or raw data. - * @enum {number} - */ -export enum PixelFormat { - /** - * 16-bit texture without Alpha channel - */ - RGB565 = GFXFormat.R5G6B5, - /** - * 16-bit textures: RGB5A1 - */ - RGB5A1 = GFXFormat.RGB5A1, - /** - * 16-bit textures: RGBA4444 - */ - RGBA4444 = GFXFormat.RGBA4, - /** - * 24-bit texture: RGB888 - */ - RGB888 = GFXFormat.RGB8, - /** - * 32-bit texture: RGBA8888 - */ - RGBA8888 = GFXFormat.RGBA8, - /** - * 32-bit float texture: RGBA32F - */ - RGBA32F = GFXFormat.RGBA32F, - /** - * 8-bit textures used as masks - */ - A8 = GFXFormat.A8, - /** - * 8-bit intensity texture - */ - I8 = GFXFormat.L8, - /** - * 16-bit textures used as masks - */ - AI8 = GFXFormat.LA8, - /** - * rgb 2 bpp pvrtc - */ - RGB_PVRTC_2BPPV1 = GFXFormat.PVRTC_RGB2, - /** - * rgba 2 bpp pvrtc - */ - RGBA_PVRTC_2BPPV1 = GFXFormat.PVRTC_RGBA2, - /** - * rgb 4 bpp pvrtc - */ - RGB_PVRTC_4BPPV1 = GFXFormat.PVRTC_RGB4, - /** - * rgba 4 bpp pvrtc - */ - RGBA_PVRTC_4BPPV1 = GFXFormat.PVRTC_RGBA4, - /** - * rgb etc1 - */ - RGB_ETC1 = GFXFormat.ETC_RGB8, - /** - * rgb etc2 - */ - RGB_ETC2 = GFXFormat.ETC2_RGB8, - /** - * rgba etc2 - */ - RGBA_ETC2 = GFXFormat.ETC2_RGBA8, -} - -/** - * The texture wrap mode. - * @enum {number} - */ -export enum WrapMode { - /** - * Specifies that the repeat warp mode will be used. - */ - REPEAT = GFXAddress.WRAP, - /** - * Specifies that the clamp to edge warp mode will be used. - */ - CLAMP_TO_EDGE = GFXAddress.CLAMP, - /** - * Specifies that the mirrored repeat warp mode will be used. - */ - MIRRORED_REPEAT = GFXAddress.MIRROR, - /** - * Specifies that the clamp to border wrap mode will be used. - */ - CLAMP_TO_BORDER = GFXAddress.BORDER, -} - -/** - * The texture filter mode - * @enum {number} - */ -export enum Filter { - NONE = GFXFilter.NONE, - /** - * Specifies linear filtering. - */ - LINEAR = GFXFilter.LINEAR, - /** - * Specifies nearest filtering. - */ - NEAREST = GFXFilter.POINT, -} - @ccclass('cc.TextureBase') export class TextureBase extends EventTargetFactory(Asset) { diff --git a/cocos/renderer/models/skinning-model.ts b/cocos/renderer/models/skinning-model.ts index bfd49759af..810d8a4e4d 100644 --- a/cocos/renderer/models/skinning-model.ts +++ b/cocos/renderer/models/skinning-model.ts @@ -1,8 +1,8 @@ // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. import Skeleton from '../../3d/assets/skeleton'; +import { Filter, PixelFormat, WrapMode } from '../../assets/asset-enum'; import { Texture2D } from '../../assets/texture-2d'; -import { Filter, PixelFormat, WrapMode } from '../../assets/texture-base'; import { mat4, vec3, vec4 } from '../../core/vmath'; import { GFXBuffer } from '../../gfx/buffer'; import { GFXBufferUsageBit, GFXMemoryUsageBit } from '../../gfx/define';