mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-10 04:49:28 -05:00
"class glTF_VRM: gltf" to "partial class glTF_extensions"
This commit is contained in:
@@ -59,9 +59,9 @@ public class VRMTest
|
||||
exporter.Export();
|
||||
|
||||
// import
|
||||
context.ParseJson<glTF_VRM>(gltf.ToJson(), new SimpleStorage());
|
||||
context.ParseJson(gltf.ToJson(), new SimpleStorage());
|
||||
Debug.LogFormat("{0}", context.Json);
|
||||
gltfImporter.Import<glTF>(context);
|
||||
gltfImporter.Import(context);
|
||||
|
||||
AssertAreEqual(go.transform, context.Root.transform);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace VRM
|
||||
return FirstPersonFlag.Auto;
|
||||
}
|
||||
|
||||
foreach(var x in context.VRM.extensions.VRM.firstPerson.meshAnnotations)
|
||||
foreach(var x in context.GLTF.extensions.VRM.firstPerson.meshAnnotations)
|
||||
{
|
||||
if (x.mesh == index)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace VRM
|
||||
{
|
||||
var context = new VRMImporterContext(path);
|
||||
|
||||
context.ParseVrm(File.ReadAllBytes(context.Path));
|
||||
context.ParseGlb(File.ReadAllBytes(context.Path));
|
||||
|
||||
//
|
||||
// https://answers.unity.com/questions/647615/how-to-update-import-settings-for-newly-created-as.html
|
||||
|
||||
@@ -9,12 +9,12 @@ namespace VRM
|
||||
{
|
||||
public class VRMExporter : gltfExporter
|
||||
{
|
||||
public VRMExporter(glTF_VRM gltf) : base(gltf)
|
||||
public VRMExporter(glTF gltf) : base(gltf)
|
||||
{ }
|
||||
|
||||
public static glTF_VRM Export(GameObject go)
|
||||
public static glTF Export(GameObject go)
|
||||
{
|
||||
var gltf = new glTF_VRM();
|
||||
var gltf = new glTF();
|
||||
using (var exporter = new VRMExporter(gltf)
|
||||
{
|
||||
#if VRM_EXPORTER_USE_SPARSE
|
||||
@@ -30,7 +30,7 @@ namespace VRM
|
||||
return gltf;
|
||||
}
|
||||
|
||||
public static void _Export(glTF_VRM gltf, VRMExporter exporter, GameObject go)
|
||||
public static void _Export(glTF gltf, VRMExporter exporter, GameObject go)
|
||||
{
|
||||
exporter.Prepare(go);
|
||||
exporter.Export();
|
||||
|
||||
@@ -3,6 +3,34 @@ using System.Collections.Generic;
|
||||
using UniGLTF;
|
||||
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public partial class glTFUsedExtensions
|
||||
{
|
||||
[UsedExtension]
|
||||
static string VRMGetUsedExtension
|
||||
{
|
||||
get
|
||||
{
|
||||
return "VRM";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public partial class glTF_extensions : JsonSerializableBase
|
||||
{
|
||||
public VRM.glTF_VRM_extensions VRM = new VRM.glTF_VRM_extensions();
|
||||
|
||||
[JsonSerializeMembers]
|
||||
void VRMSerializeMembers(GLTFJsonFormatter f)
|
||||
{
|
||||
f.KeyValue(() => VRM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
[Serializable]
|
||||
@@ -28,32 +56,4 @@ namespace VRM
|
||||
f.KeyValue(() => materialProperties);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class glTF_extensions : JsonSerializableBase
|
||||
{
|
||||
public glTF_VRM_extensions VRM = new glTF_VRM_extensions();
|
||||
|
||||
protected override void SerializeMembers(GLTFJsonFormatter f)
|
||||
{
|
||||
f.KeyValue(() => VRM);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class glTF_VRM : glTF
|
||||
{
|
||||
public glTF_extensions extensions = new glTF_extensions();
|
||||
public List<string> extensionsUsed = new List<string>
|
||||
{
|
||||
"VRM",
|
||||
};
|
||||
|
||||
protected override void SerializeMembers(GLTFJsonFormatter f)
|
||||
{
|
||||
f.KeyValue(() => extensionsUsed);
|
||||
f.KeyValue(() => extensions);
|
||||
base.SerializeMembers(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace VRM
|
||||
public static GameObject LoadFromPath(string path)
|
||||
{
|
||||
var context = new VRMImporterContext(path);
|
||||
context.ParseVrm(File.ReadAllBytes(path));
|
||||
context.ParseGlb(File.ReadAllBytes(path));
|
||||
LoadFromBytes(context);
|
||||
return context.Root;
|
||||
}
|
||||
@@ -29,14 +29,14 @@ namespace VRM
|
||||
public static GameObject LoadFromBytes(Byte[] bytes)
|
||||
{
|
||||
var context = new VRMImporterContext();
|
||||
context.ParseVrm(bytes);
|
||||
context.ParseGlb(bytes);
|
||||
LoadFromBytes(context);
|
||||
return context.Root;
|
||||
}
|
||||
|
||||
public static void LoadFromPath(VRMImporterContext context)
|
||||
{
|
||||
context.ParseVrm(File.ReadAllBytes(context.Path));
|
||||
context.ParseGlb(File.ReadAllBytes(context.Path));
|
||||
LoadFromBytes(context);
|
||||
}
|
||||
|
||||
@@ -44,16 +44,16 @@ namespace VRM
|
||||
{
|
||||
context.CreateMaterial = VRMImporter.GetMaterialFunc(glTF_VRM_Material.Parse(context.Json));
|
||||
|
||||
gltfImporter.Import<glTF_VRM>(context);
|
||||
gltfImporter.Import(context);
|
||||
if (string.IsNullOrEmpty(context.Path))
|
||||
{
|
||||
if (string.IsNullOrEmpty(context.VRM.extensions.VRM.meta.title))
|
||||
if (string.IsNullOrEmpty(context.GLTF.extensions.VRM.meta.title))
|
||||
{
|
||||
context.Root.name = "VRM_LOADED";
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Root.name = context.VRM.extensions.VRM.meta.title;
|
||||
context.Root.name = context.GLTF.extensions.VRM.meta.title;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -82,7 +82,7 @@ namespace VRM
|
||||
var CreateZWrite = gltfImporter.CreateMaterialFuncFromShader(new ShaderStore("VRM/UnlitTransparentZWrite"));
|
||||
CreateMaterialFunc fallback = (ctx, i) =>
|
||||
{
|
||||
var vrm = ctx.GLTF as glTF_VRM;
|
||||
var vrm = ctx.GLTF;
|
||||
if (vrm != null && vrm.materials[i].name.ToLower().Contains("zwrite"))
|
||||
{
|
||||
// 一応。不要かも
|
||||
@@ -184,7 +184,7 @@ namespace VRM
|
||||
|
||||
LoadBlendShapeMaster(context);
|
||||
VRMSpringUtility.LoadSecondary(context.Root.transform, context.Nodes,
|
||||
context.VRM.extensions.VRM.secondaryAnimation);
|
||||
context.GLTF.extensions.VRM.secondaryAnimation);
|
||||
LoadFirstPerson(context);
|
||||
|
||||
return Unit.Default;
|
||||
@@ -213,7 +213,7 @@ namespace VRM
|
||||
{
|
||||
var firstPerson = context.Root.AddComponent<VRMFirstPerson>();
|
||||
|
||||
var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson;
|
||||
var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson;
|
||||
if (gltfFirstPerson.firstPersonBone != -1)
|
||||
{
|
||||
firstPerson.FirstPersonBone = context.Nodes[gltfFirstPerson.firstPersonBone];
|
||||
@@ -236,7 +236,7 @@ namespace VRM
|
||||
context.BlendShapeAvatar = ScriptableObject.CreateInstance<BlendShapeAvatar>();
|
||||
context.BlendShapeAvatar.name = "BlendShape";
|
||||
|
||||
var blendShapeList = context.VRM.extensions.VRM.blendShapeMaster.blendShapeGroups;
|
||||
var blendShapeList = context.GLTF.extensions.VRM.blendShapeMaster.blendShapeGroups;
|
||||
if (blendShapeList != null && blendShapeList.Count > 0)
|
||||
{
|
||||
foreach (var x in blendShapeList)
|
||||
@@ -386,7 +386,7 @@ namespace VRM
|
||||
|
||||
private static void LoadHumanoid(VRMImporterContext context)
|
||||
{
|
||||
context.AvatarDescription = context.VRM.extensions.VRM.humanoid.ToDescription(context.Nodes);
|
||||
context.AvatarDescription = context.GLTF.extensions.VRM.humanoid.ToDescription(context.Nodes);
|
||||
context.AvatarDescription.name = "AvatarDescription";
|
||||
context.HumanoidAvatar = context.AvatarDescription.CreateAvatar(context.Root.transform);
|
||||
context.HumanoidAvatar.name = Path.GetFileNameWithoutExtension(context.Path);
|
||||
@@ -512,14 +512,14 @@ namespace VRM
|
||||
public static void LoadVrmAsync(string path, Action<GameObject> onLoaded, Action<Exception> onError = null, bool show = true)
|
||||
{
|
||||
var context = new VRMImporterContext(path);
|
||||
context.ParseVrm(File.ReadAllBytes(path));
|
||||
context.ParseGlb(File.ReadAllBytes(path));
|
||||
LoadVrmAsync(context, onLoaded, onError, show);
|
||||
}
|
||||
|
||||
public static void LoadVrmAsync(Byte[] bytes, Action<GameObject> onLoaded, Action<Exception> onError = null, bool show = true)
|
||||
{
|
||||
var context = new VRMImporterContext();
|
||||
context.ParseVrm(bytes);
|
||||
context.ParseGlb(bytes);
|
||||
LoadVrmAsync(context, onLoaded, onError, show);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,26 +21,13 @@ namespace VRM
|
||||
public BlendShapeAvatar BlendShapeAvatar;
|
||||
public VRMMetaObject Meta;
|
||||
|
||||
public glTF_VRM VRM
|
||||
{
|
||||
get
|
||||
{
|
||||
return (glTF_VRM)GLTF;
|
||||
}
|
||||
}
|
||||
|
||||
public void ParseVrm(byte[] bytes)
|
||||
{
|
||||
ParseGlb<glTF_VRM>(bytes);
|
||||
}
|
||||
|
||||
public VRMMetaObject ReadMeta(bool createThumbnail=false)
|
||||
{
|
||||
var meta=ScriptableObject.CreateInstance<VRMMetaObject>();
|
||||
meta.name = "Meta";
|
||||
meta.ExporterVersion = VRM.extensions.VRM.exporterVersion;
|
||||
meta.ExporterVersion = GLTF.extensions.VRM.exporterVersion;
|
||||
|
||||
var gltfMeta = VRM.extensions.VRM.meta;
|
||||
var gltfMeta = GLTF.extensions.VRM.meta;
|
||||
meta.Version = gltfMeta.version; // model version
|
||||
meta.Author = gltfMeta.author;
|
||||
meta.ContactInformation = gltfMeta.contactInformation;
|
||||
@@ -55,10 +42,10 @@ namespace VRM
|
||||
else if (createThumbnail)
|
||||
{
|
||||
// 作成する(先行ロード用)
|
||||
if(gltfMeta.texture >= 0 && gltfMeta.texture < VRM.textures.Count)
|
||||
if(gltfMeta.texture >= 0 && gltfMeta.texture < GLTF.textures.Count)
|
||||
{
|
||||
var t = new TextureItem(VRM, gltfMeta.texture);
|
||||
t.Process(VRM, Storage);
|
||||
var t = new TextureItem(GLTF, gltfMeta.texture);
|
||||
t.Process(GLTF, Storage);
|
||||
meta.Thumbnail=t.Texture;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,5 @@ namespace VRM
|
||||
public const int MINOR = 41;
|
||||
|
||||
public const string VERSION = "0.41";
|
||||
|
||||
public const string DecrementMenuName = "VRM/Version(0.41) Decrement";
|
||||
public const string IncrementMenuName = "VRM/Version(0.41) Increment";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace VRM
|
||||
|
||||
public void OnImported(VRMImporterContext context)
|
||||
{
|
||||
var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson;
|
||||
var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson;
|
||||
Horizontal.Apply(gltfFirstPerson.lookAtHorizontalOuter);
|
||||
VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown);
|
||||
VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp);
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace VRM
|
||||
RightEye = OffsetOnTransform.Create(animator.GetBoneTransform(HumanBodyBones.RightEye));
|
||||
}
|
||||
|
||||
var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson;
|
||||
var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson;
|
||||
HorizontalInner.Apply(gltfFirstPerson.lookAtHorizontalInner);
|
||||
HorizontalOuter.Apply(gltfFirstPerson.lookAtHorizontalOuter);
|
||||
VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown);
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace VRM
|
||||
|
||||
Head = OffsetOnTransform.Create(head);
|
||||
|
||||
var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson;
|
||||
var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson;
|
||||
switch (gltfFirstPerson.lookAtType)
|
||||
{
|
||||
case LookAtType.Bone:
|
||||
|
||||
Reference in New Issue
Block a user