UNPKG

3js-game-framework

Version:

3js-game-framework is a lightweight and flexible framework designed to streamline the creation of 3D games and interactive applications using Three.js

55 lines 2.17 kB
import * as THREE from "three"; import constants from "../constants"; export class TJSBox { /** * @param game - The game instance * @param options - Initial options for the box (width, height, depth, color) * @description Creates a box in the game scene with the specified width, height, and color. * If no options are provided, default values from constants are used. */ constructor(game, options = {}) { this.name = "TJSBox"; this.game = game; const defaultBoxOptions = constants.box; const width = (options === null || options === void 0 ? void 0 : options.width) || defaultBoxOptions.width; const height = (options === null || options === void 0 ? void 0 : options.height) || defaultBoxOptions.height; const depth = (options === null || options === void 0 ? void 0 : options.depth) || defaultBoxOptions.depth; const color = (options === null || options === void 0 ? void 0 : options.color) || defaultBoxOptions.color; // Create box geometry this.geometry = new THREE.BoxGeometry(width, height, depth); // Create basic material this.material = options.material || new THREE.MeshBasicMaterial({ color }); // Create the mesh and add it to the scene this.mesh = new THREE.Mesh(this.geometry, this.material); } /** * * @description Creates a box in the game scene with the specified width, height, and color. */ start() { if (this.game) { this.game.scene.add(this.mesh); } else { console.warn("game is undefined in:", this.name); } } update(dt) { // Update logic can be added here if needed } end() { if (this.mesh) { this.game.scene.remove(this.mesh); this.mesh.geometry.dispose(); if (Array.isArray(this.mesh.material)) { this.mesh.material.forEach((material) => { material.dispose(); }); } else { this.mesh.material.dispose(); } } } } //# sourceMappingURL=TJSBox.js.map