/
physic-material.ts
86 lines (70 loc) · 2.14 KB
/
physic-material.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// @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;
}
}
}