private IEnumerator createFile(Bounds UnityBounds, List <Layer> layerList) { freezeLayers(layerList, true); Debug.Log(layerList.Count); Vector3RD bottomLeftRD = CoordConvert.UnitytoRD(UnityBounds.min); Vector3RD topRightRD = CoordConvert.UnitytoRD(UnityBounds.max); boundingbox = new MeshClipper.RDBoundingBox(bottomLeftRD.x, bottomLeftRD.y, topRightRD.x, topRightRD.y); DxfFile file = new DxfFile(); file.SetupDXF(); yield return(null); MeshClipper meshClipper = new MeshClipper(); loadingScreen.ShowMessage("dxf-bestand genereren..."); loadingScreen.ProgressBar.Percentage(0f); int layercounter = 0; foreach (var layer in layerList) { List <GameObject> gameObjectsToClip = getTilesInLayer(layer, bottomLeftRD, topRightRD); if (gameObjectsToClip.Count == 0) { continue; } foreach (var gameObject in gameObjectsToClip) { meshClipper.SetGameObject(gameObject); for (int submeshID = 0; submeshID < gameObject.GetComponent <MeshFilter>().sharedMesh.subMeshCount; submeshID++) { meshClipper.clipSubMesh(boundingbox, submeshID); string layerName = gameObject.GetComponent <MeshRenderer>().sharedMaterials[submeshID].name.Replace(" (Instance)", ""); file.AddLayer(meshClipper.clippedVerticesRD, layerName, getColor(gameObject.GetComponent <MeshRenderer>().sharedMaterials[submeshID])); yield return(null); } } loadingScreen.ProgressBar.Percentage(50 * layercounter / layerList.Count); layercounter++; } freezeLayers(layerList, false); file.Save(); loadingScreen.Hide(); Debug.Log("file saved"); }
// Start is called before the first frame update void Start() { //preparation setup the boundingBox MeshClipper.RDBoundingBox bbox = new MeshClipper.RDBoundingBox(minX, minY, maxX, maxY); // start the new meshclipper MeshClipper clipper = new MeshClipper(); // tell the clipper which gameObject the mesh is attached to. // at this point the clipper will translate the unityCoordinates (mesh + gameObject.origin) to RD-coordinates clipper.SetGameObject(go); // clip the desired submesh clipper.ClipSubMesh(bbox, 0); // after clipping the clipper contains a list of Vector3RD coordinates. each set of 3 coordinates describes a triangle (orientation is counterClockwise CreateMesh(clipper.clippedVerticesRD); // it is now possible to clip the next submesh ( if there is one) without having to translate coordinates }
private IEnumerator CreateFile(Bounds UnityBounds, List <Layer> layerList) { FreezeLayers(layerList, true); Debug.Log(layerList.Count); Vector3RD bottomLeftRD = CoordConvert.UnitytoRD(UnityBounds.min); Vector3RD topRightRD = CoordConvert.UnitytoRD(UnityBounds.max); boundingbox = new MeshClipper.RDBoundingBox(bottomLeftRD.x, bottomLeftRD.y, topRightRD.x, topRightRD.y); DxfFile dxfFile = new DxfFile(); dxfFile.SetupDXF(); yield return(null); MeshClipper meshClipper = new MeshClipper(); loadingScreen.ShowMessage("DXF-bestand genereren..."); loadingScreen.ProgressBar.SetMessage(""); loadingScreen.ProgressBar.Percentage(0.1f); yield return(new WaitForEndOfFrame()); int layercounter = 0; foreach (var layer in layerList) { layercounter++; loadingScreen.ProgressBar.Percentage((float)layercounter / ((float)layerList.Count + 1)); loadingScreen.ProgressBar.SetMessage("Laag '" + layer.name + "' wordt omgezet..."); yield return(new WaitForEndOfFrame()); List <GameObject> gameObjectsToClip = GetTilesInLayer(layer, bottomLeftRD, topRightRD); if (gameObjectsToClip.Count == 0) { continue; } foreach (var gameObject in gameObjectsToClip) { meshClipper.SetGameObject(gameObject); for (int submeshID = 0; submeshID < gameObject.GetComponent <MeshFilter>().sharedMesh.subMeshCount; submeshID++) { string layerName = gameObject.GetComponent <MeshRenderer>().sharedMaterials[submeshID].name.Replace(" (Instance)", ""); loadingScreen.ProgressBar.SetMessage("Laag '" + layer.name + "' object " + layerName + " wordt uitgesneden..."); yield return(new WaitForEndOfFrame()); meshClipper.ClipSubMesh(boundingbox, submeshID); dxfFile.AddLayer(meshClipper.clippedVerticesRD, layerName, GetColor(gameObject.GetComponent <MeshRenderer>().sharedMaterials[submeshID])); yield return(new WaitForEndOfFrame()); } yield return(new WaitForEndOfFrame()); } yield return(new WaitForEndOfFrame()); } loadingScreen.ProgressBar.Percentage((float)layerList.Count / ((float)layerList.Count + 1)); loadingScreen.ProgressBar.SetMessage("Het AutoCAD DXF (.dxf) bestand wordt afgerond..."); yield return(new WaitForEndOfFrame()); dxfFile.Save(); loadingScreen.Hide(); FreezeLayers(layerList, false); Debug.Log("file saved"); }