Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Krabl Mesh Processors [RELEASED]

Discussion in 'Assets and Asset Store' started by Pflugshaupt, Jan 3, 2014.

  1. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Krabl Mesh Processors is an add-on for Unity to perform mesh processing. It consists of a C# mesh processing library and an editor extension which provides a mesh import processing workflow inside the Unity editor.

    Different kinds of mesh processors can be chained together right inside the Unity mesh inspector. These import programs are executed every time Unity imports a mesh (inside a model).

    Processors include mesh simplification (polygon reduction) and mesh subdivision. The system is designed to be extended with more processors and workflows in the future.

    Unity Asset Store Page
    http://u3d.as/content/krabl-com/krabl-mesh-processors

    Watch an introduction movie on YouTube here:
    http://youtu.be/M-fs73ofGq4

    Read the pdf user manual here:
    http://krabl.com/meshprocessors/manual.pdf

    Browse the library scripting docs here:
    http://krabl.com/meshprocessors/librarydocs

    Features:

    • C# mesh processing library with Unity3D editor integration.
    • Supports Unity3D Free and Pro on all platforms. Requires Unity v4.0 or newer.
    • High quality mesh simplification (polygon reduction).
    • Quad-based mesh subdivision.
    • Mesh attributes filtering, crease detection.
    • Extends the Unity3D mesh inspector to work like the texture inspector.
    • Adds UV displays to the Unity3D mesh inspector.
    • Automated mesh import programs with build target dependent settings.
    • Comes with full source code (C#) and a utility class to easily process meshes in your own scripts during runtime (in any language supported by Unity3D).

    $2_cubecross_small.png
    $3_processor_types.png
    $4_demoscript_2.png

    Please use this thread if there are any questions/issues/requests.
     
    Last edited: Jan 4, 2014
  2. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Quad mesh subdivision is interesting. Do you have examples of the output?
     
  3. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    The first image shows subdivision on the right side. The second image shows the player model from the Unity AngryBots demo with one and two subdivision iterations. Note that the algorithm first has to detect quads from triangles because all meshes are imported as triangle meshes in Unity. Sometimes quad detection is not perfect, especially in models that have not been created with quads, so I've already started to work on a triangle-based subdivision algorithm for a future update.

    $1_kmp_pic_small.png
    $Screen Shot 2014-01-06 at 00.28.23.png
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Wow, this looks absolutely fantastic! I had to buy it...
     
  5. sefou

    sefou

    Joined:
    Aug 30, 2011
    Posts:
    287
    Bookmark. ;)
     
  6. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Yes, forgot that it was Unity only imports triangles. Perhaps you can do as a standalone tool. There isn't a good quad simplification tool yet.
     
  7. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    I doubt there will ever be a quad based simplification tool - all I know of are vertex-collapse based and that implies triangles. However in my opinion that's not a problem. It's subdivision that it helped by quad meshes. Unity does support quad meshes internally and my library can handle quad meshes. However so far all the formats I tried importing into Unity turned out to be converted to triangle meshes on import. Maybe that will change in the future.

    In many cases the algorithm I use to convert quads to triangles works just fine as you can see in the above screenshot with the AngryBots player mesh. In the screenshot with the green plant you can see that I had quad-mesh output enabled during development. Unfortunately I had to disable it in the last minute because there were problems with quad meshes and directx. It only worked correctly on OS X.

    So if Unity completes quad-mesh support with import and direct x support, the library will be ready.
     
  8. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    It's unlikely unity will support quiad import. The quad is always done at the modeling software side. What I meant was quad reduction preserveration, which is reduce but still preserving the quad. That is the challenge.
     
  9. Hynopsis

    Hynopsis

    Joined:
    Oct 25, 2012
    Posts:
    54
    So i have a marching cubes voxel terrain, and i need a quick runtime method to generate a reduced mesh collider. Since the triangles can be high, the mesh collider can lag on some systems when set from the normal mesh. Will this tool work for that purpose? I would imagine it would be faster since there is not need for the other vertex data (uvs, etc).
     
  10. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    It depends on what you mean by quick method and high triangle count. How much time can you spare and how high can triangle counts get? Can you export an example mesh asset? I could then run it through the simplification algorithm and tell you the results.
     
  11. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    405
    Nice work. Can you clarify the trimesh simplification algorithm you're using (e.g. Garland-Heckbert QEM, etc?) We've got some very complex runtime-generated content that behaves quite differently under different algorithms.
     
  12. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    The algorithm used works similar to the QSlim algorithm by Garland. So error terms based on distances to the neighbouring are summed up to determine error introduced by moving vertices. In vertex repositioning mode, the minimum position of the summed error terms are used to determine the new vertex position. A number of algorithms excludes vertices from being processed in order to get a topologically sound result mesh.
     
  13. perspecdev

    perspecdev

    Joined:
    Oct 25, 2013
    Posts:
    9
    Very nice work! If you don't mind, can you tell me how fast (in milliseconds) it would be able to process the attached mesh? I know it would differ depending on computer hardware, but if you could try it on your computer it would be helpful to me. If it's fast enough, I would like to try using this for a sort of dynamic LOD for meshes that are procedurally generated at runtime.
     

    Attached Files:

  14. perspecdev

    perspecdev

    Joined:
    Oct 25, 2013
    Posts:
    9
    Very nice work! If you don't mind, can you tell me how fast (in milliseconds) it would be able to process the attached mesh? I know it would differ depending on computer hardware, but if you could try it on your computer it would be helpful to me. If it's fast enough, I would like to try using this for a sort of dynamic LOD for meshes that are procedurally generated at runtime.

    Edit: Sorry, I should have clarified what I mean when I say "process" the mesh. I mean simplify.
     
  15. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
    great stuff
     
  16. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    ok I'll give it a shot on my insanely fast machine :p. but it's also important to know how much to simplify. There some setup time, but most of the time depends on the amount of vertices to remove. I'll just do some percentages for you.
     
  17. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Ok i tried your mesh. It has only 336 triangles unless I'm mistaken. Simplifiying to 100 triangles on my Core i7 running at about 4 gHz took 25 ms. Low poly stuff like that is really fast, so I guess most of those 25ms is setup and mesh assignment. I had to add border constraints to get a nice result.

    If your mesh had nicer UV the results would be better. It almost looks like it has no real UV, just dummy UV that hurts my algorithm. Disabling UV protection I got the attached result for 100 triangles (right side is original - I also had to recalculate normal as the obj had flat shaded faces).

    Simplifying a mesh with 50'000 triangles to 1000 takes like 1 second on my machine. It usually takes unity much longer to import a mesh than for the algorithm to simplify it.

    $testobj.PNG
     

    Attached Files:

    Last edited: Mar 23, 2014
  18. perspecdev

    perspecdev

    Joined:
    Oct 25, 2013
    Posts:
    9
    Awesome, thanks! You've sold me on it. Will probably be buying this week :)
     
  19. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
  20. ferretnt

    ferretnt

    Joined:
    Apr 10, 2012
    Posts:
    405
    Hi,

    We're using your mesh simplification at runtime, on mobile, and the results are impressive.

    A couple of quick questions:


    1. We have some cases with user-constructed input "meshes" (by which I don't mean UnityEngine.Mesh, just our own vertex/index array) with >65536 verts, which we would like to then simplify to <65536 so we can stuff them into a single mesh at runtime. I should probably just check the code, but what does your algorithm use as its internal data structures - does it have this restriction, or can I pass it larger mesh data as some sort of input vertex array, and get out a <65536 tri array that we can then feed into a Unity Mesh.

    2. We also have cases of compound meshes with multiple materials. Do you support multi-material meshes and material preservation in the simplification process? If not, do you have any suggestions for how best to handle a compound mesh (actually not a Unity Mesh) with >65536 verts and many materials? A naive approach would be to split the object into one Unity Mesh per material, determine a target face count, and divide that equally amongst the input meshes based on their input vert count (so eg, if I have a 300k vert mesh and a 100k vert mesh, we simplify the 300k to 30k, and the 100k to 10k) then combine the results. Or can you suggest a better algorithm?

    Thanks a lot. Great work, with full source included. Excellent value.
     
  21. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    1) There is nothing internal preventing >65536 verts. The data is all stored in Lists, basically one list of vertices with attributes and one list of faces. You could look at KMImportExport.cs to see how the Unity Mesh is converted to the internal data structures and write your own converter. A mesh with >65536 verts might get a bit slow to simplify (multiple seconds).

    2) Multiple-Material meshes are supported and there is also a setting in the simplification settings struct that determines how much seams between materials are preserved - this allows you to lock the shape position of the seams i. Every face can be assigned a material index (just an integer). I would not recommend splitting the mesh and simplifying indidual parts as maybe the parts wouldn't fit together nicely later and you'd get a lot of (unnecessary) extra vertices.
     
  22. DanielFF

    DanielFF

    Joined:
    Aug 29, 2012
    Posts:
    41
    Hi,

    That works with animated meshs ?

    thank you!
     
  23. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Yes, the mesh manipulations work with animated meshes. The only thing not supported are the new Blendshapes that were added to Unity 4.5 because they are not fully accessible from mono code.

    Subdivision just adds vertices with interpolated weights and simplification can try to preserve animated features based on their bone weight differences. However simplification does not take into account the shape of the distored mesh, it just can be configured to simplify less where deformation could occur.
     
  24. kaaJ

    kaaJ

    Joined:
    Mar 21, 2007
    Posts:
    150
    Good work, bought it yesterday. Nicely written en very useful.
    Do you think you'll implement some of the KrablMeshUtilities as less processor-intensive coroutines? (So I can use it realtime on procedural objects). Just to know, because if you do, I won't have to write it myself. ;-)

    Thanks for these cool utilities!
     
  25. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,917
    Very nice asset :)

    Can it be used to bake the simplified meshes to the mesh asset for use without the script ?
     
  26. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Thanks! I guess you mean adding the possiblity of async simplification, meaning the main thread would not block during simplification. A coroutine would just check the worker thread. Of course this does not really make it less CPU intensive, it just means things could go on in the meantime. I gave that some thought, but it's not implemented. I pondered doing multi-threaded simplification, but it's a very hard problem as the simplification algorithm consists of many steps that are all depending on each other (it's iterative).

    The simplification itself could work on an independent thread because it is independent on Unity and just pure C# using its own data structures. however converting from and to the actual Unity mesh would still have to be done on the main thread. As far as I know, Unity does not like calling any of it's methods on a different thread. Unfortunately converting the result back to a Unity mesh takes a lot of time - often that's what takes the most time - I guess that's because the data needs to be converted for GPU usage and uploaded to the GPU.

    So overall I'm not sure it would be worth the effort and I haven't planned to implement something like that myself.
     
  27. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Basically that's what it does if the editor import components are used. During mesh import, the meshes get processed and then Unity writes the processed mesh to the Asset database.

    I did work on code that would allow to write the results to independent .asset files as well, but that is not implemented yet.
     
  28. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    How about saving the meshes?
    Can i use a 'standard plug-in' to export the meshes after the process? With ObjExporter for example?
     
  29. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Yes. Of course that will only support the mesh attributes the ObjExporter supports. From looking at its source I see vertices, normals, main UV coords and materials. That means uv2, vertex colors and boneweights would not be saved this way.

    It would be trivial to write something similar to ObjExporter that just saves a mesh to a Unity asset which would support all mesh features - it's just not sure how future-proof this would be with Unity changing things rapidly.
     
  30. kaaJ

    kaaJ

    Joined:
    Mar 21, 2007
    Posts:
    150
    Thanks for answering!
    Indeed, I meant an async function... I've implemented it for the creation of procedural content in my current project, so I don't get any framerate-drops while creating meshes dynamically. (I'm yielding between selectable iterations).
    But I can see this is probably only useful for a small percentage of your customers, so no worries. I'll try to implement something myself.

    Cheers!
     
  31. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I just recently got this and i have posted to say it's great and extremely useful, cheers!
     
  32. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Just saw in the manual the 'UV Display' function. Do you have an option for saving (PNG) the UV map?
     
  33. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    ??
     
  34. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Sorry.. it seems the topic notifications didn't reach me :(. Anyway there is no built-in option to save the UV map to a PNG, but adding something like that seems maybe doable in the future. I'd had to check out whether I can easily draw to a buffer the same way I do it for the GUI and I'm not sure about that. Why not just take a screenshot in the meantime? .. well I guess borders would be a problem. So overall thanks for suggesting this possible improvement of my editor extension.
     
  35. BeyondReality

    BeyondReality

    Joined:
    Mar 25, 2013
    Posts:
    7
    Does this plugin allow me to do this? I want to do quadrical subdivision, without 'smoothing' my resulting mesh.
    I want to use this to fix distorted UV's on lowpoly geometry, but I want to keep the position of my original vertices.

    quadricalsubdivision.jpg
     
  36. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Hi BeyondReality,

    I can get the processors to do something similar to what you show in the image, but it's basically using them in a weird way they weren't designed for and I think for a more complex mesh, the result would not be ideal. What i did was to first use a subdivision processor to just fuse triangles to quads (based on edge angles) and then I added a processor to mark all quad edges as creases and if I then subdivide I get what you showed in the image. However if a mesh consisted of more than just two triangles, this would lead to split normals for all edges.

    What you'd really need would be different processors than what I currently offer. You'd need first a process to fuse triangles to quads and I can tell you it's a big problem to do this reliably because there's many possible corner cases. And you'd need a subdivision processor without smoothing. Mine is designed to do catmull-clark like subdivision and while it internally can turn of smoothing, it's functionality I chose not to present to the user.

    So overall I don't think my package is the right thing to solve your problem. It's close but not a perfect match and some additional code would be needed for reliable results. Screen Shot 2014-10-10 at 19.14.59.png
     
    BeyondReality likes this.
  37. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Hi Adrian,
    So does this plugin work on triangulated meshes as well? Which algorithms have you incorporated in this asset? Catmull-Clark Subdivision, Loop subdivision or what? ;)

    And have you considered using Plankton? It's in early stages of development but seems like a nice way to deal with mesh data structures.

    Here's the GitHub link to the project (Originally developed for Grasshopper3D)

    https://github.com/Dan-Piker/Plankton
     
  38. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Hi Curious,

    Yes it works on triangulated meshes. The subdivision algorithm is similar to catmull-clark, but the crease handling is slightly different, but with the exposed functionality that shouldn't make a difference. In order to get reasonable subdivision results, the mesh is first analyzed and triangles are combined into quads where possible. It would be ideal to start out with quads, but when I wrote it, there was no way to preserve quad information when unity imports a mesh.

    I also worked on triangle based subdivision (sqrt-3 algorithm), but never completed the work. Maybe next year, IMHO it would be great to have and it could also do adaptive/selective subdivision nicely.

    I didn't know Plankton, I wrote my own mesh library and data structures to handle mesh alterations. Initially I used a half-edge data structure like Plankton, but I had problems with simplification because the simplification edge-collapsing algorithm I use (similar to QSlim) can lead to non-manifold intermediate steps and half-edge cannot really handle that nicely. At least that's what I found. Also unity supports non-manifold meshes and these cannot be transformed to half-edge cleanly. Another problematic area I found with the half-edge structure is how to deal with the meta information like UV / normals etc in cases where the mesh is not continuous. I'm sure there's solutions for all that, but it just got too complicated for my liking and I finally settled with a redundant face based data structure.
     
  39. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    OK, good points.

    You know what would be cool, you have a poly reduction which uses a mesh of choice and reduces the number of faces/vertices, right?
    Is it possible to calculate the mesh before it was subdivided from an already subdivided mesh? (the reverse of subdivision perhaps?)
     
  40. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    hmm you guess mean a reverse subdivision process for a mesh known to be the result of subdivision. I believe this would only possible inside modelling software when the order of the result quads and vertices is known. What is visible from Unity is triangulated and more or less in random order, so information that would be needed for such a process is missing. I also think it doesn't make much sense.. in such a case, you would just not subdivide a mesh.
    I you mean "is it possible to subdivide a mesh and the do polygon reduction with the framework" then the answer is of course yes.
     
  41. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Nah, I was just thinking about scanning curved real-world objects in hi-poly then do some kind of reverse subdivision on them and have a simple control-point like mesh in unity that could be subdivided multiple times to form a nicely curved final mesh in different platforms as your plugin suggests. :D
    btw, I just bought your plugin, gonna have some fun with it now :D
     
  42. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    ah ok. I guess that would mean getting a mesh with nice topology from a high-poly source. afaik no such system exists without (lots of) human intervention as "nice topology" is hard to measure. If you use my plugin, you can actually simplify the input and then subdivide again and you'll get a smoother mesh - but the simplified topology will shine through in the end result and you won't get a uniform face-size. This might get better once I finish triangular root of 3 subdivision. It tends to be less topology dependent that quad-based.

    I made an example below where I simplified a 3d scanned source obj (right side) to 1/16 of its triangles (was about 2'700). Then I applied 2 quad-subdivision steps to get the one on the left side. I think an actual smoothing filter would produce better results, but it's still quite ok. An additional problem is that subdivision a la catmull-clark always produces a smaller mesh than the input mesh and simplification tries to keep the volume. So this smooth mesh is slightly smaller than the input. That's another problem that would be solved by root-3 subdivision.

    Screen Shot 2014-10-13 at 17.04.16.png
     
  43. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Niiiiice. Yeah, that's pretty much something I was expecting :D
     
  44. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Adrian, do you have any road map you'd want to share with us?
     
  45. radjudy

    radjudy

    Joined:
    Oct 23, 2013
    Posts:
    13
    Hi,
    i'm trying to adjust the triangle count of some submeshes on a mesh that i imported. On import Unity subdivides with the largest triangle count it can, to reduce the number of submeshes. Ideally, i want to keep the fidelity of my model and just have more submeshes, but i don't think this is possible (unless you have any ideas? ) So i've been looking at the asset store, and your product looks promising as a way to reduce the triangles of the submeshes. but, before i buy this, can you tell me if i reduce these submeshes, will they align together how they are supposed to, or will the simplification make them gappy and no longer cohesive?
    Please do advise!
    thanks,
    -- judy
     
  46. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Hi Judy,

    I'm not sure I completely understand what you want to do. By submeshes, do you mean the way Unity deals (splits) with 65k+ models or do you mean materials? Or do you mean multiple meshes inside the same imported file? I'm a bit confused.

    I can tell you what my krabl mesh processors can do. They can avoid gaps if a mesh has multiple materials, which is a form of submeshes. However while the C# library could deal with >65k meshes, the editor flow I wrote won't work well for these. IMHO Unity in general doesn't handle meshes with >65k well and I think they should be avoided if one wants to stay out of trouble and therefore I decided not to bother with them for now.

    With my processors, If you independently simplify multiple meshes that should fit together, you'll indeed get gaps and inconsistent topologies.
     
  47. MoonbladeStudios

    MoonbladeStudios

    Joined:
    Oct 14, 2013
    Posts:
    185
    Any plans to update this asset in the future? 10x
     
  48. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Yup, there will be an update for Unity 5 once that is final and released. There are plans for additional processors/algorithms, but I'm not sure I'll find the time to complete these.
     
    MoonbladeStudios likes this.
  49. AndersKlok

    AndersKlok

    Joined:
    Jan 6, 2013
    Posts:
    5
    I recently disregarded the plugin for just a import processor -- but if it can run realtime / at runtime? I will have your babies!
    What is processing time for 1 and 2 levels of SubDivision of a 2k (quads) mesh?
     
  50. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Yes there is code in the asset that can run at runtime. I just never got around to create a GUI for that and at the time I thought the import workflow was more important. There is a utility class included which can apply subdivision to a mesh with just one api call - just beware of the Unity 65K vert limit, it's quickly reached with subdivision.

    Processing time depends a lot on the platform. It's all C# code and subdivision is fairly fast - at lot faster than simplification.

    I subdivided a 2k quad mesh on my MacBook Pro Retina Core i7 2.6 gHz using Unity Beta 5, so maybe things are off - I somehow remember it to be faster...

    One iteration: 293 ms
    Two iterations: 1029 ms + getting very close to the 65k limit

    About 1/3 of the time is used when the mesh is fed to unity after processing and (maybe?) loaded to the GPU in the process.

    This is the code for the experiment:

    KrablMeshUtility.SubdivideQuadsMesh(mesh, iterations);