Beispiel #1
0
        static FirstPersonFlag GetFirstPersonFlag(VRMImporterContext context, Renderer r)
        {
            var mesh = r.transform.GetSharedMesh();

            if (mesh == null)
            {
                return(FirstPersonFlag.Auto);
            }

            var index = context.Meshes.FindIndex(x => x.Mesh == mesh);

            if (index == -1)
            {
                return(FirstPersonFlag.Auto);
            }

            foreach (var x in context.GLTF.extensions.VRM.firstPerson.meshAnnotations)
            {
                if (x.mesh == index)
                {
                    return(EnumUtil.TryParseOrDefault <FirstPersonFlag>(x.firstPersonFlag));
                }
            }

            return(FirstPersonFlag.Auto);
        }
Beispiel #2
0
        public void EnumUtilTestSimplePasses()
        {
            Assert.AreEqual(default(HumanBodyBones), EnumUtil.TryParseOrDefault <HumanBodyBones>("xxx"));

#if UNITY_5_6_OR_NEWER
            Assert.AreEqual(HumanBodyBones.UpperChest, EnumUtil.TryParseOrDefault <HumanBodyBones>("upperchest"));
#else
            Assert.AreEqual(default(HumanBodyBones), EnumUtil.TryParseOrDefault <HumanBodyBones>("upperchest"));
#endif
        }
Beispiel #3
0
        public static HumanBodyBones ToHumanBodyBone(this VRMBone bone)
        {
#if  UNITY_5_6_OR_NEWER
            if (bone == VRMBone.upperChest)
            {
                return(HumanBodyBones.LastBone);
            }
#endif
            return(EnumUtil.TryParseOrDefault <HumanBodyBones>(bone.ToString(), HumanBodyBones.LastBone));
        }
Beispiel #4
0
        private static void LoadHumanoidObsolete(VRMImporterContext context)
        {
            var parsed   = context.Json.ParseAsJson()["extensions"]["VRM"];
            var skeleton = context.Root.transform.Traverse().Select(x => ToSkeletonBone(x)).ToArray();

            var description = new HumanDescription
            {
                human = parsed[HUMANOID_KEY]["bones"]
                        .ObjectItems
                        .Select(x => new { x.Key, Index = x.Value.GetInt32() })
                        .Where(x => x.Index != -1)
                        .Select(x =>
                {
                    var humanBone = EnumUtil.TryParseOrDefault <HumanBodyBones>(x.Key);
                    var hb        = new HumanBone
                    {
                        boneName  = context.Nodes[x.Index].name,
                        humanName = ToHumanBoneName(humanBone)
                    };
                    hb.limit.useDefaultValues = true;
                    return(hb);
                }).ToArray(),
                skeleton      = skeleton,
                lowerArmTwist = 0.5f,
                upperArmTwist = 0.5f,
                upperLegTwist = 0.5f,
                lowerLegTwist = 0.5f,
                armStretch    = 0.05f,
                legStretch    = 0.05f,
                feetSpacing   = 0.0f,
            };

            context.HumanoidAvatar      = AvatarBuilder.BuildHumanAvatar(context.Root, description);
            context.HumanoidAvatar.name = Path.GetFileNameWithoutExtension(context.Path);

            context.AvatarDescription      = UniHumanoid.AvatarDescription.CreateFrom(description);
            context.AvatarDescription.name = "AvatarDescription";
            var humanoid = context.Root.AddComponent <VRMHumanoidDescription>();

            humanoid.Avatar      = context.HumanoidAvatar;
            humanoid.Description = context.AvatarDescription;

            var animator = context.Root.GetComponent <Animator>();

            if (animator == null)
            {
                animator = context.Root.AddComponent <Animator>();
            }
            animator.avatar = context.HumanoidAvatar;
        }
Beispiel #5
0
        void OnEnable()
        {
            // Debug.Log("OnEnable");
            Undo.willFlushUndoRecord   += OnWizardUpdate;
            Selection.selectionChanged += OnWizardUpdate;

            m_tmpMeta = ScriptableObject.CreateInstance <VRMMetaObject>();

            if (m_settings == null)
            {
                m_settings = ScriptableObject.CreateInstance <VRMExportSettings>();
            }
            if (m_Inspector == null)
            {
                m_Inspector = Editor.CreateEditor(m_settings);
            }

            m_lang = EnumUtil.TryParseOrDefault <VRMExporterWizardMessages.Languages>(EditorPrefs.GetString(LANG_KEY, default(VRMExporterWizardMessages.Languages).ToString()));
        }
Beispiel #6
0
        private static BlendShapeClip LoadBlendShapeBind(VRMImporterContext context,
                                                         glTF_VRM_BlendShapeGroup group)
        {
            var asset     = ScriptableObject.CreateInstance <BlendShapeClip>();
            var groupName = group.name;
            var prefix    = "BlendShape.";

            while (groupName.StartsWith(prefix))
            {
                groupName = groupName.Substring(prefix.Length);
            }
            asset.name = "BlendShape." + groupName;

            if (group != null)
            {
                asset.BlendShapeName = groupName;
                asset.Preset         = EnumUtil.TryParseOrDefault <BlendShapePreset>(group.presetName);
                if (asset.Preset == BlendShapePreset.Unknown)
                {
                    // fallback
                    asset.Preset = EnumUtil.TryParseOrDefault <BlendShapePreset>(group.name);
                }
                asset.Values = group.binds.Select(x =>
                {
                    var mesh         = context.Meshes[x.mesh].Mesh;
                    var node         = context.Root.transform.Traverse().First(y => y.GetSharedMesh() == mesh);
                    var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(node, context.Root.transform);
                    return(new BlendShapeBinding
                    {
                        RelativePath = relativePath,
                        Index = x.index,
                        Weight = x.weight,
                    });
                })
                               .ToArray();
                asset.MaterialValues = group.materialValues.Select(x =>
                {
                    var value = new Vector4();
                    for (int i = 0; i < x.targetValue.Length; ++i)
                    {
                        switch (i)
                        {
                        case 0: value.x = x.targetValue[0]; break;

                        case 1: value.y = x.targetValue[1]; break;

                        case 2: value.z = x.targetValue[2]; break;

                        case 3: value.w = x.targetValue[3]; break;
                        }
                    }
                    return(new MaterialValueBinding
                    {
                        MaterialName = x.materialName,
                        ValueName = x.propertyName,
                        TargetValue = value,
                        BaseValue = context.Materials.First(y => y.name == x.materialName).GetColor(x.propertyName),
                    });
                })
                                       .ToArray();
            }

            return(asset);
        }
Beispiel #7
0
 static UssageLicense FromString(string src)
 {
     return(EnumUtil.TryParseOrDefault <UssageLicense>(src));
 }
 public static VRMBone FromHumanBodyBone(this HumanBodyBones human)
 {
     return(EnumUtil.TryParseOrDefault <VRMBone>(human.ToString(), VRMBone.unknown));
 }
        BlendShapeClip LoadBlendShapeBind(glTF_VRM_BlendShapeGroup group, Dictionary <Mesh, Transform> transformMeshTable)
        {
            var asset     = ScriptableObject.CreateInstance <BlendShapeClip>();
            var groupName = group.name;
            var prefix    = "BlendShape.";

            while (groupName.StartsWith(prefix))
            {
                groupName = groupName.Substring(prefix.Length);
            }
            asset.name = "BlendShape." + groupName;

            if (group != null)
            {
                asset.BlendShapeName = groupName;
                asset.Preset         = EnumUtil.TryParseOrDefault <BlendShapePreset>(group.presetName);
                asset.IsBinary       = group.isBinary;
                if (asset.Preset == BlendShapePreset.Unknown)
                {
                    // fallback
                    asset.Preset = EnumUtil.TryParseOrDefault <BlendShapePreset>(group.name);
                }
                asset.Values = group.binds.Select(x =>
                {
                    var mesh         = Meshes[x.mesh].Mesh;
                    var node         = transformMeshTable[mesh];
                    var relativePath = UniGLTF.UnityExtensions.RelativePathFrom(node, Root.transform);
                    return(new BlendShapeBinding
                    {
                        RelativePath = relativePath,
                        Index = x.index,
                        Weight = x.weight,
                    });
                })
                               .ToArray();
                asset.MaterialValues = group.materialValues.Select(x =>
                {
                    var value = new Vector4();
                    for (int i = 0; i < x.targetValue.Length; ++i)
                    {
                        switch (i)
                        {
                        case 0: value.x = x.targetValue[0]; break;

                        case 1: value.y = x.targetValue[1]; break;

                        case 2: value.z = x.targetValue[2]; break;

                        case 3: value.w = x.targetValue[3]; break;
                        }
                    }

                    var material     = GetMaterials().FirstOrDefault(y => y.name == x.materialName);
                    var propertyName = x.propertyName;
                    if (x.propertyName.EndsWith("_ST_S") ||
                        x.propertyName.EndsWith("_ST_T"))
                    {
                        propertyName = x.propertyName.Substring(0, x.propertyName.Length - 2);
                    }

                    var binding = default(MaterialValueBinding?);

                    if (material != null)
                    {
                        try
                        {
                            binding = new MaterialValueBinding
                            {
                                MaterialName = x.materialName,
                                ValueName    = x.propertyName,
                                TargetValue  = value,
                                BaseValue    = material.GetColor(propertyName),
                            };
                        }
                        catch (Exception)
                        {
                            // do nothing
                        }
                    }

                    return(binding);
                })
                                       .Where(x => x.HasValue)
                                       .Select(x => x.Value)
                                       .ToArray();
            }

            return(asset);
        }