File size: 4,226 Bytes
7668be8 555f4de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>3D Apartment Visualization</title>
<!-- Content Security Policy: relax eval restrictions -->
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline';"
/>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #202020;
}
canvas {
display: block;
}
</style>
</head>
<body>
<script type="module">
// Import Three.js and OrbitControls directly from the CDN.
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js';
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js';
// Set up the scene.
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x202020);
// Set up the camera.
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(100, 100, 300);
// Set up the renderer.
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Set up OrbitControls.
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
// Apartment data.
const apartments = [
{ rank: 1, pricePerSqm: 90788, block: 'D' },
{ rank: 2, pricePerSqm: 95584, block: 'D' },
{ rank: 3, pricePerSqm: 96545, block: 'C' },
{ rank: 4, pricePerSqm: 100171, block: 'C' },
{ rank: 5, pricePerSqm: 101833, block: 'C' },
{ rank: 6, pricePerSqm: 102200, block: 'B' },
{ rank: 7, pricePerSqm: 106238, block: 'D' },
{ rank: 8, pricePerSqm: 106327, block: 'B' },
{ rank: 9, pricePerSqm: 107423, block: 'B' },
{ rank: 10, pricePerSqm: 109136, block: 'A' }
];
// Create a group to hold all apartment spheres.
const apartmentGroup = new THREE.Group();
scene.add(apartmentGroup);
// Define colors for the blocks.
const blockColors = {
'A': 0xff0000,
'B': 0x0000ff,
'C': 0x00ff00,
'D': 0xffff00
};
// Create a sphere for each apartment.
apartments.forEach(apartment => {
// Calculate position based on apartment data.
const x = apartment.rank * 30;
const y = -(apartment.pricePerSqm - 90000) / 50;
let z;
switch (apartment.block) {
case 'A':
z = 0;
break;
case 'B':
z = 100;
break;
case 'C':
z = 200;
break;
case 'D':
z = 300;
break;
default:
z = 0;
}
// Create the sphere geometry and material.
const geometry = new THREE.SphereGeometry(5, 16, 16);
const material = new THREE.MeshPhongMaterial({
color: blockColors[apartment.block] || 0xffffff
});
const sphere = new THREE.Mesh(geometry, material);
sphere.position.set(x, y, z);
apartmentGroup.add(sphere);
});
// Add lighting.
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(0, 1, 1);
scene.add(directionalLight);
// Handle window resize.
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Animation loop.
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
|