履歴: プログラミング/JavaScript/three.js/再入門
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 9 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2022/3/22 8:56:37 | プログラミング/JavaScript/three.js/再入門 最新版 | 11,685 | +4 | -2 | 表示 | 表示中 | — |
| 2022/3/21 23:56:37 | プログラミング/JavaScript/three.js/再入門 | 11,473 | +26 | -38 | 表示 | 差分 | 選択 |
| 2022/3/20 11:15:11 | プログラミング/JavaScript/three.js/再入門 | 11,870 | +4 | -0 | 表示 | 差分 | 選択 |
| 2022/3/20 5:06:13 | プログラミング/JavaScript/three.js/再入門 | 11,721 | +52 | -3 | 表示 | 差分 | 選択 |
| 2022/3/18 5:21:43 | プログラミング/JavaScript/three.js/再入門 | 10,232 | +3 | -0 | 表示 | 差分 | 選択 |
| 2022/3/18 5:21:43 | プログラミング/JavaScript/three.js/再入門 | 10,152 | +21 | -10 | 表示 | 差分 | 選択 |
| 2022/3/16 13:47:19 | プログラミング/JavaScript/three.js/再入門 | 10,154 | +78 | -11 | 表示 | 差分 | 基準 |
| 2022/3/16 5:22:28 | プログラミング/JavaScript/three.js/再入門 | 8,227 | +310 | -8 | 表示 | 差分 | 選択 |
| 2022/3/16 3:23:04 | プログラミング/JavaScript/three.js/再入門 | 1,009 | — | — | 表示 | — | 選択 |
基準: プログラミング/JavaScript/three.js/再入門 (2022/3/16 13:47:19) → 比較: プログラミング/JavaScript/three.js/再入門 (2022/3/22 8:56:37) 最新版
@@ -82,7 +82,8 @@
const scene = new THREE.Scene();
// ここでシーンにオブジェクトや光源を追加する
- // setup_scene(scene);
+ // setup_objects(scene);
+ // setup_lights(scene);
// レンダリング
renderer.render(scene, camera);
@@ -132,7 +133,7 @@
// レンダリング
renderer.render(scene, camera);
-としていた部分を、
+としていた部分を、たとえば
LANG:js
function renderFrame() {
@@ -288,7 +289,7 @@
const mesh = new THREE.Mesh( geometry, material );
scene.add(mesh);
- // シーンを更新する(箱を回転させる)
+ // シーンを更新する(回転させる)
scene.update = function() {
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
@@ -317,9 +318,9 @@
const extrudeSettings = {
steps: 2, // 押し出し方向の分割数
depth: 160, // 押し出し長さ
- bevelEnabled: true,
- bevelThickness: 30, // 押し出し方向
- bevelSize: 30, // 面内方向
+ bevelEnabled: true, // bevel で面取りができる
+ bevelThickness: 30, // 押し出し方向の面取り量(depth の外側に追加)
+ bevelSize: 30, // 面内方向の面取り量
bevelOffset: 20, // 外形からの距離(って何だ?)
bevelSegments: 1 // 大きくすると丸くなる
};
@@ -351,7 +352,7 @@
LANG:js
const shape = new THREE.Shape();
- shape.absarc(0, 0, 100);
+ shape.absarc(0, 0, 100); // 円弧を書く
const extrudeSettings = {
steps: 2, // 押し出し方向の分割数
@@ -361,7 +362,7 @@
bevelSize: 20, // 面内方向
bevelOffset: 0, // 外形からの距離(って何だ?)
bevelSegments: 10, // 大きくすると丸くなる
- curveSegments: 60, // 大きくすると丸くなる
+ curveSegments: 60, // 大きくすると丸くなる
};
const geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
@@ -372,7 +373,7 @@
curveSegments のデフォルトは 12 なので、これを大きくしないとガタガタになる(右図)。
-* スムースシェーディング [#jbc741e4]
+* スムーズシェーディング [#jbc741e4]
https://discourse.threejs.org/t/smooth-shading-for-extruded-circle/25782
@@ -383,7 +384,7 @@
LANG:js
const shape = new THREE.Shape();
- shape.absarc(0, 0, 100);
+ shape.absarc(0, 0, 100); // 円弧を書く
const extrudeSettings = {
steps: 2, // 押し出し方向の分割数
@@ -393,24 +394,80 @@
bevelSize: 20, // 面内方向
bevelOffset: 0, // 外形からの距離(って何だ?)
bevelSegments: 5, // 大きくすると丸くなる
- curveSegments: 60, // 大きくすると丸くなる
+ curveSegments: 20, // 大きくすると丸くなる
};
const geometry1 = new THREE.ExtrudeGeometry( shape, extrudeSettings );
- geometry1.deleteAttribute( 'normal' );
- geometry1.deleteAttribute( 'uv' );
- const geometry = THREE.BufferGeometryUtils.mergeVertices( geometry1 );
- geometry.computeVertexNormals();
+ geometry1.deleteAttribute( 'normal' ); // 余計な属性を除去して
+ geometry1.deleteAttribute( 'uv' ); // 余計な属性を除去してから
+ const geometry = THREE.BufferGeometryUtils.mergeVertices( geometry1 ); // 頂点をマージ&インデックス
+ geometry.computeVertexNormals(); // 法線ベクトルを計算する
-本来なら curveSegments = 30 くらいでも良さそうなのだけれど、
-なぜだかはじめと終わりの継ぎ目と思われる部分にちょっとだけガタが残る。
+なぜだかはじめと終わりの継ぎ目と思われる部分にちょっとだけガタが残る(左)。
+&ref(disk4.gif);
&ref(disk3.gif);
-&attachref(disk4.gif);
-上のリンク先でも、
+ LANG:js
+ const geometry = THREE.BufferGeometryUtils.mergeVertices( geometry1, 1 );
-> You could try to use BufferGeometryUtils.mergeVertices() 12 to create an indexed geometry. However this function can only merge vertices if all existing vertex data match (vertices, normals, uvs, colors etc.). This makes it problematic to use it with ExtrudeGeometry see https://jsfiddle.net/r6zguh09/1/ 39.
->
->It’s probably best if you create a custom cylinder mesh in Blender and import it as a glTF asset.
+のようにトレランスを大きくしたら良くなったかも(右)。
-と言われていて・・・これではうまく行かないのかもしれない?
+
+* ガラス&テクスチャ [#p5065ff4]
+
+参考:~
+https://tympanus.net/codrops/2021/10/27/creating-the-effect-of-transparent-glass-and-plastic-in-three-js/
+
+上のスムーズシェーディングが有効になった円盤をガラス材質にしてみる。
+
+透けていることが分かるように背景に長方形を置いてそこに画像を貼る。
+
+material の設定部分以下を次のようにする。
+
+ LANG:js
+ // 透明感のある材質
+ const material = new THREE.MeshPhysicalMaterial({
+ roughness: 0.05,
+ transmission: 1,
+ })
+ material.thickness = 40; // 屈折させるため厚みを持たせる
+
+ const mesh = new THREE.Mesh( geometry, material );
+ scene.add(mesh);
+
+ // 背景画像を読み込む
+ const loader = new THREE.TextureLoader();
+ // Thanks, Lukas Blazek@goumbik https://unsplash.com/photos/EWDvHNNfUmQ
+ loader.load('lukas-blazek-EWDvHNNfUmQ-unsplash.jpg' , function(texture) {
+ const bgGeometry = new THREE.PlaneGeometry(1200, 800); // パネルを用意して
+ const bgMaterial = new THREE.MeshBasicMaterial({ map: texture });
+ const bgMesh = new THREE.Mesh(bgGeometry, bgMaterial); // 画像を貼る
+ bgMesh.position.set(0, 0, -500); // 場所を背後にする
+ scene.add(bgMesh);
+ });
+
+&attachref(disk5.gif);
+
+* 参考 [#secc2ddd]
+
+メッシュの表示:~
+http://www.mwsoft.jp/programming/webgl/geometry.html
+
+キャラクター~
+https://tympanus.net/codrops/2021/10/04/creating-3d-characters-in-three-js/
+
+雲~
+https://tympanus.net/codrops/2020/01/28/how-to-create-procedural-clouds-using-three-js-sprites/
+
+BufferGeometry~
+https://threejs.org/docs/index.html#api/en/core/BufferGeometry
+
+透明について~
+https://r105.threejsfundamentals.org/threejs/lessons/threejs-transparency.html ~
+https://qiita.com/masato_makino/items/ce57452196d480aaa203 ~
+https://stackoverflow.com/questions/15994944/transparent-objects-in-threejs ~
+https://r105.threejsfundamentals.org/threejs/lessons/threejs-transparency.html ~
+https://pisuke-code.com/three-js-mesh-x-ray-effect/
+
+全般的なチュートリアル~
+https://ics.media/tutorial-three/