From 131b8c505b379783556c392f81392875b1080d21 Mon Sep 17 00:00:00 2001 From: "takahashi.yutaka" Date: Sun, 10 Nov 2019 23:39:46 +0900 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E8=A6=8F=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BoneMapExporter/Scripts/BoneMapExporter.cs | 103 +++++++++++++++++++++ LICENSE | 21 +++++ README.md | 18 ++++ 3 files changed, 142 insertions(+) create mode 100644 BoneMapExporter/Scripts/BoneMapExporter.cs create mode 100644 LICENSE create mode 100644 README.md diff --git a/BoneMapExporter/Scripts/BoneMapExporter.cs b/BoneMapExporter/Scripts/BoneMapExporter.cs new file mode 100644 index 0000000..b281335 --- /dev/null +++ b/BoneMapExporter/Scripts/BoneMapExporter.cs @@ -0,0 +1,103 @@ +using System.IO; +using System.Text; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +using VRM; + +public class BoneMapExporter : EditorWindow +{ + /** + * + */ + [MenuItem("BoneMap/Export")] + private static void Create() + { + if (Selection.gameObjects.Length == 0) + { + Debug.Log("select the correct file."); + return; + } + + foreach (var obj in Selection.gameObjects) + { + var path = AssetDatabase.GetAssetOrScenePath(obj); + if (path.Length == 0) + { + Debug.Log("select the correct file."); + continue; + } + var beginPosition = path.IndexOf("Assets/"); + var endPosition = path.LastIndexOf("."); + if (beginPosition >= 0) + { + beginPosition += "Assets/".Length; + } + else + { + beginPosition = 0; + } + if (endPosition < 0) + { + endPosition = path.Length; + } + path = path.Substring(beginPosition, endPosition - beginPosition); + + ExportAvatarDescription(path, obj); + } + } + /** + * + */ + private static void ExportAvatarDescription(string filename, GameObject selectedObject) + { + if (selectedObject == null) + { + Debug.Log("select the correct file."); + return; + } + VRMHumanoidDescription component = selectedObject.GetComponent(); + if (component == null) + { + Debug.Log(selectedObject.name + " has no VRMHumanoidDescription"); + return; + } + Dictionary boneMap = new Dictionary(); + foreach (var human in component.Description.human) + { + boneMap[human.humanBone.ToString()] = human.boneName; + } + var json = ToJson(boneMap); + var path = Application.dataPath + "/" + filename + ".bmap"; + var writer = new StreamWriter(path, false); + writer.WriteLine(json); + writer.Flush(); + writer.Close(); + + Debug.Log("Export Successful. path = " + path); + } + /** + * + */ + private static string ToJson(Dictionary dictionary) + { + StringBuilder sb = new StringBuilder(); + + sb.Append("{"); + bool isFirst = true; + foreach (var pair in dictionary) + { + if (isFirst) + { + isFirst = false; + } + else + { + sb.Append(","); + } + sb.Append("\"").Append(pair.Key).Append("\":").Append("\"").Append(pair.Value).Append("\""); + } + sb.Append("}"); + return sb.ToString(); + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1187bec --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Yutaka Takahashi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d629ae --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +## BoneMapExporter とは +VMC4UE で使用するボーンマップ情報を Export するプログラムです。 + +## 動作環境 +- Unity 2018.4.5f1 + +## 使い方 +https://github.com/HAL9HARUKU/BoneMapExporter/wiki + +## ライセンス +MIT + +## 作者 +[はるく](https://twitter.com/HAL9_HARUKU) + +## 履歴 +2019/11/10 v0.1.0 +新規作成。