diff --git a/cocos/3d/framework/physics/detail/physics-based-component.ts b/cocos/3d/framework/physics/detail/physics-based-component.ts index 899a7585ad..4c1ac33fb3 100644 --- a/cocos/3d/framework/physics/detail/physics-based-component.ts +++ b/cocos/3d/framework/physics/detail/physics-based-component.ts @@ -94,6 +94,7 @@ class SharedRigidBody { this._afterStepCallback = this._afterStep.bind(this); this._onCollidedCallback = this._onCollided.bind(this); this._body.addCollisionCallback(this._onCollidedCallback); + this._world.addBeforeStep(this._beforeStepCallback); } public get body () { @@ -155,12 +156,14 @@ class SharedRigidBody { } private _activeBody () { + if (!this._transformInitialized) { + return; + } if (this._actived) { return; } this._actived = true; this._body.setWorld(this._world); - this._world.addBeforeStep(this._beforeStepCallback); this._world.addAfterStep(this._afterStepCallback); } @@ -194,9 +197,11 @@ class SharedRigidBody { if (!this._transformInitialized) { // d(`Initialize`); this.syncPhysWithScene(this._node); + this._activeBody(); } else if (!this.body.isPhysicsManagedTransform() && this._node.hasChanged) { // d(`Synchronize`); this.syncPhysWithScene(this._node); + this._activeBody(); } } diff --git a/cocos/3d/framework/physics/physics-system.ts b/cocos/3d/framework/physics/physics-system.ts index 27c0083e63..5680237bca 100644 --- a/cocos/3d/framework/physics/physics-system.ts +++ b/cocos/3d/framework/physics/physics-system.ts @@ -5,6 +5,7 @@ export class PhysicsSystem { private _world: PhysicsWorldBase; private _paused = false; private _singleStep = false; + private _deltaTime = 1.0 / 60.0; constructor () { this._world = createPhysicsWorld(); @@ -29,7 +30,7 @@ export class PhysicsSystem { if (this._paused) { return; } - this._world.step(deltaTime); + this._world.step(this._deltaTime); if (this._singleStep) { this._paused = true; } diff --git a/cocos/3d/physics/cannon-impl.ts b/cocos/3d/physics/cannon-impl.ts index 968dde3055..39c1a2d55b 100644 --- a/cocos/3d/physics/cannon-impl.ts +++ b/cocos/3d/physics/cannon-impl.ts @@ -27,6 +27,7 @@ export class CannonWorld implements PhysicsWorldBase { private _onCannonPreStepListener: Function; private _onCannonPostStepListener: Function; private _cannonRaycastResult = new CANNON.RaycastResult(); + // private _initedBodys = new Set(); constructor () { this._cannonWorld = new CANNON.World(); @@ -59,6 +60,19 @@ export class CannonWorld implements PhysicsWorldBase { public step (deltaTime: number) { this._callCustomBeforeSteps(); + + // const initBodys: CannonRigidBody[] = []; + // this._cannonWorld.bodies.forEach((b) => { + // const body = getWrap(b); + // if (!this._initedBodys.has(body)) { + // this._initedBodys.add(body); + // initBodys.push(body); + // } + // }); + // if (initBodys.length !== 0) { + // console.log(`Frame ${this._cannonWorld.stepnumber} add bodys:\n${initBodys.map((b) => b._devStrinfy()).join('\n')}`); + // } + this._cannonWorld.step(deltaTime); this._callCustomAfterSteps(); } @@ -223,8 +237,8 @@ export class CannonRigidBody implements RigidBodyBase { } public commitShapeUpdates () { - this._cannonBody.updateMassProperties(); this._cannonBody.updateBoundingRadius(); + this._cannonBody.updateMassProperties(); } public getMass () { @@ -308,11 +322,13 @@ export class CannonRigidBody implements RigidBodyBase { position = new Vec3(); vec3.copy(position, this._cannonBody.position); } + this._cannonBody.wakeUp(); this._cannonBody.applyForce(toCannonVec3(force), toCannonVec3(position)); } public applyImpulse (impulse: Vec3) { - this._cannonBody.applyImpulse(toCannonVec3(impulse), toCannonVec3(new Vec3())); + this._cannonBody.wakeUp(); + this._cannonBody.applyImpulse(toCannonVec3(impulse), this._cannonBody.position); } public setCollisionFilter (group: number, mask: number) { @@ -392,6 +408,11 @@ export class CannonRigidBody implements RigidBodyBase { return `${this._name.length ? this._name : ''}`; } + public _devStrinfy () { + const shapes = this._cannonBody.shapes.map((s) => getWrap(s)._devStrinfy()).join('; '); + return `Name: [[${this._name.length ? this._name : ''}]], position: ${stringfyVec3(this._cannonBody.position)}, shapes: [${shapes}]`; + } + private _resetBodyTypeAccordingMess () { if (this._cannonBody.mass <= 0) { this._cannonBody.type = CANNON.Body.STATIC; @@ -510,6 +531,13 @@ export class CannonShape implements ShapeBase { } + public _devStrinfy () { + if (!this._body) { + return ``; + } + return `centerOffset: ${stringfyVec3(this._body.shapeOffsets[this._index])}`; + } + private _recalcCenter () { if (!this._body) { return; @@ -544,6 +572,10 @@ export class CannonSphereShape extends CannonShape implements SphereShapeBase { this._recalcRadius(); } + public _devStrinfy () { + return `Sphere(${super._devStrinfy()}, radius: ${this._cannonSphere.radius})`; + } + private _recalcRadius () { this._cannonSphere.radius = this._radius * maxComponent(this._scale); // console.log(`[[CANNON]] Set sphere radius to ${this._cannonSphere.radius}.`); @@ -578,6 +610,10 @@ export class CannonBoxShape extends CannonShape implements BoxShapeBase { return `${this._body ? getWrap(this._body)._stringfyThis() : ''}(Box)`; } + public _devStrinfy () { + return `Box(${super._devStrinfy()}, halfExtents: ${stringfyVec3(this._cannonBox.halfExtents)})`; + } + private _recalcExtents () { vec3.multiply(this._cannonBox.halfExtents, this._halfExtent, this._scale); // console.log(`[[CANNON]] Set ${this._stringfyThis()} half extents to ${stringfyVec3(this._cannonBox.halfExtents)}.`); diff --git a/cocos/3d/ui/components/canvas-component.ts b/cocos/3d/ui/components/canvas-component.ts index 1fce47f4cc..4585cc39f5 100644 --- a/cocos/3d/ui/components/canvas-component.ts +++ b/cocos/3d/ui/components/canvas-component.ts @@ -182,7 +182,7 @@ export class CanvasComponent extends Component { }); this._camera!.fov = 45; - this._camera!.clearFlag = GFXClearFlag.DEPTH | GFXClearFlag.STENCIL; + this._camera!.clearFlag = GFXClearFlag.COLOR | GFXClearFlag.DEPTH | GFXClearFlag.STENCIL; const device = cc.director.root.device; this._camera!.resize(device.width, device.height); diff --git a/cocos/assets/CCAssetLibrary.js b/cocos/assets/CCAssetLibrary.js index fb6020b08a..039b398037 100644 --- a/cocos/assets/CCAssetLibrary.js +++ b/cocos/assets/CCAssetLibrary.js @@ -120,7 +120,7 @@ let AssetLibrary = { asset.scene.dependAssets = getDependsRecursively(key); } } - if (CC_EDITOR || isScene(asset)) { + if (isScene(asset)) { var id = cc.loader._getReferenceKey(uuid); cc.loader.removeItem(id); } diff --git a/cocos/load-pipeline/CCLoader.js b/cocos/load-pipeline/CCLoader.js index d67269edd1..49354c26b8 100644 --- a/cocos/load-pipeline/CCLoader.js +++ b/cocos/load-pipeline/CCLoader.js @@ -270,13 +270,6 @@ class CCLoader extends Pipeline { completeCallback = null; } - if (CC_EDITOR) { - for (let id in self._cache) { - if (self._cache[id].complete) { - self.removeItem(id); - } - } - } items.destroy(); }); });