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 }