27 lines
831 B
TypeScript
27 lines
831 B
TypeScript
import { Mesh, Vector3 } from 'three';
|
|
import { Brick } from './brick.object';
|
|
import { gameObjectGeometries } from './geometries';
|
|
import type Rapier from '@dimforge/rapier3d';
|
|
|
|
export class Cylinder extends Brick {
|
|
public objectType = 'Cylinder';
|
|
protected mesh = new Mesh(this.geometry, this.material);
|
|
|
|
constructor() {
|
|
super(gameObjectGeometries.cylinderGeometry);
|
|
this.name = this.objectType;
|
|
}
|
|
|
|
protected override createCollider(
|
|
factory: typeof Rapier,
|
|
world: Rapier.World,
|
|
body?: Rapier.RigidBody
|
|
) {
|
|
const scale = this.getWorldScale(new Vector3());
|
|
const height = Math.abs(scale.y) / 2;
|
|
const radius = (Math.abs(scale.x) / 2 + Math.abs(scale.z) / 2) / 2;
|
|
const collider = factory.ColliderDesc.cylinder(height, radius);
|
|
return world.createCollider(collider, body);
|
|
}
|
|
}
|