From 5348e1f7d417d562b0479d4da8a53f9ee4234756 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 22 Oct 2021 20:18:35 +0900 Subject: [PATCH] =?UTF-8?q?ScriptedImporter=20=E3=81=AE=E3=83=A1=E3=83=A2?= =?UTF-8?q?=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 +```