Update index.html
Browse files- index.html +68 -35
index.html
CHANGED
|
@@ -19,10 +19,20 @@
|
|
| 19 |
#scene-container {
|
| 20 |
width: 80vw;
|
| 21 |
height: 80vh;
|
|
|
|
| 22 |
}
|
| 23 |
#uploadForm {
|
| 24 |
margin-top: 20px;
|
| 25 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
</style>
|
| 27 |
</head>
|
| 28 |
<body>
|
|
@@ -31,6 +41,20 @@
|
|
| 31 |
<input type="file" id="imageInput" accept="image/*">
|
| 32 |
<button type="button" onclick="processImage()">画像を処理</button>
|
| 33 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
<button id="replayButton" style="margin-top: 10px; display: none;" onclick="replayAnimation()">もう一度再生</button>
|
| 35 |
<canvas id="canvas" style="display: none;"></canvas>
|
| 36 |
<div id="scene-container"></div>
|
|
@@ -75,8 +99,7 @@
|
|
| 75 |
// Three.jsの基本設定
|
| 76 |
scene = new THREE.Scene();
|
| 77 |
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 78 |
-
|
| 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を削除
|
|
@@ -86,39 +109,37 @@
|
|
| 86 |
animate();
|
| 87 |
}
|
| 88 |
|
| 89 |
-
function createCubesFromImage() {
|
| 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 |
function animate() {
|
| 124 |
animationFrameId = requestAnimationFrame(animate);
|
|
@@ -137,9 +158,21 @@ function createCubesFromImage() {
|
|
| 137 |
}
|
| 138 |
|
| 139 |
function replayAnimation() {
|
| 140 |
-
// アニメーションの再生をリセット
|
| 141 |
create3DScene();
|
| 142 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
</script>
|
| 144 |
</body>
|
| 145 |
</html>
|
|
|
|
| 19 |
#scene-container {
|
| 20 |
width: 80vw;
|
| 21 |
height: 80vh;
|
| 22 |
+
margin-top: 20px;
|
| 23 |
}
|
| 24 |
#uploadForm {
|
| 25 |
margin-top: 20px;
|
| 26 |
}
|
| 27 |
+
#settings {
|
| 28 |
+
margin-top: 20px;
|
| 29 |
+
display: flex;
|
| 30 |
+
flex-direction: column;
|
| 31 |
+
align-items: center;
|
| 32 |
+
}
|
| 33 |
+
#settings label {
|
| 34 |
+
margin: 5px;
|
| 35 |
+
}
|
| 36 |
</style>
|
| 37 |
</head>
|
| 38 |
<body>
|
|
|
|
| 41 |
<input type="file" id="imageInput" accept="image/*">
|
| 42 |
<button type="button" onclick="processImage()">画像を処理</button>
|
| 43 |
</form>
|
| 44 |
+
<div id="settings">
|
| 45 |
+
<label>
|
| 46 |
+
背景色: <input type="color" id="bgColorPicker" value="#222222" onchange="updateBackgroundColor()">
|
| 47 |
+
</label>
|
| 48 |
+
<label>
|
| 49 |
+
カメラ X: <input type="range" id="cameraX" min="-500" max="500" value="-100" oninput="updateCameraPosition()">
|
| 50 |
+
</label>
|
| 51 |
+
<label>
|
| 52 |
+
カメラ Y: <input type="range" id="cameraY" min="-500" max="500" value="-100" oninput="updateCameraPosition()">
|
| 53 |
+
</label>
|
| 54 |
+
<label>
|
| 55 |
+
カメラ Z: <input type="range" id="cameraZ" min="-1000" max="1000" value="300" oninput="updateCameraPosition()">
|
| 56 |
+
</label>
|
| 57 |
+
</div>
|
| 58 |
<button id="replayButton" style="margin-top: 10px; display: none;" onclick="replayAnimation()">もう一度再生</button>
|
| 59 |
<canvas id="canvas" style="display: none;"></canvas>
|
| 60 |
<div id="scene-container"></div>
|
|
|
|
| 99 |
// Three.jsの基本設定
|
| 100 |
scene = new THREE.Scene();
|
| 101 |
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 102 |
+
updateCameraPosition(); // カメラ位置を初期設定
|
|
|
|
| 103 |
renderer = new THREE.WebGLRenderer();
|
| 104 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 105 |
document.getElementById('scene-container').innerHTML = ''; // 既存のcanvasを削除
|
|
|
|
| 109 |
animate();
|
| 110 |
}
|
| 111 |
|
| 112 |
+
function createCubesFromImage() {
|
| 113 |
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
| 114 |
+
|
| 115 |
+
for (let y = 0; y < canvas.height; y++) {
|
| 116 |
+
for (let x = 0; x < canvas.width; x++) {
|
| 117 |
+
const index = (y * canvas.width + x) * 4;
|
| 118 |
+
const r = imageData[index];
|
| 119 |
+
const g = imageData[index + 1];
|
| 120 |
+
const b = imageData[index + 2];
|
| 121 |
+
const a = imageData[index + 3];
|
| 122 |
+
|
| 123 |
+
const color = new THREE.Color(`rgb(${r},${g},${b})`);
|
| 124 |
+
const geometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
|
| 125 |
+
const material = new THREE.MeshBasicMaterial({
|
| 126 |
+
color: color,
|
| 127 |
+
transparent: true,
|
| 128 |
+
opacity: a / 255
|
| 129 |
+
});
|
| 130 |
+
|
| 131 |
+
const cube = new THREE.Mesh(geometry, material);
|
| 132 |
+
|
| 133 |
+
cube.position.set(
|
| 134 |
+
(x - canvas.width / 2) * cubeSize * 1.2 + Math.random() * 2200 - 100,
|
| 135 |
+
(canvas.height / 2 - y) * cubeSize * 1.2 + Math.random() * 2200 - 100,
|
| 136 |
+
Math.random() * 2200 - 100
|
| 137 |
+
);
|
| 138 |
+
scene.add(cube);
|
| 139 |
+
cubes.push(cube);
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
}
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
function animate() {
|
| 145 |
animationFrameId = requestAnimationFrame(animate);
|
|
|
|
| 158 |
}
|
| 159 |
|
| 160 |
function replayAnimation() {
|
|
|
|
| 161 |
create3DScene();
|
| 162 |
}
|
| 163 |
+
|
| 164 |
+
function updateBackgroundColor() {
|
| 165 |
+
const color = document.getElementById('bgColorPicker').value;
|
| 166 |
+
document.body.style.backgroundColor = color;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function updateCameraPosition() {
|
| 170 |
+
const x = parseFloat(document.getElementById('cameraX').value);
|
| 171 |
+
const y = parseFloat(document.getElementById('cameraY').value);
|
| 172 |
+
const z = parseFloat(document.getElementById('cameraZ').value);
|
| 173 |
+
camera.position.set(x, y, z);
|
| 174 |
+
camera.lookAt(new THREE.Vector3(0, 0, 0));
|
| 175 |
+
}
|
| 176 |
</script>
|
| 177 |
</body>
|
| 178 |
</html>
|