201 lines
5.3 KiB
JavaScript
201 lines
5.3 KiB
JavaScript
|
|
/**
|
||
|
|
* Nexus Base Room Template
|
||
|
|
*
|
||
|
|
* This is the base template for all Nexus rooms.
|
||
|
|
* Copy and customize this template for new room types.
|
||
|
|
*
|
||
|
|
* Compatible with Three.js r128+
|
||
|
|
*/
|
||
|
|
|
||
|
|
(function() {
|
||
|
|
'use strict';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Configuration object for the room
|
||
|
|
*/
|
||
|
|
const CONFIG = {
|
||
|
|
name: 'base_room',
|
||
|
|
dimensions: {
|
||
|
|
width: 20,
|
||
|
|
height: 10,
|
||
|
|
depth: 20
|
||
|
|
},
|
||
|
|
colors: {
|
||
|
|
primary: '#1A1A2E',
|
||
|
|
secondary: '#16213E',
|
||
|
|
accent: '#D4AF37', // Timmy's gold
|
||
|
|
light: '#E0F7FA', // Sovereignty crystal
|
||
|
|
},
|
||
|
|
lighting: {
|
||
|
|
ambientIntensity: 0.3,
|
||
|
|
accentIntensity: 0.8,
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create the base room
|
||
|
|
* @returns {THREE.Group} The room group
|
||
|
|
*/
|
||
|
|
function createBaseRoom() {
|
||
|
|
const room = new THREE.Group();
|
||
|
|
room.name = CONFIG.name;
|
||
|
|
|
||
|
|
// Create floor
|
||
|
|
createFloor(room);
|
||
|
|
|
||
|
|
// Create walls
|
||
|
|
createWalls(room);
|
||
|
|
|
||
|
|
// Setup lighting
|
||
|
|
setupLighting(room);
|
||
|
|
|
||
|
|
// Add room features
|
||
|
|
addFeatures(room);
|
||
|
|
|
||
|
|
return room;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create the floor
|
||
|
|
*/
|
||
|
|
function createFloor(room) {
|
||
|
|
const floorGeo = new THREE.PlaneGeometry(
|
||
|
|
CONFIG.dimensions.width,
|
||
|
|
CONFIG.dimensions.depth
|
||
|
|
);
|
||
|
|
const floorMat = new THREE.MeshStandardMaterial({
|
||
|
|
color: CONFIG.colors.primary,
|
||
|
|
roughness: 0.8,
|
||
|
|
metalness: 0.2,
|
||
|
|
});
|
||
|
|
const floor = new THREE.Mesh(floorGeo, floorMat);
|
||
|
|
floor.rotation.x = -Math.PI / 2;
|
||
|
|
floor.receiveShadow = true;
|
||
|
|
floor.name = 'floor';
|
||
|
|
room.add(floor);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create the walls
|
||
|
|
*/
|
||
|
|
function createWalls(room) {
|
||
|
|
const wallMat = new THREE.MeshStandardMaterial({
|
||
|
|
color: CONFIG.colors.secondary,
|
||
|
|
roughness: 0.9,
|
||
|
|
metalness: 0.1,
|
||
|
|
side: THREE.DoubleSide
|
||
|
|
});
|
||
|
|
|
||
|
|
const { width, height, depth } = CONFIG.dimensions;
|
||
|
|
|
||
|
|
// Back wall
|
||
|
|
const backWall = new THREE.Mesh(
|
||
|
|
new THREE.PlaneGeometry(width, height),
|
||
|
|
wallMat
|
||
|
|
);
|
||
|
|
backWall.position.set(0, height / 2, -depth / 2);
|
||
|
|
backWall.receiveShadow = true;
|
||
|
|
room.add(backWall);
|
||
|
|
|
||
|
|
// Left wall
|
||
|
|
const leftWall = new THREE.Mesh(
|
||
|
|
new THREE.PlaneGeometry(depth, height),
|
||
|
|
wallMat
|
||
|
|
);
|
||
|
|
leftWall.position.set(-width / 2, height / 2, 0);
|
||
|
|
leftWall.rotation.y = Math.PI / 2;
|
||
|
|
leftWall.receiveShadow = true;
|
||
|
|
room.add(leftWall);
|
||
|
|
|
||
|
|
// Right wall
|
||
|
|
const rightWall = new THREE.Mesh(
|
||
|
|
new THREE.PlaneGeometry(depth, height),
|
||
|
|
wallMat
|
||
|
|
);
|
||
|
|
rightWall.position.set(width / 2, height / 2, 0);
|
||
|
|
rightWall.rotation.y = -Math.PI / 2;
|
||
|
|
rightWall.receiveShadow = true;
|
||
|
|
room.add(rightWall);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Setup lighting
|
||
|
|
*/
|
||
|
|
function setupLighting(room) {
|
||
|
|
// Ambient light
|
||
|
|
const ambientLight = new THREE.AmbientLight(
|
||
|
|
CONFIG.colors.primary,
|
||
|
|
CONFIG.lighting.ambientIntensity
|
||
|
|
);
|
||
|
|
ambientLight.name = 'ambient';
|
||
|
|
room.add(ambientLight);
|
||
|
|
|
||
|
|
// Accent light (Timmy's gold)
|
||
|
|
const accentLight = new THREE.PointLight(
|
||
|
|
CONFIG.colors.accent,
|
||
|
|
CONFIG.lighting.accentIntensity,
|
||
|
|
50
|
||
|
|
);
|
||
|
|
accentLight.position.set(0, 8, 0);
|
||
|
|
accentLight.castShadow = true;
|
||
|
|
accentLight.name = 'accent';
|
||
|
|
room.add(accentLight);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Add room features
|
||
|
|
* Override this function in custom rooms
|
||
|
|
*/
|
||
|
|
function addFeatures(room) {
|
||
|
|
// Base room has minimal features
|
||
|
|
// Custom rooms should override this
|
||
|
|
|
||
|
|
// Example: Add a center piece
|
||
|
|
const centerGeo = new THREE.SphereGeometry(1, 32, 32);
|
||
|
|
const centerMat = new THREE.MeshStandardMaterial({
|
||
|
|
color: CONFIG.colors.accent,
|
||
|
|
emissive: CONFIG.colors.accent,
|
||
|
|
emissiveIntensity: 0.3,
|
||
|
|
roughness: 0.3,
|
||
|
|
metalness: 0.8,
|
||
|
|
});
|
||
|
|
const centerPiece = new THREE.Mesh(centerGeo, centerMat);
|
||
|
|
centerPiece.position.set(0, 2, 0);
|
||
|
|
centerPiece.castShadow = true;
|
||
|
|
centerPiece.name = 'centerpiece';
|
||
|
|
room.add(centerPiece);
|
||
|
|
|
||
|
|
// Animation hook
|
||
|
|
centerPiece.userData.animate = function(time) {
|
||
|
|
this.position.y = 2 + Math.sin(time) * 0.2;
|
||
|
|
this.rotation.y = time * 0.5;
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Dispose of room resources
|
||
|
|
*/
|
||
|
|
function disposeRoom(room) {
|
||
|
|
room.traverse((child) => {
|
||
|
|
if (child.isMesh) {
|
||
|
|
child.geometry.dispose();
|
||
|
|
if (Array.isArray(child.material)) {
|
||
|
|
child.material.forEach(m => m.dispose());
|
||
|
|
} else {
|
||
|
|
child.material.dispose();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// Export
|
||
|
|
if (typeof module !== 'undefined' && module.exports) {
|
||
|
|
module.exports = { createBaseRoom, disposeRoom, CONFIG };
|
||
|
|
} else if (typeof window !== 'undefined') {
|
||
|
|
window.NexusRooms = window.NexusRooms || {};
|
||
|
|
window.NexusRooms.base_room = createBaseRoom;
|
||
|
|
}
|
||
|
|
|
||
|
|
return { createBaseRoom, disposeRoom, CONFIG };
|
||
|
|
})();
|