gltfクレートによる3Dモデルの読み込み(とバグ取り) < rusterizer-from-dots
from 点を描くところから始めるRust製ソフトウェアラスタライザ
3Dモデルの読み込み < rusterizer-from-dots
バーテックスシェーダー・フラグメントシェーダーで構成されたレンダリングパイプライン < 点を描くところから始めるRust製ソフトウェアラスタライザ
https://gyazo.com/1eade565fe9711c8a798502f244ea151
ようやく光の表現とか影の表現がやりやすい環境が整いつつある!
Phongシェーダーに行きたい
でも、その前に今の造形でそれをやろうとするのはめちゃ大変なのでちょっと考えたい。
できれば、外部ファイルからモデルを読み込みたいappbird.icon
fbxってよく聞くし、fbxを読むことを考えようかな
目次
そもそもfbxって自力でパーサーかける?どういう仕様なんすか?
---> fbx読むの大変そう
gltfって何?
まずWorldのフォルダを整えていく
カラー頂点属性を持ったモデルのロード < rusterizer-from-dots
gltfの基本的な使い方とテスト
gltfのデータをVertexArrayObjectに変換する
カラー頂点属性を持ったモデルのレンダリング
bugfix: y軸方向に空いたポリゴンのスリット
bugfix: cullingをonにすると正しく描画されなくなる
bugfix: glTFとBlenderの座標系における前方向の違い
テクスチャを持ったモデルのロード < rusterizer-from-dots
Stanford Bunnyを表示させてみたくはないか?
sponzaを表示してみる
テクスチャをglTFデータから取ってくる
関数の戻り値がVAOUVでImageを返せないのでタプルにする
bugfix: load_from_memoryからImageBuffer::from_rawへ
bugfix: 異なる画像フォーマットへの対応
そもそもfbxって自力でパーサーかける?どういう仕様なんすか?appbird.icon
簡単に読めるなら組んでみようかな
FBX はもともと Kaydara が開発した “Filmbox” というモーションキャプチャ/3Dデータ管理ソフトのフォーマットを起源とします。その後 Autodesk が買収・発展させました。GPT.icon
フォーマット自体はプロプライエタリ(非公開仕様)で、Autodesk が提供する FBX SDK を使って読み書きするのが正式な手段とされています。
!!?!?!?!?!appbird.icon じゃあBlenderで触れるのは一体....
テキスト形式とバイナリ形式があるよGPT.icon
code:txt
NodeType: プロパティリスト {
子ノード1 : プロパティ… { … }
子ノード2 : プロパティ… { … }
…
}
はぇ~appbird.icon 形式自体は簡単っぽそうだけど、いろんなデータの種類に対応していくのはかなり面倒くさそうだ
バイナリ形式はより複雑ですが、リバースエンジニアリングによって仕様がかなり判明しています。GPT.icon
With no public documentation available on the binary FBX format, Blender Foundation asked Alexander to write up what he has figured out sofar. We hope this will lead to better interoperability of 3D applications in general. Blender”s next release (2.69) will support binary FBX file reading as well.
https://code.blender.org/2013/08/fbx-binary-file-format-specification/
....3D界隈も結構大変な基盤の作り方されてんねぇ.....appbird.icon
う~~ん、こりゃ複雑かもな
仕様書を読み解いてやるのも大事だろうけど、今回はスキップ また今度やるね
...うーん大変そうだなぁappbird.icon
というわけでライブラリに頼りたい
fbxcel使うといいでGPT.icon バイト列読むためのツールと高レベルに読むツールの二種類があるで
FBXの構造を強く型付けしてるでGPT.icon
はぇ~appbird.icon
こんな感じに頂点データとかを抽出できるGPT.icon
このコードは動かなかった....(多分バージョン違いかなぁ)appbird.icon
code:rs
use fbxcel_dom::FbxDom; // ---> ?
use anyhow::Result;
use std::fs::File;
fn main() -> Result<()> {
let file = File::open("model.fbx")?;
let dom = FbxDom::from_reader(file)?;
// Geometryノードを探索
for geom in dom.objects().iter().filter(|o| o.class() == "Geometry") {
if let Some(data) = geom.properties().get("Vertices") {
println!("Vertices: {:?}", data);
}
if let Some(data) = geom.properties().get("PolygonVertexIndex") {
println!("Indices: {:?}", data);
}
}
Ok(())
}
読み込んだfbxをvaoに収めよう
fbx
code:cmd
cargo add fbxcel fbxcel-dom
まず、fbxのファイルをロードしようappbird.icon
code:rs
fn load_vao(path:&Path) -> Result<VertexArrayObject<texture_pipeline::Attribute>> {
let file = File::open(path)?;
let reader = std::io::BufReader::new(file);
match AnyDocument::from_seekable_reader(reader).expect("Failed to load document") {
AnyDocument::V7400(fbx_ver, doc) => {
todo!()
}
_ => panic!("Got FBX document of unsupported version.")
};
Ok(())
}
欲しいのは頂点データとColorのデータかなappbird.icon
...どうやってやればいいんだ?
なんかドキュメントも整備されてないし...うん!?未完成!?
If you want to interpret and render FBX data, you need another library or need to do it yourself. (fbxcel-dom is incomplete and currently unmaintained, but it can help you know what kind of tasks are needed to interpret FBX data.)
...自力でやるのってどれぐらい難しい?appbird.icon
めっちゃめんどいでGPT.icon 頂点データの読み取りとかアニメーションデータの読み取りとか、仕様を読み解きながら数百行の実装が必要
ほなやめとくか....appbird.icon
objはどう?GPT.icon
いやアニメーションないしな...appbird.icon
代わりにgltfがあるでGPT.icon
2025-10-14
gltfって何?
https://github.com/KhronosGroup/glTF-Tutorials/blob/main/gltfTutorial/README.md
https://www.khronos.org/gltf/
glTF: The JPEG of 3D
The core of glTF is a JSON file that describes the structure and composition of a scene containing 3D models, which can be stored in a single binary glTF file (.glb). The top-level elements of the file include: Scenes and nodes, cameras, meshes, buffers, materials, textures, skins and animations.
khronosによって策定された3Dモデルの標準フォーマットだそう
GPT.iconいわくfbxを置き換える勢いとか言われてるけど本当?appbird.icon
あぁでも確かにデータ形式もすごく読みやすいなこれappbird.icon
よし、これにするかappbird.icon
というわけで、まずWorldのフォルダを整えていくかねappbird.icon
今Worldフォルダにいろいろありすぎて。。。
code:powershell
PS ...> tree /f ./renderer_core/src/world
actor.rs
camera.rs
mesh.rs
mesh_renderer.rs
plane.rs
tetrahedron.rs
textured_mesh_renderer.rs
transform.rs
world.rs
リファクタリング
/componentと/actorにわけていくよ
/meshにはmesh.rs(今のVertexArrayObjectが入ってるやつ)を入れるよ
名前はvaoにする
code:mesh.rs
mod vao;
pub use vao::VertexArrayObject;
動作確認◎
カラー頂点属性を持ったモデルのロード < rusterizer-from-dots
テクスチャを持ったモデルのロード < rusterizer-from-dots