Medieval Town Visualization (1500s)
Here's a complete HTML file with a detailed 3D visualization of a town from the 1500s using Three.js. The scene includes buildings, streets, a church, market stalls, and environmental elements like trees and a sky.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Medieval Town (1500s)</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000;
}
canvas {
display: block;
}
#info {
position: absolute;
bottom: 10px;
width: 100%;
text-align: center;
color: white;
font-family: Arial, sans-serif;
pointer-events: none;
text-shadow: 1px 1px 1px rgba(0,0,0,0.8);
}
</style>
</head>
<body>
<div id="info">Medieval Town (1500s) - Use mouse to orbit, zoom and pan</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
<script>
// Scene setup
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
// Lighting
const ambientLight = new THREE.AmbientLight(0xcccccc, 0.4);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffcc, 0.8);
directionalLight.position.set(50, 100, 50);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.width = 2048;
directionalLight.shadow.mapSize.height = 2048;
directionalLight.shadow.camera.near = 0.5;
directionalLight.shadow.camera.far = 500;
directionalLight.shadow.camera.left = -100;
directionalLight.shadow.camera.right = 100;
directionalLight.shadow.camera.top = 100;
directionalLight.shadow.camera.bottom = -100;
scene.add(directionalLight);
// Materials
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x8B4513,
roughness: 0.9,
metalness: 0.1
});
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0x808080,
roughness: 0.8,
metalness: 0.2
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x5D4037,
roughness: 0.7,
metalness: 0.1
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: 0x8D6E63,
roughness: 0.9,
metalness: 0.1
});
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xE0E0E0,
roughness: 0.8,
metalness: 0.1
});
const churchMaterial = new THREE.MeshStandardMaterial({
color: 0xD7CCC8,
roughness: 0.7,
metalness: 0.2
});
const treeTrunkMaterial = new THREE.MeshStandardMaterial({
color: 0x5D4037,
roughness: 0.9,
metalness: 0.1
});
const treeLeavesMaterial = new THREE.MeshStandardMaterial({
color: 0x2E7D32,
roughness: 0.8,
metalness: 0.1
});
// Ground
const groundGeometry = new THREE.PlaneGeometry(200, 200);
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.1;
ground.receiveShadow = true;
scene.add(ground);
// Main street
const streetGeometry = new THREE.PlaneGeometry(10, 80);
const streetMaterial = new THREE.MeshStandardMaterial({
color: 0x9E9E9E,
roughness: 0.9,
metalness: 0.1
});
const mainStreet = new THREE.Mesh(streetGeometry, streetMaterial);
mainStreet.rotation.x = -Math.PI / 2;
mainStreet.position.y = 0;
mainStreet.receiveShadow = true;
scene.add(mainStreet);
// Cross street
const crossStreetGeometry = new THREE.PlaneGeometry(80, 8);
const crossStreet = new THREE.Mesh(crossStreetGeometry, streetMaterial);
crossStreet.rotation.x = -Math.PI / 2;
crossStreet.position.y = 0;
crossStreet.receiveShadow = true;
scene.add(crossStreet);
// Function to create a medieval building
function createBuilding(x, z, width, depth, height, type = 'normal') {
const group = new THREE.Group();
// Base building
const buildingGeometry = new THREE.BoxGeometry(width, height, depth);
const buildingMaterial = type === 'church' ? churchMaterial : wallMaterial;
const building = new THREE.Mesh(buildingGeometry, buildingMaterial);
building.position.set(0, height / 2, 0);
building.castShadow = true;
building.receiveShadow = true;
group.add(building);
// Roof
if (type !== 'church') {
const roofHeight = height * 0.5;
const roofGeometry = new THREE.ConeGeometry(width * 0.7, roofHeight, 4);
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.position.set(0, height + roofHeight / 2, 0);
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
group.add(roof);
} else {
// Church tower
const towerGeometry = new THREE.BoxGeometry(width * 0.3, height * 1.5, width * 0.3);
const tower = new THREE.Mesh(towerGeometry, churchMaterial);
tower.position.set(width * 0.3, height + height * 0.75, 0);
tower.castShadow = true;
group.add(tower);
// Church tower roof
const towerRoofGeometry = new THREE.ConeGeometry(width * 0.25, height * 0.5, 4);
const towerRoof = new THREE.Mesh(towerRoofGeometry, roofMaterial);
towerRoof.position.set(width * 0.3, height + height * 1.5 + height * 0.25, 0);
towerRoof.rotation.y = Math.PI / 4;
towerRoof.castShadow = true;
group.add(towerRoof);
// Church roof
const churchRoofGeometry = new THREE.BoxGeometry(width, height * 0.3, depth);
const churchRoof = new THREE.Mesh(churchRoofGeometry, roofMaterial);
churchRoof.position.set(0, height + height * 0.15, 0);
churchRoof.castShadow = true;
group.add(churchRoof);
}
// Windows and doors
if (type !== 'church') {
// Door
const doorGeometry = new THREE.BoxGeometry(width * 0.2, height * 0.4, 0.1);
const door = new THREE.Mesh(doorGeometry, woodMaterial);
door.position.set(0, height * 0.2, depth / 2 + 0.05);
group.add(door);
// Windows
const windowGeometry = new THREE.BoxGeometry(width * 0.15, height * 0.15, 0.1);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xFFFFFF,
roughness: 0.2,
metalness: 0.8,
transparent: true,
opacity: 0.7
});
// Front windows
const frontWindow1 = new THREE.Mesh(windowGeometry, windowMaterial);
frontWindow1.position.set(-width * 0.25, height * 0.6, depth / 2 + 0.05);
group.add(frontWindow1);
const frontWindow2 = new THREE.Mesh(windowGeometry, windowMaterial);
frontWindow2.position.set(width * 0.25, height * 0.6, depth / 2 + 0.05);
group.add(frontWindow2);
// Side windows
const sideWindow1 = new THREE.Mesh(windowGeometry, windowMaterial);
sideWindow1.position.set(width / 2 + 0.05, height * 0.6, 0);
sideWindow1.rotation.y = Math.PI / 2;
group.add(sideWindow1);
const sideWindow2 = new THREE.Mesh(windowGeometry, windowMaterial);
sideWindow2.position.set(-width / 2 - 0.05, height * 0.6, 0);
sideWindow2.rotation.y = Math.PI / 2;
group.add(sideWindow2);
} else {
// Church door
const doorGeometry = new THREE.BoxGeometry(width * 0.3, height * 0.6, 0.1);
const door = new THREE.Mesh(doorGeometry, woodMaterial);
door.position.set(0, height * 0.3, depth / 2 + 0.05);
group.add(door);
// Church windows
const windowGeometry = new THREE.BoxGeometry(width * 0.15, height * 0.3, 0.1);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xE1F5FE,
roughness: 0.2,
metalness: 0.8,
transparent: true,
opacity: 0.7
});
// Front windows
for (let i = -2; i <= 2; i++) {
if (i !== 0) { // Skip center for door
const churchWindow = new THREE.Mesh(windowGeometry, windowMaterial);
churchWindow.position.set(i * width * 0.2, height * 0.6, depth / 2 + 0.05);
group.add(churchWindow);
}
}
// Side windows
for (let i = -2; i <= 2; i++) {
const sideWindow = new THREE.Mesh(windowGeometry, windowMaterial);
sideWindow.position.set(width / 2 + 0.05, height * 0.6, i * depth * 0.2);
sideWindow.rotation.y = Math.PI / 2;
group.add(sideWindow);
const sideWindow2 = new THREE.Mesh(windowGeometry, windowMaterial);
sideWindow2.position.set(-width / 2 - 0.05, height * 0.6, i * depth * 0.2);
sideWindow2.rotation.y = Math.PI / 2;
group.add(sideWindow2);
}
}
group.position.set(x, 0, z);
return group;
}
// Function to create a tree
function createTree(x, z, height) {
const group = new THREE.Group();
// Trunk
const trunkGeometry = new THREE.CylinderGeometry(0.3, 0.5, height * 0.4, 8);
const trunk = new THREE.Mesh(trunkGeometry, treeTrunkMaterial);
trunk.position.y = height * 0.2;
trunk.castShadow = true;
trunk.receiveShadow = true;
group.add(trunk);
// Leaves
const leavesGeometry = new THREE.ConeGeometry(height * 0.3, height * 0.8, 8);
const leaves = new THREE.Mesh(leavesGeometry, treeLeavesMaterial);
leaves.position.y = height * 0.6;
leaves.castShadow = true;
group.add(leaves);
group.position.set(x, 0, z);
return group;
}
// Function to create a market stall
function createMarketStall(x, z, width, depth) {
const group = new THREE.Group();
// Base
const baseGeometry = new THREE.BoxGeometry(width, 0.1, depth);
const base = new THREE.Mesh(baseGeometry, woodMaterial);
base.position.y = 0.05;
base.receiveShadow = true;
group.add(base);
// Counter
const counterGeometry = new THREE.BoxGeometry(width, 0.8, depth * 0.8);
const counter = new THREE.Mesh(counterGeometry, woodMaterial);
counter.position.y = 0.4;
counter.position.z = -depth * 0.1;
counter.castShadow = true;
counter.receiveShadow = true;
group.add(counter);
// Canopy poles
const poleGeometry = new THREE.CylinderGeometry(0.05, 0.05, 2, 8);
const pole1 = new THREE.Mesh(poleGeometry, woodMaterial);
pole1.position.set(width / 2 - 0.1, 1, depth / 2 - 0.1);
pole1.castShadow = true;
group.add(pole1);
const pole2 = new THREE.Mesh(poleGeometry, woodMaterial);
pole2.position.set(-width / 2 + 0.1, 1, depth / 2 - 0.1);
pole2.castShadow = true;
group.add(pole2);
// Canopy
const canopyGeometry = new THREE.BoxGeometry(width + 0.3, 0.05, depth + 0.3);
const canopyMaterial = new THREE.MeshStandardMaterial({
color: 0xFFEB3B,