52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { BoxGeometry, CylinderGeometry, SphereGeometry } from 'three';
|
|
|
|
class GameObjectFactory {
|
|
public boxGeometry = new BoxGeometry();
|
|
public sphereGeometry = new SphereGeometry(0.5);
|
|
public cylinderGeometry = new CylinderGeometry(0.5, 0.5);
|
|
public wedgeGeometry = new BoxGeometry();
|
|
public wedgeCornerGeometry = new BoxGeometry();
|
|
public wedgeInnerCornerGeometry = new BoxGeometry();
|
|
|
|
constructor() {
|
|
this.makeProceduralShapes();
|
|
this.finalize();
|
|
}
|
|
|
|
private makeProceduralShapes() {
|
|
const pos = this.wedgeGeometry.attributes.position;
|
|
for (let i = 0; i < pos.count; i++) {
|
|
if (pos.getX(i) < 0 && pos.getY(i) > 0) pos.setY(i, -0.5);
|
|
}
|
|
this.wedgeGeometry.computeVertexNormals();
|
|
|
|
const pos2 = this.wedgeCornerGeometry.attributes.position;
|
|
for (let i = 0; i < pos2.count; i++) {
|
|
if (pos2.getY(i) > 0 && (pos2.getX(i) !== 0.5 || pos2.getZ(i) !== -0.5)) {
|
|
pos2.setY(i, -0.5);
|
|
}
|
|
}
|
|
this.wedgeCornerGeometry.computeVertexNormals();
|
|
|
|
const pos3 = this.wedgeInnerCornerGeometry.attributes.position;
|
|
for (let i = 0; i < pos3.count; i++) {
|
|
if (pos3.getY(i) > 0 && pos3.getX(i) === 0.5 && pos3.getZ(i) === 0.5) {
|
|
pos3.setY(i, -0.5);
|
|
}
|
|
}
|
|
this.wedgeInnerCornerGeometry.computeVertexNormals();
|
|
}
|
|
|
|
private finalize() {
|
|
this.boxGeometry.computeBoundingBox();
|
|
this.sphereGeometry.computeBoundingBox();
|
|
this.cylinderGeometry.computeBoundingBox();
|
|
this.wedgeGeometry.computeBoundingBox();
|
|
this.wedgeCornerGeometry.computeBoundingBox();
|
|
this.wedgeInnerCornerGeometry.computeBoundingBox();
|
|
}
|
|
}
|
|
|
|
export const gameObjectFactory = new GameObjectFactory();
|
|
Object.freeze(gameObjectFactory);
|