ScriptedImporter のメモ書き

This commit is contained in:
ousttrue
2021-10-22 20:18:35 +09:00
parent 3cf9fe2dc9
commit 5348e1f7d4
6 changed files with 52 additions and 1 deletions

View File

@@ -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

3
docs/_static/custom.css vendored Normal file
View File

@@ -0,0 +1,3 @@
.wy-nav-content {
max-width: 1200px !important;
}

View File

@@ -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']

View File

@@ -8,4 +8,5 @@ texture_manipulation
coordinate
fast_spring_bone
first_person
scripted_importer
```

View File

@@ -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 の扱い

View File

@@ -1,3 +1,10 @@
# SimpleViewer
Runtime ローダーのサンプルです。
```{gitinclude} c89e Assets/VRM_Samples/SimpleViewer/ViewerUI.cs
:language: csharp
:linenos:
:caption:
:emphasize-lines" 434-485
```