-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
takahashi.yutaka
committed
Nov 10, 2019
1 parent
60447be
commit 131b8c5
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<VRMHumanoidDescription>(); | ||
if (component == null) | ||
{ | ||
Debug.Log(selectedObject.name + " has no VRMHumanoidDescription"); | ||
return; | ||
} | ||
Dictionary<string, string> boneMap = new Dictionary<string, string>(); | ||
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("<b><color=green>Export Successful.</color></b> path = " + path); | ||
} | ||
/** | ||
* | ||
*/ | ||
private static string ToJson<TKey, TValue>(Dictionary<TKey, TValue> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
新規作成。 |