# "Carving" a Mesh

 0 Many 3d authoring applications support some shape or form of this. Some refer to the technique of creating shapes by carving them with other shapes as a "Boolean Operation". There's a nice acedemic term for this, but I can't seem to remember it right now. Nothing is stopping you from programming this in Unity, however it's pretty heavy on math, so you'd probably not want to start without a cup of coffee on your desk. more ▼ answered Jan 15 '10 at 12:21 PM Lucas Meijer 1 ♦♦ 7.9k ● 19 ● 43 ● 85 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Have you looked into creating a mesh with lots of vertices and then altering the mesh? You'll need to do a camera.ScreenPointToRay() to find which triangle you are clicking on, then using the triangle you can find it's 3 points and then alter the mesh accordingly. You'd need to compensate for the rotation of the object etc. Example from Unity Reference Manual ``````function Update () { // Only if we hit something, do we continue var hit : RaycastHit; if (!Physics.Raycast (camera.ScreenPointToRay(Input.mousePosition), hit)) return; // Just in case, also make sure the collider also has a renderer material and texture var meshCollider = hit.collider as MeshCollider; if (meshCollider == null || meshCollider.sharedMesh == null) return; var mesh : Mesh = meshCollider.sharedMesh; var vertices = mesh.vertices; var triangles = mesh.triangles; // Extract local space vertices that were hit var p0 = vertices[triangles[hit.triangleIndex * 3 + 0]]; var p1 = vertices[triangles[hit.triangleIndex * 3 + 1]]; var p2 = vertices[triangles[hit.triangleIndex * 3 + 2]]; // Transform local space vertices to world space var hitTransform : Transform = hit.collider.transform; p0 = hitTransform.TransformPoint(p0); p1 = hitTransform.TransformPoint(p1); p2 = hitTransform.TransformPoint(p2); // Display with Debug.DrawLine Debug.DrawLine(p0, p1); Debug.DrawLine(p1, p2); Debug.DrawLine(p2, p0); } `````` more ▼ answered Jan 12 '10 at 03:44 AM David O'Donoghue 61 ● 4 ● 4 ● 9 So if I wanted to apply this to the plane I'd collide the plane with the mesh collider and copy the mesh without the vertices in the direction of the normal from then plane? Jan 15 '10 at 12:22 AM lathomas64 To carve a "branch" you'd probably want to take a cylinder (or mesh object), detect where the carve should occur then move the vertices inside the mesh itself a little to give the impression the object is being carved. If you want to break a mesh up so that half of the mesh just doesn't show, I'm not sure how to do it but the dumbest way would be to move the vertices inside the mesh so that they are "hidden"See examples here: http://tinypic.com/r/xp8nyu/6 Jan 18 '10 at 02:49 AM David O'Donoghue I've been busy since posting this but I've finally gotten the time to sit down with a pencil and paper to draw this out so I could understand it properly. Basically when i have a plane intersecting with an object i need to translate all the vertices above the plane along its normal to be just below the plane! It is sort of like flattening the mesh out instead of carving but I think the desired effect will be achieved. I'll have to test this out when I get home. Jun 22 '10 at 09:33 PM lathomas64 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1354
x491
x298

asked: Dec 31 '09 at 02:04 PM

Seen: 3178 times

Last Updated: Dec 31 '09 at 06:52 PM