From 5348e1f7d417d562b0479d4da8a53f9ee4234756 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 22 Oct 2021 20:18:35 +0900 Subject: [PATCH 1/4] =?UTF-8?q?ScriptedImporter=20=E3=81=AE=E3=83=A1?= =?UTF-8?q?=E3=83=A2=E6=9B=B8=E3=81=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sphinx.yml | 1 + docs/_static/custom.css | 3 ++ docs/conf.py | 2 +- docs/implementation/index.md | 1 + docs/implementation/scripted_importer.md | 39 ++++++++++++++++++++++++ docs/vrm0/sample/SimpleViewer.md | 7 +++++ 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 docs/_static/custom.css create mode 100644 docs/implementation/scripted_importer.md diff --git a/.github/workflows/sphinx.yml b/.github/workflows/sphinx.yml index 654c821d6..54044aac4 100644 --- a/.github/workflows/sphinx.yml +++ b/.github/workflows/sphinx.yml @@ -17,6 +17,7 @@ jobs: - run: pip install sphinx-rtd-theme - run: sudo apt install gettext - run: pip install sphinx-intl + - run: pip install gitinclude - name: sphinx build(ja) working-directory: ./docs run: sphinx-build . ../public/ja diff --git a/docs/_static/custom.css b/docs/_static/custom.css new file mode 100644 index 000000000..8aa6c288f --- /dev/null +++ b/docs/_static/custom.css @@ -0,0 +1,3 @@ +.wy-nav-content { + max-width: 1200px !important; +} diff --git a/docs/conf.py b/docs/conf.py index 8614c5922..5426ecfc0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ author = 'VRM Consortium' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['myst_parser'] +extensions = ['myst_parser', 'gitinclude'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/docs/implementation/index.md b/docs/implementation/index.md index 19087e53f..15fb976a7 100644 --- a/docs/implementation/index.md +++ b/docs/implementation/index.md @@ -8,4 +8,5 @@ texture_manipulation coordinate fast_spring_bone first_person +scripted_importer ``` diff --git a/docs/implementation/scripted_importer.md b/docs/implementation/scripted_importer.md new file mode 100644 index 000000000..a28ea7111 --- /dev/null +++ b/docs/implementation/scripted_importer.md @@ -0,0 +1,39 @@ +# ScriptedImporter の実装 + +`v0.68.0` 以降 の `glb/gltf editor importer` と `VRM-1.0 editor importer` の実装で使用している [ScriptedImporter](https://docs.unity3d.com/ja/2019.4/ScriptReference/Experimental.AssetImporters.ScriptedImporter.html) に関して。 + +> `VRM-1.0` の実装と拡張子がぶつかってしまうので `VRM-0.x` への `ScriptedImporter` 実装はしません + +## ScriptedImporter 採用の利点 + +### Texture の Asset化 が楽 + +`AssetPostprocessor` だと普通の方法では実装できない Texture のバイト列を出力して Asset 化して、 +これを参照する Material をアセット化するということが、 +`ScriptedImporter.GetExternalObjectMap` により無理をせずに実装できます。 + +> UniVRM では抜け道として `EditorApplication.delayCall` を使用しています。 + +### Import 設定を作れる + +`ScriptedImporter` を継承したクラスの `public member` や `[SerializeField]` に情報を保存できます。 + +```cs +// 例 +[ScriptedImporter(1, "cube")] +public class CubeImporter : ScriptedImporter +{ + public float m_Scale = 1; // これを Asset の Inspector で変更して Apply すると、新しい設定で再importできる + + // 省略 +} +``` + +### ForceText 時に import が低速化するのを回避できる + +`ScriptedImporter` の SubAsset にすることで、 `mesh` などがテキスト(yaml)で Asset 化されることを回避できます。 +巨大なアセットで差が出ます。 + +## ScriptedImporter 実装 + +TODO: ExternalObjectMap の扱い diff --git a/docs/vrm0/sample/SimpleViewer.md b/docs/vrm0/sample/SimpleViewer.md index 96166e296..7ad55aeba 100644 --- a/docs/vrm0/sample/SimpleViewer.md +++ b/docs/vrm0/sample/SimpleViewer.md @@ -1,3 +1,10 @@ # SimpleViewer Runtime ローダーのサンプルです。 + +```{gitinclude} c89e Assets/VRM_Samples/SimpleViewer/ViewerUI.cs +:language: csharp +:linenos: +:caption: +:emphasize-lines" 434-485 +``` From 8b9b3fa7e135d01ca04015f4ce5c8768c6f80a54 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 22 Oct 2021 20:29:50 +0900 Subject: [PATCH 2/4] how_to_customize_material_import --- docs/gltf/0_82_glb_import.md | 14 +------------ docs/gltf/how_to_customize_material_import.md | 21 +++++++++++++++++++ docs/gltf/index.md | 9 ++++++-- 3 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 docs/gltf/how_to_customize_material_import.md diff --git a/docs/gltf/0_82_glb_import.md b/docs/gltf/0_82_glb_import.md index 23c961b42..cab05c296 100644 --- a/docs/gltf/0_82_glb_import.md +++ b/docs/gltf/0_82_glb_import.md @@ -97,19 +97,7 @@ async RuntimeGltfInstance Load(GltfData data) ### materialGenerator で URP 用のマテリアルをロードする -`materialGenerator` 引き数(省略可能)を指定することで URP マテリアルを生成するようにカスタムできます。 - -```csharp -async RuntimeGltfInstance Load(GltfData data) -{ - var materialGenerator = new GltfUrpMaterialDescriptorGenerator(); - using(var loader = new UniGLTF.ImporterContext(data, materialGenerator: materialGenerator) - { - var instance = await loader.LoadAsync(); - return instance; - } -} -``` +{doc}`Import 時に生成される Material をカスタマイズする ` ## 3. インスタンスを使用する diff --git a/docs/gltf/how_to_customize_material_import.md b/docs/gltf/how_to_customize_material_import.md new file mode 100644 index 000000000..b78f2b75f --- /dev/null +++ b/docs/gltf/how_to_customize_material_import.md @@ -0,0 +1,21 @@ +# Import 時に生成される Material をカスタマイズする + +`IMaterialDescriptorGenerator` を実装することで import 時に適用されるマテリアルを差し替えることができます。 + +## materialGenerator で URP 用のマテリアルをロードする + +URP マテリアルを生成するようにカスタムする例です。 + + + +```csharp +async RuntimeGltfInstance Load(GltfData data) +{ + IMaterialDescriptorGenerator materialGenerator = new GltfUrpMaterialDescriptorGenerator(); + using(var loader = new UniGLTF.ImporterContext(data, materialGenerator: materialGenerator) + { + var instance = await loader.LoadAsync(); + return instance; + } +} +``` diff --git a/docs/gltf/index.md b/docs/gltf/index.md index c1332b2ad..b8893ffa0 100644 --- a/docs/gltf/index.md +++ b/docs/gltf/index.md @@ -12,7 +12,12 @@ :maxdepth: 1 0_82_glb_import -how_to_impl_extension +how_to_customize_material_import 0_36_update -format +``` + +```{toctree} +:maxdepth: 1 +format +how_to_impl_extension ``` From 7b974077eaa49ec2dcf68e1f19540cd1c27f5b63 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 22 Oct 2021 20:39:14 +0900 Subject: [PATCH 3/4] RuntimeExporter --- docs/vrm0/sample/RuntimeExporterSample.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/vrm0/sample/RuntimeExporterSample.md b/docs/vrm0/sample/RuntimeExporterSample.md index 537fc5e0d..7bcbad88d 100644 --- a/docs/vrm0/sample/RuntimeExporterSample.md +++ b/docs/vrm0/sample/RuntimeExporterSample.md @@ -1,3 +1,10 @@ # RuntimeExporter VRM を Runtime Export するサンプルです。 + +```{gitinclude} v0.87.0 Assets/VRM_Samples/RuntimeExporterSample/VRMRuntimeExporter.cs +:language: csharp +:linenos: +:lines: 106-127 +:caption: +``` From 76c8c4ead3ad1206f960044468d9fb5bbdf24f7b Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 22 Oct 2021 20:45:12 +0900 Subject: [PATCH 4/4] first person --- docs/vrm0/sample/FirstPersonSample.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/vrm0/sample/FirstPersonSample.md b/docs/vrm0/sample/FirstPersonSample.md index a3626bff6..7cebf1f3d 100644 --- a/docs/vrm0/sample/FirstPersonSample.md +++ b/docs/vrm0/sample/FirstPersonSample.md @@ -8,3 +8,11 @@ VR アプリで FistPerson の設定に合わせて、可視設定を反映す * その他のカメラ の描画を例示します。 + +```{gitinclude} v0.87.0 Assets/VRM_Samples/FirstPersonSample/VRMRuntimeLoader.cs +:language: csharp +:linenos: +:lines: 31-53 +:emphasize-lines: 15 +:caption: +```