Files
cocos4/cocos/3d/framework/physics/collider/box-collider-component.ts
T
jiaxin.lai 34c8e6650d Physics builtin (#4547)
* Rename built-in-*** to builtin-***

* Rename r to radius and c to center;

* Add method : transkateAndRotate & setScale to obb & sphere;
Delete unneed class box in box.ts file

* Fix builtin physics Bug of #751 & Modify the physics relative component

* Add macro condition, some method is not declare in builtin

* Rename CC_PHYISCS_*** to CC_PHYSICS_***;

* rename BuiltIn*** to Builtin***

* Typing intersect
2019-06-05 10:27:09 +08:00

69 lines
1.6 KiB
TypeScript

import {
ccclass,
executeInEditMode,
executionOrder,
menu,
property,
} from '../../../../core/data/class-decorator';
import Vec3 from '../../../../core/value-types/vec3';
import { vec3 } from '../../../../core/vmath';
import { BoxShapeBase } from '../../../physics/api';
import { createBoxShape } from '../../../physics/instance';
import { ColliderComponentBase } from './collider-component';
@ccclass('cc.BoxColliderComponent')
@executionOrder(98)
@menu('Components/BoxColliderComponent')
@executeInEditMode
export class BoxColliderComponent extends ColliderComponentBase {
private _shape!: BoxShapeBase;
/// PRIVATE PROPERTY ///
@property
private _size: Vec3 = new Vec3(0, 0, 0);
constructor () {
super();
if (!CC_EDITOR) {
this._shape = createBoxShape(this._size);
this._shape.setUserData(this);
this._shapeBase = this._shape;
}
}
/// COMPONENT LIFECYCLE ///
public onLoad () {
super.onLoad();
if (!CC_EDITOR) {
this.size = this._size;
this._shape.setScale(this.node._scale);
}
}
/// PUBLIC PROPERTY GETTER\SETTER ///
/**
* The size of the box, in local space.
* @note Shall not specify size with component 0.
*/
@property({ type: Vec3 })
get size () {
return this._size;
}
set size (value) {
vec3.copy(this._size, value);
if (!CC_EDITOR) {
this._shape.setSize(this._size);
if (!CC_PHYSICS_BUILT_IN) {
this.sharedBody.body.commitShapeUpdates();
}
}
}
}