diff --git a/Assets/UniGLTF/doc/DepthFirstScheduler.README.md b/Assets/UniGLTF/doc/DepthFirstScheduler.README.md index f62408945..8c41bb7a3 100644 --- a/Assets/UniGLTF/doc/DepthFirstScheduler.README.md +++ b/Assets/UniGLTF/doc/DepthFirstScheduler.README.md @@ -8,7 +8,7 @@ Asynchronous task scheduler for Unity-5.6 or later # 使い方 -```cs +```csharp var schedulable = new Schedulable(); schedulable diff --git a/Assets/UniGLTF/doc/UniJSON.README.md b/Assets/UniGLTF/doc/UniJSON.README.md index 89136662f..a66d8b737 100644 --- a/Assets/UniGLTF/doc/UniJSON.README.md +++ b/Assets/UniGLTF/doc/UniJSON.README.md @@ -5,7 +5,7 @@ JSON serializer and deserializer and schema utilities for Unity(.Net3.5) ### JSON Create -```cs +```csharp var f = new JsonFormatter(); f.BeginMap(); f.Key("X"); f.Value(1); @@ -20,7 +20,7 @@ var json = f.ToString(); Serialize public fields automatically. -```cs +```csharp var f = new JsonFormatter(); f.Serialize(new Vector3(1, 2, 3)); var json = f.ToString(); @@ -29,7 +29,7 @@ var json = f.ToString(); ### JSON Parse -```cs +```csharp var json = "{\"X\":1,\"Y\":2,\"Z\":3}"; var parsed = json.ParseAsJson(); var x = parsed["X"].GetInt32(); @@ -37,14 +37,14 @@ var x = parsed["X"].GetInt32(); ### JSON Deserialize -```cs +```csharp var v = default(Vector3); json.Deserialize(ref v); ``` ### JSON Schema -```cs +```csharp [Serializable] public class glTFSparseIndices { @@ -82,7 +82,7 @@ public void AccessorSparseIndices() Same as json interface -```cs +```csharp var f = new MsgPackFormatter(); f.Serialize(new Vector3(1, 2, 3)); ArraySegment msgpack = f.GetStoreBytes(); @@ -95,7 +95,7 @@ var x = parsed["X"].GetInt32(); WIP -```cs +```csharp var toml =@" X = 1 Y = 2 diff --git a/docs/_templates/layout.html b/docs/_templates/layout.html new file mode 100644 index 000000000..d25a78edd --- /dev/null +++ b/docs/_templates/layout.html @@ -0,0 +1,13 @@ +{% extends "!layout.html" %} + +{% block sidebarlogo %} + +{{ super() }} +{% endblock %} \ No newline at end of file diff --git a/docs/build.md b/docs/build.md new file mode 100644 index 000000000..944c24bd3 --- /dev/null +++ b/docs/build.md @@ -0,0 +1,19 @@ +# アプリケーションのビルド + +## ビルドに含めるシェーダー + +`Project Settings = Graphics - Always Included Shaders` などに設定して、ビルドに含まれるようにしてください。 + +### Unlit + +* `Assets\VRMShaders\GLTF\UniUnlit\Resources\UniGLTF\UniUnlit.shader` + +### MToon + +* `Assets\VRMShaders\VRM\MToon\MToon\Resources\Shaders\MToon.shader` + +### ランタイム import/export 時のテクスチャー変換用のシェーダー + +* `Assets\VRMShaders\GLTF\IO\Resources\UniGLTF\NormalMapExporter.shader` +* `Assets\VRMShaders\GLTF\IO\Resources\UniGLTF\StandardMapExporter.shader` +* `Assets\VRMShaders\GLTF\IO\Resources\UniGLTF\StandardMapImporter.shader` diff --git a/docs/conf.py b/docs/conf.py index 7f68b1455..e0c2c1b85 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -56,3 +56,5 @@ html_static_path = ['_static'] locale_dirs = ['locale/'] gettext_compact = False + +html_context = {"language": language} diff --git a/docs/implementation/coordinate.md b/docs/implementation/coordinate.md new file mode 100644 index 000000000..8737c1670 --- /dev/null +++ b/docs/implementation/coordinate.md @@ -0,0 +1,63 @@ +# 座標系の変換 + +UniVRMは、インポート・エクスポート時に座標変換を実行しています。 + +| | 右 | 上 | 前 | 掌性 | UV原点 | | +|-------|----|----|----|------|--------|--------------------------------------------------------| +| Unity | +X | +Y | +Z | 左手 | 左下 | | +| VRM-0 | +X | +Y | -Z | 右手 | 左上 | | +| VRM-1 | -X | +Y | +Z | 右手 | 左上 | | +| glTF | | +Y | | 右手 | 左上 | デフォルトはVRM-0方式。オプションでVRM-1方式を選べます | + +## UV + +以下のように変換します。 + +```{math} +V^{\prime} = 1 - V +``` + +## Unity <-> VRM0 + +Z軸を反転します。 + +### Vector3: Position, Normalなど + +```csharp +public static Vector3 ReverseZ(this Vector3 v) +{ + return new Vector3(v.x, v.y, -v.z); +} +``` + +### Quaternion: Rotation + +```csharp +public static Quaternion ReverseZ(this Quaternion q) +{ + float angle; + Vector3 axis; + q.ToAngleAxis(out angle, out axis); + return Quaternion.AngleAxis(-angle, ReverseZ(axis)); +} +``` + +### Matrix: BindMatrices + +スケール値が入っているとうまくいきません + +```csharp +public static Matrix4x4 ReverseZ(this Matrix4x4 m) +{ +#if UNITY_2017_1_OR_NEWER + m.SetTRS(m.GetColumn(3).ReverseZ(), m.rotation.ReverseZ(), Vector3.one); +#else + m.SetTRS(m.ExtractPosition().ReverseZ(), m.ExtractRotation().ReverseZ(), Vector3.one); +#endif + return m; +} +``` + +## Unity <-> VRM1 + +X軸を反転します。 diff --git a/docs/implementation/texture_manipulation.md b/docs/implementation/texture_manipulation.md new file mode 100644 index 000000000..d6c124b61 --- /dev/null +++ b/docs/implementation/texture_manipulation.md @@ -0,0 +1,65 @@ +# Texture関連 + +## Unity の linear の テクスチャーの挙動について + +### Runtime + +new する場合は、 + +```csharp +var texture = new Texture2D(width, height, format, mipChain, linear = true); +``` + +とする。 + +### Editor(Asset) + +AssetFolder の png/jpg からloadする場合は、 +事前に設定が必用。 + +```csharp +var textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; +textureImporter.sRGBTexture = false; // Linear +textureImporter.SaveAndReimport(); + +// linear でロードされます +var texture =AssetDatabase.LoadAssetAtPath(assetPath); +``` + +## Unity の NormalMap の挙動について + +> MToon の NormalMap も同じ + +### Runtime + +new する場合は、 + +```csharp +var texture = new Texture2D(width, height, format, mipChain, linear = true); +``` + +とする。 +また、 `DXT5nm` という仕様で格納する必要があるので変換します。 +y と w の2要素だけを使います。 + +```hlsl +half4 normal; +normal.x = 1.0; +normal.y = col.y; +normal.z = 1.0; +normal.w = col.x; +``` + +### Editor(Asset) + +AssetFolder の png/jpg からloadする場合は、 +ロードする前に設定が必用。 + +```csharp +var textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; +textureImporter.textureType = TextureImporterType.NormalMap; // normalMap +textureImporter.SaveAndReimport(); + +// DXT5nm でロードされます。 +var texture =AssetDatabase.LoadAssetAtPath(assetPath); +``` diff --git a/docs/index.md b/docs/index.md index 9e9cbc0ff..c35471bcf 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,8 +9,16 @@ UnityでVRMをエクスポートする方法などについては [manual](https ```{toctree} :maxdepth: 1 -package.md -history.md +package +history +``` + +## build + +UniVRMを使うアプリケーションのビルドに関する注意事項 + +```{toctree} +build ``` ## glTF @@ -18,9 +26,9 @@ history.md ```{toctree} :maxdepth: 1 -gltf/0_82_glb_import.md -gltf/how_to_impl_extension.md -gltf/0_36_update.md +gltf/0_82_glb_import +gltf/how_to_impl_extension +gltf/0_36_update ``` ## VRM @@ -28,20 +36,23 @@ gltf/0_36_update.md ```{toctree} :maxdepth: 1 -vrm0/0_82_runtime_import.md -vrm0/0_79_runtime_import.md -vrm0/0_77_runtime_import.md -vrm0/0_68_runtime_import.md -vrm0/0_44_runtime_import.md -vrm0/0_58_blendshape.md -vrm0/firstperson.md +vrm0/0_82_runtime_import +vrm0/0_79_runtime_import +vrm0/0_77_runtime_import +vrm0/0_68_runtime_import +vrm0/0_44_runtime_import +vrm0/0_58_blendshape +vrm0/firstperson ``` ## 実装メモ ```{toctree} +:maxdepth: 1 -implementation/runtime_resource_management.md +implementation/runtime_resource_management +implementation/texture_manipulation +implementation/coordinate ``` ### Samples @@ -56,11 +67,11 @@ implementation/runtime_resource_management.md ```{toctree} :maxdepth: 2 -vrm1/vrm1_runtime_load.md -vrm1/vrm1_get_humanoid.md -vrm1/vrm1_expression.md -vrm1/vrm1_lookat.md -vrm1/vrm1_firstperson.md +vrm1/vrm1_runtime_load +vrm1/vrm1_get_humanoid +vrm1/vrm1_expression +vrm1/vrm1_lookat +vrm1/vrm1_firstperson ``` ### Samples