我试图根据之前计算得到的一些贝塞尔曲线在 Three.js 中绘制一条弯曲的道路,问题是我找不到转换曲线序列的方法(一条从上一条曲线的末尾开始)到一个曲面。
我有一个 3D 场景,其中有一些汽车、一条用飞机创建的道路,并且绘制了即将到来的道路的路径。我使用我所说的贝塞尔曲线将路径表示为一条线
function createAdasisBezier(initx, inity, cp1x, cp1y, cp2x, cp2y, finalx, finaly) {
bezier = new THREE.CubicBezierCurve3(
new THREE.Vector3(initx, inity, 0),
new THREE.Vector3(cp1x, cp1y, 0),
new THREE.Vector3( cp2x, cp2y, 0),
new THREE.Vector3(finalx, finaly, 0)
);
curvePath = new THREE.CurvePath();
curvePath.add(bezier);
var geoPath = curvePath.createPointsGeometry( 5 );
var lineMat = new THREE.LineBasicMaterial({color: 0xff0000});
curveLine = new THREE.Line(geoPath, lineMat);
curveLine.rotation.set(-Math.PI/2,0,0);
curveLine.position.y = 0.1;
scene.add(curveLine);
}
Run Code Online (Sandbox Code Playgroud)
首先,我尝试挤压这条线,但后来我意识到这可能不是解决方案,因为我想做一条路,尽管我可以移动 X 和 Y 上的顶部顶点,将它们放置在贝塞尔曲线附近,以便成为外部曲线的一部分,结果不仅不利,而且无法保持左右曲线之间的关系。
为了移动顶点(一旦确定),我做了一个循环并手动移动它们:
for (var i = 0; i …Run Code Online (Sandbox Code Playgroud) 按照这个主题,我尝试生成一个3D弯曲三角形作为NURBS曲面,但是我不知道如何设置3D点来实现。
这是当前的实现:
var edges = this.getEdges(), // An edge is a line following 4 dots as a bezier curve.
dots = self.getDotsFromEdges(edges), // Get all dots in order for building the surface.
ctrlPoints = [ // Is generated only once before, but copy-pasted here for this sample code.
[
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1)
],
[
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, …Run Code Online (Sandbox Code Playgroud)