public void TestCsgFilteringIntersections() { var s1 = new Sphere(); var s2 = new Cube(); var i1 = new Intersection(1, s1); var i2 = new Intersection(2, s2); var i3 = new Intersection(3, s1); var i4 = new Intersection(4, s2); var xs = new Intersections(i1, i2, i3, i4); var op = new CsgOperation[] { CsgOperation.Union, CsgOperation.Intersection, CsgOperation.Difference }; var x0 = new int[] { 0, 1, 0 }; var x1 = new int[] { 3, 2, 1 }; for (int i = 0; i < op.Length; i++) { var c = new CSG(op[i], s1, s2); Intersections result = c.FilterIntersections(xs); Assert.AreEqual(result.Count, 2, i.ToString()); Assert.AreEqual(result[0], xs[x0[i]], i.ToString()); Assert.AreEqual(result[1], xs[x1[i]], i.ToString()); } }
public void Experimental() { CSG.EPSILON = 1e-5f; // Adjustable epsilon value CSG csg = new CSG(); GameObject[] bricks = GameObject.FindGameObjectsWithTag("Brick"); // Debug.Log ("Number of bricks is " + bricks.Length); foreach (GameObject brick in bricks) { csg.Target = brick; GameObject newOne; Collider[] hitColliders = Physics.OverlapSphere(brick.transform.position, brickLength); // Debug.Log ("Number of hitColliders is " + hitColliders.Length); for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders [i].gameObject.transform.tag == "Tunnel") { csg.Brush = hitColliders[i].gameObject; csg.OperationType = CSG.Operation.Subtract; csg.customMaterial = new Material(Shader.Find("Standard")); // Custom material csg.useCustomMaterial = false; // Use the above material to fill cuts csg.hideGameObjects = false; // Hide target and brush objects after operation csg.keepSubmeshes = false; // Keep original submeshes and materials newOne = csg.PerformCSG(); Destroy(csg.Target); csg.Target = newOne; newOne.name = "BrickWall"; // Debug.Log ("I am in the if statement ivolving colliders"); } } } Destroy(GameObject.Find("Tunnel")); }
public void FilterIntersectionList() { string[] str = new string[3] { "union", "intersection", "difference" }; int[,] intersectionIndices = new int[3, 2] { //lhit inl inr result { 0, 3 }, { 1, 2 }, { 0, 1 } }; Shape s1 = new Sphere(); Shape s2 = new Cube(); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(1, s1)); xs.Add(new Intersection(2, s2)); xs.Add(new Intersection(3, s1)); xs.Add(new Intersection(4, s2)); for (int i = 0; i < 3; i++) { CSG c = new CSG(str[i], s1, s2); List <Intersection> result = c.FilterIntersections(xs); Assert.AreEqual(result.Count, 2); Assert.AreEqual(result[0], xs[intersectionIndices[i, 0]]); Assert.AreEqual(result[1], xs[intersectionIndices[i, 1]]); } }
// Use this for initialization void Start() { /* * // Create new GameObject * GameObject newObject = new GameObject(); * newObject.transform.localScale*=2f; * MeshFilter meshFilter = newObject.AddComponent<MeshFilter>(); * MeshRenderer meshRenderer = newObject.AddComponent<MeshRenderer>(); * meshRenderer.materials = new Material[2]{meshColliderA.transform.GetComponent<Renderer>().materials[0],meshColliderB.transform.GetComponent<Renderer>().materials[0]}; * * // Assign booleanMesh * BooleanMesh booleanMesh = new BooleanMesh(meshColliderA,meshColliderB); * //meshFilter.mesh = booleanMesh.Difference(); * //meshFilter.mesh = booleanMesh.Union(); * meshFilter.mesh = booleanMesh.Intersection(); */ GameObject newObject = new GameObject(); var meshFilter = newObject.AddComponent <MeshFilter>(); var meshRenderer = newObject.AddComponent <MeshRenderer>(); meshRenderer.materials = new Material[2] { meshColliderA.transform.GetComponent <Renderer>().materials[0], meshColliderB.transform.GetComponent <Renderer>().materials[0] }; meshFilter.mesh = CSG.Intersect(meshColliderA, meshColliderB); }
private void makeHole(GameObject plane, GameObject go) { // Preparing CSG objects for substraction. // Again, passing a new refference to the same mesh is important for some reason. CSG planeToCut = CSG.fromMesh(plane.GetComponent <MeshFilter>().mesh, plane.transform); CSG formCutter = CSG.fromMesh(go.GetComponent <MeshFilter>().mesh, go.transform); // Save the operation, this does not affect neither meshes yet. CSG result = planeToCut.subtract(formCutter); Mesh resultMesh = result.toMesh(); // Replace the mesh of THIS object with the mesh representation of the operation. plane.GetComponent <MeshFilter>().mesh = resultMesh; plane.GetComponent <MeshCollider>().sharedMesh = resultMesh; plane.transform.position = new Vector3(0, 0, 0); plane.transform.localScale = Vector3.one; PlaneBehaviour pb = plane.GetComponent <PlaneBehaviour>(); if (pb) { pb.updateStartPosition(plane.transform.position); } }
public static int Create(CSG csg) { int id = ms_pool.Length; ms_pool.Add(csg); return(id); }
private GameObject Boolean(BoolOp operation) { Reset(main_object, operating_object); current_operation = TransfOp.Spectate; UpdateTransformationButtons(); Mesh m; if (CSG_operation_history.Count == 0) { StoreCurrentState("start", main_object); } switch (operation) { case BoolOp.Union: StoreCurrentState("transformation", main_object); StoreCurrentState("union", operating_object); m = CSG.Union(main_object, operating_object); break; case BoolOp.Subtract: StoreCurrentState("transformation", main_object); StoreCurrentState("subtract", operating_object); m = CSG.Subtract(main_object, operating_object); break; case BoolOp.Intersect: default: StoreCurrentState("transformation", main_object); StoreCurrentState("intersect", operating_object); m = CSG.Intersect(main_object, operating_object); break; } composite = new GameObject(); composite.name = "Constructed CSG"; composite.AddComponent <MeshFilter>().sharedMesh = m; composite.AddComponent <MeshRenderer>().sharedMaterial = materials[material_ID]; // Generate new mesh Mesh mesh = ConstructMesh(composite); // Generate new meshcollider composite.AddComponent <MeshCollider>(); composite.GetComponent <MeshCollider>().sharedMesh = mesh; // Change tag composite.tag = "csg"; Destroy(main_object); Destroy(operating_object); main_object = null; operating_object = null; // Switch new composited object to main object return(composite); }
public void Apply(CSScene obsolete, CSG sceneGraph, int deviceId, ref float[] userDataFloats, ref int[] userDataInts, ref string userDataString) { int shapesCreasedCount = 0; DeCreaseAll.CreaseGroupRecursively(sceneGraph.ApplicationState.Scene, ref shapesCreasedCount); MessageBox.Show(string.Format("Shapes De-Creased: {0}", shapesCreasedCount)); }
static void Main(string[] args) { Console.WriteLine("Generating a CSG!"); var cube = new Cube(); cube.Material.Color = Color.Yellow; var sphere = new Sphere(); sphere.Transform = Matrix.Translation(-0.5, 0.5, 0.5); sphere.Material.Color = Color.Red; var csg = new CSG(CsgOperation.Difference, cube, sphere); var world = new World(); world.Lights.Add(new PointLight(new Point(10, 10, 10), Color.White)); world.Objects.Add(csg); var camera = new Camera(400, 200, Math.PI / 3); camera.Transform = Matrix.ViewTransform(new Point(-1.5, 2, 5), Point.Zero, Vector.VectorY); var c = camera.Render(world); System.IO.File.WriteAllText("Csg.ppm", c.GetPPM()); Console.WriteLine("Done!"); }
public void test() { List <IVector3d> H_points = helvetica_H.ToList(); List <IVector3d> e_points = helvetica_e.ToList(); H_points = H_points.Distinct().ToList(); e_points = e_points.Distinct().ToList(); CSG HLetter = Extrude.points(Vector3d.xyz(0, 0, 10), H_points); CSG eLetter = Extrude.points(Vector3d.xyz(0, 0, 10), e_points); Console.Out.WriteLine("H number of polygons: " + HLetter.getPolygons().Count); Console.Out.WriteLine("e number of polygons: " + eLetter.getPolygons().Count); // CSG.setDefaultOptType(CSG.OptType.CSG_BOUND); CSG simpleUnionOfNonIntersectingBodies = eLetter.union(HLetter); int numPolysExpected = HLetter.getPolygons().Count + eLetter.getPolygons().Count; Console.Out.WriteLine("Both number of polygons: " + simpleUnionOfNonIntersectingBodies.getPolygons().Count); // assumption only valid if optimization is enabled! (see above) // assumption is wrong for CSG.setDefaultOptType(CSG.OptType.NONE); // assertTrue(numPolysExpected == simpleUnionOfNonIntersectingBodies.getPolygons().size()); }
// Use this for initialization void Start() { // Getting the mesh of THIS object (the plane). this.sourceMesh = GetComponent <MeshFilter>().mesh; this.precomputedEdges = MeshExtrusion.BuildManifoldEdges(this.sourceMesh); // Defining transformations to extrude the mesh. Matrix4x4[] sections = new Matrix4x4[2]; // Starting point (where the mesh already is, but its needed so the new mesh does not generate with a hole). sections[0] = this.transform.localToWorldMatrix; // The end point. sections[1] = this.transform.worldToLocalMatrix * Matrix4x4.TRS(new Vector3(0, 1, 1), Quaternion.Euler(0, 45, 0), new Vector3(0.75f, 2, 1)); // Get the mesh again (the script need a different reference to the same mesh for some reason?). Mesh mesh = GetComponent <MeshFilter>().mesh; // Actually perform the extrusion, the parameter [invertFaces] is extremely important in this case but its kind of hard to programatically tell when it is needed. // I would guess you would need to somehow see the direction of the normals before even creating the face. MeshExtrusion.ExtrudeMesh(this.sourceMesh, mesh, sections, true); // Preparing CSG objects for substraction. // Again, passing a new refference to the same mesh is important for some reason. CSG plane = CSG.fromMesh(GetComponent <MeshFilter>().mesh, this.transform); CSG cube = CSG.fromMesh(this.cubeCutter.GetComponent <MeshFilter>().mesh, this.cubeCutter.transform); // Save the operation, this does not affect neither meshes yet. CSG result = plane.subtract(cube); // Replace the mesh of THIS object with the mesh representation of the operation. this.GetComponent <MeshFilter>().mesh = result.toMesh(); // Hide the cube to visualize the result. this.cubeCutter.SetActive(false); }
// Construct an axis-aligned solid cuboid. Optional parameters are `center` and // `radius`, which default to `[0, 0, 0]` and `[1, 1, 1]`. The radius can be // specified using a single number or a list of three numbers, one for each axis. static public CSG cube(CSGVector3 center, CSGVector3 halfSize, CSGShared shared) { int[][][] data = new int[][][] { new int[][] { new int[] { 0, 4, 6, 2 }, new int[] { -1, 0, 0 } }, new int[][] { new int[] { 1, 3, 7, 5 }, new int[] { +1, 0, 0 } }, new int[][] { new int[] { 0, 1, 5, 4 }, new int[] { 0, -1, 0 } }, new int[][] { new int[] { 2, 6, 7, 3 }, new int[] { 0, +1, 0 } }, new int[][] { new int[] { 0, 2, 3, 1 }, new int[] { 0, 0, -1 } }, new int[][] { new int[] { 4, 5, 7, 6 }, new int[] { 0, 0, +1 } } }; List <CSGPolygon> polygons = new List <CSGPolygon>(); foreach (int[][] info in data) { List <CSGVertex> vertices = new List <CSGVertex>(); foreach (int i in info[0]) { CSGVector3 pos = new CSGVector3( center.x + halfSize.x * (2 * ((i & 1) != 0 ? 1 : 0) - 1), center.y + halfSize.y * (2 * ((i & 2) != 0 ? 1 : 0) - 1), center.z + halfSize.z * (2 * ((i & 4) != 0 ? 1 : 0) - 1) ); vertices.Add(new CSGVertex(pos, new CSGVector3(info[1][0], info[1][1], info[1][2]))); } polygons.Add(new CSGPolygon(vertices, shared)); } return(CSG.fromPolygons(polygons)); }
/// <summary> /// Cuts out the cutouts from the given object at the given position (relative to the object). /// </summary> public static void CutOutObjects(pb_Object o, List <Cutout> cuts) { o.ToMesh(); o.Refresh(); Vector3 oldPostion = o.transform.position; Quaternion oldRotation = o.transform.rotation; o.transform.position = Vector3.zero; o.transform.rotation = Quaternion.identity; GameObject tempObject = new GameObject(); MeshFilter mf = tempObject.AddComponent <MeshFilter>(); mf.mesh = new CSG_Model(o.gameObject).ToMesh(); foreach (Cutout c in cuts) { c.obj.transform.position = c.location; mf.mesh = CSG.Subtract(mf.gameObject, c.obj.gameObject); } pb_MeshImporter mI = new pb_MeshImporter(o); mI.Import(tempObject, pb_MeshImporter.Settings.Default); o.transform.position = oldPostion; o.transform.rotation = oldRotation; Object.DestroyImmediate(tempObject); }
void Start() { var mf = GetComponent <MeshFilter>(); var t1 = CSG.GenCsgTree(g1.transform); var t2 = CSG.GenCsgTree(g2.transform); if (g3 != null) { var t3 = CSG.GenCsgTree(g3.transform); var t4 = t1.Oparation(t2, op1); mf.mesh = CSG.Meshing(t4.Oparation(t3, op2)); } else { var sw = new System.Diagnostics.Stopwatch(); sw.Start(); mf.mesh = CSG.Meshing(t1.Oparation(t2, op1)); sw.Stop(); Debug.Log(sw.ElapsedMilliseconds + "ms"); } foreach (Transform t in transform) { t.gameObject.SetActive(false); } }
public void SubtractFrom(GameObject s0, GameObject s1) { Mesh m = CSG.Subtract(s0, s1); s0.GetComponent <MeshFilter>().sharedMesh = m; GameObject.Destroy(s1); }
void Boolean(BoolOp operation) { Mesh m = new Mesh(); switch (operation) { case BoolOp.Union: m = CSG.Union(first, second); break; case BoolOp.Subtract: m = CSG.Subtract(first, second); break; case BoolOp.Intersect: m = CSG.Intersect(first, second); break; } composite = new GameObject(); composite.AddComponent <MeshFilter>().mesh = m; composite.AddComponent <MeshRenderer>().material = first.GetComponent <MeshRenderer>().material; GenerateBarycentric(composite); }
private UVDLPApp() { m_supportmode = eSupportEditMode.eNone; SceneFileName = ""; m_callbackhandler = new CallbackHandler(); m_appconfig = new AppConfig(); m_printerinfo = new MachineConfig(); m_buildparms = new SliceBuildConfig(); m_deviceinterface = new DeviceInterface(); m_buildmgr = new BuildManager(); m_slicer = new Slicer(); m_slicer.m_slicemethod = Slicer.eSliceMethod.eNormalCount;// configure the slicer to user the new normal count - Thanks Shai!!! m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv); //m_dispmgr = DisplayManager.Instance(); // initialize the singleton for early event app binding //m_flexslice = new FlexSlice(); m_gcode = new GCodeFile(""); // create a blank gcode to start with m_supportconfig = new SupportConfig(); m_supportgenerator = new SupportGenerator(); m_supportgenerator.SupportEvent += new SupportGeneratorEvent(SupEvent); CSG.Instance().CSGEvent += new CSG.CSGEventDel(CSGEvent); m_proj_cmd_lst = new prjcmdlst(); m_plugins = new List <PluginEntry>(); // list of user plug-ins m_pluginstates = PluginStates.Instance(); // initialize the plugin state singleton m_undoer = new Undoer(); m_2d_graphics = new C2DGraphics(); m_gui_config = new GuiConfigManager(); m_AuxBuildCmds = AuxBuildCmds.Instance(); // make sure the singleton doesn't go away... m_sequencemanager = SequenceManager.Instance(); }
// Use this for initialization void Start() { Debug.Log("Mesh go1: " + go1.GetComponent <MeshFilter>().mesh.vertices.Length); Debug.Log("Mesh go2: " + go2.GetComponent <MeshFilter>().mesh.vertices.Length); //Debug.Log (ObjExporter.MeshToString(go2.GetComponent<MeshFilter>())); //ObjExporter.MeshToString(go2.GetComponent<MeshFilter>()); /*Mesh m = CSG.Union(go1, go2); * * // Create a gameObject to render the result * GameObject composite = new GameObject(); * composite.transform.position = new Vector3(8,8,8); * composite.AddComponent<MeshFilter>().sharedMesh = m; * composite.AddComponent<MeshRenderer>().sharedMaterial = material;*/ CSG A = CSG.fromMesh(go1.GetComponent <MeshFilter>().mesh, go1.transform); CSG B = CSG.fromMesh(go2.GetComponent <MeshFilter>().mesh, go2.transform); CSG result = null; result = A.union(B); GameObject composite = new GameObject(); if (result != null) { composite.AddComponent <MeshFilter>().mesh = result.toMesh(); } composite.transform.position = new Vector3(20, 20, 20); composite.AddComponent <MeshRenderer>().sharedMaterial = material; //saveMeshAsAsset sa = composite.AddComponent<saveMeshAsAsset>() as saveMeshAsAsset; }
// Construct a CSG solid from a list of `CSG.Polygon` instances. static public CSG fromPolygons(List <CSGPolygon> polygons) { CSG csg = new CSG(); csg.polygons = polygons; return(csg); }
// Construct a solid sphere. Optional parameters are `center`, `radius`, // `slices`, and `stacks`, which default to `[0, 0, 0]`, `1`, `16`, and `8`. // The `slices` and `stacks` parameters control the tessellation along the // longitude and latitude directions. // // Example usage: // // var sphere = CSG.sphere({ // center: [0, 0, 0], // radius: 1, // slices: 16, // stacks: 8 // }); static public CSG sphere(CSGVector3 center, float radius, int slices, int stacks, CSGShared shared) { List <CSGPolygon> polygons = new List <CSGPolygon>(); for (float i = 0; i < slices; i++) { for (float j = 0; j < stacks; j++) { List <CSGVertex> vertices = new List <CSGVertex>(); sphereVertex(center, radius, i / slices, j / stacks, vertices); if (j > 0) { sphereVertex(center, radius, (i + 1) / slices, j / stacks, vertices); } if (j < stacks - 1) { sphereVertex(center, radius, (i + 1) / slices, (j + 1) / stacks, vertices); } sphereVertex(center, radius, i / slices, (j + 1) / stacks, vertices); polygons.Add(new CSGPolygon(vertices, shared)); } } return(CSG.fromPolygons(polygons)); }
public void SubdividingACSGShapeSubdividesItsChildren() { var s1 = new Sphere { Transform = Transform.Translation(-1.5, 0, 0) }; var s2 = new Sphere { Transform = Transform.Translation(1.5, 0, 0) }; var left = Group.Of(s1, s2); var s3 = new Sphere { Transform = Transform.Translation(0, 0, -1.5) }; var s4 = new Sphere { Transform = Transform.Translation(0, 0, 1.5) }; var right = Group.Of(s3, s4); var shape = new CSG(Operation.DIFFERENCE, left, right); shape.Divide(1); Assert.AreEqual(Group.Of(s1), left[0]); Assert.AreEqual(Group.Of(s2), left[1]); Assert.AreEqual(Group.Of(s3), right[0]); Assert.AreEqual(Group.Of(s4), right[1]); }
public void Tunnel() { CSG.EPSILON = 1e-5f; // Adjustable epsilon value CSG csg = new CSG(); GameObject[] bricks = GameObject.FindGameObjectsWithTag("StructureBrick"); foreach (GameObject brick in bricks) { csg.Target = brick; GameObject newOne; Collider[] hitColliders = Physics.OverlapSphere(brick.transform.position, GameObject.Find("Circular").GetComponent <ArchBuild>().brickDepth); for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders [i].gameObject.transform.tag == "Tunnel") { csg.Brush = hitColliders [i].gameObject; csg.OperationType = CSG.Operation.Subtract; csg.customMaterial = new Material(Shader.Find("Standard")); // Custom material csg.useCustomMaterial = false; // Use the above material to fill cuts csg.hideGameObjects = false; // Hide target and brush objects after operation csg.keepSubmeshes = true; // Keep original submeshes and materials newOne = csg.PerformCSG(); Destroy(csg.Target); csg.Target = newOne; newOne.name = "NewBrick"; newOne.tag = "StructureBrick"; newOne.transform.parent = GameObject.Find("Vault Structure").transform; } } } }
public void CutExtrude(float extrude_length) { SimpleExtrude(-extrude_length); extruded_object.GetComponent <MeshRenderer>().enabled = true; SearchSelectedGeometry().GetComponent <MeshRenderer>().enabled = true; Mesh m = CSG.Subtract(SearchSelectedGeometry(), extruded_object); //objecthat is cut,object that cuts //Mesh m = CSG.Subtract(GameObject.Find("Cube"), GameObject.Find("Sphere")); //Debug.Log(SearchSelectedGeometry().transform.parent.name); //Debug.Log(extruded_object.transform.parent.name); composite = new GameObject(); MeshCollider mc = composite.AddComponent <MeshCollider>(); mc.sharedMesh = m; composite.AddComponent <MeshFilter>().sharedMesh = m; composite.AddComponent <MeshRenderer>().sharedMaterial = mtl; composite.GetComponent <MeshRenderer>().material.shader = Shader.Find("Custom/VertexColor"); composite.name = "Extrusion"; composite.transform.SetParent(sketchToExtude.transform); extruded_object.GetComponent <MeshRenderer>().enabled = false; SearchSelectedGeometry().GetComponent <MeshRenderer>().enabled = false; //Destroy(extruded_object); //Destroy(SearchSelectedGeometry()); //GenerateBarycentric(composite); }
public CSG modified(CSG csg) { CSG result = csg.clone(); modify(result); return(result); }
public void T06_IntersectingARayWithACSGObjectMiss() { CSG c = new CSG(CSG.Operation.Union, new Sphere(), new Cube()); Ray r = new Ray(new Point(0, 2, -5), new Vector(0, 0, 1)); List <Intersection> xs = c.Intersect(r); Assert.IsEmpty(xs); }
public void ARayMissesACSGObject() { var c = new CSG(Operation.UNION, new Sphere(), new Cube()); var r = new Ray(new Point(0, 2, -5), new Vector(0, 0, 1)); var xs = c.Intersects(r); Assert.AreEqual(0, xs.Count); }
public void TestCsgRayMisses() { var c = new CSG(CsgOperation.Union, new Sphere(), new Cube()); var r = new Ray(new Point(0, 2, -5), Vector.VectorZ); var xs = c.Intersect(r); Assert.AreEqual(xs.Count, 0); }
public void RayMissesCSG() { CSG c = new CSG("union", new Sphere(), new Cube()); Ray r = new Ray(Tuple.Point(0, 2, -5), Tuple.Vector(0, 0, 1)); List <Intersection> xs = c.LocalIntersect(r); Assert.AreEqual(xs.Count, 0); }
public void OnSubtractButtonClick() { CombineInstance[] combinesPlanes = new CombineInstance[2]; MeshFilter meshFilterPlane1 = _plane1.gameObject.GetComponent <MeshFilter>(); combinesPlanes[0].mesh = meshFilterPlane1.sharedMesh; combinesPlanes[0].transform = meshFilterPlane1.transform.localToWorldMatrix; MeshFilter meshFilterPlane2 = _plane2.gameObject.GetComponent <MeshFilter>(); combinesPlanes[1].mesh = meshFilterPlane2.sharedMesh; combinesPlanes[1].transform = meshFilterPlane2.transform.localToWorldMatrix; Mesh combinedMeshPlanes = new Mesh(); combinedMeshPlanes.CombineMeshes(combinesPlanes); GameObject combinedPlanes = new GameObject(); combinedPlanes.AddComponent <MeshFilter>().sharedMesh = combinedMeshPlanes; combinedPlanes.AddComponent <MeshRenderer>().sharedMaterial = _plane1.material; // Perform boolean operation CombineInstance[] combines = new CombineInstance[_objsToSubtract.Length]; for (int i = 0; i < _objsToSubtract.Length; i++) { MeshFilter meshFilter = _objsToSubtract[i].gameObject.GetComponent <MeshFilter>(); combines[i].mesh = meshFilter.sharedMesh; combines[i].transform = meshFilter.transform.localToWorldMatrix; } Mesh combinedMesh = new Mesh(); combinedMesh.CombineMeshes(combines); GameObject combinedObj = new GameObject(); combinedObj.AddComponent <MeshFilter>().sharedMesh = combinedMesh; combinedObj.AddComponent <MeshRenderer>().sharedMaterial = _obj1.material; //Mesh m = CSG.Subtract(_obj1.gameObject, combinedPlanes); Mesh m = CSG.Subtract(combinedPlanes, combinedObj); // Create a gameObject to render the result GameObject composite = new GameObject(); composite.AddComponent <MeshFilter>().sharedMesh = m; composite.AddComponent <MeshRenderer>().sharedMaterial = _obj1.material; Debug.Log("m.triangles.Length: " + m.triangles.Length); Debug.Log("m.vertexCount: " + m.vertexCount); _obj1.gameObject.SetActive(false); }
public static GameObject GetIntersection(GameObject obj, GameObject hemisphere, Material truncatedMaterial, bool disableHemispheres) { GameObject cube = hemisphere.transform.Find("GuideCube").gameObject; Vector3 size = cube.transform.lossyScale; size.x -= 0.01F; size.y -= 0.01F; size.z -= 0.01F; //check if there is indeed area that is overlapping between the two objects Collider[] hitColliders = Physics.OverlapBox(cube.transform.position, size / 2, cube.transform.rotation); bool isColliding = false; foreach (Collider col in hitColliders) { if (col.gameObject == obj) { isColliding = true; } } if (!isColliding) { hemisphere.gameObject.SetActive(false); obj.gameObject.SetActive(false); return(null); } Vector3 position; position = obj.transform.position; obj.transform.position = new Vector3(0, 0, 0); hemisphere.transform.position = obj.transform.position; Mesh n = CSG.Intersect(cube, obj); n.name = "Truncated Sphere"; GameObject final = new GameObject("Final"); final.AddComponent <MeshFilter>().sharedMesh = n; final.AddComponent <MeshRenderer>().sharedMaterial = truncatedMaterial; final.AddComponent <MeshCollider>(); final.GetComponent <MeshCollider>().sharedMesh = n; obj.transform.position = position; hemisphere.transform.position = position; final.transform.position = position; final.layer = LayerMask.NameToLayer("final"); final.tag = "Final"; //GameObject VectorLineObj = DrawHemisphereLines(final, "final"); //VectorLineObj.transform.parent = final.transform; //VectorLineObj.name = "HemiLine"; if (disableHemispheres) { obj.GetComponent <MeshRenderer>().enabled = false; hemisphere.GetComponent <MeshRenderer>().enabled = false; } return(final); }