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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="ar" dir="rtl">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>THE Z-CRAFT PRO | BY THE ZYZ STUDIO</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--primary-color: #4CAF50;
|
| 10 |
+
--bg-dark: rgba(0, 0, 0, 0.9);
|
| 11 |
+
--accent-color: #f1c40f;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
body { margin: 0; overflow: hidden; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #000; }
|
| 15 |
+
canvas { display: block; }
|
| 16 |
+
|
| 17 |
+
/* شاشة البداية */
|
| 18 |
+
#overlay {
|
| 19 |
+
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
|
| 20 |
+
background: var(--bg-dark); color: white;
|
| 21 |
+
display: flex; flex-direction: column; justify-content: center; align-items: center;
|
| 22 |
+
z-index: 1000; transition: opacity 0.5s ease;
|
| 23 |
+
}
|
| 24 |
+
#overlay h1 { font-size: 5rem; margin-bottom: 10px; color: var(--primary-color); text-shadow: 4px 4px #000; letter-spacing: 5px; }
|
| 25 |
+
#overlay p { font-size: 1.2rem; margin-bottom: 30px; opacity: 0.8; }
|
| 26 |
+
|
| 27 |
+
.menu-btn {
|
| 28 |
+
padding: 15px 50px; font-size: 1.5rem; cursor: pointer;
|
| 29 |
+
background: var(--primary-color); color: white; border: none; border-radius: 8px;
|
| 30 |
+
transition: 0.3s; box-shadow: 0 6px #2E7D32; font-weight: bold; margin: 10px;
|
| 31 |
+
}
|
| 32 |
+
.menu-btn:hover { background: #66BB6A; transform: translateY(-3px); box-shadow: 0 9px #2E7D32; }
|
| 33 |
+
|
| 34 |
+
/* واجهة الإعدادات */
|
| 35 |
+
#settings-menu {
|
| 36 |
+
position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 37 |
+
background: rgba(40, 40, 40, 0.98); color: white; padding: 30px;
|
| 38 |
+
border-radius: 15px; display: none; z-index: 2000; border: 4px solid var(--primary-color);
|
| 39 |
+
min-width: 350px; box-shadow: 0 0 30px rgba(0,0,0,0.5);
|
| 40 |
+
}
|
| 41 |
+
.setting-item { display: flex; justify-content: space-between; margin: 15px 0; align-items: center; font-size: 1.1rem; }
|
| 42 |
+
.key-btn {
|
| 43 |
+
background: #444; color: #fff; border: 2px solid #666;
|
| 44 |
+
padding: 8px 15px; cursor: pointer; width: 100px; text-align: center; border-radius: 5px;
|
| 45 |
+
}
|
| 46 |
+
.key-btn.waiting { background: var(--accent-color); color: #000; animation: blink 0.5s infinite; border-color: #fff; }
|
| 47 |
+
@keyframes blink { 50% { opacity: 0.5; } }
|
| 48 |
+
|
| 49 |
+
/* شريط الأدوات (Hotbar) */
|
| 50 |
+
#hotbar {
|
| 51 |
+
position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
|
| 52 |
+
display: flex; gap: 12px; background: rgba(0,0,0,0.6); padding: 12px;
|
| 53 |
+
border-radius: 15px; border: 3px solid #fff;
|
| 54 |
+
}
|
| 55 |
+
.slot {
|
| 56 |
+
width: 55px; height: 55px; border: 4px solid #555;
|
| 57 |
+
display: flex; justify-content: center; align-items: center;
|
| 58 |
+
background: #777; position: relative; transition: 0.2s;
|
| 59 |
+
}
|
| 60 |
+
.slot.active { border-color: var(--accent-color); box-shadow: 0 0 20px var(--accent-color); background: #aaa; transform: scale(1.1); }
|
| 61 |
+
.slot-num { position: absolute; top: 2px; right: 4px; font-size: 12px; color: white; font-weight: bold; }
|
| 62 |
+
.block-preview { width: 30px; height: 30px; border: 1px solid #000; }
|
| 63 |
+
|
| 64 |
+
#crosshair {
|
| 65 |
+
position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
| 66 |
+
color: white; font-size: 28px; pointer-events: none; user-select: none;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
#instructions {
|
| 70 |
+
position: absolute; top: 20px; left: 20px; color: white;
|
| 71 |
+
background: rgba(0,0,0,0.5); padding: 15px; border-radius: 10px; font-size: 14px;
|
| 72 |
+
border-left: 5px solid var(--primary-color);
|
| 73 |
+
}
|
| 74 |
+
</style>
|
| 75 |
+
</head>
|
| 76 |
+
<body>
|
| 77 |
+
|
| 78 |
+
<div id="overlay">
|
| 79 |
+
<h1>THE Z-CRAFT</h1>
|
| 80 |
+
<p>صنع بواسطة The ZYZ Studio | Yassine Hamrouni</p>
|
| 81 |
+
<button class="menu-btn" id="start-btn">ابدأ المغامرة</button>
|
| 82 |
+
<button class="menu-btn" id="open-settings-btn" style="background: #555; box-shadow: 0 6px #333;">الإعدادات</button>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<div id="settings-menu">
|
| 86 |
+
<h2 style="text-align: center; color: var(--primary-color);">⚙️ إعدادات التحكم</h2>
|
| 87 |
+
<div id="keys-container"></div>
|
| 88 |
+
<div class="setting-item">
|
| 89 |
+
<span>حساسية الماوس:</span>
|
| 90 |
+
<input type="range" id="sensitivity-slider" min="0.001" max="0.01" step="0.001" value="0.002">
|
| 91 |
+
</div>
|
| 92 |
+
<button class="menu-btn" id="close-settings" style="width: 100%; margin-top: 20px;">حفظ وإغلاق</button>
|
| 93 |
+
</div>
|
| 94 |
+
|
| 95 |
+
<div id="crosshair">+</div>
|
| 96 |
+
|
| 97 |
+
<div id="instructions">
|
| 98 |
+
تحرك: <span id="key-forward">W</span>, <span id="key-back">S</span>, <span id="key-left">A</span>, <span id="key-right">D</span><br>
|
| 99 |
+
قفز: <span id="key-jump">Space</span> | إعدادات: <span id="key-settings">E</span><br>
|
| 100 |
+
<b>بناء: كليك يمين | هدم: كلي�� يسار</b>
|
| 101 |
+
</div>
|
| 102 |
+
|
| 103 |
+
<div id="hotbar">
|
| 104 |
+
<div class="slot active" data-id="1"><span class="slot-num">1</span><div class="block-preview" style="background: #4CAF50;"></div></div>
|
| 105 |
+
<div class="slot" data-id="2"><span class="slot-num">2</span><div class="block-preview" style="background: #8B4513;"></div></div>
|
| 106 |
+
<div class="slot" data-id="3"><span class="slot-num">3</span><div class="block-preview" style="background: #808080;"></div></div>
|
| 107 |
+
<div class="slot" data-id="4"><span class="slot-num">4</span><div class="block-preview" style="background: #FFD700;"></div></div>
|
| 108 |
+
<div class="slot" data-id="5"><span class="slot-num">5</span><div class="block-preview" style="background: #0000FF;"></div></div>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
| 112 |
+
|
| 113 |
+
<script>
|
| 114 |
+
/**
|
| 115 |
+
* THE Z-CRAFT PRO ENGINE
|
| 116 |
+
* Fixed: Start Button & Pointer Lock Logic
|
| 117 |
+
*/
|
| 118 |
+
|
| 119 |
+
let controls = {
|
| 120 |
+
forward: 'KeyW',
|
| 121 |
+
backward: 'KeyS',
|
| 122 |
+
left: 'KeyA',
|
| 123 |
+
right: 'KeyD',
|
| 124 |
+
jump: 'Space',
|
| 125 |
+
settings: 'KeyE'
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
let mouseSensitivity = 0.002;
|
| 129 |
+
const blockTypes = {
|
| 130 |
+
1: { color: 0x4CAF50, name: 'Grass' },
|
| 131 |
+
2: { color: 0x8B4513, name: 'Dirt' },
|
| 132 |
+
3: { color: 0x808080, name: 'Stone' },
|
| 133 |
+
4: { color: 0xFFD700, name: 'Gold' },
|
| 134 |
+
5: { color: 0x0000FF, name: 'Water' }
|
| 135 |
+
};
|
| 136 |
+
let selectedBlock = 1;
|
| 137 |
+
|
| 138 |
+
let scene, camera, renderer, clock;
|
| 139 |
+
let moveForward = false, moveBackward = false, moveLeft = false, moveRight = false, canJump = false;
|
| 140 |
+
let velocity = new THREE.Vector3();
|
| 141 |
+
let direction = new THREE.Vector3();
|
| 142 |
+
let objects = [];
|
| 143 |
+
let isLocked = false;
|
| 144 |
+
|
| 145 |
+
const overlay = document.getElementById('overlay');
|
| 146 |
+
const startBtn = document.getElementById('start-btn');
|
| 147 |
+
const settingsMenu = document.getElementById('settings-menu');
|
| 148 |
+
const closeSettings = document.getElementById('close-settings');
|
| 149 |
+
const openSettingsBtn = document.getElementById('open-settings-btn');
|
| 150 |
+
|
| 151 |
+
function init() {
|
| 152 |
+
scene = new THREE.Scene();
|
| 153 |
+
scene.background = new THREE.Color(0x87CEEB);
|
| 154 |
+
scene.fog = new THREE.Fog(0x87CEEB, 0, 100);
|
| 155 |
+
|
| 156 |
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 157 |
+
camera.rotation.order = 'YXZ';
|
| 158 |
+
camera.position.set(0, 2, 5);
|
| 159 |
+
|
| 160 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
|
| 161 |
+
scene.add(ambientLight);
|
| 162 |
+
|
| 163 |
+
const sunLight = new THREE.DirectionalLight(0xffffff, 0.8);
|
| 164 |
+
sunLight.position.set(10, 20, 10);
|
| 165 |
+
scene.add(sunLight);
|
| 166 |
+
|
| 167 |
+
renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 168 |
+
renderer.setPixelRatio(window.devicePixelRatio);
|
| 169 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 170 |
+
document.body.appendChild(renderer.domElement);
|
| 171 |
+
|
| 172 |
+
clock = new THREE.Clock();
|
| 173 |
+
|
| 174 |
+
// أرضية البداية
|
| 175 |
+
for (let x = -15; x < 15; x++) {
|
| 176 |
+
for (let z = -15; z < 15; z++) {
|
| 177 |
+
createBlock(x, 0, z, 1);
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
setupEventListeners();
|
| 182 |
+
renderSettings();
|
| 183 |
+
animate();
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
function createBlock(x, y, z, type) {
|
| 187 |
+
const geometry = new THREE.BoxGeometry(1, 1, 1);
|
| 188 |
+
const material = new THREE.MeshLambertMaterial({ color: blockTypes[type].color });
|
| 189 |
+
const block = new THREE.Mesh(geometry, material);
|
| 190 |
+
block.position.set(x, y, z);
|
| 191 |
+
scene.add(block);
|
| 192 |
+
objects.push(block);
|
| 193 |
+
return block;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
function setupEventListeners() {
|
| 197 |
+
// --- إصلاح زر البداية ---
|
| 198 |
+
startBtn.addEventListener('click', () => {
|
| 199 |
+
document.body.requestPointerLock();
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
+
openSettingsBtn.addEventListener('click', () => {
|
| 203 |
+
settingsMenu.style.display = 'block';
|
| 204 |
+
});
|
| 205 |
+
|
| 206 |
+
document.addEventListener('pointerlockchange', () => {
|
| 207 |
+
if (document.pointerLockElement === document.body) {
|
| 208 |
+
isLocked = true;
|
| 209 |
+
overlay.style.opacity = '0';
|
| 210 |
+
setTimeout(() => overlay.style.display = 'none', 500);
|
| 211 |
+
} else {
|
| 212 |
+
isLocked = false;
|
| 213 |
+
overlay.style.display = 'flex';
|
| 214 |
+
overlay.style.opacity = '1';
|
| 215 |
+
}
|
| 216 |
+
});
|
| 217 |
+
|
| 218 |
+
document.addEventListener('keydown', (e) => {
|
| 219 |
+
if (!isLocked) return;
|
| 220 |
+
if (e.code === controls.forward) moveForward = true;
|
| 221 |
+
if (e.code === controls.backward) moveBackward = true;
|
| 222 |
+
if (e.code === controls.left) moveLeft = true;
|
| 223 |
+
if (e.code === controls.right) moveRight = true;
|
| 224 |
+
if (e.code === controls.jump && canJump) {
|
| 225 |
+
velocity.y += 5;
|
| 226 |
+
canJump = false;
|
| 227 |
+
}
|
| 228 |
+
if (e.code === controls.settings) {
|
| 229 |
+
document.exitPointerLock();
|
| 230 |
+
settingsMenu.style.display = 'block';
|
| 231 |
+
}
|
| 232 |
+
if (e.key >= 1 && e.key <= 5) {
|
| 233 |
+
selectedBlock = parseInt(e.key);
|
| 234 |
+
updateHotbarUI();
|
| 235 |
+
}
|
| 236 |
+
});
|
| 237 |
+
|
| 238 |
+
document.addEventListener('keyup', (e) => {
|
| 239 |
+
if (e.code === controls.forward) moveForward = false;
|
| 240 |
+
if (e.code === controls.backward) moveBackward = false;
|
| 241 |
+
if (e.code === controls.left) moveLeft = false;
|
| 242 |
+
if (e.code === controls.right) moveRight = false;
|
| 243 |
+
});
|
| 244 |
+
|
| 245 |
+
document.addEventListener('mousemove', (e) => {
|
| 246 |
+
if (!isLocked) return;
|
| 247 |
+
camera.rotation.y -= e.movementX * mouseSensitivity;
|
| 248 |
+
camera.rotation.x -= e.movementY * mouseSensitivity;
|
| 249 |
+
camera.rotation.x = Math.max(-Math.PI/2, Math.min(Math.PI/2, camera.rotation.x));
|
| 250 |
+
});
|
| 251 |
+
|
| 252 |
+
document.addEventListener('mousedown', (e) => {
|
| 253 |
+
if (!isLocked) return;
|
| 254 |
+
const raycaster = new THREE.Raycaster();
|
| 255 |
+
raycaster.setFromCamera(new THREE.Vector2(0, 0), camera);
|
| 256 |
+
const intersects = raycaster.intersectObjects(objects);
|
| 257 |
+
|
| 258 |
+
if (intersects.length > 0) {
|
| 259 |
+
const intersect = intersects[0];
|
| 260 |
+
if (e.button === 0) { // يسار: هدم
|
| 261 |
+
if (intersect.object.position.y !== 0 || objects.length > 100) {
|
| 262 |
+
scene.remove(intersect.object);
|
| 263 |
+
objects = objects.filter(obj => obj !== intersect.object);
|
| 264 |
+
}
|
| 265 |
+
} else if (e.button === 2) { // يمين: بناء
|
| 266 |
+
const pos = intersect.object.position.clone().add(intersect.face.normal);
|
| 267 |
+
createBlock(pos.x, pos.y, pos.z, selectedBlock);
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
});
|
| 271 |
+
|
| 272 |
+
document.addEventListener('contextmenu', e => e.preventDefault());
|
| 273 |
+
|
| 274 |
+
closeSettings.addEventListener('click', () => {
|
| 275 |
+
mouseSensitivity = parseFloat(document.getElementById('sensitivity-slider').value);
|
| 276 |
+
settingsMenu.style.display = 'none';
|
| 277 |
+
document.body.requestPointerLock();
|
| 278 |
+
});
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
function updateHotbarUI() {
|
| 282 |
+
document.querySelectorAll('.slot').forEach(slot => {
|
| 283 |
+
slot.classList.remove('active');
|
| 284 |
+
if (slot.dataset.id == selectedBlock) slot.classList.add('active');
|
| 285 |
+
});
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
function renderSettings() {
|
| 289 |
+
const container = document.getElementById('keys-container');
|
| 290 |
+
container.innerHTML = '';
|
| 291 |
+
for (let action in controls) {
|
| 292 |
+
const div = document.createElement('div');
|
| 293 |
+
div.className = 'setting-item';
|
| 294 |
+
div.innerHTML = `<span>${action === 'forward' ? 'للأمام' : action === 'backward' ? 'للخلف' : action === 'left' ? 'يسار' : action === 'right' ? 'يمين' : action === 'jump' ? 'قفز' : 'إعدادات'}:</span>
|
| 295 |
+
<button class="key-btn" id="btn-${action}">${controls[action]}</button>`;
|
| 296 |
+
container.appendChild(div);
|
| 297 |
+
|
| 298 |
+
const btn = div.querySelector('.key-btn');
|
| 299 |
+
btn.onclick = () => {
|
| 300 |
+
btn.classList.add('waiting');
|
| 301 |
+
btn.innerText = '...';
|
| 302 |
+
const captureKey = (e) => {
|
| 303 |
+
e.preventDefault();
|
| 304 |
+
controls[action] = e.code;
|
| 305 |
+
btn.innerText = e.code;
|
| 306 |
+
btn.classList.remove('waiting');
|
| 307 |
+
document.removeEventListener('keydown', captureKey);
|
| 308 |
+
updateInstructionLabels();
|
| 309 |
+
};
|
| 310 |
+
document.addEventListener('keydown', captureKey);
|
| 311 |
+
};
|
| 312 |
+
}
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
function updateInstructionLabels() {
|
| 316 |
+
document.getElementById('key-forward').innerText = controls.forward.replace('Key', '');
|
| 317 |
+
document.getElementById('key-back').innerText = controls.backward.replace('Key', '');
|
| 318 |
+
document.getElementById('key-left').innerText = controls.left.replace('Key', '');
|
| 319 |
+
document.getElementById('key-right').innerText = controls.right.replace('Key', '');
|
| 320 |
+
document.getElementById('key-jump').innerText = controls.jump;
|
| 321 |
+
document.getElementById('key-settings').innerText = controls.settings.replace('Key', '');
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
function animate() {
|
| 325 |
+
requestAnimationFrame(animate);
|
| 326 |
+
if (!isLocked) {
|
| 327 |
+
renderer.render(scene, camera);
|
| 328 |
+
return;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
const delta = clock.getDelta();
|
| 332 |
+
velocity.x -= velocity.x * 10.0 * delta;
|
| 333 |
+
velocity.z -= velocity.z * 10.0 * delta;
|
| 334 |
+
velocity.y -= 9.8 * 2.0 * delta;
|
| 335 |
+
|
| 336 |
+
direction.z = Number(moveForward) - Number(moveBackward);
|
| 337 |
+
direction.x = Number(moveRight) - Number(moveLeft);
|
| 338 |
+
direction.normalize();
|
| 339 |
+
|
| 340 |
+
if (moveForward || moveBackward) velocity.z -= direction.z * 400.0 * delta;
|
| 341 |
+
if (moveLeft || moveRight) velocity.x -= direction.x * 400.0 * delta;
|
| 342 |
+
|
| 343 |
+
const moveVector = new THREE.Vector3();
|
| 344 |
+
camera.getWorldDirection(moveVector);
|
| 345 |
+
moveVector.y = 0;
|
| 346 |
+
moveVector.normalize();
|
| 347 |
+
|
| 348 |
+
const sideVector = new THREE.Vector3();
|
| 349 |
+
sideVector.crossVectors(camera.up, moveVector).normalize();
|
| 350 |
+
|
| 351 |
+
const nextPos = camera.position.clone();
|
| 352 |
+
nextPos.addScaledVector(moveVector, -velocity.z * delta * 0.05);
|
| 353 |
+
nextPos.addScaledVector(sideVector, velocity.x * delta * 0.05);
|
| 354 |
+
nextPos.y += velocity.y * delta;
|
| 355 |
+
|
| 356 |
+
let collided = false;
|
| 357 |
+
const playerRadius = 0.3;
|
| 358 |
+
for (let obj of objects) {
|
| 359 |
+
const blockBox = new THREE.Box3().setFromObject(obj);
|
| 360 |
+
const playerBox = new THREE.Box3().setFromCenterAndSize(
|
| 361 |
+
nextPos, new THREE.Vector3(playerRadius * 2, 1.8, playerRadius * 2)
|
| 362 |
+
);
|
| 363 |
+
if (blockBox.intersectsBox(playerBox)) {
|
| 364 |
+
collided = true;
|
| 365 |
+
if (camera.position.y >= blockBox.max.y) {
|
| 366 |
+
velocity.y = 0;
|
| 367 |
+
nextPos.y = blockBox.max.y + 0.1;
|
| 368 |
+
canJump = true;
|
| 369 |
+
} else {
|
| 370 |
+
nextPos.copy(camera.position);
|
| 371 |
+
}
|
| 372 |
+
break;
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
if (!collided) camera.position.copy(nextPos);
|
| 377 |
+
else if (velocity.y < 0) camera.position.copy(nextPos);
|
| 378 |
+
|
| 379 |
+
if (camera.position.y < 2) {
|
| 380 |
+
velocity.y = 0;
|
| 381 |
+
camera.position.y = 2;
|
| 382 |
+
canJump = true;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
renderer.render(scene, camera);
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
window.addEventListener('resize', () => {
|
| 389 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 390 |
+
camera.updateProjectionMatrix();
|
| 391 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 392 |
+
});
|
| 393 |
+
|
| 394 |
+
init();
|
| 395 |
+
</script>
|
| 396 |
+
</body>
|
| 397 |
+
</html>
|