예제 #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(CacheEnum.TryParseOrDefault <FirstPersonFlag>(x.firstPersonFlag, true));
                }
            }

            return(FirstPersonFlag.Auto);
        }
예제 #2
0
        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         = CacheEnum.TryParseOrDefault <BlendShapePreset>(group.presetName, true);
                asset.IsBinary       = group.isBinary;
                if (asset.Preset == BlendShapePreset.Unknown)
                {
                    // fallback
                    asset.Preset = CacheEnum.TryParseOrDefault <BlendShapePreset>(group.name, true);
                }
                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);
        }
 static UssageLicense FromString(string src)
 {
     return(CacheEnum.TryParseOrDefault <UssageLicense>(src, true));
 }