Code Monkey home page Code Monkey logo

unitymeshsimplifier's People

Contributors

amirebrahimi avatar bawar9 avatar hybridherbst avatar is3d-1 avatar sbeca avatar semantic-release-bot avatar whinarn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unitymeshsimplifier's Issues

Change SaveAssetPath

Hiya,

The asset save path seems to be hard coded to always be under UMS_LODs, regardless if the saveAssetPath is set.

If I set saveAssetPath, it just creates that path under the folder Assets/UMS_LODs.

It's also seems to remove spaces from the folder name and inject '_' s

Mesh with vertex colors issue

Hi,

i have another request (it's more enhancement than bug).

To maximize perfromances in VR I use special shader and vertex color of a mesh.
but when decimation is performed on a mesh with submeshes and several colors then you remove some vertices (maybe ducplicate) but without verifying the color of vertice

Here is the result.

decimated
notdecimated

Could you do something? without impacting too much the performances of decimation?

TIA.

Compatibility with Pro-builder pb_objects

I am struggling to get this work correctly with pro-builder objects; with pro-builder being integrated into Unity core it will be important going forward. Any chance you could look into it?

Meshsimply error

I use as this:

public class TestSimplifier : MonoBehaviour {

// Use this for initialization
void Start () {

    SkinnedMeshRenderer mr =  this.GetComponent<SkinnedMeshRenderer>();

    float quality = 0.5f;
    var meshSimplifier = new UnityMeshSimplifier.MeshSimplifier();
    meshSimplifier.Initialize(mr.sharedMesh);
    meshSimplifier.EnableSmartLink = true;
    meshSimplifier.PreserveBorders = true;
    meshSimplifier.SimplifyMesh(quality);

    var destMesh = meshSimplifier.ToMesh();
    mr.sharedMesh = destMesh;
}

// Update is called once per frame
void Update () {
	
}

}
and the result is that, the simply mesh is rotation wrong, see the attach file:
image

Discord Server

Is there a Discord channel for this tool? If not, can we create one? It would be really nice to get people together that are using this asset so we can help each other out, collaborate, and contribute to this amazing tool! :)

Batching

Is this will do dynamic batching? Or we need to do it using some other plugins?

Supporting F16 vertex data

Hi. Unity 2019.3 now supports low level Mesh API, like vertex data attribute and custom buffer. So user can create F16 format vertex data.

I want to know whether UnityMeshSimplifier supports that vertex format and preserve its format for output mesh.

Seems like normals are inverted (fix in comment)

I'm not sure if it's our meshes in particular that are setup causing the inverted normals, but they were backwards -- I just changed this to fix locally:

+++ UnityMeshSimplifier/UnityMeshSimplifier-master/Runtime/MeshSimplifier.cs
@@ -1385,7 +1385,7 @@ private void UpdateMesh(int iteration)
                     p20 = p2 - p0;
                     Vector3d.Cross(ref p10, ref p20, out n);
                     n.Normalize();
-                    triangles[i].n = n;
+                    triangles[i].n = -n;

                     sm = new SymmetricMatrix(n.x, n.y, n.z, -Vector3d.Dot(ref n, ref p0));
                     vertices[v0].q += sm;

Crash in GetSubMeshTriangles

Hello,

First Thanks for this very good and usefull development (and sorry for my English).

I know that it's huge but I have a mesh with 98500 SubMeshes (I don't know the triangles and vertices number).
When I Simplify it I have a crash in SubMeshesTriangles (Index out of bounds)
Is it possible for you to identify the reason?

My data is a CAD data which I cannot provide to you (confidential)

Bug in Skinned Mesh Combiner

Hi, I came across a problem when checking "combine mesh" option during LOD generation. The combined meshes seemed to be totally invalid. I have also noticed that this doesn't happen with every model. Also what I've noticed is that it only combines Skinned Renderers in an invalid way. Static Renderers are combined correctly. I attach some images below that show you 2 models after combining meshes and before combining meshes.

Model 1(Barbarian Before Combining Meshes)
Before1Combining

Model 1(Barbarian After Combining Meshes)
AfterCombining1

Model 2(Troll Before Combining Meshes)
BeforeCombining2

Model 2(Troll After Combining Meshes)
AfterCombining2

Here is a video that demonstrates this as well.

https://youtu.be/hQbkqB0P1S8

And here is the UnityPackage with the MeshSimplifier and the afore mentioned 3d models.

https://filebin.net/c0b5quc8gjbrm3py/MeshCombineBug.unitypackage?t=uextr26c

Wrong behavior on combined mesh

After generating a level, I'd like to get rid of unnecessary vertices by combining different meshs then using the mesh simplifier.

In this exemple, I'm starting with a grid of 900 square plane merged in one mesh using Mesh.CombineMeshes (3600 Vertices 1800 Triangles):
image

At this point, i'm using SimplifyMesh with the PreserveBorderEdges option to try to get a simplified square.
Here's what result (540 Vertices, 180 triangles):
image

While it is totally possible that there is something that I don't get about the way the API works, this result doesn't feel right.

Documentation

This package, while it seems very capable, has absolutely no documentation from what I have found. I would really like to use it, but I have no idea how. ANY examples or documentation would be needed greatly.

Pull Requests - here or on Unity's repository?

Seeing that you're both active in this one and the Unity fork, I'm curious as to
a) which one I should be using in my project
b) where to fork from for pull requests with fixes/changes.

Last LODs Generated Are Not Saved

Description:
The LODs that are generated for the last object are not saved. This occurs when following the steps below.

Steps to reproduce the behavior:

  1. Extract and import the "Silver_and_White_Azerillo_Sporty_Hatchbacks.unitypackage" into Unity 2019.3.9f1
    Silver_and_White_Azerillo_Sporty_Hatchbacks.zip
  2. Double-click the "Assets/Azerilo/Car Model No.1201 Asset/Prefab/Sporty_Hatchback_silver.prefab" to open it.
  3. Select the "Sporty_Hatchback_silver" node in the prefab hierarchy.
  4. In the inspector menu, click "Add Component" and Select the LOD Generator Helper.
  5. Enter the following settings, then right-click the LOD Generator Helper Component and select "Copy Component", then click the "Generate LODs" button.
    image
  6. Next, double-click the "Assets/Azerilo/Car Model No.1201 Asset/Prefab/Sporty_Hatchback_white.prefab" to open it.
  7. Select the "Sporty_Hatchback_white" node in the prefab hierarchy.
  8. In the inspector menu, click "Add Component" and Select the LOD Generator Helper.
  9. Right-click the LOD Generator Helper Component and select "Paste Component Values".
  10. Click the Generate LODs button.
  11. Double-click the "Assets/Azerilo/Car Model No.1201 Asset/Prefab/Sporty_Hatchback_silver.prefab" to re-open it.
  12. Then, double-click the "Assets/Azerilo/Car Model No.1201 Asset/Prefab/Sporty_Hatchback_white.prefab" to re-open it.
  13. The LODs that were generated in Step 10 were not saved and the "Generate LODs" button must be pressed again to re-generate LODs.

Expectation was that the generated LODs would still be there once I went away from the prefab and came back.

Thanks,
Nathan

multiple thread support

First of all thanks for such a great tool, will this be support multiple thread process future? It process big model to lod group cost so many times.

Best

uv is NaN at certain indices on the simplified mesh

Description
Using this to simplify a procedural created mesh. The mesh is simplified correctly. But the uv values at certain indices is NaN. Because of this texture is not applied properly.

I tried to debug, but could not find exactly where the uv is set once the mesh is simplified after each iteration.

To Reproduce
https://drive.google.com/file/d/1PyZMOA9543x4F1wod-0NUtHv0ZRUPdSH/view?usp=sharing

  1. Download and extract the above
  2. Place the Model.fbx in the scene
  3. Simplify the mesh in the model (Attached the script I used)
  4. Try applying the texture "Green_square" attached to the model with standard shader after simplification

Different optimization level for a height range?

I would like to have the mesh (terrain) being detailed at a certain elevation level say -1 to +2 meters. This would create a better beach. On the other side I would like to have a highly optimised mesh in higher elevations, because it would always be in the distance since my game is happening at ocean level.

Question is, where I would to have to dig into to not have vertices at a given y range being optimised.

Unity 2021 Indexbuffer fix

I wanted to try to make a commit and pull request, but don't think I can (don't use Github that much ๐Ÿ˜Š)

Anyway, the conditionals need to have Unity 2021 included to make 32bit indices work, in that version. Otherwise, large meshes become a garbage. With it, it works perfect :-).

So in MeshUtils.cs:

#if UNITY_2018_2 || UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020 || UNITY_2021
#define UNITY_8UV_SUPPORT
#endif

#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020 || UNITY_2021
#define UNITY_MESH_INDEXFORMAT_SUPPORT
#endif

Get Mappings between reduced and original vertices

Is there currently a way to get the reduced vertex index based on the original vertex index? E.g. let's say the algorithm reduced vertex index 2 and 3 to 2, would there be a way to get the array of [2,3] based on the new index "2"?

This would be very helpful to e.g. use a simplified mesh for heavy calculation, but use full mesh for rendering, e.g. on cloth / softbody components.

Out of memory when SimplifyMesh a big model, any suggestion ?

Hi
I have a very big model file, vertex count 8810599, triangle count 13439326.
My goal is import that model file at runtime (DONE)
and run SimplifyMesh to make a reducing.

but when I execute SimplifyMesh, it throw "Out of memory" exception, at IncreaseCapacity function in ResizableArray.cs
I debug a little,found IncreaseCapacity with size 40M.

Any suggestion with this issue?

ps: My PC has 16G DDR4 memory, if I add it to 64G will it help ?

Unable to install through Package Manager

For some reason, the extension/add-on for Unity won't install. I've tried the steps listed here: https://github.com/Whinarn/UnityMeshSimplifier/wiki/Installing-through-package-manager
I've also installed Git which I didn't have installed prior to the issue popping up. I'm too scared that I might screw something up in the process of setting up the addon.

I get this error message upon attempting to install via Git link:

[Package Manager Window] Error adding package: https://github.com/Whinarn/UnityMeshSimplifier.git.
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()

and

[Package Manager Window] Cannot perform upm operation: Unable to add package [https://github.com/Whinarn/UnityMeshSimplifier.git]:
  No 'git' executable was found. Please install Git on your system then restart Unity and Unity Hub [NotFound].
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()

Environment (please complete the following information):

  • OS: Windows 10 (64-bit)
  • Unity Version: 2020.3.26f1

Additional context
I already have both Git and a code editor installed.

Lossless simplification?

I have a 3D tile based map editor tool that I use to quickly create stuff for my game (building interiors, etc). At the start of runtime, I have to merge all these tiles into one big mesh because otherwise there's a huge performance drop (thousands+ of tiles. Static batching doesn't really help either, especially with post-processing is also on). This mesh, however has a lot of triangles that don't really need to be there, causing the mesh to have a lot more triangles than it needs.

The solution I feel that would be best for this is some sort of variant(?) of the Greedy Mesh algorithm made to work on arbitrary meshes instead of voxels (Greedy Meshing is mostly/solely used in minecraft-esque games).

Make MeshUtils.GetUsedUVComponents configurable

Currently, UV layout is attempted to be auto-detected. This resulted in a really hard to find bug for me: I am using uv0.xyzw with z and w being data channels. On some meshes, those data channels are both 0, but the meshes still need to use 4-channel UVs so all shaders properly work (zw are undefined / sometimes 1 after only setting UV2 channels on new mesh generation).

It would be great if this default behaviour could be overriden to prevent such failures. I understand that this is a rare edge case.

burst / jobs ?

there is this entry in the package json:
"com.unity.burst": "1.0.4"

... but I cannot find any burst related code. Is there intentions to use the job system?
That would be a big gain.

Simplifying a decimated mesh

I'm trying to simplify a ~500 triangle mesh that has a topology similar to a decimated mesh.
image

But I seem to lose volume quickly as I get down toward my goal of 100 tris.
image

If my mesh is a little more rounded to begin with, though, it maintains its volume much better. Any suggestions?
image
100 tri result:
image

Why doesn't the algorithm lead to simplifying this to a ~2x1x2 cube?

Values need to be initialized in SimplificationOptions to prevent silent failure/exit

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:
Use the sample script provided in https://github.com/Whinarn/UnityMeshSimplifier/wiki/Mesh-Simplifier-API
Add this after meshSimplifier.Initialize(sourceMesh);
meshSimplifier.SimplificationOptions = so;
where so is exposed in editor (needs to have default min values set) - However, all values are 0 and false, which leads to silent exit

Expected behavior
Mesh Simplification should not silent exit

Documentation for the LOD Generator Helper

Could you please provide me with some instructions for using the LOD Generator Helper? It would be very helpful to have instructions for common use. It would also be nice to have a list of do's and don'ts to reduce the occurrence of unexpected behavior and to know its limitations.

I have encountered various issues when generating LODs for vehicle models. I have roughly 21 unique vehicle models. Each vehicle model has up to 9 color variant prefabs. Each color variant prefab is a duplicate of the original model, but has a different/unique material and color applied. I am trying to generate LODs for the body of each prefab variant and then generate LOD for the wheels for each prefab variant. But my attempts have been unsuccessful due to the following issues:

  • After generating LODs for each of the 4 wheels of one of the vehicle prefabs, the LODs that are generated for the last wheel are not saved. This issue was also encountered when generating LODs for vehicle body as well.
  • To work-a-round the issue above, I tried regenerating the LODs for the body or wheel and manually adding the LOD Backup Component script to try to force it to save the generated LOD. Sometimes manually adding the LOD Backup Component script would cause all the other color variants of that vehicle type to loose their assigned color and they would need to be re-imported.
  • I ran into another issue on occasion, where destroying LODs removes the vehicle's mesh renderer. Parts of the vehicle disappear and the original prefab must be re-imported.
  • After generating LODs for the body and wheels of all color variant prefabs for a particular vehicle type, there were instances where the sliders for LOD switching had no affect on some of the variants but worked on others. They would switch based on the original LOD switching values instead of using the new ones.

Here is an example of how the vehicle color variant prefabs are named:
image

Below is an example of the body and wheel groups that I need to generate LODs for. Notice that each prefab color variant has the same names for it's body and wheel groups. If the LOD Helper Component settings are copied from one wheel and applied to all 4 wheels of each color variant, would this cause a conflict?
image
image

Here is what the generated LOD folders look like in the Assets/UMS_LODs/ folder:
image

If I add a LOD Generator Helper Component to Sporty_Hatchback_white/Wheel_FL and then set the LOD settings, copy the Component Settings, generate LODs, then open Sporty_Hatchback_silver and add a LOD Generator Helper Component to Sporty_Hatchback_silver/Wheel_FL and paste the Component Settings from Sporty_Hatchback_white/Wheel_FL, will it cause a conflict?

I figured that I would reach out for help first before listing these issues as bugs. It very well could be user error. I appreciate any help that you could provide!

Thanks,
Nathan

several triangles turn black when this mesh is decimated

https://drive.google.com/file/d/1PgrIRS4AE_ekia7p29VeiRp77NEGZgpR/view?usp=sharing

Describe the bug
Decimating meshes like this with submeshes and colour data seems make several of the triangles black in colour, the mesh appears to have been decimated perfectly fine, its just the colour data that is broken...

To Reproduce
import this unity package (unity 2019.3.13f1)

https://drive.google.com/file/d/1PgrIRS4AE_ekia7p29VeiRp77NEGZgpR/view?usp=sharing

decimate the mesh (use lossless, or whatever settings you like)
notice some triangles look like they are missing, infact, they aren't missing, their colour data has just been set to black.

Expected behavior

Colour data would be retained!

Screenshots
image
image

Image1 (before decimate)
Image2 (after decimate) - notice a few black polygons...

Environment (please complete the following information):
Windows10 - unity 2019.3.13f1

Additional context
This mesh is made out of many submeshes, it only contains Verts,Normals and Colours.
DecimateBug.zip

Better support for skinned meshes

Currently there are several problems with simplifying skinned meshes.

  1. If the helper methods for initializing and generating Unity meshes are used, bindposes are not automatically copied.
  2. Bone weights are not properly merged, introducing artifacts while the skinned mesh is being animated.

Related to #4

Create a component for out of the box LOD generation

Create a component for out of the box LOD (level of detail) generation.

The component must be easy to use and configure and allow to save the configuration for easy regeneration of the LODs when necessary.

Combine triangles with close proximity of each other

Hello, first of all, thank you for providing this useful and efficient mesh tool!

I suppose this is more of a suggestion/enhancement post, as I would love to have some tools/methods for merging massive clusters of triangles. I try to create terrain by merging land meshes, which unfortunately leads to excessive triangles and vertices as seen on the provided images.

Overview of merged mesh terrain.
meshsimplifier1
Lots of unnecessary triangles and vertices...
meshsimplifier2
What a mess of triangles!
meshsimplifier3

I have tried setting "quality" to a variety of levels. While lower levels do reduce the triangle and vertex count, it quickly affects the outer edges of the terrain by creating long lines of terrain, which honestly doesn't look that nice.

quality = 1.0f (full quality, but yes, it's low poly models)
meshsimplifier4_1f
quality = 0.8f (still acceptable)
meshsimplifier5_08f
quality = 0.6f (not that pretty with the sharp corner!)
meshsimplifier6_06f

Oh, another thing, I tried to preserve the corners by setting the special booleans to true, but the results were:
preserveBorderEdges = true; // Minimal impact, doesn't preserve borders?...
preserveUVSeamEdges = true; // Also minimal impact.
preserveUVFoldoverEdges = true; // However, this one preserves everything and leads to minimal (if any) simplification.

I would truly appreciate it if you would consider these suggestions!

  • Erlend

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.