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

57 lines 2.26 kB
import * as THREE from "three"; import constants from "../constants"; export class TJSPlane { /** * @param game - The game instance * @param initOptions - Initialization options for the plane (width, height, color) * @description Creates a plane in the game scene with the specified width, height, and color. * If no options are provided, default values from constants are used. * The plane is created with a double-sided material. */ constructor(game, initOptions) { this.game = game; this.initOptions = initOptions || {}; } /** * * @param game - The game instance * @description Creates a plane in the game scene with the specified width, height, and color. */ start(game) { var _a, _b, _c; this.game = game; const defaultPlaneOptions = constants.plane; const width = ((_a = this.initOptions) === null || _a === void 0 ? void 0 : _a.width) || defaultPlaneOptions.width; const height = ((_b = this.initOptions) === null || _b === void 0 ? void 0 : _b.height) || defaultPlaneOptions.height; const color = ((_c = this.initOptions) === null || _c === void 0 ? void 0 : _c.color) || defaultPlaneOptions.color; // Create a plane geometry and material this.geometry = new THREE.PlaneGeometry(width, height); this.material = new THREE.MeshBasicMaterial({ color, side: THREE.DoubleSide, }); // Create the mesh and add it to the scene this.mesh = new THREE.Mesh(this.geometry, this.material); this.mesh.rotation.x = -Math.PI / 2; // Rotate to make it horizontal this.game.scene.add(this.mesh); } update(dt, args) { // Method not implemented. } 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(); } } this.mesh = undefined; } } //# sourceMappingURL=TJSPlane%20copy.js.map