简体   繁体   English

沿着弯曲的 3D 网格均匀放置标签

[英]Placing labels evenly along curved 3D mesh

I have a single mesh game object that is essentially a long line that curves and slopes up/down.我有一个单一的网格游戏 object,它本质上是一条向上/向下弯曲和倾斜的长线。 What I'm trying to do is generate some text along this line at a specified distance interval.我想要做的是在指定的距离间隔沿这条线生成一些文本。 Let's say every 100 units along the line some text should appear.假设沿线每 100 个单位出现一些文本。 If it was a straight line it would be easy, but the curves and slopes are throwing me off.如果它是一条直线,那会很容易,但是曲线和斜坡让我很失望。

I retrieved the vertices that created this mesh by doing:我通过执行以下操作检索了创建此网格的顶点:

model.GetComponent<MeshFilter>().mesh.vertices

I then transform them to world-space by looping over them and doing:然后我通过循环它们并执行以下操作将它们转换为世界空间:

meshFilter.gameObject.transform.TransformPoint(vertices[i])

Now, these vertices are NOT evenly spaced.现在,这些顶点不是均匀分布的。 For slopes and curves, there are a lot of vertices.对于斜率和曲线,有很多顶点。 For the straighter parts, there are less.对于较直的部分,数量较少。 But these straight parts still vary slightly (usually by ~.10 of the Y value).但是这些直线部分仍然略有不同(通常是 Y 值的 ~.10)。 Originally I was looping through and keeping track of the distance to find the vertices closest to the interval, but that was when I thought they were evenly spaced.最初我循环并跟踪距离以找到最接近间隔的顶点,但那时我认为它们是均匀分布的。

Here's part of the model:这是 model 的一部分:

在此处输入图像描述

I colored all the vertices black here to show how condensed they are at curves/slopes vs ~straight parts:我在这里将所有顶点都涂成黑色,以显示它们在曲线/斜率与~直线部分的压缩程度:

在此处输入图像描述

Here's the inspector for the model just incase:这是 model 的检查器,以防万一:

在此处输入图像描述

Do you use a static single mesh?您是否使用 static 单网?
In your solution, I think the problem is vertices.在您的解决方案中,我认为问题出在顶点。 you have to find vertices along your line and ignore the vertical group of them and its too difficult.你必须沿着你的线找到顶点并忽略它们的垂直组,这太难了。
If your mesh may be changed by player, I suggest you to use Trail Render Component, get its vertices and solve a simple Knapsack problem to put your characters (suggest you use TextmeshPro)如果你的网格可能被玩家改变,我建议你使用 Trail Render Component,获取它的顶点并解决一个简单的背包问题来放置你的角色(建议你使用 TextmeshPro)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM