Update index.html
Browse files- index.html +21 -18
index.html
CHANGED
|
@@ -65,19 +65,21 @@
|
|
| 65 |
|
| 66 |
function create3DScene() {
|
| 67 |
if (renderer) {
|
|
|
|
| 68 |
cancelAnimationFrame(animationFrameId);
|
| 69 |
cubes.forEach(cube => scene.remove(cube));
|
| 70 |
cubes = [];
|
| 71 |
renderer.dispose();
|
| 72 |
}
|
| 73 |
|
|
|
|
| 74 |
scene = new THREE.Scene();
|
| 75 |
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 76 |
camera.position.set(300, 300, 300);
|
| 77 |
camera.lookAt(new THREE.Vector3(0, 0, 0));
|
| 78 |
renderer = new THREE.WebGLRenderer();
|
| 79 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 80 |
-
document.getElementById('scene-container').innerHTML = '';
|
| 81 |
document.getElementById('scene-container').appendChild(renderer.domElement);
|
| 82 |
|
| 83 |
createCubesFromImage();
|
|
@@ -93,23 +95,23 @@
|
|
| 93 |
const r = imageData[index];
|
| 94 |
const g = imageData[index + 1];
|
| 95 |
const b = imageData[index + 2];
|
| 96 |
-
const a = imageData[index + 3];
|
| 97 |
-
|
| 98 |
-
//
|
| 99 |
-
if (a
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
}
|
| 114 |
}
|
| 115 |
}
|
|
@@ -131,6 +133,7 @@
|
|
| 131 |
}
|
| 132 |
|
| 133 |
function replayAnimation() {
|
|
|
|
| 134 |
create3DScene();
|
| 135 |
}
|
| 136 |
</script>
|
|
|
|
| 65 |
|
| 66 |
function create3DScene() {
|
| 67 |
if (renderer) {
|
| 68 |
+
// 既存のシーンをクリア
|
| 69 |
cancelAnimationFrame(animationFrameId);
|
| 70 |
cubes.forEach(cube => scene.remove(cube));
|
| 71 |
cubes = [];
|
| 72 |
renderer.dispose();
|
| 73 |
}
|
| 74 |
|
| 75 |
+
// Three.jsの基本設定
|
| 76 |
scene = new THREE.Scene();
|
| 77 |
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 78 |
camera.position.set(300, 300, 300);
|
| 79 |
camera.lookAt(new THREE.Vector3(0, 0, 0));
|
| 80 |
renderer = new THREE.WebGLRenderer();
|
| 81 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 82 |
+
document.getElementById('scene-container').innerHTML = ''; // 既存のcanvasを削除
|
| 83 |
document.getElementById('scene-container').appendChild(renderer.domElement);
|
| 84 |
|
| 85 |
createCubesFromImage();
|
|
|
|
| 95 |
const r = imageData[index];
|
| 96 |
const g = imageData[index + 1];
|
| 97 |
const b = imageData[index + 2];
|
| 98 |
+
const a = imageData[index + 3]; // アルファチャネル(透明度)
|
| 99 |
+
|
| 100 |
+
// アルファ値が0より大きい(透明でない)場合のみキューブを作成
|
| 101 |
+
if (a > 0) {
|
| 102 |
+
const color = new THREE.Color(`rgb(${r},${g},${b})`);
|
| 103 |
+
const geometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
|
| 104 |
+
const material = new THREE.MeshBasicMaterial({ color: color });
|
| 105 |
+
const cube = new THREE.Mesh(geometry, material);
|
| 106 |
+
|
| 107 |
+
cube.position.set(
|
| 108 |
+
(x - canvas.width / 2) * cubeSize * 1.2,
|
| 109 |
+
(canvas.height / 2 - y) * cubeSize * 1.2,
|
| 110 |
+
Math.random() * 2200 - 100
|
| 111 |
+
);
|
| 112 |
+
scene.add(cube);
|
| 113 |
+
cubes.push(cube);
|
| 114 |
+
}
|
| 115 |
}
|
| 116 |
}
|
| 117 |
}
|
|
|
|
| 133 |
}
|
| 134 |
|
| 135 |
function replayAnimation() {
|
| 136 |
+
// アニメーションの再生をリセット
|
| 137 |
create3DScene();
|
| 138 |
}
|
| 139 |
</script>
|