C# 实时切割网格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19573860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 15:19:38  来源:igfitidea点击:

Cutting mesh in realtime

c#unity3dmeshunityscript

提问by Kala J

I want to slice a mesh object into at least five parts. I've done some research and some people on here have cloned objects when sliced and just instantiate two objects from a single slice?

我想将网格对象切成至少五个部分。我做了一些研究,这里的一些人在切片时克隆了对象,只是从单个切片中实例化了两个对象?

I'm pretty new to Unity and C#. So any beginner tutorials on where to start or where I can read for learning how to cut mesh would be nice. Like what functions/methods should I be looking into? What methodology is behind cutting mesh?

我对 Unity 和 C# 还很陌生。所以任何关于从哪里开始或我可以阅读以学习如何切割网格的初学者教程都会很好。比如我应该研究哪些函数/方法?切割网格背后的方法是什么?

From my understanding, I haven't seen any tutorial or asset that actually cuts triangular mesh? If there is, how is it done? What is the logic behind it? I guess I need help understanding the logic behind it and how to get started or what I should look into?

根据我的理解,我还没有看到任何实际切割三角形网格的教程或资产?如果有,是怎么做的?它背后的逻辑是什么?我想我需要帮助理解其背后的逻辑以及如何开始或我应该研究什么?

Cut mesh in realtime I mean.

我的意思是实时切割网格。

EDIT:

编辑:

Attempt at understanding and playing around with code:

尝试理解和玩弄代码:

I used the fake slicer 3.0 (http://unitycoder.com/blog/2011/08/09/fake-mesh-slicer-v3-0/) and included in the sample, they have a capsule that the slicer works on.

我使用了假切片器 3.0 ( http://unitycoder.com/blog/2011/08/09/fake-mesh-slicer-v3-0/) 并包含在示例中,他们有一个切片器可以处理的胶囊。

If I added a cube or another capsule with rigidbodies properties and collider property, the slicer (aka plane) only clones the object and doesn't slice it off. Why is that? How can I manipulate the code above to work for all kinds of objects?

如果我添加了一个立方体或另一个具有刚体属性和对撞机属性的胶囊,切片器(又名平面)只会克隆对象而不会将其切掉。这是为什么?如何操作上面的代码以适用于所有类型的对象?

I get this console error and I don't know what it means:

我收到此控制台错误,但我不知道这意味着什么:

UnasssignedReferenceException: The variable cutplane of 'Slice_mesh3_js' has not been assigned. You probably need to assign the cutplane variable of the Slice_mesh3_js script in the inspector. 

回答by VicM

Have you tried the turbo slicer asset?

您是否尝试过涡轮切片机资产?

https://www.assetstore.unity3d.com/#/content/4169There is a demo in their website.

https://www.assetstore.unity3d.com/#/content/4169在他们的网站上有一个演示。

There are ways to achieve what you want, however the noted asset could be the easiest one.

有多种方法可以实现您想要的目标,但是所提到的资产可能是最简单的一种。

Worth looking assets for slicing, breaking apart:

值得寻找用于切片、拆分的资产:

Also you can:

你也可以:

  1. Use your preferred modeling program and model the object in parts and with an animation slice the object as a result of certain action.
  2. Programmatically disappear the complete object and appear the slices using maybe a particle system to improve the effect.
  1. 使用您喜欢的建模程序并按部分对对象进行建模,并使用动画将对象作为特定动作的结果切片。
  2. 以编程方式消失整个对象并使用粒子系统出现切片以改善效果。

回答by Stas BZ

You can see new one here http://u3d.as/qSNThis asset has very fast algorithms for 3D models and in comparison to its alternatives, it have much more clean code.

你可以在这里看到新的http://u3d.as/qSN这个资产有非常快的 3D 模型算法,与它的替代品相比,它有更干净的代码。

  • It supports asynchronous slice if you are not happy with speed. But my tests shows that it is not necessary, it is fast enough to do it in main loop.
  • It slices colliders converting them to MeshCollider-s.
  • And it is easy to customize.
  • 如果您对速度不满意,它支持异步切片。但是我的测试表明它没有必要,它在主循环中已经足够快了。
  • 它对碰撞器进行切片,将它们转换为 MeshCollider-s。
  • 而且很容易定制。

enter image description here

在此处输入图片说明

Also if you want to slice characters, see this http://u3d.as/Z4F

另外,如果您想对字符进行切片,请参阅此http://u3d.as/Z4F