UE4 道路编辑 Spline的使用

游戏中道路如何创建,做模型模型师会崩溃,而UE4本身提供的组件恰好能解决这个问题
新建一个继承与Actor的蓝图
手动添加Spline组件如图
这里写图片描述

for循环添加Splinemesh组件得到Spline的点数减2,实际就是添加Spline的点数减1个splinemesh 如果减1spline重点就不在最后一个splinemesh的顶点位置
这里写图片描述

设置splinemesh的起始点和终点位置
这里写图片描述
这里写图片描述

把蓝图拖到世界里就可以编辑了
源码地址
源码地址

  • 3
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
Wellesley, Massachusetts, A K Peters, Ltd., 1995. — 404 p. — ISBN 1-56881-016-4, OCR.Our intention is to provide an elementary and directly applicable introduction to the computation of those (as simple as possible) spline functions, which are determined by the requirement of smooth and shape-preserving interpolation and (in two cases) the smoothing of measured or collected data.Preface. Polynomial Interpolation. The Lagrange Form of the Interpolating Polynomial. The Newton Form of the Interpolating Polynomial. Polygonal Paths as Linear Spline Interpolants. General Spline Interpolants. arious Representations of a Polygonal Path. Evaluation by Searching an Ordered List. Properties of Polygonal Paths. When the Knots and Interpolation Nodes Are Different. Parametric Polygonal Paths. Smoothing with Polygonal Paths I. Smoothing with Polygonal Paths II. Quadratic Spline Interpolants. Knots the Same as Nodes. Optimal Initial Slope. Periodic Quadratic Spline Interpolants with Knots the Same as Nodes. Knots at the Midpoints of the Nodes. Knots Variable between the Nodes. Periodic Quadratic Spline Interpolants with Variable Knots between the Nodes. Nodes Variable between Knots. Quadratic Histosplines. Quadratic Hermite Spline Interpolants. Approximation of First Derivative Values I. Shape Preservation through the Choice of Additional Knots. Quadratic Splines with Given Slopes at Intermediate Points. Cubic Spline Interpolants. First Derivatives as Unknowns. Second Derivatives as Unknowns. Periodic Cubic Spline Interpolants. Properties of Cubic Spline Interpolants. First Derivatives Prescribed. Second Derivatives Prescribed. Smoothing with Cubic Spline Functions. Smoothing with Periodic Cubic Spline Functions. Cubic X-Spline Interpolants. Discrete Cubic Spline Interpolants. Local Cubic Hermite Spline Interpolants. Approximation of Values for the First Derivative II. Polynomial Spline Interpolants of Degree Five and Higher. Spline Interpolants of Degree Five. Quintic Hermite Spl
实现 Spline 插值的方法主要分为两种,分别是基于节点的 Spline 插值和基于函数的 Spline 插值。下面我将使用基于节点的 Spline 插值的方式,使用 JavaScript 实现一个简单的 Spline 插值算法。 以下是实现步骤: 1. 定义节点 首先,我们需要定义一些节点,即已知的数据点,每个节点由 x 和 y 坐标组成。我们可以将这些节点表示为一个数组,例如: ```javascript var nodes = [ {x: 0, y: 0}, {x: 1, y: 3}, {x: 2, y: 1}, {x: 3, y: 4}, {x: 4, y: 2}, ]; ``` 2. 计算系数 接下来,我们需要计算 Spline 插值中的系数。在基于节点的 Spline 插值中,每个区间都有一个三次函数,所以我们需要计算每个区间的系数。具体来说,对于第 i 个节点和第 i+1 个节点之间的区间,我们需要计算出一个三次函数: ``` S(x) = a + b(x - xi) + c(x - xi)^2 + d(x - xi)^3 ``` 其中,x 为要插值的点的横坐标,a、b、c 和 d 为系数,xi 为第 i 个节点的横坐标。为了计算这些系数,我们需要解一个线性方程组。具体来说,对于每个区间,我们需要求解以下四个方程: ``` S(xi) = yi S(xi+1) = yi+1 S'(xi) = S'(xi+1) S''(xi) = S''(xi+1) ``` 这个线性方程组可以通过矩阵运算来求解,具体实现可以参考一些数值计算库中的代码,这里不再赘述。 3. 插值 有了每个区间的系数之后,我们就可以使用插值公式来计算任意横坐标对应的纵坐标了。具体来说,对于横坐标为 x 的点,我们首先找到它所在的区间,然后使用该区间的三次函数来计算它的纵坐标。代码实现如下: ```javascript function interpolate(x, nodes) { // 找到 x 所在的区间 var i = 0; while (i < nodes.length - 1 && x > nodes[i + 1].x) { i++; } // 计算系数 var xi = nodes[i].x; var xi1 = nodes[i + 1].x; var yi = nodes[i].y; var yi1 = nodes[i + 1].y; var hi = xi1 - xi; var a = yi; var b = (yi1 - yi) / hi; var ci = (3 * (yi1 - yi) / hi - 2 * xi1 * b - xi * b) / hi; var di = (2 * (yi - yi1) / hi + xi1 * b + xi * b) / (hi * hi); // 计算插值结果 var dx = x - xi; var result = a + b * dx + ci * dx * dx + di * dx * dx * dx; return result; } ``` 这个函数接受一个要插值的横坐标 x 和节点数组 nodes,返回对应的纵坐标。 使用示例: ```javascript var nodes = [ {x: 0, y: 0}, {x: 1, y: 3}, {x: 2, y: 1}, {x: 3, y: 4}, {x: 4, y: 2}, ]; console.log(interpolate(1.5, nodes)); // 输出 2.25 console.log(interpolate(2.5, nodes)); // 输出 2.5 ``` 注意,这个实现只是一个简单的 Spline 插值算法,可能存在精度问题和边界问题,实际使用时需要根据具体情况进行修改和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值