Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by lathomas64 · Dec 31, 2009 at 02:04 PM · meshgraphicsprocedural

"Carving" a Mesh

How would I go about breaking a mesh up where a plane intersects it? The ultimate goal would be to allow someone to do something like carving a branch. I've seen example in the procedural.zip on unity about sculpting but it looks like you can only add to the mesh with their script via adding vertexes.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bowditch · Jan 02, 2010 at 05:12 PM 0
Share

Are you wanting to allow the player to do both convex and concave edits to the mesh?

avatar image lathomas64 · Jan 03, 2010 at 02:16 AM 0
Share

Almost, I found examples of how to let them do convex edits, but am wanting to only allow concave edits.

avatar image Ashkan_gc · Jan 07, 2010 at 09:00 PM 0
Share

please tell us how to do that for convex meshes? answer your question yourself and also earn a badge for it

avatar image lathomas64 · Jan 08, 2010 at 10:33 PM 1
Share

convex edits as in adding to a mesh, making it bigger in some places. There is an example of that in the procedural example stuff on unity's website. http://unity3d.com/support/resources/example-projects/procedural-examples But this is not what I am trying to do. I am trying to take way from the mesh not add onto it.

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Lucas Meijer 1 · Jan 15, 2010 at 12:21 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by David O'Donoghue · Jan 12, 2010 at 03:44 AM

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);

}

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lathomas64 · Jan 15, 2010 at 12:22 AM 0
Share

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?

avatar image David O'Donoghue · Jan 18, 2010 at 02:49 AM 0
Share

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

avatar image lathomas64 · Jun 22, 2010 at 09:33 PM 1
Share

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 ins$$anonymous$$d of carving but I think the desired effect will be achieved. I'll have to test this out when I get home.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Is it possible to set smoothness and metallic of a mesh per-vertex instead of the whole material? 0 Answers

Polygon buffering/offsetting? 1 Answer

Procedurally modified mesh is displayed wrong 1 Answer

Creating a Tesseract - a 4D cube. 5 Answers

Water on a non-planar mesh 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges