skyline自动化建模;DWG翻模

2019-04-13 12:30发布

一、背景

自动化建模就是根据点位和姿态角,将模型添加至skyline之后,模型根据姿态角自动调整,形成一个完整的模型场景。假设读者已经获得了点位数据。本文主要讲述如何计算姿态角和新建要素图层,设置属性信息,以及添加模型。

数据来源:DWG工程图,关于DWG的读数据问题,可以参见我前面的博客。
注:本博客代码中设计的自定义数据结构,请忽略。

二、正文

1.如何计算姿态角

skyline提供计算姿态角的方法: public void CalRollYawPitch(SGWorld66 mSG, Point3DF ptA, Point3DF ptB,out double Yaw, out double Roll,out double Pitch) { IPosition66 posA = mSG.Creator.CreatePosition(ptA.YL, ptA.XB, ptA.Z); IPosition66 posB = mSG.Creator.CreatePosition(ptB.YL, ptB.XB, ptB.Z); IPosition66 pos = posA.AimTo(posB); Yaw = pos.Yaw; Roll = pos.Roll; Pitch = pos.Pitch; }

2.新建要素图层

public IFeatureLayer66 CreatePipeFeatureLayer(SGWorld66 mSG) { IFeatureLayer66 CylindresLayer = mSG.Creator.CreateNewFeatureLayer("管线图层", LayerGeometryType.LGT_POINT, "FileName=model.shp;TEPlugName=OGR;", mSG.ProjectTree.RootID); CylindresLayer.Streaming = false; CylindresLayer.StreamStatus = StreamLayerStatus.SLS_NOT_STREAMED_LAYER; CylindresLayer.Refresh(); // the pipes are always created in absolute CylindresLayer.FeatureGroups.Point.SetProperty("Altitude Method", 10); //不能设置为12-On Terrain //CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("构件名称", AttributeTypeCode.AT_TEXT, 50); CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Yaw", AttributeTypeCode.AT_DOUBLE, 0, 20); CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Roll", AttributeTypeCode.AT_DOUBLE, 0, 20); CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Pitch", AttributeTypeCode.AT_DOUBLE, 0, 20); CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Texture", AttributeTypeCode.AT_TEXT, 1024); //CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Rotate", AttributeTypeCode.AT_DOUBLE, 100); CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("RadiusX", AttributeTypeCode.AT_DOUBLE, 0); CylindresLayer.DataSourceInfo.Attributes.CreateAttribute("Height", AttributeTypeCode.AT_DOUBLE, 0); // style the feature group CylindresLayer.FeatureGroups.Point.DisplayAs = ObjectTypeCode.OT_CYLINDER; CylindresLayer.FeatureGroups.Point.SetProperty("Number of sides", 16); CylindresLayer.FeatureGroups.Point.SetProperty("Line Opacity", 0); CylindresLayer.FeatureGroups.Point.SetProperty("Fill Opacity", 100); CylindresLayer.FeatureGroups.Point.SetProperty("Yaw", "[Yaw]"); CylindresLayer.FeatureGroups.Point.SetProperty("Roll", "[Roll]"); CylindresLayer.FeatureGroups.Point.SetProperty("Pitch", "[Pitch]"); CylindresLayer.FeatureGroups.Point.SetProperty("Texture File", "[Texture]"); //CylindresLayer.FeatureGroups.Point.SetProperty("Rotate", "[Rotate]"); CylindresLayer.FeatureGroups.Point.SetProperty("Radius X", "[RadiusX]"); CylindresLayer.FeatureGroups.Point.SetProperty("Height", "[Height]"); return CylindresLayer; }
新建图层之后,随即绑定属性,这样当添加模型的时候,模型的属性信息自动关联。

3.添加模型

a.绘制管线为例:CylindresLayer.FeatureGroups.Point.CreateFeature(new double[] { position.X, position.Y, position.Altitude }, position.Yaw + ";" + position.Roll + ";" + position.Pitch + ";" + TextureFile + ";" + Radius + ";" + Height);
b.添加dae模型或xpl模型为例: public void AddModel(string objname, LinePoint pt, string modelfile) { IPoint geometry = mSG.Creator.GeometryCreator.CreatePointGeometry(new double[]{pt.x,pt.y,pt.z}); string fid = mFlayer.FeatureGroups.Point.CreateFeature(geometry, objname + ";" + pt.ToDKString() + ";" + pt.LC.ToString() + ";" + pt.yaw.ToString() + ";" + pt.roll.ToString() + ";0;" + modelfile + ";geek;" + DateTime.Today.ToShortDateString() + ";http://www.baidu.com"); }

三、效果