public void TestPolygonOperations() { Vector3 transMatrix = Util.CreateRandomTransMatrix(); string gid = ChainXModel.PAINT_TOOL_GROUP_ID + Util.GetGUID(); string objPath = Const.TEST_OBJ_PATH + "monkey.obj"; string[] posIDs = ObjLoadHelper.LoadOnlyObj(objPath, Util.CreateRandomVector3(-100, 100)); string[] destPosIDs = new string[posIDs.Length]; for (int p = 0; p < posIDs.Length; ++p) { Vector3 v = Util.SplitPosID(posIDs[p]); Vector3 destV = v + transMatrix; destPosIDs[p] = Util.CreatePosID(destV); } this.CheckInsertPolygon(gid, posIDs, objPath); switch (UnityEngine.Random.Range(1, 2 + 1)) { case 1: { this.CheckMovePolygon(gid, posIDs, destPosIDs, transMatrix); this.CheckDeletePolygon(gid, destPosIDs); //ここで break; } case 2: { this.CheckDeletePolygon(gid, posIDs); //ここか break; } } }
public static string[] LoadOnlyObj(string filepath, Vector3 targetV) { GameObject target = OBJLoader.LoadOBJFile(filepath); string[] emptyPosIDs = ObjLoadHelper.ShiftPosition(target, targetV); Object.Destroy(target); return(emptyPosIDs); }
private static string[] ShiftPosition(GameObject target, Vector3 targetV) { //TODO(Tasuku): 位置をどう決めるかをそのうち決める必要がある target.transform.position = targetV; //ボクセルブロックに合わせるため,メッシュを移動させる ObjLoadHelper.MoveCenterToCorner(target); string[] emptyPosIDs = ObjLoadHelper.GetEmptyVoxels(target); return(emptyPosIDs); }
public static string[] LoadObj(string[] filepaths, Vector3 targetV, bool isTest = true) { GameObject target = OBJLoader.LoadOBJFile(filepaths[0]); string[] emptyPosIDs = ObjLoadHelper.ShiftPosition(target, targetV); if (target.transform.childCount > 0) { Texture2D texture = TextureLoader.LoadTexture(filepaths[1]); foreach (Transform child in target.transform) { child.gameObject.AddComponent <MeshCollider> (); child.gameObject.GetComponent <Renderer> ().material = new Material(Const.DIFFUSE_SHADER); child.gameObject.GetComponent <Renderer> ().material.mainTexture = texture; } } return(emptyPosIDs); //return target; }
public ChainXModel() { this.VOXEL_PLATE_DIAMETER = GameObject.Find(Const.PAINT_TOOL_PATH + "VoxelPlate").GetComponent <Renderer>().bounds.size.x - 2.2f; this.initPaintTool(); this.objLoadHelper = new ObjLoadHelper(); }
public IEnumerator Listen() { //this.SendBinary(-1, Const.START_BINARY_HEADER); byte[] msgBinary = null; string[] filepaths = { "", "" }; while (true) { msgBinary = this.ws.Recv(); if (msgBinary != null) { //Debug.Log (Encoding.ASCII.GetString(msgBinary)); //byte[] idBinary = this.getIdFromEndUntilAt(ref receivedBinary); //int destID = System.BitConverter.ToInt32(idBinary, 0); //送り先!! //byte[] msgBinary = this.getOperationFromEndUntilAt(ref receivedBinary); if (this.partEqual(ref msgBinary, ref Const.OPERATION_BINARY_HEADER)) { string line = Encoding.UTF8.GetString(msgBinary); line = line.Remove(0, Const.OPERATION_HEADER.Length).Trim(); Operation op = Operation.FromJson(line); this.controller.cv.apply(op, ChainVoxel.REMOTE_OPERATION); } else if (this.partEqual(ref msgBinary, ref Const.JOIN_BINARY_HEADER)) { string msg = Encoding.UTF8.GetString(msgBinary); msg = msg.Replace(Const.JOIN_HEADER, ""); int intID = int.Parse(msg); if (!this.siteIDs.Contains(intID)) { this.siteIDs.Add(intID); } //foreach (int sid in this.siteIDs) { Debug.Log("sid: " + sid); } //Debug.Log("this.id:" + this.id); //Debug.Log("joined id:" + intID); } else if (this.partEqual(ref msgBinary, ref Const.ID_LIST_BINARY_HEADER)) { string msg = Encoding.UTF8.GetString(msgBinary); int atIndex = msg.IndexOf(Const.MSG_SPLIT_CHAR); string idsLine = msg.Substring(atIndex + 1); //atIndex+1から最後まで String[] strIDs = idsLine.Split(Const.SPLIT_CHAR); foreach (string strID in strIDs) { int intID = int.Parse(strID); if (!this.siteIDs.Contains(intID)) { this.siteIDs.Add(intID); } } this.leaderID = this.siteIDs[0]; this.id = this.siteIDs[this.siteIDs.Count - 1]; } else if (this.partEqual(ref msgBinary, ref Const.SOME_FILE_BINARY_HEADER)) { string filepath = this.getPathUntilAt(ref msgBinary); int start_i = Const.SOME_FILE_HEADER.Length + filepath.Length + 1; //1='@' string path = Application.persistentDataPath + "/" + filepath; FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); fs.Write(msgBinary, start_i, msgBinary.Length - start_i); fs.Close(); if (Path.GetExtension(path) == ".txt") { //Debug.Log (path); this.controller.cv.LoadSavedData(path); } else if (Path.GetExtension(path) == ".obj") { filepaths[0] = path; } else if (Path.GetExtension(path) == ".jpg") { filepaths[1] = path; } if (filepaths[0] != "" && filepaths[1] != "") { // // When all dependent files of a 3d obj have been collected, // Build the 3d obj. // string[] posIDs = ObjLoadHelper.LoadObj(filepaths, new Vector3(0, 5, 0)); //string[] posIDs = ObjLoadHelper.LoadOnlyObj(filepaths[0], new Vector3 (0,5,0)); Operation op = new Operation(0, Operation.INSERT_POLYGON, "{\"posIDs\": \"" + Util.GetCommaLineFrom(posIDs) + "\", \"gid\": \"" + ChainXModel.CreateGID() + "\", \"objPath\":\"" + filepaths[0] + "\"}"); //Debug.Log(Operation.ToJson(op)); this.controller.cv.apply(op, ChainVoxel.LOCAL_OPERATION); filepaths = new string[] { "", "" }; //Clear for the next 3d objs } } } if (this.ws.error != null) { Debug.LogError("Error: " + this.ws.error); break; } yield return(0); } this.ws.Close(); }