コード例 #1
0
        public JsonFaceData(JsonData data)
        {
            JsonData att = data["attributes"];

            Gender = (GenderType)Enum.Parse(typeof(GenderType), (string)att["gender"]["value"]);
            Age    = (int)att["age"]["value"];
            float _az = AvatarTools.ReadJsonFloat(att["headpose"]["yaw_angle"]) * Mathf.Deg2Rad;
            float _ax = AvatarTools.ReadJsonFloat(att["headpose"]["pitch_angle"]) * Mathf.Deg2Rad;
            float _ay = AvatarTools.ReadJsonFloat(att["headpose"]["roll_angle"]) * Mathf.Deg2Rad;

            Angle = new Vector3(_ax, _ay, _az);
            //Glass = att["glass"]["value"].ToString();
            data     = data["landmark"];
            JsonData = new Dictionary <string, Vector2>();
            JsonKeys = AvatarTools.GetJsonKeys(data);
            for (int i = 0; i < JsonKeys.Length; i++)
            {
                Vector2 v = new Vector2(AvatarTools.ReadJsonFloat(data[JsonKeys[i]]["x"]), AvatarTools.ReadJsonFloat(data[JsonKeys[i]]["y"]));
                JsonData.Add(JsonKeys[i], v);
            }
            //rewrite angle.z
            Vector2 v0     = JsonData[AvatarTools.FaceLeft];
            Vector2 v1     = JsonData[AvatarTools.FaceRight];
            float   _angle = Vector2.Dot(Vector2.right, (v1 - (v0 + v1) / 2f).normalized);

            _angle = Mathf.Acos(_angle);
            _angle = v1.y > v0.y ? -_angle : _angle;
            Angle  = new Vector3(_ax, _ay, _angle);
        }
コード例 #2
0
ファイル: AvatarObject.cs プロジェクト: carefreeq/Avatar_Face
 void OnGUI()
 {
     if (GUI.Button(new Rect(0, 0, 300, 100), "发送"))
     {
         LoadFaceTex(tex);
     }
     if (GUI.Button(new Rect(0, 150, 300, 100), "头发"))
     {
         hairIndex = (hairIndex + 1) % HairMesh.Length;
         LoadSkinnedMesh(Hair, HairMesh[hairIndex]);
     }
     if (GUI.Button(new Rect(0, 300, 300, 100), "上衣"))
     {
         upperIndex = (upperIndex + 1) % UpperMesh.Length;
         LoadSkinnedMesh(UpperCloth, UpperMesh[upperIndex]);
     }
     if (GUI.Button(new Rect(0, 450, 300, 100), "裤子"))
     {
         lowerIndex = (lowerIndex + 1) % LowerMesh.Length;
         LoadSkinnedMesh(LowerCloth, LowerMesh[lowerIndex]);
     }
     if (GUI.Button(new Rect(0, 600, 300, 100), "保存"))
     {
         AvatarTools.SaveAvatarData(GetAvatarData());
     }
     if (GUI.Button(new Rect(0, 750, 300, 100), "加载"))
     {
         SetAvatarData(AvatarTools.ReadAvtarDatas()[0]);
     }
 }
コード例 #3
0
ファイル: AvatarObject.cs プロジェクト: carefreeq/Avatar_Face
        private void JsonManager(bool isDone, string json, Texture2D tex)
        {
            if (LoadResultEvent != null)
            {
                LoadResultEvent(isDone);
            }
            if (!isDone)
            {
                return;
            }
            IJsonFaceData jsonData = new JsonFaceData(AvatarTools.ReadFaceJson(json));

            Gender   = jsonData.Gender;
            Age      = jsonData.Age;
            FaceData = new FaceData(transform, Face);
            Dictionary <string, BoneInfo> dataBone = new JsonFaceDataBone(jsonData);
            IFaceImageData imageData = new JsonFaceDataImage(jsonData, tex);

            FaceData = new FaceData(transform, Face, dataBone, true, null);
            AvatarTools.FaceTexMapper(imageData, FaceData);
            SetFaceImage(FaceData.DataImage);
            AvatarDebug.Log("LoadFaceTex done!");
            StartCoroutine(BoneChange(changeTime));
        }
コード例 #4
0
ファイル: AvatarTools.cs プロジェクト: carefreeq/Avatar_Face
 /// <summary>
 /// 删除本地的Avatar数据
 /// </summary>
 public static void DeleteAvatarDatas(AvatarData data)
 {
     File.Delete(AvatarTools.GetAvatarDataFilePath(data.GUID));
 }
コード例 #5
0
 /// <summary>
 /// 删除本地的Avatar数据
 /// </summary>
 public static void DeleteAvatarDatas(AvatarData data)
 {
     File.Delete(AvatarTools.GetAvatarDataFilePath(data.GUID));
     AvatarDebug.Log("DeleteAvatarDatas done! avatarName:" + data.AvatarName);
 }
コード例 #6
0
ファイル: AvatarObject.cs プロジェクト: carefreeq/Avatar_Face
 /// <summary>
 /// 读取贴图到Face++,然后根据数据变化
 /// </summary>
 /// <param name="tex"></param>
 public void LoadFaceTex(Texture2D tex)
 {
     AvatarDebug.Log("start load texture:" + "width:" + tex.width + ",height:" + tex.height);
     StartCoroutine(AvatarTools.PostTex(tex, JsonManager));
 }