Skip to content

Commit

Permalink
リファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
ics-sawada-h committed Aug 20, 2024
1 parent 410ae5f commit a8100cf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
36 changes: 18 additions & 18 deletions src/multiple-animation/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const observer = new IntersectionObserver(
// スクロールボタンのアニメーション定義
// ---------------------------
/** シート"KV Animation"の定義 */
const scrollButtonO = kvSheet.object("ScrollButton", {
const kvScrollButtonObj = kvSheet.object("ScrollButton", {
visibility: types.stringLiteral("visible", {
visible: "visible",
hidden: "hidden",
Expand All @@ -88,7 +88,7 @@ const scrollButtonO = kvSheet.object("ScrollButton", {
y: types.number(1, { range: [0, 2] }),
}),
});
scrollButtonO.onValuesChange((values) => {
kvScrollButtonObj.onValuesChange((values) => {
scrollButton.style.visibility = values.visibility;
scrollButton.style.scale = `${values.scale.x} ${values.scale.y}`;
});
Expand All @@ -113,15 +113,6 @@ scrollButtonObj.onValuesChange((values) => {
const scene = new THREE.Scene();
scene.background = new THREE.Color("#1d1d26");

// カメラを作成:THREE.PerspectiveCamera(視野角, アスペクト比, near, far)
const camera = new THREE.PerspectiveCamera(
45,
document.body.clientWidth / window.innerHeight, // document.body.clientWidth:スクロールバーを幅含まない横幅
1,
1000,
);
camera.position.z = 45;

// ---------------------------
// テキストのアニメーション定義
// ---------------------------
Expand Down Expand Up @@ -194,12 +185,13 @@ textLoopObj.onValuesChange((value) => {
// ---------------------------
// キューブのアニメーション定義
// ---------------------------
const cubeMaterial = new THREE.MeshStandardMaterial({
// キューブのメッシュ
const material = new THREE.MeshStandardMaterial({
color: "#ff9900",
emissive: "#049ef4",
});
const boxGeometry = new THREE.BoxGeometry(6, 6, 6);
const cube = new THREE.Mesh(boxGeometry, cubeMaterial);
const geometry = new THREE.BoxGeometry(6, 6, 6);
const cube = new THREE.Mesh(geometry, material);
scene.add(cube); // three.jsのシーンに追加

/** シート"KV Animation"の定義 */
Expand Down Expand Up @@ -231,7 +223,7 @@ cubeObj.onValuesChange((values) => {
cube.position.set(px, py, pz);
const { sx, sy, sz } = values.scale;
cube.scale.set(sx, sy, sz);
cubeMaterial.color = values.color;
material.color = values.color;
});

/**
Expand All @@ -247,6 +239,17 @@ rectAreaLight.position.set(-20, 40, 10);
rectAreaLight.lookAt(new THREE.Vector3(0, 0, 0)); // 座標原点の方を照らす
scene.add(rectAreaLight);

/**
* カメラ
*/
const camera = new THREE.PerspectiveCamera(
45,
document.body.clientWidth / window.innerHeight, // document.body.clientWidth:スクロールバーを幅含まない横幅
1,
1000,
);
camera.position.z = 45;

/**
* レンダラー
*/
Expand All @@ -263,9 +266,6 @@ const tick = () => {
// レンダリング
renderer.render(scene, camera);

// カメラはemptyObjectの方向を見るように
// camera.lookAt(cube.position);

window.requestAnimationFrame(tick);
};
tick();
Expand Down
4 changes: 4 additions & 0 deletions src/sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@

<body>
<div id="app"></div>

<footer class="navigation">
<a href="../">目次へもどる</a>
</footer>
</body>
</html>
30 changes: 17 additions & 13 deletions src/sample/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh); // three.jsのシーンに追加

/**
* シート "Cube animation" のアニメーション定義
* シート "KV Animation" のアニメーション定義
*/
const cubeObj = sheet.object("Cube", {
// GUIから入力できるよう、変更させたいプロパティを定義
// 回転を定義
rotation: types.compound({
// types.compound() でグループ化
x: types.number(mesh.rotation.x, { range: [-2, 2] }),
y: types.number(mesh.rotation.y, { range: [-2, 2] }),
z: types.number(mesh.rotation.z, { range: [-2, 2] }),
x: types.number(0, { range: [-2, 2] }), // −360 〜 360度 の想定
y: types.number(0, { range: [-2, 2] }),
z: types.number(0, { range: [-2, 2] }),
}),
// 位置を定義
position: types.compound({
px: types.number(mesh.position.x, { range: [-100, 100] }),
py: types.number(mesh.position.y, { range: [-100, 100] }),
pz: types.number(mesh.position.z, { range: [-100, 100] }),
px: types.number(0, { range: [-100, 100] }),
py: types.number(0, { range: [-100, 100] }),
pz: types.number(0, { range: [-100, 100] }),
}),
// スケール
scale: types.compound({
sx: types.number(mesh.scale.x, { range: [0, 4] }),
sy: types.number(mesh.scale.y, { range: [0, 4] }),
sz: types.number(mesh.scale.z, { range: [0, 4] }),
sx: types.number(0, { range: [0, 4] }),
sy: types.number(0, { range: [0, 4] }),
sz: types.number(0, { range: [0, 4] }),
}),
// 色を定義
color: types.rgba({ r: 255, g: 0, b: 0, a: 1 }),
Expand All @@ -66,7 +66,7 @@ const cubeObj = sheet.object("Cube", {
cubeObj.onValuesChange((values) => {
// 回転を反映
const { x, y, z } = values.rotation;
mesh.rotation.set(x * Math.PI, y * Math.PI, z * Math.PI);
mesh.rotation.set(x * Math.PI, y * Math.PI, z * Math.PI); // three.jsの回転は度数法ではなくラジアンなので変換しておく
// 位置を反映
const { px, py, pz } = values.position;
mesh.position.set(px, py, pz);
Expand All @@ -91,7 +91,9 @@ rectAreaLight.position.set(-20, 40, 10);
rectAreaLight.lookAt(new THREE.Vector3(0, 0, 0)); // 座標原点の方を照らす
scene.add(rectAreaLight);

/** カメラを作成:THREE.PerspectiveCamera(視野角, アスペクト比, near, far) */
/**
* カメラ
*/
const camera = new THREE.PerspectiveCamera(
45,
document.body.clientWidth / window.innerHeight, // document.body.clientWidth:スクロールバーを含まない横幅
Expand All @@ -100,7 +102,9 @@ const camera = new THREE.PerspectiveCamera(
);
camera.position.z = 50;

/** レンダラーを作成 */
/**
* レンダラー
*/
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.render(scene, camera);

Expand Down
7 changes: 2 additions & 5 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ html {
height: 100vh;
padding: 0 16px;
margin: 0 auto;
line-height: 2;
color: #fff;
text-align: center;

.aboutSection_inner {
width: 100%;
padding: 100px 32px;
padding: 90px 32px 100px;
background-color: rgb(255 255 255 / 40%);
-webkit-backdrop-filter: blur(4px);
backdrop-filter: blur(4px);
Expand All @@ -80,10 +81,6 @@ html {
font-weight: 700;
color: #ffdaf0;
}

p {
line-height: 2;
}
}

.navigation {
Expand Down

0 comments on commit a8100cf

Please sign in to comment.