SlideShare a Scribd company logo
1 of 46
三角ポリゴンの描き方
ソラノアナ
SE 兼 個人ゲームディベロッパ
Twitter @soranoana_dev
Github Soranoana
目次
1. 自己紹介
2. はじめに
3. ポリゴンとは何か?
4. ポリゴンの原理
5. 三角ポリゴン実装
6. 複数枚ポリゴンの原理
7. 複数枚ポリゴンの実装
8. 複数枚ポリゴンを用いた立体の原理
9. 複数枚ポリゴンを用いた立体の実装
10. 応用して立方体を表示
11. これまでに作ったもの
12. おわりに
22021/1/10 三角ポリゴンの描き方
1. 自己紹介
• 名前 ソラノアナ
• 職業 SE 兼 個人ゲームディベロッパ
• 最終学歴 大学院卒(工学)
• 趣味 ゲーム開発(VR、PC、スマホ)、
ツール開発、シミュレータ開発、
研究、ゲーム(プレイ)、漫画、
アニメ etc…
• 苦手なもの デザイン
(苦手なのでスライドがモノクロ……)
2021/1/10 三角ポリゴンの描き方 3
2. はじめに(1)
• 今回伝えたい点
• ポリゴンを構成する要素・仕組み
• 普段見かける3DCGや懐かしのゲームのすごさ
42021/1/10 三角ポリゴンの描き方
2. はじめに(2)
• 今回の内容はあくまで「そういう方法もある」程度の話
• ファイルフォーマットや3Dモデリングツールによっても違う
• ググれば他のやり方も出てくる
• 三角ポリゴンだけの話に限定
(四角ポリゴンなどは別の話)
• 統合開発環境Unity(ver 2020.1.10f1)及びUnity C#での
実装・検証・説明
52021/1/10 三角ポリゴンの描き方
3. ポリゴンとは何か?(1)
• ポリゴンと言われて思い浮かぶものは? 今回はこっちの方の
ポリゴンの話
62021/1/10 三角ポリゴンの描き方
©Nintendo
©SQUARE ENIX
3. ポリゴンとは何か?(2)
• 「ポリゴン(Polygon)」とは、3点以上の頂点を結んでできた
多角形データのことを指し、曲面を構成する最小単位です。
(デジタルハリウッドスクールより抜粋 https://school.dhw.co.jp/course/3dcg/contents/w_polygon.html)
• ここで浮かぶ疑問
• 3つの頂点だけあればポリゴンになるのか?
• どういう形式で管理・表現しているのか?
• →今回はこれらの疑問の答えを説明していきます。
72021/1/10 三角ポリゴンの描き方
4. ポリゴンの原理(1)
• ポリゴンは以下のような3点の頂点座標(Vertex)で1セット
• 今回は例として3次元座標系
• 座標値はVector3(float)
(Unityだと)
b (0.5f, 1.0f, 0.0f)
a (0.0f, 0.0f, 0.0f) c (1.0f, 0.0,f 0.0f)
82021/1/10 三角ポリゴンの描き方
4. ポリゴンの原理(2)
• プログラム的には以下(C#にて一部部分のみ記載)
• このプログラムには順番も大事となっている。
Vector3[] Vertex = new Vector3[3];
Vertex[0] = new Vector3(0.0f, 0.0f, 0.0f); //a
Vertex[1] = new Vector3(0.5f, 1.0f, 0.0f); //b
Vertex[2] = new Vector3(1.0f, 0.0f, 0.0f); //c
// ※Vector3型はUnityでは以下のように
// 定義されている構造体。
// Vector3.Vector3(float x, float y, float z);
b (0.5f, 1.0f, 0.0f)
a (0.0f, 0.0f, 0.0f) c (1.0f, 0.0,f 0.0f)
92021/1/10 三角ポリゴンの描き方
4. ポリゴンの原理(3)
• 時計回り • 反時計回り
• ポリゴンの組合せを記載する面情報(Face)整数配列を用意する。
• 記載するのは頂点の配列番号。
• 順番は原則時計回りに定義する必要がある。
• 反時計回りだと見たい方向からポリゴンが表裏反転してしまう。
int[] Face = new int[3] { 0, 1, 2 }; //a, b, c int[] Face = new int[3] { 0, 2, 1 }; //a, c, b
b (0.5f, 1.0f, 0.0f)
a (0.0f, 0.0f, 0.0f) c (1.0f, 0.0,f 0.0f)
b (0.5f, 1.0f, 0.0f)
a (0.0f, 0.0f, 0.0f) c (1.0f, 0.0,f 0.0f)
実際には枠すら
見えない……
102021/1/10 三角ポリゴンの描き方
4. ポリゴンの原理(4)
• 法線ベクトル(Normal)を
設定することで、ポリゴンの表裏とは
別にポリゴンの向きを設定できる。
• 法線とは頂点から表向き方向に
向くベクトル。
• 任意の方向からの光線に対し、
影や反射の計算に用いられる。
デジタル・フロンティア記事より画像を転載
https://dftalk.jp/?p=20271
112021/1/10 三角ポリゴンの描き方 ©デジタル・フロンティア
©デジタル・フロンティア
4. ポリゴンの原理(5)
• プログラム的には以下
• または以下のAPIでまとめてUnity側で法線を計算させられる。
MeshFilter meshFilter;
meshFilter.mesh.normals = new Vector3[3] {
new Vector3(0, 0, -1),
new Vector3(0, 0, -1),
new Vector3(0, 0, -1)
};
// ※MeshFilter型はUnityでは
// ポリゴン周りの情報(Mesh)を扱う
// クラスとして定義されている。
MeshFilter meshFilter;
meshFilter.mesh.RecalculateNormals();
122021/1/10 三角ポリゴンの描き方
5. 三角ポリゴン実装(1)
• ここまでの内容をプログラムに起こす。
• 合わせて、キャプションや、Unity独自の記載なども記載して
いく。
• 次頁にて、説明した箇所は赤枠で囲ってある。
132021/1/10 三角ポリゴンの描き方
5. 三角ポリゴン実装(2)
142021/1/10 三角ポリゴンの描き方
5. 三角ポリゴン実装(3)
• 裏表を正しくポリゴンを表示
• 動画
• https://youtu.be/LdAE5tDEl48
152021/1/10 三角ポリゴンの描き方
5. 三角ポリゴン実装(4)
• 静止画
エディタ画面 実行(ビルド時)画面
162021/1/10 三角ポリゴンの描き方
5. 三角ポリゴン実装(5)
• 表裏反対のポリゴンを表示
• 動画
• https://youtu.be/Ml4uwl3oDAk
172021/1/10 三角ポリゴンの描き方
5. 三角ポリゴン実装(6)
• 静止画
エディタ画面(表)
実行(ビルド時)画面
エディタ画面(裏)
182021/1/10 三角ポリゴンの描き方
6. 複数枚ポリゴンの原理
• 基本はポリゴン一枚のときの拡張。
• 頂点座標は4か所。
• 面情報の配列長は6。
• 他は同じ
b (0.0f, 1.0f, 0.0f)
a (0.0f, 0.0f, 0.0f) c (1.0f, 0.0,f 0.0f)
d (1.0f, 1.0f, 0.0f)
Vertex[0] = new Vector3(0, 0, 0); //a
Vertex[1] = new Vector3(0, 1, 0); //b
Vertex[2] = new Vector3(1, 0, 0); //c
Vertex[3] = new Vector3(1, 1, 0); //d
int[] Face = new int[6] { 0, 1, 2, //a, b, c
1, 3, 2 }; //b, d, c
192021/1/10 三角ポリゴンの描き方
7. 複数枚ポリゴンの実装(1)
202021/1/10 三角ポリゴンの描き方
7. 複数枚ポリゴンの実装(2)
• ポリゴン2枚で正方形を表示
• 動画
• https://youtu.be/2laY4hT4XNQ
212021/1/10 三角ポリゴンの描き方
7. 複数枚ポリゴンの実装(3)
• 静止画
エディタ画面 実行(ビルド時)画面
222021/1/10 三角ポリゴンの描き方
8. 複数枚ポリゴンを用いた立体の原理(1)
• 基本はポリゴン複数枚のときと同じ……ではない。
• 以下は結論から記載していく。
• 頂点座標は8か所。
Vertex[0] = new Vector3(0, 0, 0); //a
Vertex[1] = new Vector3(0, 1, 0); //b
Vertex[2] = new Vector3(1, 0, 0); //c =g
Vertex[3] = new Vector3(1, 1, 0); //d =h
Vertex[4] = new Vector3(1, 0, 1); //e
Vertex[5] = new Vector3(1, 1, 1); //f
Vertex[6] = new Vector3(1, 0, 0); //g =c
Vertex[7] = new Vector3(1, 1, 0); //h =d
a (0.0f, 0.0f, 0.0f) c, g (1.0f, 0.0,f 0.0f)
d, h (1.0f, 1.0f, 0.0f)
f (1.0f, 1.0f, 1.0f)
e (1.0f, 0.0f, 1.0f)
b (0.0f, 1.0f, 0.0f)
232021/1/10 三角ポリゴンの描き方
8. 複数枚ポリゴンを用いた立体の原理(2)
• 面情報の配列長は12。
• 面情報はそのままだが、
頂点情報が特殊。
• 頂点情報は、法線の違う面同士で
共有できない。
• そのため、同じ座標にある別の頂点を
設定する必要がある。
• 共有すると法線が
わかりやすく死ぬ。
int[] Face = new int[12] { 0, 1, 2, //a, b, c
1, 3, 2, //b, d, c
6, 7, 5, //g, h, f
6, 5, 4, };//g, f, e
a (0.0f, 0.0f, 0.0f) c, g (1.0f, 0.0,f 0.0f)
d, h (1.0f, 1.0f, 0.0f)
f (1.0f, 1.0f, 1.0f)
e (1.0f, 0.0f, 1.0f)
b (0.0f, 1.0f, 0.0f)
242021/1/10 三角ポリゴンの描き方
9. 複数枚ポリゴンを用いた立体の実装(1) –失敗ver-
252021/1/10 三角ポリゴンの描き方
9. 複数枚ポリゴンを用いた立体の実装(2)-失敗ver-
• 6頂点で失敗する様子
• 動画
• https://youtu.be/BZoYbsJWMMc
262021/1/10 三角ポリゴンの描き方
9. 複数枚ポリゴンを用いた立体の実装(3)-失敗ver-
• 静止画
エディタ画面 実行(ビルド時)画面
272021/1/10 三角ポリゴンの描き方
9. 複数枚ポリゴンを用いた立体の実装(4) –成功ver-
282021/1/10 三角ポリゴンの描き方
9. 複数枚ポリゴンを用いた立体の実装(5)-成功ver-
• 8頂点で成功する様子
• 動画
• https://youtu.be/inQSEL2C_uI
292021/1/10 三角ポリゴンの描き方
9. 複数枚ポリゴンを用いた立体の実装(6)-成功ver-
• 静止画
エディタ画面 実行(ビルド時)画面
302021/1/10 三角ポリゴンの描き方
9. 複数枚ポリゴンを用いた立体の実装(7)-比較-
• エディタ画面で比較
• 頂点を分けると、法線が正しく計算され、ぱきっとした見た目
になる。
失敗ver(頂点情報6つ) 成功ver(頂点情報8つ)
312021/1/10 三角ポリゴンの描き方
10. 応用して立方体を表示(1)
• ここまでの内容を応用すると、どんな3Dモデルでもスクリプト
で記載可能になる。
• 線形、円、三角関数、放物線、
n次関数などを組み合わせれば、
より自然で滑らかな図形を
簡単に量産できる。
• ポリゴンの設計や、座標、法線を
把握できるので、エフェクトや
メモリ管理も容易。
• 次頁以降でこれまでの応用で立方体を
表示する。
322021/1/10 三角ポリゴンの描き方
10. 応用して立方体を表示(2)
332021/1/10 三角ポリゴンの描き方
10. 応用して立方体を表示(3)
• 応用していくと立方体でも表示できる
• 動画
• https://youtu.be/rLtMP4dinYw
342021/1/10 三角ポリゴンの描き方
10. 応用して立方体を表示(4)
• 静止画
352021/1/10 三角ポリゴンの描き方
エディタ画面 実行(ビルド時)画面
11. これまでに作ったもの(1)
• 今回の内容を応用し、これまでに作ったものを紹介する。
• 先日作った三角関数をグラフっぽく表示するもの。
• 立方体の表示はそのままに、縦横高さなどの編集機能を加えた。
• プログラムは長いため割愛する。
詳しくは以下Githubへ……
• Soranoana - 3dAndVrUserInterfaces
https://github.com/Soranoana/3dAndVrUserInterfaces
362021/1/10 三角ポリゴンの描き方
11. これまでに作ったもの(2)
• waveCube
• 動画
• https://youtu.be/3Zo8rehra-U
372021/1/10 三角ポリゴンの描き方
11. これまでに作ったもの(3)
• 静止画
382021/1/10 三角ポリゴンの描き方
エディタ画面 実行(ビルド時)画面
11. これまでに作ったもの(4)
• 大学院の研究で開発した仮想キーボード。
• 円柱ではなくバームクーヘンのひとかけらを作って表示する
ような設計。
• 円、分割数、円の滑らかさなどのパラメータから
”半”動的にモデルを変更できる。
※このプログラムでは実行前にのみパラメータの変更・反映が可能。
• プログラムは長いため割愛する。
詳しくは以下Githubへ……
• Soranoana - RadiallyInterface
https://github.com/Soranoana/RadiallyInterface
392021/1/10 三角ポリゴンの描き方
11. これまでに作ったもの(5)
• RadiallyInterface
• 動画
• https://youtu.be/5mAZyWpCqFg
402021/1/10 三角ポリゴンの描き方
11. これまでに作ったもの(6)
• 静止画
412021/1/10 三角ポリゴンの描き方
エディタ画面 実行(ビルド時)画面
12. おわりに(1)
• 今回はポリゴンの原理と、プログラムによる再現を行った。
• ポリゴンには3頂点と、その裏表を表す面情報、
法線情報が必要。
• 向き(法線)の異なる面同士では頂点を共有できないため、同
じ座標にある別の頂点を設定する必要がある。
422021/1/10 三角ポリゴンの描き方
12. おわりに(2)
所感
• 現代ではもうほぼ意識する必要のない技術ではある。
• 大体は開発環境やエンジン、3Dモデリングツールがやってくれる。
• 普段PCやスマホで見ているポリゴンがどう動いているのかを
知ることで、飲み会などの場で話題になれば幸いです。
• スパゲッティコードを整理するいい機会になった。
432021/1/10 三角ポリゴンの描き方
参考・出典・画像元
• Soranoana - 3dAndVrUserInterfaces (今回のプログラム)
https://github.com/Soranoana/3dAndVrUserInterfaces
• Soranoana - RadiallyInterface
https://github.com/Soranoana/RadiallyInterface
• ポケモンずかん
https://zukan.pokemon.co.jp/detail/137
• ゲーム2chまとめ ピコピコ通信
https://stkn-games.net/18959.html
• デジタルハリウッドスクールより抜粋
https://school.dhw.co.jp/course/3dcg/contents/w_polygon.html
• デジタル・フロンティア記事
https://dftalk.jp/?p=20271
442021/1/10 三角ポリゴンの描き方
ご清聴ありがとうございました。
452021/1/10 三角ポリゴンの描き方
補足資料(1)
• マテリアル(色、柄、テクスチャなどの設定)を忘れた場合
• 一応表示される。
• 色は蛍光ピンクで固定
• Unity使ってる人はこれを見ると
卒倒するらしい……
462021/1/10 三角ポリゴンの描き方

More Related Content

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

三角ポリゴンの描き方 - How to draw a triangular polygon