mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
Merge branch '3d-stable' of https://github.com/cocos-creator/engine into 3d
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ export class CannonWorld implements PhysicsWorldBase {
|
||||
private _onCannonPreStepListener: Function;
|
||||
private _onCannonPostStepListener: Function;
|
||||
private _cannonRaycastResult = new CANNON.RaycastResult();
|
||||
// private _initedBodys = new Set<CannonRigidBody>();
|
||||
|
||||
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<CannonRigidBody>(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 : '<No-name>'}`;
|
||||
}
|
||||
|
||||
public _devStrinfy () {
|
||||
const shapes = this._cannonBody.shapes.map((s) => getWrap<CannonShape>(s)._devStrinfy()).join('; ');
|
||||
return `Name: [[${this._name.length ? this._name : '<No-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 `<NotAttached>`;
|
||||
}
|
||||
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<CannonRigidBody>(this._body)._stringfyThis() : '<No-body>'}(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)}.`);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user