private static void ProcessFile(FileInfo info) { if (info != null) { string file = info.FullName; FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); float[] args = new float[CNT]; BinaryReader br = new BinaryReader(fs); RoleShape shape = (RoleShape)br.ReadInt32(); for (int i = 0; i < CNT; i++) { args[i] = br.ReadSingle(); } NeuralData data = new NeuralData { callback = Capture, boneArgs = args, shape = shape, name = "model_" + info.Name.Replace(".bytes", "") }; NeuralInput(data); br.Close(); fs.Close(); } }
public void Initial(GameObject go, RoleShape shape) { if (mat == null) { mat = AssetDatabase.LoadAssetAtPath <Material>("Assets/Resource/RawData/FaceMakeup.mat"); } string child = "Player_" + shape.ToString().ToLower() + "_face"; Transform face = go.transform.Find(child); var skr = face.gameObject.GetComponent <SkinnedMeshRenderer>(); child = "Player_" + shape.ToString().ToLower() + "_helmet"; helmet = go.transform.Find(child).gameObject; outputMat = skr.sharedMaterial; roleShape = shape; if (camera == null) { camera = GameObject.FindObjectOfType <Camera>(); } if (mainTex == null) { FecthMainTex(); } if (mainRt == null) { CreateRT(); } Update(); EditorSceneManager.sceneClosed -= OnSceneClose; EditorSceneManager.sceneClosed += OnSceneClose; }
private static void SaveRenderTex(RenderTexture rt, string name, RoleShape shape) { RenderTexture.active = rt; Texture2D tex = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false); tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); tex.Apply(); byte[] bytes = tex.EncodeToJPG(); if (bytes != null && bytes.Length > 0) { try { if (!Directory.Exists(EXPORT)) { Directory.CreateDirectory(EXPORT); } File.WriteAllBytes(EXPORT + name + ".jpg", bytes); } catch (IOException ex) { Debug.Log("转换图片失败" + ex.Message); } } GameObject.DestroyImmediate(tex); }
static int _CreateRoleShapeKeyValuePair(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2) { uint arg0 = (uint)LuaScriptMgr.GetNumber(L, 1); RoleShape arg1 = (RoleShape)LuaScriptMgr.GetNetObject(L, 2, typeof(RoleShape)); KeyValuePair <uint, RoleShape> obj = new KeyValuePair <uint, RoleShape>(arg0, arg1); LuaScriptMgr.PushValue(L, obj); return(1); } else if (count == 0) { KeyValuePair <uint, RoleShape> obj = new KeyValuePair <uint, RoleShape>(); LuaScriptMgr.PushValue(L, obj); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: KeyValuePair<uint,RoleShape>.New"); } return(0); }
public RoleShape GetConfig(uint roleShapeId) { RoleShape data = null; configs.TryGetValue(roleShapeId, out data); return(data); }
static int GetConfig(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); RoleShapeConfig obj = (RoleShapeConfig)LuaScriptMgr.GetNetObjectSelf(L, 1, "RoleShapeConfig"); uint arg0 = (uint)LuaScriptMgr.GetNumber(L, 2); RoleShape o = obj.GetConfig(arg0); LuaScriptMgr.PushObject(L, o); return(1); }
static int ContainsValue(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); Dictionary <uint, RoleShape> obj = (Dictionary <uint, RoleShape>)LuaScriptMgr.GetNetObjectSelf(L, 1, "Dictionary<uint,RoleShape>"); RoleShape arg0 = (RoleShape)LuaScriptMgr.GetNetObject(L, 2, typeof(RoleShape)); bool o = obj.ContainsValue(arg0); LuaScriptMgr.Push(L, o); return(1); }
static int Add(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 3); Dictionary <uint, RoleShape> obj = (Dictionary <uint, RoleShape>)LuaScriptMgr.GetNetObjectSelf(L, 1, "Dictionary<uint,RoleShape>"); uint arg0 = (uint)LuaScriptMgr.GetNumber(L, 2); RoleShape arg1 = (RoleShape)LuaScriptMgr.GetNetObject(L, 3, typeof(RoleShape)); obj.Add(arg0, arg1); return(0); }
static int get_Item(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); Dictionary <uint, RoleShape> obj = (Dictionary <uint, RoleShape>)LuaScriptMgr.GetNetObjectSelf(L, 1, "Dictionary<uint,RoleShape>"); uint arg0 = (uint)LuaScriptMgr.GetNumber(L, 2); RoleShape o = obj[arg0]; LuaScriptMgr.PushObject(L, o); return(1); }
static int Init(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 3); PlayerModel obj = (PlayerModel)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerModel"); RoleShape arg0 = (RoleShape)LuaScriptMgr.GetNetObject(L, 2, typeof(RoleShape)); bool arg1 = LuaScriptMgr.GetBoolean(L, 3); obj.Init(arg0, arg1); return(0); }
static int TryGetValue(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 3); Dictionary <uint, RoleShape> obj = (Dictionary <uint, RoleShape>)LuaScriptMgr.GetNetObjectSelf(L, 1, "Dictionary<uint,RoleShape>"); uint arg0 = (uint)LuaScriptMgr.GetNumber(L, 2); RoleShape arg1 = null; bool o = obj.TryGetValue(arg0, out arg1); LuaScriptMgr.Push(L, o); LuaScriptMgr.PushObject(L, arg1); return(2); }
public void NeuralProcess(NeuralData data) { OnEnable(); this.shape = data.shape; CreateAvatar(); suit_select = UnityEngine.Random.Range(0, fashionInfo.Length - 1); DrawSuit(); Update(); bone.NeuralProcess(data.boneArgs); paint.NeuralProcess(); data.callback(data.name); }
void OnGUI() { GUILayout.BeginVertical(); GUILayout.Space(4); shape = (RoleShape)EditorGUILayout.EnumPopup("Gender", shape); clip = (AnimationClip)EditorGUILayout.ObjectField("Clip ", clip, typeof(AnimationClip), true); if (go == null || (go != null && go.name != shape.ToString()) || shape.ToString() != go.name) { CreateAvatar(); } if (fashionInfo != null) { suit_select = EditorGUILayout.Popup("Suit ", suit_select, fashionDesInfo); if (suit_pre != suit_select || shape != shape_pre) { DrawSuit(true, true); suit_pre = suit_select; shape_pre = shape; } } GUILayout.EndVertical(); GUILayout.Space(12); GUILayout.BeginHorizontal(); if (GUILayout.Button("Sync-Picture", GUILayout.Width(120))) { string name = ""; float[] args = new float[NeuralInterface.CNT]; float[] args2 = new float[NeuralInterface.CNT2]; if (NeuralInterface.ParseFromPicture(ref args, ref args2, ref name)) { bone.NeuralProcess(args); paint.NeuralProcess(args2); } } if (GUILayout.Button("Sync-Model", GUILayout.Width(120))) { string file = UnityEditor.EditorUtility.OpenFilePanel("Select model file", NeuralInterface.MODEL, "bytes"); if (!string.IsNullOrEmpty(file)) { FileInfo info = new FileInfo(file); float[] args, args2; NeuralInterface.ProcessFile(info, out args, out args2); bone.NeuralProcess(args); paint.NeuralProcess(args2); } } GUILayout.EndHorizontal(); paint.OnGui(); bone.OnGui(); }
public void Initial(GameObject go, RoleShape shape) { RoleParts = go.GetComponent <XRoleParts>(); string path = "Assets/BundleRes/Config/" + shape.ToString().ToLower(); TextAsset ta = AssetDatabase.LoadAssetAtPath <TextAsset>(path + ".bytes"); if (ta != null) { MemoryStream ms = new MemoryStream(ta.bytes); fbData = new FaceBoneDatas(ms); CleanData(); MakeControlGroups(); ms.Close(); } }
static int _CreateRoleShape(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 0) { RoleShape obj = new RoleShape(); LuaScriptMgr.PushObject(L, obj); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: RoleShape.New"); } return(0); }
private static void RandomExportModels(int expc, RoleShape shape, string prefix, bool noise, bool complete) { XEditorUtil.SetupEnv(); float[] args = new float[CNT]; FileStream fs = new FileStream(EXPORT + "db_description", FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); bw.Write(expc); for (int j = 0; j < expc; j++) { string name = string.Format("db_{0:00000}_{1}", j, (int)shape); bw.Write(name); for (int i = 0; i < CNT; i++) { args[i] = UnityEngine.Random.Range(0.0f, 1.0f); bw.Write(noise ? AddNoise(args[i], i) : args[i]); } float[] args2 = new float[CNT2]; int r = UnityEngine.Random.Range(0, 3); args2[r] = 1; r = UnityEngine.Random.Range(3, 6); args2[r] = 1; args2[6] = UnityEngine.Random.Range(0.2f, 0.8f); args2[7] = UnityEngine.Random.Range(0.2f, 0.8f); for (int i = 0; i < CNT2; i++) { bw.Write(args2[i]); } NeuralData data = new NeuralData { callback = Capture, boneArgs = args, paintArgs = args2, shape = shape, name = name }; UnityEditor.EditorUtility.DisplayProgressBar(prefix, string.Format("is generating {0}/{1}", j, expc), (float)j / expc); NeuralInput(data, complete, true); } UnityEditor.EditorUtility.DisplayProgressBar(prefix, "post processing, wait for a moment", 1); bw.Close(); fs.Close(); MoveDestDir("db_*", prefix + "_" + shape.ToString().ToLower() + "/"); UnityEditor.EditorUtility.ClearProgressBar(); }
public static void DrawFace(GameObject go, RoleShape shape, string suffix, Transform[] bones, uint presentid) { string sshape = shape.ToString().ToLower(); Transform transf = go.transform.Find("Player_" + sshape + "_" + TCConst.FACE); string shape_dir = "Player_" + sshape; var row = XFashionLibrary.FindRole(presentid); if (row != null) { string cname = "Player_" + sshape + "_common_" + TCConst.FACE + "_" + row.ID; string asset = "Assets/BundleRes/FBXRawData/" + shape_dir + "/Common/" + cname; DrawPart(transf, asset, bones, null, null); } else { Debug.LogError("not find present id in profession table, " + presentid); } }
public void Init(RoleShape shape, bool isFashion = false) { _shapeID = shape.roleShapeId; _shape = shape; m_bFashionMode = isFashion; BodyInfo bodyInfo = GameSystem.Instance.BodyInfoListConfig.GetConfig(shape.body_id); string resPath = string.Format("Object/Player/body/{0}", bodyInfo.type_id); ResourceLoadManager.Instance.LoadCharacter(resPath, OnLoadPlayerBody); if (mPlayer.gameObject.GetComponent <Renderer>() != null) { mOriginalMtl = mPlayer.gameObject.GetComponent <Renderer>().material; mOriginalColor = mPlayer.gameObject.GetComponent <Renderer>().material.color; } }
private void OnEnable() { suit_select = 0; suit_pre = -1; shape = RoleShape.FEMALE; if (fData == null) { fData = AssetDatabase.LoadAssetAtPath <FaceData>("Assets/BundleRes/Config/FaceData.asset"); } if (paint == null) { paint = new FacePaint(fData); } if (bone == null) { bone = new FaceBone(fData); } }
public void ReadConfig() { if (isLoadFinish == false) { return; } isLoadFinish = false; lock (LockObject) { GameSystem.Instance.readConfigCnt += 1; } Debug.Log("Config reading " + name); string text = ResourceLoadManager.Instance.GetConfigText(name); if (text == null) { Debug.LogError("LoadConfig failed: " + name); return; } //读取以及处理XML文本的类 XmlDocument doc = CommonFunction.LoadXmlConfig(name, text); XmlNode node_data = doc.SelectSingleNode("Data"); foreach (XmlNode node_line in node_data.SelectNodes("Line")) { if (CommonFunction.IsCommented(node_line)) { continue; } RoleShape data = new RoleShape(); data.roleShapeId = uint.Parse(node_line.SelectSingleNode("role_shape_id").InnerText); data.height = uint.Parse(node_line.SelectSingleNode("height").InnerText); data.body_id = uint.Parse(node_line.SelectSingleNode("body_id").InnerText); data.hair_id = uint.Parse(node_line.SelectSingleNode("hair_id").InnerText); data.upper_id = uint.Parse(node_line.SelectSingleNode("upper_id").InnerText); data.lower_id = uint.Parse(node_line.SelectSingleNode("lower_id").InnerText); data.shoes_id = uint.Parse(node_line.SelectSingleNode("shoes_id").InnerText); data.back_id = uint.Parse(node_line.SelectSingleNode("back_id").InnerText); configs.Add(data.roleShapeId, data); } }
public static void DrawPart(GameObject go, string part, RoleShape shape, string dir, string suffix, Transform[] bones, string[] dbones, FashionList.RowData row) { string sshape = shape.ToString().ToLower(); Transform transf = go.transform.Find("Player_" + sshape + "_" + suffix); string asset = string.Empty; string shape_dir = "Player_" + sshape; if (string.IsNullOrEmpty(part)) { string cname = "Player_" + sshape + "_" + dir + "_" + suffix; asset = "Assets/BundleRes/FBXRawData/" + shape_dir + "/" + shape_dir + "_" + dir + "/" + cname; DrawPart(transf, asset, bones, dbones, row); } else if (!part.Equals("E")) { string cname = "Player_" + sshape + "_common_" + suffix + "_" + part; asset = "Assets/BundleRes/FBXRawData/" + shape_dir + "/Common/" + cname; DrawPart(transf, asset, bones, dbones, row); } }
private void OnGUI() { GUILayout.BeginVertical(); GUILayout.Label("Generate Dataset", XEditorUtil.titleLableStyle); GUILayout.Space(10); shape = (RoleShape)EditorGUILayout.EnumPopup("Gender", shape); set = (Dataset)EditorGUILayout.EnumPopup("Dataset", set); complete = EditorGUILayout.Toggle("complete show", complete); addNoise = EditorGUILayout.Toggle("trainset noise", addNoise); weight = EditorGUILayout.Slider("data capacity", weight, 0, 1); GUILayout.Label("count: " + (int)(datacnt * weight)); GUILayout.Space(8); if (GUILayout.Button("Generate")) { if (UnityEditor.EditorUtility.DisplayDialog("warn", "make sure enough memory's left to generate?", "ok", "cancel")) { RandomExportModels((int)(datacnt * weight), shape, set.ToString().ToLower(), addNoise, complete); EditorUtility.Open(EXPORT); } } GUILayout.EndVertical(); }
static int set_back_id(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); RoleShape obj = (RoleShape)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name back_id"); } else { LuaDLL.luaL_error(L, "attempt to index back_id on a nil value"); } } obj.back_id = (uint)LuaScriptMgr.GetNumber(L, 3); return(0); }
public static RoleShape ProcessFile(FileInfo info, out float[] args, out float[] args2) { string file = info.FullName; FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); args = new float[CNT]; args2 = new float[CNT2]; BinaryReader br = new BinaryReader(fs); RoleShape shape = (RoleShape)br.ReadInt32(); for (int i = 0; i < CNT; i++) { args[i] = br.ReadSingle(); } for (int i = 0; i < CNT2; i++) { args2[i] = br.ReadSingle(); } br.Close(); fs.Close(); return(shape); }
void OnGUI() { GUILayout.BeginVertical(); GUILayout.Label(XEditorUtil.Config.suit_pre, XEditorUtil.titleLableStyle); GUILayout.Space(8); GUILayout.BeginHorizontal(); GUILayout.Label("Role Shape"); shape = (RoleShape)EditorGUILayout.EnumPopup(shape); GUILayout.EndHorizontal(); GUILayout.Space(4); GUILayout.BeginHorizontal(); GUILayout.Label("Select Clip"); clip = (AnimationClip)EditorGUILayout.ObjectField(clip, typeof(AnimationClip), true); GUILayout.EndHorizontal(); GUILayout.Space(4); if (go == null || (go != null && go.name != shape.ToString()) || shape.ToString() != go.name) { CreateAvatar(); } if (fashionInfo != null) { GUILayout.BeginHorizontal(); GUILayout.Label("Select Suit"); suit_select = EditorGUILayout.Popup(suit_select, fashionDesInfo); if (suit_pre != suit_select || shape != shape_pre) { DrawSuit(); suit_pre = suit_select; shape_pre = shape; } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); paint.OnGui(); bone.OnGui(); }
static int get_height(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); RoleShape obj = (RoleShape)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name height"); } else { LuaDLL.luaL_error(L, "attempt to index height on a nil value"); } } LuaScriptMgr.Push(L, obj.height); return(1); }
private static void Capture(string name, RoleShape shape) { if (camera == null) { camera = GameObject.FindObjectOfType <Camera>(); } if (rt == null) { string path = "Assets/Engine/Editor/EditorResources/CameraOuput.renderTexture"; rt = AssetDatabase.LoadAssetAtPath <RenderTexture>(path); RenderTexture.active = rt; } else { rt.Release(); } camera.targetTexture = rt; camera.Render(); camera.Render(); SaveRenderTex(rt, name, shape); rt.Release(); Clear(); }
public static void DrawWeapon(GameObject go, RoleShape shape, string dir, XRolePart part, uint presentid, int weapon_index, FashionList.RowData row) { string sshape = shape.ToString().ToLower(); Transform transf = go.transform.Find("Player_" + sshape + "_" + TCConst.WEAPON); string shape_dir = "Player_" + sshape; string cname = "Player_" + sshape + "_" + dir + "_" + TCConst.WEAPON + "_" + presentid + "_" + weapon_index; string asset = "Assets/BundleRes/FBXRawData/" + shape_dir + "/" + shape_dir + "_" + dir + "/" + cname; for (int i = 0; i < part.weapon.Length; i++) { if (part.weapon[i].presentid == presentid) { if (weapon_index == 1) { FashionUtility.DrawPart(transf, asset, part.weapon[i].weapon1, part.weapon[i].sweapon1, row); } else { DrawPart(transf, asset, part.weapon[i].weapon2, part.weapon[i].sweapon2, row); } break; } } }
public static FashionSuit.RowData[] GetFashionsInfo(RoleShape shape) { return(_suit.Table.Where(x => x.shape == (int)shape).ToArray()); }
private Texture2D GetPaintTex(string name, RoleShape shape) { string path = "Assets/BundleRes/Knead/" + name + "_" + shape.ToString().ToLower() + ".tga"; return(AssetDatabase.LoadAssetAtPath <Texture2D>(path)); }