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
2
Question by CHPedersen · May 09, 2011 at 01:04 PM · cubegeometrysolidconstruction

Constructive Solid Geometry on procedural pipes

Dear all,

First off, sorry about this huge text, but it was important for me to explain the problem properly. :)

I have a pretty hairy geometry question I've been pondering for a while. I'm developing an application that involves the generation of some pipes. The pipes consist of meshes created at runtime, two meshes per pipe (one with triangles facing out, the other with triangles facing in, so that it doesn't become invisible from neither the inside or outside). The meshes are drawn around a line in space defined by a series of points that are read into the program from an XML file. Think of them as subway tunnels, basically.

Occasionally, the tunnel might have sidetracks that split apart from the main pipe. Sticking to the subway analogy, this is just a connecting tunnel. The sidetrack is defined by a series of points just like the mainpipe, and then a certain position that indicates where it connects to the main pipe.

At the moment, I'm simply drawing the sidetrack with the exact same algorithm as the mainpipe, with no regard to intersecting geometry. From the outside, this looks fine:

Sidetrack from the outside

The sidetrack seems to just blend into the mainpipe seamlessly.

But when you move the camera closer so that the near clipping plane cuts open the geometry, the fact that they are simply drawn on top of one another without any kind of attention to intersection becomes painfully obvious:

Sidetrack from the inside

This is a problem, since I need the user to be able to traverse the inside of the pipes and see where they split apart properly from the inside as well. This is a Constructive Solid Geometry problem, i.e. it involves the merging of two parametric surfaces. These problems aren't usually trivial, and I've sweated over how to solve it for a while, and I have a few ideas, but I'd like your input on how to best do it, which is why I'm posting the problem here. :)

My idea is to try and generate a voxel grid surrounding each pipe, and then perform set operations on them to remove the voxels that overlap in space, that is, the voxels from a sidetrack that end up inside the mainpipe's geometry. After that, I would reconstruct the triangle mesh using some implementation of the Marching Cubes algorithm.

So I guess the question is two-fold. First, can you think of a better way to accomplish the merger of this geometry where the pipes intersect? Second, if not, do you know of a library for Unity that specializes in constructive solid geometry, or am I on my own? Thanks in advance!

  • Christian
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by sneftel · May 09, 2011 at 01:47 PM

This actually sounds like a pretty straightforward CSG problem. It's all about cutting planes.

Your pipe network is made up of edges (in the graph-theoretical sense of the word). The presence of an edge in your pipe network leads to the creation of a single pipe mesh. This pipe mesh can be thought of as an infinite cylinder, collinear in its center line with the pipe edge, which is cut by a series of planes (aka boolean intersection with half-spaces). For instance, a single pipe edge would lead to a single cylinder, with two half-planes cutting it (one for each end).

If a pipe just ends, the cutting plane on that side is perpendicular to the pipe. (I assume -- that would be the natural way to do it.)

If two pipe edges meet at a vertex (again, in the graph-theoretical sense), they are each cut by a cutting plane is (a) parallel to the cross product of the two pipes' edge vectors, and (b) also parallel to the bisector of the two pipe vectors. So if AB and AC are the normalized vectors along two pipes which meet at A, they will be cut by a plane which contains A and has the normal (AB + AC) x (AB x AC).

If you've got a bunch of pipe edges meeting at a vertex, there will be a cutting plane for each pair of edges. That cutting plane will affect only those edges. So for AB, AC, and AD meeting at A, B will be cut by the AB-AC and AB-AD cutting planes, but not by the AC-AD cutting plane.

Once you have all the cutting planes for a pipe, consider the pipe in terms of the edges (in the mesh sense) which run from one end of the pipe to the other, parallel to the center of the pipe. Each one has its own extents, determined by intersecting the potentially infinite line with all the cutting planes for that pipe.

Once you have the extents for all those edges, just connect them up in the normal cylinder way, and you have your pipes.

A degenerate case to consider: some of those lines may have zero extents (corresponding to a pipe which, due to its short length and oblique cutting planes, no longer goes all the way around), which may require some clever stitching.

Note that this won't entirely eliminate gaps if the pipes are not all coplanar, since you need to choose where to start going around the rim of the pipe. Having more radial subdivisions will minimize this problem.

Let me know if you have questions about any of this.

Comment
Add comment · Show 1 · 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 CHPedersen · May 10, 2011 at 12:13 PM 0
Share

Thanks a lot for this very thoroughly explained suggestion. :) I followed your line of thought on a sketch of pipelines as I went through the method, and it seems you might be onto something. $$anonymous$$y time is unfortunately my boss's to prioritize before it's my own, so I'm going to have to come back to this later after I've dealt with some tasks that recently landed on my desk. I'll let you know how it goes.

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

No one has followed this question yet.

Related Questions

How to detect if an object is above another one 0 Answers

Possible to create primitive cube offset from own origin 0 Answers

How to set thickness to terrain plane 2 Answers

Get vertices inside a box collider 1 Answer

How do I cause the collision of one object affect the movement of another object? 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