-
Notifications
You must be signed in to change notification settings - Fork 1
/
3dgraphics.html
257 lines (226 loc) · 10.6 KB
/
3dgraphics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!DOCTYPE html>
<html lang="ja">
<head>
<link rel="icon" type="image/x-icon" href="image/icontestHtml.png">
<title>図形生成アプリ | 3D図形</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { margin: 0; overflow: hidden; font-family: Arial, sans-serif; background-color: #333; color: #fff; }
#controls {
position: absolute;
top: 10px;
left: 10px;
z-index: 100;
background-color: rgba(255, 255, 255, 0.1);
padding: 15px;
border-radius: 5px;
font-family: Arial, sans-serif;
color: #fff;
}
#controls ul {
padding-left: 20px;
list-style-type: disc;
margin-bottom: 20px;
}
#controls li {
margin-bottom: 5px;
}
#controls a {
color: #ff9999;
text-decoration: none;
}
#controls a:hover {
text-decoration: underline;
}
#controls label {
display: block;
margin-top: 10px;
font-weight: bold;
}
#controls input {
width: 100%;
margin-top: 5px;
color: #000;
}
</style>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@700&display=swap" rel="stylesheet">
</head>
<body id="3dgraphics">
<header>
<div class="logo">
<a href="index.html"><img src="image/zukeiapplogo.png" alt=
"図形生成アプリ" width="200">
</a>
</div>
<nav>
<!-- 画像をクリックするとツイッターに飛ぶリンク -->
<!-- <div class="link">
<a id="twitterLink" href="https://x.com/0526ngs" target="_blank">
<img src="image/iconTwitterhrmcngsHtml.png" alt="Twitter Link Image" width="100">
</a>
<a id="twitterLink" href="https://Instagram.com/0526ngs" target="_blank">
<img src="image/iconInstagramhrmcngsHtml.png" alt="Instagram Link Image" width="100">
</a>
<a id="twitterLink" href="https://github.com/hrmcngs" target="_blank">
<img src="image/iconGithubhrmcngsHtml.png" alt="Github Link Image" width="100">
</a>
<a id="twitterLink" href="https://x.com/RenkonUmauma65" target="_blank">
<img src="image/iconTwitterrenkonHtml.png" alt="Twitter Link Image" width="100">
</a>
<a id="twitterLink" href="https://github.com/Renkon65" target="_blank">
<img src="image/iconGithubrenkonHtml.png" alt="github Link Image" width="100">
</a>
</div>-->
<div class="global-nav">
<ul>
<li><a class="button" href="rotation.html">回転</a></li>
<li><a class="button" href="pythagorean-theorem.html">三平方の定理</a></li>
<li><a class="button" href="canvas-arc.html">円弧</a></li>
<li><a class="button" href="3dgraphics.html">3D図形</a></li>
</ul>
</div>
</div>
</nav>
</header>
<div id="controls">
<label for="width">幅 (Width):</label>
<input type="number" id="width" value="2" step="0.1" min="0.1">
<label for="height">高さ (Height):</label>
<input type="number" id="height" value="2" step="0.1" min="0.1">
<label for="depth">奥行き (Depth):</label>
<input type="number" id="depth" value="2" step="0.1" min="0.1">
<label for="rotationX">回転X (Rotation X):</label>
<input type="range" id="rotationX" min="0" max="360" value="0">
<label for="rotationY">回転Y (Rotation Y):</label>
<input type="range" id="rotationY" min="0" max="360" value="0">
<label for="rotationZ">回転Z (Rotation Z):</label>
<input type="range" id="rotationZ" min="0" max="360" value="0">
<label for="cameraX">カメラX位置 (Camera X Position):</label>
<input type="range" id="cameraX" min="-50" max="50" value="5">
<label for="cameraY">カメラY位置 (Camera Y Position):</label>
<input type="range" id="cameraY" min="-50" max="50" value="5">
<label for="cameraZ">カメラZ位置 (Camera Z Position):</label>
<input type="range" id="cameraZ" min="5" max="50" value="5">
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
// シーン、カメラ、レンダラーのセットアップ
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(5, 5, 5);
camera.lookAt(scene.position);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// 照明の追加
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(10, 10, 10);
scene.add(directionalLight);
// メッシュとラインの宣言
let mesh, wireframe;
// 初期図形の作成
function createShape(width, height, depth) {
if (mesh) scene.remove(mesh);
if (wireframe) scene.remove(wireframe);
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = new THREE.MeshPhongMaterial({ color: 0x156289, emissive: 0x072534, shininess: 100, side: THREE.DoubleSide });
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
const edgeGeometry = new THREE.EdgesGeometry(geometry);
const edgeMaterial = new THREE.LineBasicMaterial({ color: 0xffffff, linewidth: 2 });
wireframe = new THREE.LineSegments(edgeGeometry, edgeMaterial);
scene.add(wireframe);
}
// 初期図形を作成
createShape(2, 2, 2);
// コントロール要素の取得
const widthInput = document.getElementById('width');
const heightInput = document.getElementById('height');
const depthInput = document.getElementById('depth');
const rotationXInput = document.getElementById('rotationX');
const rotationYInput = document.getElementById('rotationY');
const rotationZInput = document.getElementById('rotationZ');
const cameraXInput = document.getElementById('cameraX');
const cameraYInput = document.getElementById('cameraY');
const cameraZInput = document.getElementById('cameraZ');
// 図形を更新する関数
function updateShape() {
const width = parseFloat(widthInput.value);
const height = parseFloat(heightInput.value);
const depth = parseFloat(depthInput.value);
createShape(width, height, depth);
}
// スクロールでスライダー操作を可能にする
function enableScrollControl(input) {
input.addEventListener('wheel', function(event) {
event.preventDefault();
const step = input.step ? parseFloat(input.step) : 1;
const value = parseFloat(input.value);
const min = parseFloat(input.min);
const max = parseFloat(input.max);
const delta = event.deltaY < 0 ? step : -step;
const newValue = Math.min(Math.max(value + delta, min), max);
input.value = newValue;
input.dispatchEvent(new Event('input'));
});
}
// スクロール制御を有効にする
enableScrollControl(widthInput);
enableScrollControl(heightInput);
enableScrollControl(depthInput);
enableScrollControl(rotationXInput);
enableScrollControl(rotationYInput);
enableScrollControl(rotationZInput);
enableScrollControl(cameraXInput);
enableScrollControl(cameraYInput);
enableScrollControl(cameraZInput);
// アニメーションループ
function animate() {
requestAnimationFrame(animate);
// 回転の適用
mesh.rotation.x = THREE.MathUtils.degToRad(rotationXInput.value);
mesh.rotation.y = THREE.MathUtils.degToRad(rotationYInput.value);
mesh.rotation.z = THREE.MathUtils.degToRad(rotationZInput.value);
wireframe.rotation.copy(mesh.rotation);
// カメラの位置を更新
camera.position.x = parseFloat(cameraXInput.value);
camera.position.y = parseFloat(cameraYInput.value);
camera.position.z = parseFloat(cameraZInput.value);
// カメラを中心に向ける
camera.lookAt(scene.position);
renderer.render(scene, camera);
}
// リサイズ対応
window.addEventListener('resize', function() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
// 入力要素のイベントリスナー
widthInput.addEvent
// 入力要素のイベントリスナー
widthInput.addEventListener('input', updateShape);
heightInput.addEventListener('input', updateShape);
depthInput.addEventListener('input', updateShape);
// アニメーション開始
animate();
</script>
<div class="omake">
<h2>おまけ</h2>
<ul>
<li><a class="button" href="miencraft-blasting-smoking-campfire-cooking-recipe.html">blasting-smoking-campfire-cooking</a></li>
<li><a class="button" href="miencraft-crafting-recipe.html">minecraft-crafting-recipe</a></li>
<li><a class="button" href="miencraft-smelting-recipe.html">minecraft-smelting-recipe</a></li>
</ul>
</div>
<footer><small>2024年9月4日現在最新版</small></footer>
</body>
</html>