// //Update is called once per frame //void Update() //{ // if (GoView.Content.Zoom > LineLenght) // { // lr.enabled = false; // return; // } // lr.enabled = true; // //lr.SetWidth(GoView.Content.Zoom * ZoomAdjust, GoView.Content.Zoom * ZoomAdjust); //} //设置线段 public void Set(DXFStructure dxf, LINE item, float ScaleX = 1, float ScaleY = 1) { var goLayer = GoView.Content.GetLayer(item.C8); if (goLayer != null) { lr.material = goLayer.LayerMaterial; ZoomAdjust = goLayer.ZoomAdjust; } gg = goLayer; lr.SetVertexCount(2); var p1 = new Vector3((float)item.C10 * ScaleX, (float)item.C20 * ScaleY, (float)item.C30); var p2 = new Vector3((float)item.C11 * ScaleX, (float)item.C21 * ScaleY, (float)item.C31); lr.SetPosition(0, p1); lr.SetPosition(1, p2); LineLenght = Vector2.Distance(p1, p2) * 2; this.gameObject.isStatic = true; if (GoView.Content.MaxX < p1.x) GoView.Content.MaxX = p1.x; if (GoView.Content.MinX > p1.x) GoView.Content.MinX = p1.x; if (GoView.Content.MaxY < p1.y) GoView.Content.MaxY = p1.y; if (GoView.Content.MinY > p1.y) GoView.Content.MinY = p1.y; }
private void LoadDXF(string path = null) { //try //{ GetComponent <MeshGenerater.DataContainer>().ResetError(); if (path == null) { iLoader = new DiskFile(content); } else { iLoader = new DiskFile(path); } DXFConvert.DXFStructure dxfStructure = new DXFConvert.DXFStructure(iLoader); dxfStructure.Load(); iLoader.Dispose(); TView.Set(dxfStructure); NormalCenter.GetCenter(TView.transform); GetComponent <MeshGenerater.DataContainer>().SerializeData(); Camera.main.GetComponent <BLCameraControl>().LookAtResAutoDis(GameObject.Find("TViewBase").transform); //Debug.Log("OK:" + path); //} //catch (System.Exception ex) //{ // Debug.Log("Error:" +ex.Message); //} }
public void Set(DXFStructure dxf, P2D P1, P2D P2, GoLayer goLayer, float ScaleX = 1, float ScaleY = 1) { lr.material = goLayer.LayerMaterial; ZoomAdjust = goLayer.ZoomAdjust; lr.SetVertexCount(2); var p1 = new Vector3((float)P1.X * ScaleX, (float)P1.Y * ScaleY, 0); var p2 = new Vector3((float)P2.X * ScaleX, (float)P2.Y * ScaleY, 0); lr.SetPosition(0, p1); lr.SetPosition(1, p2); LineLenght = Vector2.Distance(p1, p2) * 2; this.gameObject.isStatic = true; if (GoView.Content.MaxX < p1.x) GoView.Content.MaxX = p1.x; if (GoView.Content.MinX > p1.x) GoView.Content.MinX = p1.x; if (GoView.Content.MaxY < p1.y) GoView.Content.MaxY = p1.y; if (GoView.Content.MinY > p1.y) GoView.Content.MinY = p1.y; }
public void Set(DXFStructure dxf, CIRCLE item, float ScaleX = 1, float ScaleY = 1) { var goLayer = GoView.Content.GetLayer(item.C8); if (goLayer != null) { lr.material = goLayer.LayerMaterial; ZoomAdjust = goLayer.ZoomAdjust; } float R = (float)item.C40; Diameter = R * 2; //计算一个圆需要多少线条 int resolution = (int)item.C40 / OptimizingLevel; if (resolution > MaxResolution) resolution = MaxResolution; if (resolution < MinResolution) resolution = MinResolution; lr.SetVertexCount(resolution + 1); for (int i = 0; i < resolution; ++i) { lr.SetPosition(i, new Vector3((R * Mathf.Cos(2 * Mathf.PI / resolution * i) + (float)item.C10) * ScaleX, (R * Mathf.Sin(2 * Mathf.PI / resolution * i) + (float)item.C20) * ScaleY, 0)); } lr.SetPosition(resolution, new Vector3((R * Mathf.Cos(2 * Mathf.PI / resolution * 0) + (float)item.C10) * ScaleX, (R * Mathf.Sin(2 * Mathf.PI / resolution * 0) + (float)item.C20) * ScaleY, 0)); this.gameObject.isStatic = true; }
//绘制块集合 public void DrawINSERTList(DXFStructure dxf, List<INSERT> INSERTList, float ScaleX = 1, float ScaleY = 1) { foreach (var item in INSERTList) { GameObject go = Instantiate(GoInsert) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoInsert>(); l.Set(dxf, item); } }
//绘制直线集合 public void DrawLINEList(DXFStructure dxf, List<LINE> LINEList, float ScaleX = 1, float ScaleY = 1) { //绘制直线 foreach (LINE item in LINEList) { GameObject go = Instantiate(GoLine) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoLine>(); l.Set(dxf, item, ScaleX, ScaleY); } }
//绘制圆集合 public void DrawCIRCLEList(DXFStructure dxf, List<CIRCLE> CIRCLEList, float ScaleX = 1, float ScaleY = 1) { // 绘制圆 foreach (var item in CIRCLEList) { GameObject go = Instantiate(GoCircle) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoCircle>(); l.Set(dxf, item, ScaleX, ScaleY); } }
//绘制椭圆集合 public void DrawELLIPSEList(DXFStructure dxf, List<ELLIPSE> ELLIPSEList, float ScaleX = 1, float ScaleY = 1) { //绘制椭圆 foreach (var item in ELLIPSEList) { GameObject go = Instantiate(GoEllipse) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoEllipse>(); l.Set(dxf, item, ScaleX, ScaleY); } }
public void Set(DXFStructure dxf) { //先初始化图层 foreach (TABLE table in dxf.TABLES.TABLEList) { if (table.LAYERList.Count == 0) continue; foreach (LAYER item in table.LAYERList) { GameObject go = Instantiate(Layer) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoLayer>(); l.Set(item); if (item.C2 != null) Layers.Add(item.C2, l); } } //构建一个默认图层,没有图层属性的对象放在此图层 GameObject goDefaultLayer = Instantiate(Layer) as GameObject; GoLayer.DefaultLayer = goDefaultLayer.GetComponent<GoLayer>(); GoLayer.DefaultLayer.ZoomAdjust = 0.8f; //绘制各图层下的元素 foreach (var item in Layers) { item.Value.Load(dxf); } //初始化相机位置 //camera.transform.position = new Vector3((MaxX + MinX) / 2, (MaxY + MinY) / 2, -10); this.transform.position = new Vector3(this.transform.position.x - (MaxX + MinX) / 2, this.transform.position.y - (MaxY + MinY) / 2, 0); camera.orthographicSize = ((MaxX - MinX) + (MaxY - MinY)) / 20; Zoom = (camera.orthographicSize / 250); //初始化优化代码 ResizeObjects.ForEach((l) => { l.ToMin(); if (l.gameObject.activeSelf) l.SetSetWidth(); }); }
//绘制圆弧集合 public void DrawARCList(DXFStructure dxf, List<ARC> ARCList, float ScaleX = 1, float ScaleY = 1) { //绘制弧线 int ii = 0; foreach (var item in ARCList) { GameObject go = Instantiate(GoArc) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoArc>(); l.Set(dxf, item, ScaleX, ScaleY); ii++; System.Diagnostics.Debug.WriteLine(ii.ToString()); } }
public void Set(DXFStructure dxf, ELLIPSE item, float ScaleX = 1, float ScaleY = 1) { var goLayer = GoView.Content.GetLayer(item.C8); if (goLayer != null) { lr.material = goLayer.LayerMaterial; ZoomAdjust = goLayer.ZoomAdjust; } Vector3 center = new Vector3((float)item.C10, (float)item.C20, (float)item.C30);//中心点 var theta = Mathf.Atan2((float)item.C21, (float)item.C11) * (180 / Mathf.PI);//椭圆的旋转角度 Quaternion q = Quaternion.AngleAxis(theta, Vector3.forward);//创建一个旋转 //长轴长度 var a = Mathf.Abs(Vector3.Distance(new Vector3(), new Vector3((float)item.C11, (float)item.C21, (float)item.C31))); LongAxis = a; //短轴长度 var b = a * (float)item.C40; //计算组层椭圆的元素数量,用于优化 int resolution = (int)((a + b) / 2.0 / OptimizingLevel); if (resolution > MaxResolution) resolution = MaxResolution; else if (resolution < MinResolution) resolution = MinResolution; lr.SetVertexCount(resolution + 1); for (int i = 0; i < resolution; i++) { var ii = (float)(i * (item.C42 - item.C41) / resolution) + (float)item.C41; //计算出的坐标点 var v = new Vector3(a * Mathf.Cos(ii), b * Mathf.Sin(ii), 0.0f); //加入旋转和中心点位置 v = q * v + center; //增加缩放 lr.SetPosition(i, new Vector3(v.x * ScaleX, v.y * ScaleY, v.z)); } //最后增加一点用于处理最后一段的连线 //计算出的坐标点 var v1 = new Vector3(a * Mathf.Cos((float)item.C42), b * Mathf.Sin((float)item.C42), 0.0f); //加入旋转和中心点位置 v1 = q * v1 + center; //增加缩放 lr.SetPosition(resolution, new Vector3(v1.x * ScaleX, v1.y * ScaleY, v1.z)); this.gameObject.isStatic = true; }
private void LoadDXF(string path) { try { DiskFile iLoader = new DiskFile(path); DXFConvert.DXFStructure dxfStructure = new DXFConvert.DXFStructure(iLoader); dxfStructure.Load(); iLoader.Dispose(); GoView.Set(dxfStructure); Debug.Log("OK:" + path); } catch (System.Exception ex) { Debug.Log("Error:" + path); Debug.LogError(ex.ToString()); } }
public void Set(DXFStructure dxf, ARC item, float ScaleX = 1, float ScaleY = 1) { var goLayer = GoView.Content.GetLayer(item.C8); if (goLayer != null) { lr.material = goLayer.LayerMaterial; ZoomAdjust = goLayer.ZoomAdjust; } float R = (float)item.C40; Diameter = R * 2; float nd = 0;//绘制的角度总数 if (item.C51 > item.C50) nd = (float)(item.C51 - item.C50); else nd = (float)(item.C51 + 360 - item.C50); //计算一个圆弧需要多少线条 float ndB=nd / 360;//圆弧占用圆的比例 int resolution = (int)(item.C40 / OptimizingLevel * ndB); if (resolution > (int)(MaxResolution * ndB)) resolution = (int)(MaxResolution * ndB); if (resolution < (int)(MinResolution * ndB)) resolution = (int)(MinResolution * ndB); lr.SetVertexCount(resolution + 1); for (int i = 0; i < resolution; i++) { var ii = (float)(i * nd / (float)resolution); ii += (float)item.C50; if (ii > 360) ii -= 360; lr.SetPosition(i, new Vector3((R * Mathf.Cos(2 * Mathf.PI / 360 * ii) + (float)item.C10) * ScaleX, (R * Mathf.Sin(2 * Mathf.PI / 360 * ii) + (float)item.C20) * ScaleY, 0)); } lr.SetPosition(resolution, new Vector3((R * Mathf.Cos(2 * Mathf.PI / 360 * (float)item.C51) + (float)item.C10) * ScaleX, (R * Mathf.Sin(2 * Mathf.PI / 360 * (float)item.C51) + (float)item.C20) * ScaleY, 0)); this.gameObject.isStatic = true; }
// Update is called once per frame public void Set(DXFStructure dxf, LWPOLYLINE item, float ScaleX = 1, float ScaleY = 1) { var goLayer = GoView.Content.GetLayer(item.C8); for (int i = 0; i < item.P2D.Count - 1; i++) { // lr.SetPosition(i, new Vector3((float)item.P2D[i].X * ScaleX, (float)item.P2D[i].Y * ScaleY, 0)); GameObject go = Instantiate(goLine) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoLine>(); l.Set(dxf, item.P2D[i], item.P2D[i + 1], goLayer, ScaleX, ScaleY); } if (item.C70 == 1 && item.P2D.Count > 2) { GameObject go = Instantiate(goLine) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoLine>(); l.Set(dxf, item.P2D[item.P2D.Count - 1], item.P2D[0], goLayer, ScaleX, ScaleY); } }
public void Set(DXFStructure dxf, INSERT insert) { gameObject.name = "Insert_" + insert.C2; var block = dxf.BLOCKS.BLOCKList.FirstOrDefault(x => x.C2 == insert.C2); if (block == null) { Debug.Log(insert.C2); return; } DrawLINEList(dxf, block.LINEList, (float)insert.C41, (float)insert.C42); DrawLWPOLYLINEList(dxf, block.LWPOLYLINEList, (float)insert.C41, (float)insert.C42); DrawTEXTList(dxf, block.TEXTList, (float)insert.C41, (float)insert.C42); DrawCIRCLEList(dxf, block.CIRCLEList, (float)insert.C41, (float)insert.C42); DrawARCList(dxf, block.ARCList, (float)insert.C41, (float)insert.C42); //DrawINSERTList(dxf, block.INSERTList, (float)insert.C41, (float)insert.C42); DrawELLIPSEList(dxf, block.ELLIPSEList, (float)insert.C41, (float)insert.C42); this.transform.position = new Vector3((float)insert.C10, (float)insert.C20, (float)insert.C30); this.transform.localEulerAngles = new Vector3(0, 0, (float)insert.C50); this.gameObject.isStatic = true; }
public void Load(DXFStructure dxf) { //找到当前层的物体 LINEList = dxf.ENTITIES.LINEList.Where(x => x.C8 == Layer.C2).ToList(); LWPOLYLINEList = dxf.ENTITIES.LWPOLYLINEList.Where(x => x.C8 == Layer.C2).ToList(); TEXTList = dxf.ENTITIES.TEXTList.Where(x => x.C8 == Layer.C2).ToList(); CIRCLEList = dxf.ENTITIES.CIRCLEList.Where(x => x.C8 == Layer.C2).ToList(); ARCList = dxf.ENTITIES.ARCList.Where(x => x.C8 == Layer.C2).ToList(); INSERTList = dxf.ENTITIES.INSERTList.Where(x => x.C8 == Layer.C2).ToList(); ELLIPSEList = dxf.ENTITIES.ELLIPSEList.Where(x => x.C8 == Layer.C2).ToList(); //绘制层下属物体 DrawLINEList(dxf, LINEList); DrawLWPOLYLINEList(dxf, LWPOLYLINEList); DrawTEXTList(dxf, TEXTList); DrawCIRCLEList(dxf, CIRCLEList); DrawARCList(dxf, ARCList); DrawINSERTList(dxf, INSERTList); DrawELLIPSEList(dxf, ELLIPSEList); }
//绘制文本集合 public void DrawTEXTList(DXFStructure dxf, List<TEXT> TEXTList, float ScaleX = 1, float ScaleY = 1) { //绘制直线 foreach (TEXT item in TEXTList) { GameObject go = Instantiate(GoText) as GameObject; go.transform.parent = gameObject.transform; var l = go.GetComponent<GoText>(); l.Set(dxf, item, ScaleX, ScaleY); } }