Skip to content

Commit

Permalink
Remove MeshRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
felixtrz committed Oct 22, 2023
1 parent b40a017 commit 1adda37
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 50 deletions.
4 changes: 2 additions & 2 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/ecs/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { GameSystem, GameSystemConstructor } from './GameSystem';
import { PhysicsConfig, PhysicsSystem } from '../physics/PhysicsSystem';
import { Scene, THREE } from '../graphics/CustomTHREE';

import { MeshRenderer } from '../graphics/meshes/MeshRendererComponent';
import { Player } from '../xr/Player';
import { SESSION_MODE } from '../constants';

Expand Down Expand Up @@ -109,7 +108,6 @@ export class Core {
private constructor() {
Core._instance = this;
this[PRIVATE].gameManager = this[PRIVATE].ecsyWorld.createEntity();
this.registerGameComponent(MeshRenderer);
}

/** Shortcut for getting the {@link PhysicsConfig} */
Expand Down
30 changes: 0 additions & 30 deletions src/graphics/meshes/MeshRendererComponent.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const FIGLET = String.raw`
export * from './graphics/CustomTHREE';
export { CurvedRaycaster } from './graphics/CurvedRaycaster';
export { GLTFModelLoader } from './graphics/GLTFModelLoader';
export { MeshRenderer } from './graphics/meshes/MeshRendererComponent';

/* -------------------------------------------------------------------------- */
/* Entity Component System */
Expand Down
22 changes: 7 additions & 15 deletions src/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {

import { Collider } from './physics/ColliderComponent';
import { GameObject } from './ecs/GameObject';
import { MeshRenderer } from './graphics/meshes/MeshRendererComponent';
import { RigidBody } from './physics/RigidBodyComponent';

const PRIMITIVE_MATERIAL = new MeshStandardMaterial({ color: 0xffffff });
Expand All @@ -36,26 +35,24 @@ const DEFAULT_CONE_HEIGHT = 1;
const DEFAULT_QUAD_SIZE = 1;

export const createPlanePrimitive = () => {
const gameObject = new GameObject();
const mesh = new Mesh(
new PlaneGeometry(DEFAULT_PLANE_SIZE, DEFAULT_PLANE_SIZE),
PRIMITIVE_MATERIAL,
);
mesh.rotateX(-Math.PI / 2);
gameObject.addComponent(MeshRenderer, { meshRef: mesh });
const gameObject = new GameObject().add(mesh);
gameObject.addComponent(RigidBody, { initConfig: {} });
const shape = new PlaneShape(DEFAULT_PLANE_SIZE, DEFAULT_PLANE_SIZE);
gameObject.addComponent(Collider, { shape: shape });
return gameObject;
};

export const createCubePrimitive = () => {
const gameObject = new GameObject();
const mesh = new Mesh(
new BoxGeometry(DEFAULT_CUBE_SIZE, DEFAULT_CUBE_SIZE, DEFAULT_CUBE_SIZE),
PRIMITIVE_MATERIAL,
);
gameObject.addComponent(MeshRenderer, { meshRef: mesh });
const gameObject = new GameObject().add(mesh);
gameObject.addComponent(RigidBody, { initConfig: {} });
const shape = new CubeShape(
DEFAULT_CUBE_SIZE,
Expand All @@ -67,20 +64,18 @@ export const createCubePrimitive = () => {
};

export const createSpherePrimitive = () => {
const gameObject = new GameObject();
const mesh = new Mesh(
new SphereGeometry(DEFAULT_SPHERE_RADIUS, 32, 32),
PRIMITIVE_MATERIAL,
);
gameObject.addComponent(MeshRenderer, { meshRef: mesh });
const gameObject = new GameObject().add(mesh);
gameObject.addComponent(RigidBody, { initConfig: {} });
const shape = new SphereShape(DEFAULT_SPHERE_RADIUS);
gameObject.addComponent(Collider, { shape: shape });
return gameObject;
};

export const createCylinderPrimitive = () => {
const gameObject = new GameObject();
const mesh = new Mesh(
new CylinderGeometry(
DEFAULT_CYLINDER_RADIUS,
Expand All @@ -90,7 +85,7 @@ export const createCylinderPrimitive = () => {
),
PRIMITIVE_MATERIAL,
);
gameObject.addComponent(MeshRenderer, { meshRef: mesh });
const gameObject = new GameObject().add(mesh);
gameObject.addComponent(RigidBody, { initConfig: {} });
const shape = new CylinderShape(
DEFAULT_CYLINDER_RADIUS,
Expand All @@ -101,12 +96,11 @@ export const createCylinderPrimitive = () => {
};

export const createCapsulePrimitive = () => {
const gameObject = new GameObject();
const mesh = new Mesh(
new CapsuleGeometry(DEFAULT_CAPSULE_RADIUS, DEFAULT_CAPSULE_HEIGHT, 32),
PRIMITIVE_MATERIAL,
);
gameObject.addComponent(MeshRenderer, { meshRef: mesh });
const gameObject = new GameObject().add(mesh);
gameObject.addComponent(RigidBody, { initConfig: {} });
const shape = new CapsuleShape(
DEFAULT_CAPSULE_RADIUS,
Expand All @@ -117,26 +111,24 @@ export const createCapsulePrimitive = () => {
};

export const createConePrimitive = () => {
const gameObject = new GameObject();
const mesh = new Mesh(
new ConeGeometry(DEFAULT_CONE_RADIUS, DEFAULT_CONE_HEIGHT, 32),
PRIMITIVE_MATERIAL,
);
mesh.rotateX(Math.PI / 2);
gameObject.addComponent(MeshRenderer, { meshRef: mesh });
const gameObject = new GameObject().add(mesh);
gameObject.addComponent(RigidBody, { initConfig: {} });
const shape = new ConeShape(DEFAULT_CONE_RADIUS, DEFAULT_CONE_HEIGHT);
gameObject.addComponent(Collider, { shape: shape });
return gameObject;
};

export const createQuadPrimitive = () => {
const gameObject = new GameObject();
const mesh = new Mesh(
new PlaneGeometry(DEFAULT_QUAD_SIZE, DEFAULT_QUAD_SIZE),
PRIMITIVE_MATERIAL,
);
gameObject.addComponent(MeshRenderer, { meshRef: mesh });
const gameObject = new GameObject().add(mesh);
gameObject.addComponent(RigidBody, { initConfig: {} });
const shape = new QuadShape(DEFAULT_QUAD_SIZE, DEFAULT_QUAD_SIZE);
gameObject.addComponent(Collider, { shape: shape });
Expand Down

0 comments on commit 1adda37

Please sign in to comment.