• 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
Question by func_Mathias · Oct 29, 2017 at 06:10 PM · meshrenderingwireframecrosssection

Render wireframe on cut section of polygons

Hi, after researc$$anonymous$$ng for a few days and trying everyt$$anonymous$$ng free I came across I'm giving in and asking here. I'm looking for a way to render wireframe so that it'll complete the lines where geometry is cut off, either because of a cross section or from the near plane on a camera. I've found that the Source Engine does t$$anonymous$$s w$$anonymous$$ch you can see in t$$anonymous$$s picture and the video. Unlike source however I'd like it to be double sided, and though unlikely, if only the clipping edge could be isolated that'd be even better.

wireframe clipping with camera

The reason I want t$$anonymous$$s behavior is that I've been looking for any way to scan a models shape in layers from the top-down using an orthograp$$anonymous$$c camera and reconstruct it using layers of textures. I've tried many ways, had a pretty good one but it relied on the model being well made, my system has to account for any model from the user. I've also tried using $$anonymous$$ghlight shaders, w$$anonymous$$ch worked well for the most part, but if a polygon is perfectly vertical (like on a building wall) there will be no $$anonymous$$ghlight since it'll be too t$$anonymous$$n.

alt text

I've come to t$$anonymous$$nk t$$anonymous$$s wireframe method is going to be the cheapest way to obtain an outline of a models shape at any point, by sending an orthograp$$anonymous$$c camera through the model with the near and far plane extremely close to eachother. I'll take any solution that isn't too heavy tho, needs to be able to make a scan relatively quick for models with millions of polygons.
Thanks for reading, hope there's a way to do somet$$anonymous$$ng like t$$anonymous$$s.

Video demonstration

wireframe-source-example01.png (31.4 kB)
model-layers.png (114.3 kB)
Comment
Bunny83

People who like this

1 Show 3
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 theLittleSettler · Oct 29, 2017 at 06:18 PM 0
Share

ok, so partial answer... instead of using one ortho camera, you should use several with your highlight shader. From one direction, the shape will never be determined, but if you have two (or more) a few degrees apart, you shouldn't have that problem. Admittedly, that makes it all the more complicated - hence partial answer :P

avatar image func_Mathias theLittleSettler · Oct 29, 2017 at 06:27 PM 0
Share

Yeah have thought of something like this but doesn't seem all that practical, rendertime will be longer and I might have to try to combine the different angles result into one somehow, dunno how. Maybe I'll look into that if I get really desperate but for now I hope there's a better way, thanks for the response though.

avatar image theLittleSettler func_Mathias · Oct 29, 2017 at 09:57 PM 0
Share

Well, to elaborate a little; the principle of triangulation and a c# script to combine the data. Or a shader, it really doesn't matter which way (ie, a volumetric shader). Rather than using slices, I would have a front-only and back-only shader that draws depth into the colour channels. Oh my...maybe I can give a decent answer. You see, if you have a shader like that, then you only need one camera. You'd take two images, compare the difference, and voila. But I think I need more info on what the end result has to be. And on what you mean by fast. Is this an editor solution or something that must happen at runtime? Well naturally that has limitations...I'm assuming there's no holes in the middle of the object, for instance. If you want it to be perfect you would indeed need to take slices.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Bunny83 · Oct 30, 2017 at 03:31 AM

I quickly created a script that will create a wireframe mesh (w$$anonymous$$ch consists of lines) based on a given object. In addition it will clip the edges against a plane.


The actual MonoBehaviour in t$$anonymous$$s script is ment for demonstration. Modify it as you need it or just use the "WireframeClipMesh" to create / update the wireframe mesh on the fly. Unfortunately Unity still has no SetIndices variant that takes a generic List. So if the number of edges that has to be drawn changes we have to create a new index array. Though even when moving through an object that shouldn't happen too often.


When you attach t$$anonymous$$s script to an object it will initialize the "WireframeClipMesh" with the mesh of the object it's attached to. It will create a c$$anonymous$$ld object "wireframe" w$$anonymous$$ch will actually draw the clipped wireframe mesh. The clipping plane is defined by a single Transform reference. The positive z-axis (forward) of that transform is the plane's normal vector. Note t$$anonymous$$ngs in front of the plane get cut away. So it's not an "allow" plane (like the viewing frustum where the normals point inwards) but a cutting plane.


It's probably easier to look at t$$anonymous$$s animated gif

Comment
func_Mathias

People who like this

1 Show 6 · 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 func_Mathias · Oct 30, 2017 at 04:06 PM 0
Share

Wow thank you very much for this, it works pretty darn well! There are some problems though, most importantly that on models that reach the max poly count of unity it gets errors. I don't expect you to do more for me for free here so I would like to contact you and offer some pay to do some fixes, additions and changes, if you're interested that is. My main specialty isn't programming and I don't think anyone on my team has much experience with this exact thing (or time to spend on it), so if you have time I'd be happy to give you something for your effort. If not thanks again for what you have done, didn't expect anyone to come with something so functional, or anything at all really. Thanks!

avatar image Bunny83 func_Mathias · Oct 31, 2017 at 01:44 AM 1
Share

Unity doesn't have a max poly count, just a max vertex count as Unity only uses 16 bit index buffers so it's not possible to address more than 65k vertices.


Well, yes if the original mesh has many shared vertices my current method does duplicate those for each edge. When i started writing the script i actually thought if i may actually create triangles as output which was the main reason to keep the vertices for each triangle.


This problem can probably be solved by simply sharing all vertices possible. Since we only deal with lines we actually don't care about vertex colors, normals, uv, ... so sharing should be no issue. The easiest would probably be a mapping dictionary to automatically merge vertices with the same position.It's probably the best to do the merging as the last step. It could be done right in the beginning, however as new vertices are generated by the clipping they would need to be merged as well.


Currently my family is around for the next few days. I will have a look at it. If it can be fixed easily I'll do it right away ^^

avatar image Bunny83 func_Mathias · Oct 31, 2017 at 02:02 AM 1
Share

It was faster than i expected ^^. Just added the merging code which is essentially just a few additional lines. I've updated the file on my dropbox. If i check the created mesh for the default sphere it actually ends up with less vertices than the original sphere.

avatar image func_Mathias Bunny83 · Oct 31, 2017 at 06:52 AM 0
Share

Man you're awesome, works nicely ^^. But sadly I still have a list of a few things that are needed before I can use it :c. Again I'd really like to reward you for what you have done and what I still need, and I'm all out of reputation points.

I'll put the list here, not because I want you to fix it for free but to give you an idea of what I need, not that I can stop you it seems :P. Show only the clip line (would probably fix the performance too), apply script to top parent only, size and orientation problems when not default I think, and nice to have would be to change line thickness and color.

Since you seem interested in helping please do give me any way to contact you so we can talk and maybe to give some back, even steam will do, assume you have a steam account to play Black Mesa at least, my name and avatar are the same on steam as here. Sorry if I'm pushy about rewarding you, just think you deserve it ^^.

Anyway thanks for everything you're awsome, glad you stumbled upon my question :D.

Show more comments
avatar image

Answer by Fyphia · Apr 19, 2021 at 07:40 AM

@Bunny83 , Hi, thanks for your sharing! I applied the script, but it seems there is no cut happens. May I ask why? I t$$anonymous$$nk that if I don't close the mesh renderer, it should show part of the object when moving the clipping plane

Comment

People who like this

0 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 Fyphia · Apr 19, 2021 at 07:53 AM 0
Share

@Bunny83 , I've checked the complete comments above and I found that you added a boolean parameter, now the cut of wireframe works well! May I ask, is there any way to perform the cut with mesh renderer instead of just wireframe so that parts of the object occurs with the clipping plane move?

avatar image Bunny83 Fyphia · Apr 19, 2021 at 05:15 PM 0
Share

Is there a way? sure, however it gets significantly more complex. When we clip a wireframe model we can work on each edge more or less seperately and just have to take care of adding the new edge at the cut. When you want to actually cut a triangle the result may need to split the original triangle into two new triangles. That's because a cut triangle may result either in a single smaller triangle (if two of three vertices are cut off) or in a trapezoid (if only one vertex is cut off). Of course a trapezoid has to be represented with two triangles. Also cutting a triangles that have textures applied also means you have to calculate the UVs for the new vertices. Also in 3d you have the additional problem of the newly created face at the cut. This face needs to be created from all the vertices around the cut and if the mesh was textured you have to find a reasonable way to texture this piece.


So there are a lot more variables to consider. It's not black magic and not overly complicated, though quite a bit of work. Currently I don't have any time to flesh out a solution for that. Also that's not what was asked here. So if you have a different question, you should ask a seperate question. However there are at least 5 questions on UA which ask for how to cut a mesh. There are (mosly paid) solutions on the asset store as well.

avatar image Fyphia Bunny83 · Apr 19, 2021 at 05:27 PM 0
Share

@Bunny83 , thanks for your reply! Maybe my expression is not accurate enough. I didn't mean the actual cut or slice. As shown in your gif, it is possible to show/render part of the object's wireframe (without its mesh renderer) when moving the plane, I wanna ask if it is possible to show part of the object with its mesh renderer.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

85 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to make an horizontal mesh? c# 0 Answers

Weapon system 0 Answers

UNITY4 all i see is the triangle/verts of objects 1 Answer

Does using Mesh Collider use up more CPU verses just a box Collider? 1 Answer

Passing Underneath Section of a 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