MeshLib icon indicating copy to clipboard operation
MeshLib copied to clipboard

MROffset to keep sharp features

Open MarcoWang1 opened this issue 3 years ago • 17 comments

you use openvdb to do mesh offset. It is good. but the origin openvdb code can not preserve sharp features. Do you have plans to optimize the code to keep sharp features?

MarcoWang1 avatar Jan 15 '23 14:01 MarcoWang1

Positive offset (outside of original surface) is a smooth surface with minimal convex curvature radius equal to offset distance (it can have sharp concave regions, but they are not in the same places where the original surface had them). Please clarify, what do you mean. If you have some samples (input and expected result), that will help us.

Fedr avatar Jan 15 '23 16:01 Fedr

I have a box with 8 vertices,12 triangles ,20mm20mm20mm, offset -1, the result doesnt have sharp edges as the input .like this 797edbe5869f259e3db7ea96a14b19a

MarcoWang1 avatar Jan 16 '23 02:01 MarcoWang1

Thanks, I see, you are interested in negative offset, which shall produce sharp edges. We will try to work on it later this year.

Fedr avatar Jan 16 '23 08:01 Fedr

you use openvdb core library to do offseting which may not keep sharp, but openvdb_houdini has functions to keep sharp,maybe it will help, https://github.com/AcademySoftwareFoundation/openvdb/blob/master/openvdb/openvdb/tools/VolumeToMesh.h#L279 https://github.com/AcademySoftwareFoundation/openvdb/blob/master/openvdb_houdini/openvdb_houdini/GeometryUtil.cc#L568

I do not understand the code above,if you solve this problem ,please tell me thanks

MarcoWang1 avatar Jan 16 '23 09:01 MarcoWang1

Currently you can highlight sharp edges using post-processing with Decimate tool: image Please increase Max Error and decrease Stabilizer for more sharpness.

The result will be as follows: image

Does it work for you?

Fedr avatar Jan 24 '23 14:01 Fedr

Decimation tool can sharpen features when Max Error is large enough ,But it will cause large deformation elsewhere, So I do not think it is a perfect solution

MarcoWang1 avatar Jan 25 '23 16:01 MarcoWang1

@Fedr Will you solve this issue recently?I really expect this function。Thank you

MarcoWang1 avatar Jan 28 '23 02:01 MarcoWang1

Yes, we are working on it.

Fedr avatar Jan 28 '23 08:01 Fedr

Please look at our latest release. It contains Sharpen Features option in Offset and Remesh tools to reproduce sharp edges and corners: image Blue - mesh with new option, grey - old offset mesh.

Fedr avatar Feb 01 '23 18:02 Fedr

If I use the function in MROffset.h ,it still can not keep sharp. So where is the function to offset mesh while keep sharp?

MarcoWang1 avatar Feb 03 '23 03:02 MarcoWang1

image dog.zip Here is a bug

MarcoWang1 avatar Feb 03 '23 03:02 MarcoWang1

Thanks for you finding. The problem with Dog mesh is that it contains big self-intersecting areas: image And our sharpening method currently requires self-intersection free meshes on input. If this condition is not satisfied, you see the artifacts as on your picture.

We will think how to reduce the amount of damage from self-intersections.

As to single function for sharp offset, yes, it is a good idea and we will create it. Currently one needs to call several functions to get sharpened result: floatGridToVdbVolume, vdbVolumeToMesh, sharpenMarchingCubesMesh.

Fedr avatar Feb 03 '23 09:02 Fedr

In the master branch of MeshLib, you can find and improvement. Now -1 offset of Dog with sharpening looks as follows: image

And we introduced simple function for this operation:

// Offsets mesh by converting it to voxels and back
// post process result using reference mesh to sharpen features
[[nodiscard]] MRMESH_API tl::expected<Mesh, std::string> sharpOffsetMesh( const Mesh& mesh, float offset, const SharpOffsetParameters& params = {} );

Fedr avatar Feb 03 '23 16:02 Fedr

Thanks I ll do more tests recently,and will tell you if I find bugs

MarcoWang1 avatar Feb 03 '23 17:02 MarcoWang1

1-2.zip 微信图片_20230222231603 I do not know how to choose parameters to generate a good mesh that keep sharp

MarcoWang1 avatar Feb 22 '23 15:02 MarcoWang1

I see your point. The best I could do with this input is to reduce voxel size to 0.3 and remove smaller connected components after offset: image Resulting mesh: 12offset.zip

The place highlighted on the picture is ragged because probably two surfaces join here at very acute angle. We will investigate and probably add another parameter to control it. Hope to return to you next week with an update.

Fedr avatar Feb 22 '23 16:02 Fedr

In today release of MeshLib and MeshInspector we introduced several improvements in Offset tool and added one more setting in UI. And now the output looks as follows (with shown parameters): image Resulting mesh: 12offsetBetter.zip

Fedr avatar Mar 02 '23 20:03 Fedr