void GenHeight() { try { Color32[] _bsdata = edit.GetPixels32(0); KDTree2D tree = new KDTree2D(); List <KDTree2D.Train> treedata = new List <KDTree2D.Train>(); FindBorder(edit.width, edit.height, _bsdata, treedata); //四次采样寻找边界,并把在边界上的点填入点集 var node = tree.CreatKDTree(treedata); //用KDTree来查找最近点 int w = edit.width; int h = edit.height; DateTime t1 = DateTime.Now; float maxlen = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (_bsdata[y * w + x].a > 0)//形状内 { //var near = tree.KDTreeFindNearest(node, new KDTree2D.Train() { positionX = x, positionY = y }); var near = tree.BBFFindNearest(node, new KDTree2D.Train() { positionX = x, positionY = y }); float d = (float)Mathf.Sqrt((near.point.positionX - x) * (near.point.positionX - x) + (near.point.positionY - y) * (near.point.positionY - y)); float wl = d / 16.0f; if (wl > 1.0f) { wl = 1.0f; } wl *= Mathf.PI * 0.5f; wl = Mathf.Sin(wl); int l = (int)(wl * 255); if (l > 255) { l = 255; } _bsdata[y * w + x].a = (byte)(l); } else { _bsdata[y * w + x].a = 0;//形状外 } } } editHeight = new Texture2D(w, h, TextureFormat.Alpha8, false); editHeight.SetPixels32(_bsdata, 0); editHeight.Apply(); _bsdata = GenNormal(w, h, _bsdata); editNormal = new Texture2D(w, h, TextureFormat.ARGB32, false); editNormal.filterMode = FilterMode.Point; editNormal.SetPixels32(_bsdata, 0); editNormal.Apply(); DateTime t2 = DateTime.Now; Debug.Log("GetTime=" + (t2 - t1).TotalSeconds); } catch { } }
void GenHeight() { try { Color32[] _bsdata = edit.GetPixels32(0); KDTree2D tree = new KDTree2D(); List<KDTree2D.Train> treedata = new List<KDTree2D.Train>(); FindBorder(edit.width, edit.height, _bsdata, treedata);//四次采样寻找边界,并把在边界上的点填入点集 var node = tree.CreatKDTree(treedata);//用KDTree来查找最近点 int w = edit.width; int h = edit.height; DateTime t1 = DateTime.Now; float maxlen = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (_bsdata[y * w + x].a > 0)//形状内 { //var near = tree.KDTreeFindNearest(node, new KDTree2D.Train() { positionX = x, positionY = y }); var near = tree.BBFFindNearest(node, new KDTree2D.Train() { positionX = x, positionY = y }); float d = (float)Mathf.Sqrt((near.point.positionX - x) * (near.point.positionX - x) + (near.point.positionY - y) * (near.point.positionY - y)); float wl = d / 16.0f; if (wl > 1.0f) wl = 1.0f; wl *= Mathf.PI * 0.5f; wl=Mathf.Sin(wl); int l = (int)(wl * 255); if (l > 255) l = 255; _bsdata[y * w + x].a = (byte)(l); } else { _bsdata[y * w + x].a = 0;//形状外 } } } editHeight = new Texture2D(w, h, TextureFormat.Alpha8, false); editHeight.SetPixels32(_bsdata, 0); editHeight.Apply(); _bsdata = GenNormal(w, h, _bsdata); editNormal = new Texture2D(w, h, TextureFormat.ARGB32, false); editNormal.filterMode = FilterMode.Point; editNormal.SetPixels32(_bsdata, 0); editNormal.Apply(); DateTime t2 = DateTime.Now; Debug.Log("GetTime=" + (t2 - t1).TotalSeconds); } catch { } }