soiz commited on
Commit
e3ca868
·
verified ·
1 Parent(s): 207a7a5

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +32 -34
index.html CHANGED
@@ -86,41 +86,39 @@
86
  animate();
87
  }
88
 
89
- function createCubesFromImage() {
90
- const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
91
-
92
- for (let y = 0; y < canvas.height; y++) {
93
- for (let x = 0; x < canvas.width; x++) {
94
- const index = (y * canvas.width + x) * 4;
95
- const r = imageData[index];
96
- const g = imageData[index + 1];
97
- const b = imageData[index + 2];
98
- const alpha = imageData[index + 3] / 255; // Alpha channel (0-1)
99
-
100
- if (alpha < 0.1) {
101
- // Skip creating a cube if the alpha is near 0 (transparent)
102
- continue;
103
- }
104
-
105
- const color = new THREE.Color(`rgb(${r},${g},${b})`);
106
- const geometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
107
- const material = new THREE.MeshBasicMaterial({
108
- color: color,
109
- transparent: true,
110
- opacity: alpha // Set opacity based on alpha value
111
- });
112
- const cube = new THREE.Mesh(geometry, material);
113
-
114
- cube.position.set(
115
- (x - canvas.width / 2) * cubeSize * 1.2,
116
- (canvas.height / 2 - y) * cubeSize * 1.2,
117
- Math.random() * 2200 - 100
118
- );
119
- scene.add(cube);
120
- cubes.push(cube);
121
- }
122
- }
123
  }
 
 
 
124
 
125
  function animate() {
126
  animationFrameId = requestAnimationFrame(animate);
 
86
  animate();
87
  }
88
 
89
+ function createCubesFromImage() {
90
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
91
+
92
+ for (let y = 0; y < canvas.height; y++) {
93
+ for (let x = 0; x < canvas.width; x++) {
94
+ const index = (y * canvas.width + x) * 4;
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
+ const color = new THREE.Color(`rgb(${r},${g},${b})`);
102
+ const geometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
103
+ const material = new THREE.MeshBasicMaterial({
104
+ color: color,
105
+ transparent: true,
106
+ opacity: a / 255 // 透明度を設定(0で完全透明、255で不透明)
107
+ });
108
+
109
+ const cube = new THREE.Mesh(geometry, material);
110
+
111
+ cube.position.set(
112
+ (x - canvas.width / 2) * cubeSize * 1.2,
113
+ (canvas.height / 2 - y) * cubeSize * 1.2,
114
+ Math.random() * 2200 - 100
115
+ );
116
+ scene.add(cube);
117
+ cubes.push(cube);
 
 
 
 
 
118
  }
119
+ }
120
+ }
121
+
122
 
123
  function animate() {
124
  animationFrameId = requestAnimationFrame(animate);