mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-19 17:27:56 -05:00
commit
c14849ec56
2
MToon
2
MToon
|
|
@ -1 +1 @@
|
|||
Subproject commit 8953362767f9556cbc15cd2c2d649518a7e9dc7a
|
||||
Subproject commit ec0fe1a730ab97af0af30081bcba78817e379848
|
||||
9
Resources.meta
Normal file
9
Resources.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 48dcd5308bfbc814ba46c9f74a040385
|
||||
folderAsset: yes
|
||||
timeCreated: 1526882640
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -15,37 +15,13 @@ namespace VRM
|
|||
Dictionary<BlendShapeKey, BlendShapeClip> m_clipMap;
|
||||
Dictionary<BlendShapeKey, float> m_valueMap;
|
||||
|
||||
class AccumulatingSetter
|
||||
{
|
||||
public Action<float> Setter;
|
||||
float m_value;
|
||||
|
||||
public void AddValue(float value)
|
||||
{
|
||||
m_value += value;
|
||||
}
|
||||
|
||||
public void Apply(float value)
|
||||
{
|
||||
Setter(value);
|
||||
m_value = 0;
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
Setter(m_value);
|
||||
m_value = 0;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_value = 0;
|
||||
Apply();
|
||||
}
|
||||
}
|
||||
Dictionary<BlendShapeBinding, AccumulatingSetter> m_setterMap;
|
||||
Dictionary<string, Material> m_materialMap;
|
||||
Dictionary<MaterialValueBinding, AccumulatingSetter> m_materialSetterMap;
|
||||
|
||||
Dictionary<BlendShapeBinding, float> m_blendShapeValueMap = new Dictionary<BlendShapeBinding, float>();
|
||||
Dictionary<BlendShapeBinding, Action<float>> m_blendShapeSetterMap = new Dictionary<BlendShapeBinding, Action<float>>();
|
||||
|
||||
Dictionary<MaterialValueBinding, float> m_materialValueMap = new Dictionary<MaterialValueBinding, float>();
|
||||
Dictionary<MaterialValueBinding, Action<float>> m_materialSetterMap = new Dictionary<MaterialValueBinding, Action<float>>();
|
||||
|
||||
public BlendShapeMerger(IEnumerable<BlendShapeClip> clips, Transform root)
|
||||
{
|
||||
|
|
@ -71,13 +47,12 @@ namespace VRM
|
|||
m_clipMap = clips.ToDictionary(x => BlendShapeKey.CreateFrom(x), x => x);
|
||||
|
||||
m_valueMap = new Dictionary<BlendShapeKey, float>();
|
||||
m_setterMap = new Dictionary<BlendShapeBinding, AccumulatingSetter>();
|
||||
m_materialSetterMap = new Dictionary<MaterialValueBinding, AccumulatingSetter>();
|
||||
|
||||
foreach (var kv in m_clipMap)
|
||||
{
|
||||
foreach (var binding in kv.Value.Values)
|
||||
{
|
||||
if (!m_setterMap.ContainsKey(binding))
|
||||
if (!m_blendShapeSetterMap.ContainsKey(binding))
|
||||
{
|
||||
var _target = root.Find(binding.RelativePath);
|
||||
SkinnedMeshRenderer target = null;
|
||||
|
|
@ -87,13 +62,10 @@ namespace VRM
|
|||
}
|
||||
if (target != null)
|
||||
{
|
||||
m_setterMap.Add(binding, new AccumulatingSetter
|
||||
{
|
||||
Setter = x =>
|
||||
m_blendShapeSetterMap.Add(binding, x =>
|
||||
{
|
||||
target.SetBlendShapeWeight(binding.Index, x);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -109,15 +81,12 @@ namespace VRM
|
|||
Material target;
|
||||
if(m_materialMap.TryGetValue(binding.MaterialName, out target))
|
||||
{
|
||||
m_materialSetterMap.Add(binding, new AccumulatingSetter
|
||||
{
|
||||
Setter = x =>
|
||||
m_materialSetterMap.Add(binding, x =>
|
||||
{
|
||||
//target.SetBlendShapeWeight(binding.Index, x);
|
||||
var propValue = binding.BaseValue + (binding.TargetValue - binding.BaseValue) * x;
|
||||
target.SetColor(binding.ValueName, propValue);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -129,27 +98,35 @@ namespace VRM
|
|||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
foreach (var kv in m_setterMap)
|
||||
{
|
||||
kv.Value.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void Restore()
|
||||
{
|
||||
foreach (var kv in m_valueMap.ToArray())
|
||||
{
|
||||
SetValue(kv.Key, kv.Value, false);
|
||||
}
|
||||
Apply();
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
foreach (var kv in m_setterMap)
|
||||
foreach (var kv in m_blendShapeValueMap)
|
||||
{
|
||||
kv.Value.Apply();
|
||||
Action<float> setter;
|
||||
if(m_blendShapeSetterMap.TryGetValue(kv.Key, out setter))
|
||||
{
|
||||
setter(kv.Value);
|
||||
}
|
||||
}
|
||||
m_blendShapeValueMap.Clear();
|
||||
|
||||
foreach(var kv in m_materialValueMap)
|
||||
{
|
||||
Action<float> setter;
|
||||
if(m_materialSetterMap.TryGetValue(kv.Key, out setter))
|
||||
{
|
||||
setter(kv.Value);
|
||||
}
|
||||
}
|
||||
m_materialValueMap.Clear();
|
||||
}
|
||||
|
||||
public void SetValue(BlendShapeKey key, float value, bool replace)
|
||||
|
|
@ -164,46 +141,54 @@ namespace VRM
|
|||
|
||||
foreach (var binding in clip.Values)
|
||||
{
|
||||
AccumulatingSetter handler;
|
||||
if (m_setterMap.TryGetValue(binding, out handler))
|
||||
if (replace)
|
||||
{
|
||||
if (replace)
|
||||
// 値置き換え
|
||||
Action<float> setter;
|
||||
if(m_blendShapeSetterMap.TryGetValue(binding, out setter))
|
||||
{
|
||||
// 値置き換え
|
||||
handler.Apply(binding.Weight * value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 積算
|
||||
handler.AddValue(binding.Weight * value);
|
||||
setter(binding.Weight * value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarningFormat("'{0}' not found", binding);
|
||||
// 積算
|
||||
float acc;
|
||||
if(m_blendShapeValueMap.TryGetValue(binding, out acc))
|
||||
{
|
||||
m_blendShapeValueMap[binding] = acc + binding.Weight * value;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_blendShapeValueMap[binding] = binding.Weight * value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// materialの更新
|
||||
foreach (var binding in clip.MaterialValues)
|
||||
{
|
||||
AccumulatingSetter handler;
|
||||
if(m_materialSetterMap.TryGetValue(binding, out handler))
|
||||
if (replace)
|
||||
{
|
||||
if (replace)
|
||||
// 値置き換え
|
||||
Action<float> setter;
|
||||
if (m_materialSetterMap.TryGetValue(binding, out setter))
|
||||
{
|
||||
// 値置き換え
|
||||
handler.Apply(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 積算
|
||||
handler.AddValue(value);
|
||||
setter(value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarningFormat("'{0}' not found", binding);
|
||||
// 積算
|
||||
float acc;
|
||||
if (m_materialValueMap.TryGetValue(binding, out acc))
|
||||
{
|
||||
m_materialValueMap[binding] = acc + value;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_materialValueMap[binding] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,14 +76,6 @@ namespace VRM
|
|||
}
|
||||
}
|
||||
|
||||
public void Restore()
|
||||
{
|
||||
if (m_merger != null)
|
||||
{
|
||||
m_merger.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
if (m_merger != null)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace VRM
|
|||
//Directory.CreateDirectory(folder);
|
||||
}
|
||||
|
||||
var textureName = string.IsNullOrEmpty(image.extra.name) ? string.Format("buffer#{0:00}", i) : image.extra.name;
|
||||
var textureName = !string.IsNullOrEmpty(image.name) ? image.name: string.Format("buffer#{0:00}", i);
|
||||
var png = Path.Combine(folder, textureName + ".png");
|
||||
var byteSegment = context.GLTF.GetViewBytes(image.bufferView);
|
||||
File.WriteAllBytes(png, byteSegment.ToArray());
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ namespace VRM
|
|||
[Serializable]
|
||||
public class glTF_VRM_extensions : JsonSerializableBase
|
||||
{
|
||||
[Obsolete("use gltf.asset.generator")]
|
||||
public string version = VRMVersion.VERSION;
|
||||
public string exporterVersion = "UniVRM-" + VRMVersion.VERSION;
|
||||
|
||||
public glTF_VRM_Meta meta = new glTF_VRM_Meta();
|
||||
public glTF_VRM_Humanoid humanoid = new glTF_VRM_Humanoid();
|
||||
|
|
@ -20,7 +19,7 @@ namespace VRM
|
|||
|
||||
protected override void SerializeMembers(JsonFormatter f)
|
||||
{
|
||||
//f.KeyValue(() => version);
|
||||
f.KeyValue(() => exporterVersion);
|
||||
f.KeyValue(() => meta);
|
||||
f.KeyValue(() => humanoid);
|
||||
f.KeyValue(() => firstPerson);
|
||||
|
|
@ -52,6 +51,7 @@ namespace VRM
|
|||
|
||||
protected override void SerializeMembers(JsonFormatter f)
|
||||
{
|
||||
f.KeyValue(() => extensionsUsed);
|
||||
f.KeyValue(() => extensions);
|
||||
base.SerializeMembers(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,8 +127,18 @@ namespace VRM
|
|||
}
|
||||
foreach (var kv in item.vectorProperties)
|
||||
{
|
||||
var v = new Vector4(kv.Value[0], kv.Value[1], kv.Value[2], kv.Value[3]);
|
||||
material.SetVector(kv.Key, v);
|
||||
if (item.textureProperties.ContainsKey(kv.Key))
|
||||
{
|
||||
// texture offset & scale
|
||||
material.SetTextureOffset(kv.Key, new Vector2(kv.Value[0], kv.Value[1]));
|
||||
material.SetTextureScale(kv.Key, new Vector2(kv.Value[2], kv.Value[3]));
|
||||
}
|
||||
else
|
||||
{
|
||||
// vector4
|
||||
var v = new Vector4(kv.Value[0], kv.Value[1], kv.Value[2], kv.Value[3]);
|
||||
material.SetVector(kv.Key, v);
|
||||
}
|
||||
}
|
||||
foreach (var kv in item.textureProperties)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,9 +38,10 @@ namespace VRM
|
|||
{
|
||||
var meta=ScriptableObject.CreateInstance<VRMMetaObject>();
|
||||
meta.name = "Meta";
|
||||
meta.ExporterVersion = VRM.extensions.VRM.exporterVersion;
|
||||
|
||||
var gltfMeta = VRM.extensions.VRM.meta;
|
||||
meta.Version = gltfMeta.version;
|
||||
meta.Version = gltfMeta.version; // model version
|
||||
meta.Author = gltfMeta.author;
|
||||
meta.ContactInformation = gltfMeta.contactInformation;
|
||||
meta.Reference = gltfMeta.reference;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,59 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
public static class VRMVersion
|
||||
{
|
||||
public const int MAJOR = 0;
|
||||
public const int MINOR = 35;
|
||||
public const int MINOR = 36;
|
||||
|
||||
public const string VERSION = "0.35";
|
||||
public const string VERSION = "0.36";
|
||||
|
||||
public const string DecrementMenuName = "VRM/Version(0.35) Decrement";
|
||||
public const string IncrementMenuName = "VRM/Version(0.35) Increment";
|
||||
public const string DecrementMenuName = "VRM/Version(0.36) Decrement";
|
||||
public const string IncrementMenuName = "VRM/Version(0.36) Increment";
|
||||
|
||||
public static bool IsNewer(string version)
|
||||
{
|
||||
if (string.IsNullOrEmpty(version))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var prefix = "UniVRM-";
|
||||
if (version.StartsWith(prefix))
|
||||
{
|
||||
version = version.Substring(prefix.Length);
|
||||
}
|
||||
|
||||
var splited = version.Split('.');
|
||||
if (splited.Length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var major = int.Parse(splited[0]);
|
||||
var minor = int.Parse(splited[1]);
|
||||
|
||||
if (major < MAJOR)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (major > MAJOR)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return minor > MINOR;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ namespace VRM
|
|||
public Dictionary<string, float> floatProperties = new Dictionary<string, float>();
|
||||
public Dictionary<string, float[]> vectorProperties = new Dictionary<string, float[]>();
|
||||
public Dictionary<string, int> textureProperties = new Dictionary<string, int>();
|
||||
|
||||
public Dictionary<string, bool> keywordMap = new Dictionary<string, bool>();
|
||||
public Dictionary<string, string> tagMap = new Dictionary<string, string>();
|
||||
|
||||
|
|
@ -145,6 +144,12 @@ namespace VRM
|
|||
material.textureProperties.Add(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
// offset & scaling
|
||||
var offset = m.GetTextureOffset(name);
|
||||
var scaling = m.GetTextureScale(name);
|
||||
material.vectorProperties.Add(name,
|
||||
new float[] { offset.x, offset.y, scaling.x, scaling.y });
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,14 @@ namespace VRM
|
|||
|
||||
so.Update();
|
||||
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(m_propMap["ExporterVersion"]);
|
||||
if (VRMVersion.IsNewer(m_propMap["ExporterVersion"].stringValue))
|
||||
{
|
||||
EditorGUILayout.HelpBox("Check UniVRM new version. https://github.com/dwango/UniVRM/releases", MessageType.Warning);
|
||||
}
|
||||
GUI.enabled = true;
|
||||
|
||||
m_foldoutInfo = EditorGUILayout.Foldout(m_foldoutInfo, "Information");
|
||||
if (m_foldoutInfo)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ namespace VRM
|
|||
{
|
||||
public class VRMMetaObject : ScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
public string ExporterVersion;
|
||||
|
||||
#region Info
|
||||
[SerializeField]
|
||||
public string Title;
|
||||
|
|
|
|||
|
|
@ -20,13 +20,14 @@ namespace VRM
|
|||
|
||||
foreach (Transform child in src)
|
||||
{
|
||||
var dstChild = new GameObject(child.name);
|
||||
dstChild.transform.SetParent(dst);
|
||||
dstChild.transform.position = child.position; // copy position only
|
||||
if (child.gameObject.activeSelf)
|
||||
{
|
||||
var dstChild = new GameObject(child.name);
|
||||
dstChild.transform.SetParent(dst);
|
||||
dstChild.transform.position = child.position; // copy position only
|
||||
|
||||
//dstChild.AddComponent<UniHumanoid.BoneGizmoDrawer>();
|
||||
|
||||
CopyAndBuild(child, dstChild.transform, boneMap);
|
||||
CopyAndBuild(child, dstChild.transform, boneMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +126,11 @@ namespace VRM
|
|||
//
|
||||
foreach (var src in go.transform.Traverse())
|
||||
{
|
||||
var dst = boneMap[src];
|
||||
Transform dst;
|
||||
if(!boneMap.TryGetValue(src, out dst))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
//
|
||||
|
|
@ -295,7 +300,7 @@ namespace VRM
|
|||
if (srcRenderer!=null && srcRenderer.enabled)
|
||||
{
|
||||
var dstFilter = dst.gameObject.AddComponent<MeshFilter>();
|
||||
dstFilter.sharedMesh = srcFilter.sharedMesh;
|
||||
dstFilter.sharedMesh = TransformMesh(srcFilter.sharedMesh, src.localToWorldMatrix);
|
||||
|
||||
var dstRenderer = dst.gameObject.AddComponent<MeshRenderer>();
|
||||
dstRenderer.sharedMaterials = srcRenderer.sharedMaterials;
|
||||
|
|
@ -306,5 +311,42 @@ namespace VRM
|
|||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
static Mesh TransformMesh(Mesh src, Matrix4x4 m)
|
||||
{
|
||||
m.SetColumn(3, new Vector4(0, 0, 0, 1));
|
||||
|
||||
var mesh = new Mesh();
|
||||
mesh.name = src.name + "(transformed)";
|
||||
|
||||
mesh.vertices = src.vertices.Select(x => m.MultiplyPoint(x)).ToArray();
|
||||
if (src.normals != null && src.normals.Length > 0)
|
||||
{
|
||||
mesh.normals = src.normals.Select(x => m.MultiplyVector(x)).ToArray();
|
||||
}
|
||||
if (src.tangents != null && src.tangents.Length > 0)
|
||||
{
|
||||
mesh.tangents = src.tangents.Select(x =>
|
||||
{
|
||||
var t = m.MultiplyVector((Vector3)x);
|
||||
return new Vector4(t.x, t.y, t.z, x.w);
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
if (src.colors != null && src.colors.Length > 0) mesh.colors = src.colors;
|
||||
if (src.uv != null && src.uv.Length > 0) mesh.uv = src.uv;
|
||||
if (src.uv2 != null && src.uv2.Length > 0) mesh.uv2 = src.uv2;
|
||||
if (src.uv3 != null && src.uv3.Length > 0) mesh.uv3 = src.uv3;
|
||||
if (src.uv4 != null && src.uv4.Length > 0) mesh.uv4 = src.uv4;
|
||||
|
||||
mesh.subMeshCount = src.subMeshCount;
|
||||
for(int i=0; i<mesh.subMeshCount; ++i)
|
||||
{
|
||||
mesh.SetIndices(src.GetIndices(i), src.GetTopology(i), i);
|
||||
}
|
||||
|
||||
return mesh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
2
UniGLTF
2
UniGLTF
|
|
@ -1 +1 @@
|
|||
Subproject commit aa21a1fdc8fd87a6226cde3ce2e95487a52ccb42
|
||||
Subproject commit 04f8a4cea3f33a080236342d8a5c95eec9cd8f50
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit e6f56c8ba8314e409338c3bab224f5f071c974fd
|
||||
Subproject commit fb94c1495da665bb9fff18e9a2cc2dfb7090b4c3
|
||||
Loading…
Reference in New Issue
Block a user