Mesh MakeMeshPot(Point3Ds ps) { Mesh mesh = new Mesh(); Double[] vertexes = new Double[12]; Double[] normals = new Double[12]; Int32[] indexes = new Int32[6]; Double[] textureCoords = new Double[8]; //设置顶点坐标,每三个一组,对应坐标系的X,Y,Z数值 // -0.661115958904828,-0.239472665266096,1646.15246582031 double offsetX = 0; double offsetY = 0; double offsetZ = 0; vertexes[0] = ps.leftbottom().X + (ps.rightbottom().X - ps.leftbottom().X) / 10 + offsetX; vertexes[1] = ps.leftbottom().Y + (ps.rightbottom().Y - ps.leftbottom().Y) / 10 + offsetY; vertexes[2] = ps.leftbottom().Z + (ps.leftup().Z - ps.leftbottom().Z) / 10 * 8 + offsetZ; vertexes[3] = ps.leftup().X + (ps.rightup().X - ps.leftup().X) / 10 + offsetX; vertexes[4] = ps.leftup().Y + (ps.rightup().Y - ps.leftup().Y) / 10 + offsetY; vertexes[5] = ps.leftup().Z - (ps.leftup().Z - ps.leftbottom().Z) / 10 + offsetZ; vertexes[6] = ps.rightup().X - (ps.rightup().X - ps.leftup().X) / 10 + offsetX; vertexes[7] = ps.rightup().Y - (ps.rightup().Y - ps.leftup().Y) / 10 + offsetY; vertexes[8] = ps.rightup().Z - (ps.rightup().Z - ps.rightbottom().Z) / 10 + offsetZ; vertexes[9] = ps.rightbottom().X - (ps.rightbottom().X - ps.leftbottom().X) / 10 + offsetX; vertexes[10] = ps.rightbottom().Y - (ps.rightbottom().Y - ps.leftbottom().Y) / 10 + offsetY; vertexes[11] = ps.rightbottom().Z + (ps.rightup().Z - ps.rightbottom().Z) / 10 * 8 + offsetZ; //设置顶点索引,用于绘制图形时应用 indexes[0] = 0; indexes[1] = 1; indexes[2] = 2; indexes[3] = 0; indexes[4] = 2; indexes[5] = 3; //设置顶点的法向量方向,设置法向量可以突出Mesh的阴影效果,更加逼真。 for (int i = 0; i < 12; i += 3) { normals[i] = 0; normals[i + 1] = 1; normals[i + 2] = 0; } mesh.Vertices = vertexes; mesh.Indexes = indexes; return(mesh); }
Mesh MakeMeshPot(Point3Ds ps) { Mesh mesh = new Mesh(); Double[] vertexes = new Double[12]; Double[] normals = new Double[12]; Int32[] indexes = new Int32[6]; Double[] textureCoords = new Double[8]; //设置顶点坐标,每三个一组,对应坐标系的X,Y,Z数值 // -0.661115958904828,-0.239472665266096,1646.15246582031 double offsetX = 0; double offsetY = 0; double offsetZ = 0; vertexes[0] = ps.leftbottom().X + (ps.rightbottom().X - ps.leftbottom().X) / 10 + offsetX; vertexes[1] = ps.leftbottom().Y + (ps.rightbottom().Y - ps.leftbottom().Y) / 10 + offsetY; vertexes[2] = ps.leftbottom().Z + (ps.leftup().Z - ps.leftbottom().Z) / 10 * 8 + offsetZ; vertexes[3] = ps.leftup().X + (ps.rightup().X - ps.leftup().X) / 10 + offsetX; vertexes[4] = ps.leftup().Y + (ps.rightup().Y - ps.leftup().Y) / 10 + offsetY; vertexes[5] = ps.leftup().Z - (ps.leftup().Z - ps.leftbottom().Z) / 10 + offsetZ; vertexes[6] = ps.rightup().X - (ps.rightup().X - ps.leftup().X) / 10 + offsetX; vertexes[7] = ps.rightup().Y - (ps.rightup().Y - ps.leftup().Y) / 10 + offsetY; vertexes[8] = ps.rightup().Z - (ps.rightup().Z - ps.rightbottom().Z) / 10 + offsetZ; vertexes[9] = ps.rightbottom().X - (ps.rightbottom().X - ps.leftbottom().X) / 10 + offsetX; vertexes[10] = ps.rightbottom().Y - (ps.rightbottom().Y - ps.leftbottom().Y) / 10 + offsetY; vertexes[11] = ps.rightbottom().Z + (ps.rightup().Z - ps.rightbottom().Z) / 10 * 8 + offsetZ; //设置顶点索引,用于绘制图形时应用 indexes[0] = 0; indexes[1] = 1; indexes[2] = 2; indexes[3] = 0; indexes[4] = 2; indexes[5] = 3; //设置顶点的法向量方向,设置法向量可以突出Mesh的阴影效果,更加逼真。 for (int i = 0; i < 12; i += 3) { normals[i] = 0; normals[i + 1] = 1; normals[i + 2] = 0; } mesh.Vertices = vertexes; mesh.Indexes = indexes; return mesh; }
public void run() { Recordset rc = dv.GetRecordset(false, CursorType.Dynamic); Dictionary<int, Feature> feas = rc.GetAllFeatures(); foreach (KeyValuePair<int, Feature> item in feas) { GeoModel gm = item.Value.GetGeometry() as GeoModel; Console.WriteLine("==" + gm.Position + "=="); GeoModel model = new GeoModel(); model.Position = gm.Position; foreach (Mesh m in gm.Meshes) { if (m.Material.TextureFile.Length > 1) { //Console.WriteLine(m.Material.TextureFile.ToString()); Point3Ds p3ds = new Point3Ds(); for (int i = 0; i < m.Vertices.Length; i += 3) { bool repition = false; foreach (Point3D p in p3ds) { if (p.X == m.Vertices[i] && p.Y == m.Vertices[i + 1] && p.Z == m.Vertices[i + 2]) { repition = true; } } if (!repition) { p3ds.Add(new Point3D(m.Vertices[i], m.Vertices[i + 1], m.Vertices[i + 2])); } } foreach (Point3D p3d in p3ds) { Console.WriteLine(string.Format(" {0},{1},{2}", p3d.X, p3d.Y, p3d.Z)); scene.TrackingLayer.Add(new GeoPoint3D(p3d.X, p3d.Y, p3d.Z), ""); } //model.Meshes.Add(MakeMeshPot(p3ds)); Mesh mesh = new Mesh(m); mesh.Material.TextureFile = @".\78310a55b319ebc41f7810198326cffc1e171629.png"; model.Meshes.Add(mesh); #region 写属性表 Dictionary<string, double> fields = new Dictionary<string, double>(); fields.Add("FaceMeshCenterX", model.Position.X); fields.Add("FaceMeshCenterY", model.Position.Y); fields.Add("FaceMeshCenterZ", model.Position.Z); fields.Add("FaceMeshLx", p3ds.leftbottom().X); fields.Add("FaceMeshLy", p3ds.leftbottom().Y); fields.Add("FaceMeshLz", p3ds.leftbottom().Z); fields.Add("FaceMeshUx", p3ds.rightup().X); fields.Add("FaceMeshUy", p3ds.rightup().Y); fields.Add("FaceMeshUz", p3ds.rightup().Z); foreach (KeyValuePair<string, double> field in fields) { if (dv.FieldInfos.IndexOf(field.Key) < 0) { FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double); dv.FieldInfos.Add(fieldInf); } string fieldName = field.Key; double fieldValue = field.Value; try { rc.SeekID(item.Value.GetID()); rc.Edit(); rc.SetFieldValue(fieldName, fieldValue); rc.Update(); } catch { Console.WriteLine("error!"); } //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue)); } #endregion } } Console.WriteLine(""); model.ComputeBoundingBox(); scene.TrackingLayer.Add(model, gm.Position.ToString()); scene.Refresh(); } }
public void run() { Recordset rc = dv.GetRecordset(false, CursorType.Dynamic); Dictionary <int, Feature> feas = rc.GetAllFeatures(); foreach (KeyValuePair <int, Feature> item in feas) { GeoModel gm = item.Value.GetGeometry() as GeoModel; Console.WriteLine("==" + gm.Position + "=="); GeoModel model = new GeoModel(); model.Position = gm.Position; foreach (Mesh m in gm.Meshes) { if (m.Material.TextureFile.Length > 1) { //Console.WriteLine(m.Material.TextureFile.ToString()); Point3Ds p3ds = new Point3Ds(); for (int i = 0; i < m.Vertices.Length; i += 3) { bool repition = false; foreach (Point3D p in p3ds) { if (p.X == m.Vertices[i] && p.Y == m.Vertices[i + 1] && p.Z == m.Vertices[i + 2]) { repition = true; } } if (!repition) { p3ds.Add(new Point3D(m.Vertices[i], m.Vertices[i + 1], m.Vertices[i + 2])); } } foreach (Point3D p3d in p3ds) { Console.WriteLine(string.Format(" {0},{1},{2}", p3d.X, p3d.Y, p3d.Z)); scene.TrackingLayer.Add(new GeoPoint3D(p3d.X, p3d.Y, p3d.Z), ""); } //model.Meshes.Add(MakeMeshPot(p3ds)); Mesh mesh = new Mesh(m); mesh.Material.TextureFile = @".\78310a55b319ebc41f7810198326cffc1e171629.png"; model.Meshes.Add(mesh); #region 写属性表 Dictionary <string, double> fields = new Dictionary <string, double>(); fields.Add("FaceMeshCenterX", model.Position.X); fields.Add("FaceMeshCenterY", model.Position.Y); fields.Add("FaceMeshCenterZ", model.Position.Z); fields.Add("FaceMeshLx", p3ds.leftbottom().X); fields.Add("FaceMeshLy", p3ds.leftbottom().Y); fields.Add("FaceMeshLz", p3ds.leftbottom().Z); fields.Add("FaceMeshUx", p3ds.rightup().X); fields.Add("FaceMeshUy", p3ds.rightup().Y); fields.Add("FaceMeshUz", p3ds.rightup().Z); foreach (KeyValuePair <string, double> field in fields) { if (dv.FieldInfos.IndexOf(field.Key) < 0) { FieldInfo fieldInf = new FieldInfo(field.Key, FieldType.Double); dv.FieldInfos.Add(fieldInf); } string fieldName = field.Key; double fieldValue = field.Value; try { rc.SeekID(item.Value.GetID()); rc.Edit(); rc.SetFieldValue(fieldName, fieldValue); rc.Update(); } catch { Console.WriteLine("error!"); } //Console.WriteLine(string.Format("{0},{1},{2}", item.GetID(), fieldName, fieldValue)); } #endregion } } Console.WriteLine(""); model.ComputeBoundingBox(); scene.TrackingLayer.Add(model, gm.Position.ToString()); scene.Refresh(); } }