Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Vonni · Jan 12, 2013 at 11:58 AM · meshverticescuttingsplitting

Cutting simple plane with a line (~2D)

Hey there!

I want to create a tool that can cut simple meshes (no depth in any of the meshes) in half by dragging a line with the mouse over a mesh.

alt text

I was thinking of raycasing on GetKeyUp, from mouseDown position to mouseUp position and vica versa to find the intersection points (5 and 6). And then rebuild the mesh using the new vertices into two meshes using the "normal" of the line to determine which mesh they belong to.

Im only looking for ideas here, some push in the right direction. Im not sure if this is even close to a good method and I'm a bit stuck.

Thanks for any help!

cutting illustration.png (29.7 kB)
Comment
Add comment · Show 1
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 tomekkie2 · Jul 15, 2016 at 04:20 AM 1
Share

You could also use plane clipping shaders. There is a few threads on them (aka cross-section shaders) on the forum, like here: http://forum.unity3d.com/threads/simple-cross-section-shader.34508/. (This is on cross-section, you don't need co care about the backfaces in your case.) You would need to apply plane clipping shader to your plane material. Then you have to deter$$anonymous$$e the cutting plane for which you need a plane point (which can be any of the clicked points) and normal which is:

Vector3 clippingPlaneNormal = Vector3.Cross((ClickedPoint1-ClickedPoint2),yourPlaneNormal);

Then you pass these parameters to the clipping shader.

2 Replies

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

Answer by Bunny83 · Jan 12, 2013 at 01:04 PM

Well the easiest way is to use the Plane class and it's Raycast function to get the two points on the plane of your mesh. Since you said all vartices lie in one plane you can take the first 3 points of the mesh to build the plane. Keep in mind that mesh vertices are in localspace and you have to use TransformPoint to get them into worldspace.

Of course it's also possible to transform the rays into local space but that's more mind challenging.

Once you have the two click points on your plane, you can use one of the 3d math functions in the wiki to calculate intersections with the border lines.

Keep in mind that a mesh is build up of triangles, so in your example above you have more intersection points ;) two for each triangle.

So i would do it like this:

  • Get the cutting line with the above mentioned way.

  • iterate trough all triangles and test each edge for an intersection

  • if you have two intersections you can split the triangle into 1 triangle and one quad (so 3 triangles)

For edge-cases when a really small triangle would be created you could calculate the area of the triangle you're going to create and drop those which are too small.

Comment
Add comment · Show 2 · 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 Vonni · Jan 12, 2013 at 01:26 PM 0
Share

Thanks a lot! Will look into this as soon as I get home :)

avatar image Vonni · Jan 12, 2013 at 03:57 PM 0
Share

I've only made some snapping tool and transformed some vertices before. But I want to boost my mesh program$$anonymous$$g skills, so will read up on a lot, thanks.

avatar image
0

Answer by Fattie · Jan 12, 2013 at 01:32 PM

For cutting a square...

alt text

the weave is:

125
526
564
463

If you have never built mesh before, begin here ! -->

http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html

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

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Splitting a Mesh into Submeshes 2 Answers

Can you apply smoothing to split vertices on a generated mesh? 1 Answer

How to take a chunk out of a mesh at runtime 1 Answer

Mesh extrusion overlapping triangles problem 0 Answers

Mesh Colours transparent 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