diff --git a/cocos/3d/framework/physics/collider-component.ts b/cocos/3d/framework/physics/collider-component.ts index e52c72ee1f..705dc3699e 100644 --- a/cocos/3d/framework/physics/collider-component.ts +++ b/cocos/3d/framework/physics/collider-component.ts @@ -8,16 +8,29 @@ import { import Vec3 from '../../../core/value-types/vec3'; import { vec3 } from '../../../core/vmath'; import { BoxShapeBase, ShapeBase, SphereShapeBase } from '../../physics/api'; -import { createBoxShape, createSphereShape } from '../../physics/instance'; +import { createBoxShape, createSphereShape, ERigidBodyType } from '../../physics/instance'; import { PhysicsBasedComponent } from './detail/physics-based-component'; export class ColliderComponentBase extends PhysicsBasedComponent { protected _shapeBase: ShapeBase | null = null; + @property + private _triggered: boolean = false; + @property + get isTrigger () { return this._triggered; } + set isTrigger (value) { + this._triggered = value; + if (this._body) { + let type = this._triggered ? ERigidBodyType.DYNAMIC : ERigidBodyType.STATIC; + this._body.setType(type); + this._body.setIsTrigger(value); + } + } + /** * The center of the collider, in local space. */ - @property({type: Vec3}) + @property({ type: Vec3 }) get center () { return this._center; } @@ -44,6 +57,7 @@ export class ColliderComponentBase extends PhysicsBasedComponent { if (this._enabled) { this.onEnable(); } + this.isTrigger = this._triggered; } public onEnable () { @@ -92,7 +106,7 @@ export class BoxColliderComponent extends ColliderComponentBase { * The size of the box, in local space. * @note Shall not specify size with component 0. */ - @property({type: Vec3}) + @property({ type: Vec3 }) get size () { return this._size; } diff --git a/cocos/3d/physics/api.d.ts b/cocos/3d/physics/api.d.ts index ba83bf531b..e95f1555da 100644 --- a/cocos/3d/physics/api.d.ts +++ b/cocos/3d/physics/api.d.ts @@ -1,6 +1,7 @@ import { Vec3, Quat } from '../../core/value-types'; import { Node } from '../../scene-graph'; import { RaycastResult } from './raycast-result'; +import { ERigidBodyType } from './instance'; export interface IRaycastOptions { collisionFilterMask?: number; @@ -59,6 +60,10 @@ export class PhysicsWorldBase { export class RigidBodyBase { constructor (options?: ICreateBodyOptions); + /**获取/设置刚体类型 : ERigidBodyType*/ + getType (): ERigidBodyType; + setType (v: ERigidBodyType): void; + addShape (shape: ShapeBase): void; removeShape (shape: ShapeBase): void; @@ -128,7 +133,7 @@ export class RigidBodyBase { getUserData (): any; - setUserData(data: any): void; + setUserData (data: any): void; } export class ShapeBase { @@ -140,7 +145,7 @@ export class ShapeBase { getUserData (): any; - setUserData(data: any): void; + setUserData (data: any): void; } export class SphereShapeBase extends ShapeBase { diff --git a/cocos/3d/physics/cannon-impl.ts b/cocos/3d/physics/cannon-impl.ts index 39c1a2d55b..e8ef421c58 100644 --- a/cocos/3d/physics/cannon-impl.ts +++ b/cocos/3d/physics/cannon-impl.ts @@ -1,7 +1,8 @@ import CANNON from 'cannon'; import { Quat, Vec3 } from '../../core/value-types'; import { quat, vec3 } from '../../core/vmath'; -import { AfterStepCallback, BeforeStepCallback, +import { + AfterStepCallback, BeforeStepCallback, BoxShapeBase, ConstraintBase, DistanceConstraintBase, ICollisionCallback, ICollisionEvent, @@ -9,9 +10,11 @@ import { AfterStepCallback, BeforeStepCallback, ILockConstraintOptions, IPointToPointConstraintOptions, IRaycastOptions, LockConstraintBase, PhysicsWorldBase, - PointToPointConstraintBase, RigidBodyBase, ShapeBase, SphereShapeBase } from './api'; + PointToPointConstraintBase, RigidBodyBase, ShapeBase, SphereShapeBase +} from './api'; import { RaycastResult } from './raycast-result'; import { stringfyQuat, stringfyVec3 } from './util'; +import { ERigidBodyType } from './instance'; const defaultCannonMaterial = new CANNON.Material(''); const defaultCannonContactMaterial = new CANNON.ContactMaterial( @@ -32,7 +35,7 @@ export class CannonWorld implements PhysicsWorldBase { constructor () { this._cannonWorld = new CANNON.World(); setWrap(this._cannonWorld, this); - this._cannonWorld.allowSleep = true; + // this._cannonWorld.allowSleep = true; this._cannonWorld.gravity.set(0, -9.81, 0); this._cannonWorld.broadphase = new CANNON.NaiveBroadphase(); this._cannonWorld.defaultMaterial = defaultCannonMaterial; @@ -216,6 +219,14 @@ export class CannonRigidBody implements RigidBodyBase { return this._name; } + public getType (): ERigidBodyType { + return this._cannonBody.type; + } + + public setType (v: ERigidBodyType): void { + this._cannonBody.type = v; + } + public addShape (shape: CannonShape) { const index = this._shapes.length; this._shapes.push(shape); @@ -296,7 +307,7 @@ export class CannonRigidBody implements RigidBodyBase { } public setIsTrigger (value: boolean): void { - this._cannonBody.collisionResponse = value; + this._cannonBody.collisionResponse = !value; } public getVelocity (): Vec3 { diff --git a/cocos/3d/physics/instance.ts b/cocos/3d/physics/instance.ts index fa4d8f93fb..acdbdeeb68 100644 --- a/cocos/3d/physics/instance.ts +++ b/cocos/3d/physics/instance.ts @@ -3,6 +3,12 @@ import { BoxShapeBase, ICreateBodyOptions, PhysicsWorldBase, RigidBodyBase, Sphe import { BoxShape, PhysicsWorld, RigidBody, SphereShape } from './impl-selector'; import { RaycastResult } from './raycast-result'; +export enum ERigidBodyType { + DYNAMIC = 1, + STATIC = 2, + KINEMATIC = 4 +} + export function createPhysicsWorld (): PhysicsWorldBase { return new PhysicsWorld(); } diff --git a/cocos/animation/types.ts b/cocos/animation/types.ts index 60594f784a..d635c55a70 100644 --- a/cocos/animation/types.ts +++ b/cocos/animation/types.ts @@ -72,7 +72,7 @@ export class WrappedInfo { public direction = 1; public stopped = true; public iterations = 0; - public frameIndex: number = NaN; + public frameIndex: number = undefined as unknown as number; constructor (info?: WrappedInfo) { if (info) { diff --git a/cocos/assets/image-asset.ts b/cocos/assets/image-asset.ts index a9cb0a99d8..0f3cf193f3 100644 --- a/cocos/assets/image-asset.ts +++ b/cocos/assets/image-asset.ts @@ -24,7 +24,7 @@ ****************************************************************************/ // @ts-check import {ccclass, property} from '../core/data/class-decorator'; -import {addon} from '../core/utils/js'; +// import {addon} from '../core/utils/js'; import { Asset } from './asset'; import { EventTargetFactory } from '../core/event/event-target-factory'; @@ -121,7 +121,8 @@ export class ImageAsset extends EventTargetFactory(Asset) { public reset (data: ImageSource) { if (!(data instanceof HTMLElement)) { - this._nativeData = Object.create(data); + // this._nativeData = Object.create(data); + this._nativeData = data; this._onDataComplete(); } else { this._nativeData = data; @@ -220,8 +221,8 @@ export class ImageAsset extends EventTargetFactory(Asset) { * !#en * This event is emitted when the asset is loaded * - * @event load + * @event loads */ -addon(ImageAsset.prototype, EventTarget.prototype); +// addon(ImageAsset.prototype, EventTarget.prototype); cc.ImageAsset = ImageAsset; diff --git a/cocos/core/event/event-target-factory.ts b/cocos/core/event/event-target-factory.ts index c089078e2a..4d087a6ff2 100644 --- a/cocos/core/event/event-target-factory.ts +++ b/cocos/core/event/event-target-factory.ts @@ -8,7 +8,7 @@ type Constructor = new(...args: any[]) => T; export type IEventTargetCallback = (...args: any[]) => void; -class Empty { protected constructor () {}; } +class Empty { protected constructor () {} } export function EventTargetFactory> (b?: Base) { let base = b; diff --git a/cocos/scene-graph/node-event-processor.ts b/cocos/scene-graph/node-event-processor.ts index ca309a7eaa..985a7349e1 100644 --- a/cocos/scene-graph/node-event-processor.ts +++ b/cocos/scene-graph/node-event-processor.ts @@ -517,6 +517,32 @@ export class NodeEventProcessor { _cachedArray.length = 0; } + public hasEventListener (type: string) { + let has = false; + if (this.bubblingTargets) { + has = this.bubblingTargets.hasEventListener(type); + } + if (!has && this.capturingTargets) { + has = this.capturingTargets.hasEventListener(type); + } + return has; + } + + public targetOff (target: string | Object) { + if (this.capturingTargets) { + this.capturingTargets.targetOff(target); + } + + if (this.touchListener && !_checkListeners(this.node, _touchEvents)) { + eventManager.removeListener(this.touchListener); + this.touchListener = null; + } + if (this.mouseListener && !_checkListeners(this.node, _mouseEvents)) { + eventManager.removeListener(this.mouseListener); + this.mouseListener = null; + } + } + // EVENT TARGET private _checknSetupSysEvent (type: string) { diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 471d8b0834..39a2ca20f3 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -1,5 +1,7 @@ import { UITransformComponent } from '../3d/ui/components/ui-transfrom-component'; import { ccclass, property } from '../core/data/class-decorator'; +import Event from '../core/event/event'; +import { eventManager } from '../core/platform/event-manager'; import { EventType } from '../core/platform/event-manager/event-enum'; import { Mat4, Quat, Vec3 } from '../core/value-types'; import Size from '../core/value-types/size'; @@ -773,7 +775,7 @@ class Node extends BaseNode { this.uiTransfromComp!.setContentSize(size, height); } - // Event + // Event: maybe remove public on (type: string | EventType, callback: Function, target?: Object, useCapture?: any) { this._eventProcessor.on(type, callback, target, useCapture); @@ -783,17 +785,33 @@ class Node extends BaseNode { this._eventProcessor.off(type, callback, target, useCapture); } - public once (type, callback, target, useCapture) { + public once (type: string, callback: Function, target?: Object, useCapture?: any) { this._eventProcessor.once(type, callback, target, useCapture); } - public emit (type, ...args: any[]) { + public emit (type: string, ...args: any[]) { this._eventProcessor.emit(type, ...args); } - public dispatchEvent (event) { + public dispatchEvent (event: Event) { this._eventProcessor.dispatchEvent(event); } + + public hasEventListener (type: string){ + return this._eventProcessor.hasEventListener(type); + } + + public targetOff (target: string | Object) { + this._eventProcessor.targetOff(target); + } + + public pauseSystemEvents (recursive: boolean) { + eventManager.pauseTarget(this, recursive); + } + + public resumeSystemEvents (recursive: boolean) { + eventManager.resumeTarget(this, recursive); + } } if (CC_EDITOR) { diff --git a/predefine.js b/predefine.js index 963c63ff30..9e8395d1d5 100644 --- a/predefine.js +++ b/predefine.js @@ -179,6 +179,10 @@ else { defineMacro('CC_SUPPORT_JIT', !(CC_WECHATGAME || CC_QQPLAY || CC_RUNTIME)); } +//#begin test code for wechat +// _global['CC_SUPPORT_JIT'] = false; +//#end + // if (CC_DEV) { diff --git a/rollup/build-engine.ts b/rollup/build-engine.ts index 4a437caf29..613974839e 100644 --- a/rollup/build-engine.ts +++ b/rollup/build-engine.ts @@ -83,19 +83,19 @@ async function _doBundle (options: IBuildOptions) { code = generated.code; - console.log(`Doing uglify...`); - - const minifyOutput = minify(code, { - compress: { - global_defs: options.globalDefines, - }, - }); - if (minifyOutput.error) { - console.error(minifyOutput.error.stack); - return null; - } else { - code = minifyOutput.code; - } + // console.log(`Doing uglify...`); + + // const minifyOutput = minify(code, { + // compress: { + // global_defs: options.globalDefines, + // }, + // }); + // if (minifyOutput.error) { + // console.error(minifyOutput.error.stack); + // return null; + // } else { + // code = minifyOutput.code; + // } return { code,