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 Adizx · Mar 30, 2015 at 03:23 AM · renderingsliceplanesdouble-sidedcrosssection

Double-sided cross section ("slice")

Hello, I've started a new project and can't force Unity to make a double-sided cross section of all meshes from z=-0.5 to z=0.5.

So far I've made a shader clipping all objects (and for "empty inside" ones works fine). However for "filled inside" objects I need to render planes from both sides, so it would look like a "slice" of any mesh.

I'm in a dead point atm, because in Unity we don't have boolean operations on meshes and shader can't render anything which is not present...

Maybe someone would have any great idea for any work-around? I'd appreciate any help ;)

alt text

problem.png (267.8 kB)
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 AlwaysSunny · Mar 30, 2015 at 03:23 AM 0
Share

Nothing I'm aware of, shy of coding your own boolean operations. Wouldn't envy that task. This is an interesting question though.

avatar image Adizx · Mar 30, 2015 at 07:16 AM 0
Share

I've also thought about using that vertices on the edges we have after clipping (maybe z-coordinate comparison and adding to array?) and bulding face from them - but I can't imagine how they should be connected, because shapes may be very complex (and thus order of them).

Hope any veteran would clarify this a bit more ;)

avatar image AlwaysSunny · Mar 30, 2015 at 04:24 PM 0
Share

I'm not familiar enough with shader lore to guarantee that this cannot be done on the GPU, but I've never seen the effect before AFAI$$anonymous$$.

Unless I'm badly mistaken, any solution is going to be non-trivial, involving a per-frame (if rot/scale/z-pos change), per-mesh boolean operation.

avatar image Glurth · Mar 30, 2015 at 05:37 PM 2
Share

One option is to create a new mesh, dynamically, based upon your original mesh and the two clipping planes. As you mentioned there are no Boolean operators for solids, so you will need to do it manually. This is obviously not a trivial algorithm, as Sunny mentioned, and getting it fast enough for runtime use can be hard.

Two possible ways I would do this: For each vertex in the mesh, deter$$anonymous$$e if it lies between the two planes (in model space). If so, include it in the final mesh. This would be fine, if we didn't care what the edge of the mesh looked like.

The trickier part will be triangles of the original mesh that cross a plane boundary. I would do this part by checking each EDGE (any line segment between two vertices) of each triangle: if all triangle verticies lies between the two planes, keep the verticies, AND the triangle. but if one vertex lies between the planes, and the other does not, we need to compute WHERE the plane intersects the edge.
Once you have the intersection (see link below) you can create a new vertex at that point. Don't forget you will need to recreate the edge triangles: any triangles the planes intersect, with two vertices inside, will need to become TWO triangles (since a truncated triangle is a quad.) Also note that any triangle that intersects the plane will have TWO edges that intersect the plane (except in rare cases- where a triangle edge lies on the plane exactly).

So lets say you have triangle ABC, and the plane intersects AB and AC at D and E respectively. If A is between the planes: our new triangle will be ADE (B and C are replaced with the two new intersection) If B and C lie between the planes: our two new triangles will be DBC and EBC ( A is replaced with the two new intersections

Edit: Closing the remaining two open sides can be complex or simple depending on if your shapes are concave or not. If not concave, using one vertex as a base, create a triangle to every other vertex(peacock-style). (here I'm referring to vertices your created in the previous part, that lie exactly on a plane.)

This is one of my favorite wiki posts, I think it will have all the line/plane and other math functions you need to do the above. http://wiki.unity3d.com/index.php/3d_$$anonymous$$ath_functions

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Trying to make a texture fill an entire Plane 0 Answers

Cross section of plane 0 Answers

Render wireframe on cut section of polygons 2 Answers

How do I fix these clouds? 0 Answers

Planes clipping through each other. 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