Update index.html
Browse files- index.html +7 -35
index.html
CHANGED
|
@@ -36,16 +36,12 @@
|
|
| 36 |
|
| 37 |
<!-- Three.js ライブラリ -->
|
| 38 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
| 39 |
-
<!-- OrbitControls ライブラリ -->
|
| 40 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/controls/OrbitControls.js"></script>
|
| 41 |
-
|
| 42 |
<script>
|
| 43 |
const canvas = document.getElementById('canvas');
|
| 44 |
const ctx = canvas.getContext('2d');
|
| 45 |
-
let scene, camera, renderer
|
| 46 |
const cubeSize = 5; // 立方体のサイズ
|
| 47 |
let cubes = []; // 立方体を格納する配列
|
| 48 |
-
let cameraSpeed = 5; // カメラの移動速度
|
| 49 |
|
| 50 |
function processImage() {
|
| 51 |
const fileInput = document.getElementById('imageInput');
|
|
@@ -74,11 +70,6 @@
|
|
| 74 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 75 |
document.getElementById('scene-container').appendChild(renderer.domElement);
|
| 76 |
|
| 77 |
-
controls = new THREE.OrbitControls(camera, renderer.domElement);
|
| 78 |
-
controls.enableDamping = true; // スムーズな操作
|
| 79 |
-
controls.dampingFactor = 0.25;
|
| 80 |
-
controls.screenSpacePanning = false;
|
| 81 |
-
|
| 82 |
createCubesFromImage();
|
| 83 |
|
| 84 |
animate(); // アニメーション開始
|
|
@@ -93,16 +84,17 @@
|
|
| 93 |
const r = imageData[index];
|
| 94 |
const g = imageData[index + 1];
|
| 95 |
const b = imageData[index + 2];
|
| 96 |
-
const color = new THREE.Color(
|
| 97 |
|
| 98 |
const geometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
|
| 99 |
const material = new THREE.MeshBasicMaterial({ color: color });
|
| 100 |
const cube = new THREE.Mesh(geometry, material);
|
| 101 |
|
|
|
|
| 102 |
cube.position.set(
|
| 103 |
-
(x - canvas.width / 2) * cubeSize * 1.2,
|
| 104 |
-
(canvas.height / 2 - y) * cubeSize * 1.2,
|
| 105 |
-
Math.random() * 200 - 100
|
| 106 |
);
|
| 107 |
scene.add(cube);
|
| 108 |
cubes.push(cube);
|
|
@@ -124,28 +116,8 @@
|
|
| 124 |
cube.position.z += (targetZ - cube.position.z) * 0.05;
|
| 125 |
});
|
| 126 |
|
| 127 |
-
controls.update(); // OrbitControls の更新
|
| 128 |
-
|
| 129 |
renderer.render(scene, camera);
|
| 130 |
}
|
| 131 |
-
|
| 132 |
-
// カメラ移動処理
|
| 133 |
-
document.addEventListener('keydown', (event) => {
|
| 134 |
-
switch (event.key) {
|
| 135 |
-
case 'w': // 前進
|
| 136 |
-
camera.position.z -= cameraSpeed;
|
| 137 |
-
break;
|
| 138 |
-
case 's': // 後退
|
| 139 |
-
camera.position.z += cameraSpeed;
|
| 140 |
-
break;
|
| 141 |
-
case 'a': // 左
|
| 142 |
-
camera.position.x -= cameraSpeed;
|
| 143 |
-
break;
|
| 144 |
-
case 'd': // 右
|
| 145 |
-
camera.position.x += cameraSpeed;
|
| 146 |
-
break;
|
| 147 |
-
}
|
| 148 |
-
});
|
| 149 |
</script>
|
| 150 |
</body>
|
| 151 |
-
</html>
|
|
|
|
| 36 |
|
| 37 |
<!-- Three.js ライブラリ -->
|
| 38 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
|
|
|
|
|
|
|
|
|
| 39 |
<script>
|
| 40 |
const canvas = document.getElementById('canvas');
|
| 41 |
const ctx = canvas.getContext('2d');
|
| 42 |
+
let scene, camera, renderer;
|
| 43 |
const cubeSize = 5; // 立方体のサイズ
|
| 44 |
let cubes = []; // 立方体を格納する配列
|
|
|
|
| 45 |
|
| 46 |
function processImage() {
|
| 47 |
const fileInput = document.getElementById('imageInput');
|
|
|
|
| 70 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 71 |
document.getElementById('scene-container').appendChild(renderer.domElement);
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
createCubesFromImage();
|
| 74 |
|
| 75 |
animate(); // アニメーション開始
|
|
|
|
| 84 |
const r = imageData[index];
|
| 85 |
const g = imageData[index + 1];
|
| 86 |
const b = imageData[index + 2];
|
| 87 |
+
const color = new THREE.Color(rgb(${r},${g},${b}));
|
| 88 |
|
| 89 |
const geometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
|
| 90 |
const material = new THREE.MeshBasicMaterial({ color: color });
|
| 91 |
const cube = new THREE.Mesh(geometry, material);
|
| 92 |
|
| 93 |
+
// x座標はそのままに、y座標のみ反転させる
|
| 94 |
cube.position.set(
|
| 95 |
+
(x - canvas.width / 2) * cubeSize * 1.2, // x座標をそのまま使用
|
| 96 |
+
(canvas.height / 2 - y) * cubeSize * 1.2, // y座標を反転
|
| 97 |
+
Math.random() * 200 - 100 // 初期位置のばらつきを与える
|
| 98 |
);
|
| 99 |
scene.add(cube);
|
| 100 |
cubes.push(cube);
|
|
|
|
| 116 |
cube.position.z += (targetZ - cube.position.z) * 0.05;
|
| 117 |
});
|
| 118 |
|
|
|
|
|
|
|
| 119 |
renderer.render(scene, camera);
|
| 120 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
</script>
|
| 122 |
</body>
|
| 123 |
+
</html>
|