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

Render wireframe on cut section of polygons

Hi, after researching for a few days and trying everything 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 this which you can see in this 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 this behavior is that I've been looking for any way to scan a models shape in layers from the top-down using an orthographic 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 highlight shaders, which worked well for the most part, but if a polygon is perfectly vertical (like on a building wall) there will be no highlight since it'll be too thin.

alt text

I've come to think this wireframe method is going to be the cheapest way to obtain an outline of a models shape at any point, by sending an orthographic 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 something like this.

Video demonstration

wireframe-source-example01.png (31.4 kB)
model-layers.png (114.3 kB)
Comment
Add comment · 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... ins$$anonymous$$d 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. $$anonymous$$aybe 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.

1 Reply

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

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

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


The actual MonoBehaviour in this 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 this script to an object it will initialize the "WireframeClipMesh" with the mesh of the object it's attached to. It will create a child object "wireframe" which 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 things 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 this animated gif

Comment
Add comment · 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. $$anonymous$$y main specialty isn't programming and I don't think anyone on my $$anonymous$$m 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

$$anonymous$$an 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 s$$anonymous$$m will do, assume you have a s$$anonymous$$m account to play Black $$anonymous$$esa at least, my name and avatar are the same on s$$anonymous$$m 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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Double-sided cross section ("slice") 0 Answers

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

Passing Underneath Section of a Mesh 0 Answers

Changing mesh.uv works in editor, but not on Android 1 Answer

Humanoid Mesh with white pixel around it 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges