mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
1a99b886b6
* basic physics abstract spec * spec tweaks * stash * cannon refactor * builtin refactor * cannon wrapper & framework tweaks * cannon wrapper import tweaks * remve unneeded code * group mask tweaks * hiding, wait for 1.0.3 * builtin tweaks * delete unneed code * export CANNON * update @cocos/cannon to 1.0.3 * using hasTigger property * fix remove cannon body * rebase * update cannon version to 1.0.4 * rename stash * rename I-rigid-body to i-rigid-body
86 lines
2.1 KiB
TypeScript
86 lines
2.1 KiB
TypeScript
|
|
// @ts-check
|
|
|
|
/**
|
|
* @category physics
|
|
*/
|
|
|
|
import { Asset } from '../../../core/assets/asset';
|
|
import { ccclass, property } from '../../../core/data/class-decorator';
|
|
import { math } from '../../../core';
|
|
|
|
@ccclass('cc.PhysicMaterial')
|
|
export class PhysicMaterial extends Asset {
|
|
|
|
public static allMaterials: PhysicMaterial[] = [];
|
|
|
|
private static _idCounter: number = 0;
|
|
|
|
@property
|
|
private _friction = 0.1;
|
|
|
|
@property
|
|
private _restitution = 0.1;
|
|
|
|
/**
|
|
* Friction for this material.
|
|
* If non-negative, it will be used instead of the friction given by ContactMaterials.
|
|
* If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used.
|
|
*/
|
|
@property
|
|
get friction () {
|
|
return this._friction;
|
|
}
|
|
|
|
set friction (value) {
|
|
if (!math.equals(this._friction, value)) {
|
|
this._friction = value;
|
|
this.emit('physics_material_update');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Restitution for this material.
|
|
* If non-negative, it will be used instead of the restitution given by ContactMaterials.
|
|
* If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used
|
|
*/
|
|
@property
|
|
get restitution () {
|
|
return this._restitution;
|
|
}
|
|
|
|
set restitution (value) {
|
|
if (!math.equals(this._restitution, value)) {
|
|
this._restitution = value;
|
|
this.emit('physics_material_update');
|
|
}
|
|
}
|
|
|
|
constructor () {
|
|
super();
|
|
PhysicMaterial.allMaterials.push(this);
|
|
if (this._uuid == '') {
|
|
this._uuid = 'pm_' + PhysicMaterial._idCounter++;
|
|
}
|
|
}
|
|
|
|
public clone () {
|
|
let c = new PhysicMaterial();
|
|
c._friction = this._friction;
|
|
c._restitution = this._restitution;
|
|
return c;
|
|
}
|
|
|
|
public destroy (): boolean {
|
|
if (super.destroy()) {
|
|
let idx = PhysicMaterial.allMaterials.indexOf(this);
|
|
if (idx >= 0) {
|
|
PhysicMaterial.allMaterials.splice(idx, 1);
|
|
}
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
} |