Skip to content

Commit

Permalink
Three.js r152→r164
Browse files Browse the repository at this point in the history
  • Loading branch information
ics-ikeda committed Apr 26, 2024
1 parent e64324f commit eb116bd
Show file tree
Hide file tree
Showing 64 changed files with 137 additions and 136 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Copyright 2019-2021 ICS INC.
Copyright 2019-2024 ICS INC.
All Rights Reserved.
2 changes: 1 addition & 1 deletion docs/camera_variation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Three.jsのカメラ
author: 池田 泰延
published_date: 2017-11-12
modified_date: 2019-01-08
modified_date: 2024-04-27
---

Three.jsにはCamera3Dクラスがあることを、入門編で紹介しました。このCamera3Dがどのようにして利用できるのか、もう少し掘り下げて学んでみましょう。
Expand Down
6 changes: 3 additions & 3 deletions docs/geometry_merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Three.jsの高速化手法:ジオメトリの結合
author: 池田 泰延
published_date: 2017-11-08
modified_date: 2022-05-20
modified_date: 2024-04-27
---

Three.jsで大量のオブジェクトを描画するときに役立つ最適化テクニックを紹介します。
Expand Down Expand Up @@ -80,7 +80,7 @@ for (let i = 0; i < CELL_NUM; i++) {
}
```

Three.jsでは、`THREE.BufferGeometryUtils.mergeBufferGeometries()`メソッドで結合できます。このメソッドはThree.js本体のコードに含まれていないので注意ください。公式GitHubの`examples/js/utils`フォルダーにJavaScriptファイルがあるので、これを`script`要素で読み込みます。作業用フォルダーに`BufferGeometryUtils.js`ファイルをコピーしておきましょう。該当ファイルは[こちら](https://github.com/mrdoob/three.js/blob/dev/examples/js/utils/BufferGeometryUtils.js)からダウンロードできます。
Three.jsでは、`THREE.BufferGeometryUtils.mergeGeometries()`メソッドで結合できます。このメソッドはThree.js本体のコードに含まれていないので注意ください。公式GitHubの`examples/js/utils`フォルダーにJavaScriptファイルがあるので、これを`script`要素で読み込みます。作業用フォルダーに`BufferGeometryUtils.js`ファイルをコピーしておきましょう。該当ファイルは[こちら](https://github.com/mrdoob/three.js/blob/dev/examples/js/utils/BufferGeometryUtils.js)からダウンロードできます。

```html
<script src="js/utils/BufferGeometryUtils.js"></script>
Expand Down Expand Up @@ -114,7 +114,7 @@ for (let i = 0; i < CELL_NUM; i++) {
}
}
// ジオメトリを生成
const geometry = THREE.BufferGeometryUtils.mergeBufferGeometries(boxes);
const geometry = THREE.BufferGeometryUtils.mergeGeometries(boxes);

// マテリアルを作成
const material = new THREE.MeshNormalMaterial();
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Three.js入門サイト
author: 池田 泰延
published_date: 2017-11-02
modified_date: 2023-02-06
published_date: 2024-04-27
modified_date: 2024-04-27
---

このサイトは、WebGLのライブラリ「[Three.js](https://threejs.org)」の入門サイトです。
Expand Down
4 changes: 2 additions & 2 deletions docs/light_shadowmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Three.jsで影を落とす方法
author: 池田 泰延
published_date: 2017-11-11
modified_date: 2019-01-08
modified_date: 2024-04-27
---

Threeでは光源に対してオブジェクトの影を別のオブジェクトに落とすことができます。影を落とすことで、リアリティーの向上につながります。
Expand Down Expand Up @@ -39,7 +39,7 @@ renderer.shadowMap.enabled = true;

```js
// 照明を作成
const light = new THREE.SpotLight(0xFFFFFF, 2, 100, Math.PI / 4, 1);
const light = new THREE.SpotLight(0xffffff, 400, 100, Math.PI / 4, 1);
// ライトに影を有効にする
light.castShadow = true;
scene.add(light);
Expand Down
14 changes: 7 additions & 7 deletions docs/nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Node.jsを使ったフロントエンド開発
author: 池田 泰延
published_date: 2019-01-17
modified_date: 2023-05-26
modified_date: 2024-04-27
---

効率のよい開発ができるよう、最新の開発環境の構築もしましょう。開発環境を整えれば最新のJavaScript言語仕様を利用でき、開発効率向上に役立つはずです。また、型定義のあるTypeScriptを使ってコード補完をフルに効かせて開発するのもオススメです。
Expand All @@ -12,7 +12,7 @@ modified_date: 2023-05-26

### import文の課題

とくに注意したいのは、Three.jsの本体に含まれていないライブラリです。本入門サイトで扱った`OrbitControls``mergeBufferGeometries``GLTFLoader`などが該当します。
とくに注意したいのは、Three.jsの本体に含まれていないライブラリです。本入門サイトで扱った`OrbitControls``mergeGeometries``GLTFLoader`などが該当します。

これらの機能はThree.js本体に含まれていないので、入門サイトでは別途JavaScriptファイルを`importmap`を使って読み込むことで利用しました。バンドルツール(webpackやVite等)を使った開発では、`importmap`での利用する方法とは異なる方式で解決しなければなりません。以下に対策方法を示します。

Expand Down Expand Up @@ -50,20 +50,20 @@ const controls = new OrbitControls(camera, renderer.domElement);



### mergeBufferGeometries の使い方
### mergeGeometries の使い方


`import`文で、`three/examples/jsm/utils/BufferGeometryUtils`から該当機能を読み込みます。`import`文により`mergeBufferGeometries`が該当機能を得ているので、これを使って利用します。`THREE.BufferGeometryUtils.mergeBufferGeometries`ではなく`mergeBufferGeometries`で参照していることがポイントです。
`import`文で、`three/examples/jsm/utils/BufferGeometryUtils`から該当機能を読み込みます。`import`文により`mergeGeometries`が該当機能を得ているので、これを使って利用します。`THREE.BufferGeometryUtils.mergeGeometries`ではなく`mergeGeometries`で参照していることがポイントです。


```js
import * as THREE from "three";
import { mergeBufferGeometries } from "three/examples/jsm/utils/BufferGeometryUtils";
import { mergeGeometries } from "three/examples/jsm/utils/BufferGeometryUtils";

// ・・・省略

// ジオメトリを生成
const geometry = mergeBufferGeometries(boxes);
const geometry = mergeGeometries(boxes);
```

もしくは、以下のように`* as BufferGeometryUtils`として`import`文を記載しても問題ありません。
Expand All @@ -75,7 +75,7 @@ import * as BufferGeometryUtils from "three/examples/jsm/utils/BufferGeometryUti
// ・・・省略

// ジオメトリを生成
const geometry = BufferGeometryUtils.mergeBufferGeometries(boxes);
const geometry = BufferGeometryUtils.mergeGeometries(boxes);
```


Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ modified_date: 2023-05-26
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion samples/camera_basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion samples/camera_basic_earth.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion samples/camera_mouse_drag.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion samples/camera_mouse_x.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions samples/camera_orbitcontrols.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.152.2/examples/jsm/"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/"
}
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions samples/camera_orbitcontrols_basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.152.2/examples/jsm/"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/"
}
}
</script>
Expand Down
8 changes: 4 additions & 4 deletions samples/camera_orthographic.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down Expand Up @@ -32,8 +32,8 @@

// 光源を作成
{
const spotLight = new THREE.SpotLight(0xffffff, 4, 2000, Math.PI / 5, 0.2, 1.5);
spotLight.position.set(500, 300, 500);
const spotLight = new THREE.SpotLight(0xffffff, 200, 2000, Math.PI / 5, 0.2, 0.5);
spotLight.position.set(500, 250, 500);
spotLight.castShadow = true; // 影を落とす設定
spotLight.shadow.mapSize.width = 2048;
spotLight.shadow.mapSize.height = 2048;
Expand All @@ -54,7 +54,7 @@
map: texture,
roughness: 0.0,
metalness: 0.6,
})
}),
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true; // 影の設定
Expand Down
10 changes: 5 additions & 5 deletions samples/camera_perspective.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand All @@ -29,11 +29,11 @@
const scene = new THREE.Scene();

// カメラを作成
const camera = new THREE.PerspectiveCamera(30, width / height);
const camera = new THREE.PerspectiveCamera(30, width / height,1, 9999);

// 光源を作成
{
const spotLight = new THREE.SpotLight(0xffffff, 4, 2000, Math.PI / 5, 0.2, 1.5);
const spotLight = new THREE.SpotLight(0xffffff, 200, 2000, Math.PI / 5, 0.2, 0.5);
spotLight.position.set(500, 300, 500);
spotLight.castShadow = true; // 影を落とす設定
spotLight.shadow.mapSize.width = 2048;
Expand All @@ -55,7 +55,7 @@
map: texture,
roughness: 0.0,
metalness: 0.6,
})
}),
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true; // 影の設定
Expand Down
4 changes: 2 additions & 2 deletions samples/class_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand All @@ -29,7 +29,7 @@
mesh.position.set(
200 * Math.cos(radian), // X座標
30, // Y座標
200 * Math.sin(radian) // Z座標
200 * Math.sin(radian), // Z座標
);

// グループに追加する
Expand Down
2 changes: 1 addition & 1 deletion samples/class_mesh.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion samples/class_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion samples/class_view3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions samples/fog.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.154.0/build/three.module.js"
}
}
</script>
Expand Down Expand Up @@ -39,7 +39,7 @@
// グループを作成
const group = new THREE.Group();
scene.add(group);
const geometry = new THREE.BoxBufferGeometry(50, 50, 50);
const geometry = new THREE.BoxGeometry(50, 50, 50);
const material = new THREE.MeshStandardMaterial();

for (let i = 0; i < 1000; i++) {
Expand Down
2 changes: 1 addition & 1 deletion samples/geometry_general.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
11 changes: 6 additions & 5 deletions samples/geometry_merge_mesh.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.152.2/examples/jsm/"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from "three";
import * as BufferGeometryUtils from "three/addons/utils/BufferGeometryUtils.js";
import * as BufferGeometryUtils from 'three/addons/utils/BufferGeometryUtils.js';


// サイズを指定
const width = 960;
Expand Down Expand Up @@ -47,7 +48,7 @@
const geometryTranslated = geometryBox.translate(
10 * (i - CELL_NUM / 2),
10 * (j - CELL_NUM / 2),
10 * (k - CELL_NUM / 2)
10 * (k - CELL_NUM / 2),
);

// ジオメトリを保存
Expand All @@ -56,7 +57,7 @@
}
}
// ジオメトリを生成
const geometry = BufferGeometryUtils.mergeBufferGeometries(boxes);
const geometry = BufferGeometryUtils.mergeGeometries(boxes);

// マテリアルを作成
const material = new THREE.MeshNormalMaterial();
Expand Down
2 changes: 1 addition & 1 deletion samples/geometry_merge_none.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.152.2/build/three.module.js"
"three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js"
}
}
</script>
Expand Down
6 changes: 3 additions & 3 deletions samples/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down Expand Up @@ -47,7 +47,7 @@
// 'position_project.html',
// 'position_world.html',
// 'quickstart.html',
// 'raycast.html',
'raycast.html',
// 'renderer_resize.html',
// 'sincos_camera.html',
// 'sincos_geo.html',
Expand All @@ -61,7 +61,7 @@
<h1>${url}</h1>
<iframe width="960" height="540" src="${url}"></iframe>
</div>
`
`,
);

console.log(doms);
Expand Down
Loading

0 comments on commit eb116bd

Please sign in to comment.