目录
一、线
1、绘制线
const options = {
points: myPoints,//3维空间点数组
updatable: true
}
let lines = BABYLON.MeshBuilder.CreateLines("lines", options, scene);
options.points[0].x +=6;
options.instance = lines;
lines = BABYLON.MeshBuilder.CreateLines("lines", options);
options:
选项 | 价值 | 默认值 |
---|---|---|
points | (Vector3[]) Vector3 的数组,行的路径REQUIRED | |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
instance | (LineMesh)要更新的线网格实例 | 无效的 |
colors | (Color4[]) Color4的数组,每个点的颜色 | 无效的 |
useVertexAlpha | (布尔值)如果不需要 alpha 混合则为 false(更快) | 真的 |
与网格不同,线条在创建后使用颜色属性而不是材质进行着色。
lines.color = new BABYLON.Color3(1, 0, 0);
mesh:
let lines = BABYLON.Mesh.CreateLines("lines", points, scene);
let lines = BABYLON.Mesh.CreateLines("lines", points, scene, updatable, instance);
2、绘制曲线
三点圆弧:
let arr=[
new BABYLON.Vector3(10,1,0),
new BABYLON.Vector3(10,1,10),
new BABYLON.Vector3(15,10,20),
]
let arc=BABYLON.Curve3.ArcThru3Points(arr[0],arr[1],arr[2],32,true,true)
let arcline=BABYLON.MeshBuilder.CreateLines('arc',
{points:arc.getPoints()})
arcThru3Points参数:
- first Vector3弧必须经过的第一个点。
- second Vector3弧必须经过的第二个点。
- 第三个 Vector3弧必须经过的第三个点。
- 步 数越大,步数越大,弧线越详细。
- 关闭 布尔可选,默认为 false,当 true 从第一点和第三点形成和弦时
- fullCircle boolean可选,默认为 false,当 true 通过三个点形成完整的圆
此静态方法返回Curve3的一个实例。
只需使用 Curve3 getPoints()方法填充您的数组:getPoints()返回一个连续Vector3的数组。length()方法返回曲线长度。
二次贝塞尔曲线:
let arr=[
new BABYLON.Vector3(10,1,0),
new BABYLON.Vector3(10,1,10),
new BABYLON.Vector3(15,10,20),
]
let arc=BABYLON.Curve3.CreateQuadraticBezier(arr[0],arr[1],arr[2],32)
let arcline=BABYLON.MeshBuilder.CreateLines('arc',
{points:arc.getPoints()})
CreateQuadraticBezier参数介绍:
- origin : Vector3原点,
- control : Vector3控制点,
- destination : Vector3目标点,
- nb_of_points:路径数组中想要的点数。
同样,只需使用 Curve3 getPoints()方法填充您的数组:getPoints()返回一个连续Vector3的数组。length()方法返回曲线长度。
三次贝塞尔曲线:
let arr=[
new BABYLON.Vector3.Zero(),
new BABYLON.Vector3(30,30,40),
new BABYLON.Vector3(-60,50,-10),
new BABYLON.Vector3(30,-50,-20),
new BABYLON.Vector3(-60,10,-20)
]
let arc=BABYLON.Curve3.CreateCubicBezier(arr[0],arr[1],arr[2],arr[3],32)
let arcline=BABYLON.MeshBuilder.CreateLines('arc',
{points:arc.getPoints()})
参数:
- origin : Vector3原点,
- control1 : Vector3第一个控制点,
- control2 : Vector3第二个控制点,
- destination : Vector3目标点,
- nb_of_points:对数组中所需的最终曲线点数进行编号。
此静态方法返回Curve3的一个实例。
只需使用 Curve3 getPoints()方法填充您的数组:getPoints()返回一个连续Vector3的数组。length()
方法返回曲线长度。
埃尔米特线:
let arr=[
new BABYLON.Vector3.Zero(),
new BABYLON.Vector3(10,30,40),
new BABYLON.Vector3(-60,10,-10),
new BABYLON.Vector3(-30,-50,20),
]
let arc=BABYLON.Curve3.CreateHermiteSpline(arr[0],arr[1],arr[2],arr[3],32)
let arcline=BABYLON.MeshBuilder.CreateLines('arc',
{points:arc.getPoints()})
参数:
- p1 : Vector3原点,
- t1 : Vector3原点正切向量,
- p2 : Vector3目标点,
- t2 : Vector3目标切线向量,
- nbPoints:对数组中所需的最终曲线点数进行编号。
此静态方法返回Curve3的一个实例。
只需使用 Curve3 getPoints()方法填充您的数组:getPoints()返回一个连续Vector3的数组。length()
方法返回曲线长度。
三次埃尔米特线:
let arr=[
new BABYLON.Vector3.Zero(),
new BABYLON.Vector3(10,30,40),
new BABYLON.Vector3(-60,10,-10),
new BABYLON.Vector3(-30,-50,20),
]
let arc=BABYLON.Curve3.CreateCatmullRomSpline(arr,20,32,true)
let arcline=BABYLON.MeshBuilder.CreateLines('arc',
{points:arc.getPoints()})
参数:
- points : Vector3曲线将通过的 Vector3 数组(控制点),
- nbPoints:编号每个控制点之间的所需曲线点数,
- closed:布尔可选,默认为false;可从 BJS V3.3 获得;当 true 形成闭合曲线时。
此静态方法返回Curve3的一个实例。
只需使用 Curve3 getPoints()方法填充您的数组:getPoints()返回一个连续Vector3的数组。length()
方法返回曲线长度。
创建自定义曲线:
自定义曲线可以使用起点连接上段曲线的终点。
var mySinus = [];
for (var i = 0; i < 30; i++) {
mySinus.push( new BABYLON.Vector3(i, Math.sin(i / 10), 0) );
}
var mySinusCurve = new BABYLON.Curve3(mySinus);
var myFullCurve = mySinusCurve.continue(bezier3).continue(bezier2);
3、3D路径
var points = [v1, v2, ..., vn];
var path3d = new BABYLON.Path3D(points);
var path3d = new BABYLON.Path3D(points);
//切线
var tangents = path3d.getTangents();
//法线
var normals = path3d.getNormals();
//副法线
var binormals = path3d.getBinormals();
//曲线
var curve = path3d.getCurve();
方法:
getTangents
,getNormals
还有getBinormals
一些其他的方法Path3D,getCurve
方法返回为创建对象而提供getCurve
的初始数组的副本。
var distances = path3d.getDistances();
该getDistances
方法按点的顺序返回从一个曲线点到下一个曲线点的距离数组,其中 0 是第一个距离。
slice
方法返回一个新的 Path3D,它是原始路径的子路径(切片)。它采用从 0.0 到 1.0 的开始和结束位置,或从 1.0 回绕的负值
为了避免内存重新分配(例如在渲染循环中),因为给定的点数Path3D
组是在内部复制的,您可以使用其update()
方法更新现有对象。
该getClosestPositionTo
函数返回从 0.0 到 1.0 的沿任意 Vector3 的路径最近的虚拟点的位置。
除了第一个法线外,还有两个参数:
raw
, 布尔值,默认为false。如果为真,则切线、法线和副法线不会被归一化。用于描述路径加速度或速度。alignTangentsWithPath
, 布尔值,默认为false。如果为真,切线将与路径对齐。
二、虚线
const options = {
points: myPoints,//3为空间点数组
updatable: true
}
let dashedlines = BABYLON.MeshBuilder.CreateDashedLines("dashedlines",
options, scene);
options.points[0].x +=6;
options.instance = lines;
lines = BABYLON.MeshBuilder.CreateDashedLines("dashedlines", options);
选项 | 价值 | 默认值 |
---|---|---|
points | (Vector3[]) Vector3 的数组,行的路径REQUIRED | |
dashSize | (数字) 破折号的大小 | 3 |
gapSize | (数量) 间隙大小 | 1 |
dashNb | (数字) 预期的破折号数 | 200 |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
instance | (LineMesh)要更新的线网格实例 | 无效的 |
mesh:
const dashedlines = BABYLON.Mesh.CreateDashedLines("dashedLines",
vector3 array, dashSize, gapSize, dashNb, scene);
const dashedlines = BABYLON.Mesh.CreateDashedLines("dashedLines",
vector3 array, dashSize, gapSize, dashNb, scene, updatable, instance);
三、线路系统
let lineSystem = BABYLON.MeshBuilder.CreateLineSystem("lineSystem",
{lines: myArray}, scene);
lineSystem = BABYLON.MeshBuilder.CreateLineSystem("lineSystem",
{lines: myArray, instance: lineSystem});
选项 | 价值 | 默认值 |
---|---|---|
lines | (Vector3[][]) 行数组,每行是一个连续的 Vector3数组 | |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
instance | (LineMesh)要更新的线系统网格的实例 | 无效的 |
colors | (Color4[]) Color4的数组,每个点的颜色 | 无效的 |
useVertexAlpha | (布尔值)如果不需要 alpha 混合则为 false(更快) | 真的 |
四、网格生成器
const options = {
pathArray: myPaths,//一个数组,其元素均为三维数组,三维数组存储网格顶点
updatable: true
}
let ribbon = BABYLON.MeshBuilder.CreateRibbon("ribbon", options, scene);
options.pathArray: myNewPaths;
myNewPaths[i].length === myPaths[i] for all i
options.instance = true;
ribbon = BABYLON.MeshBuilder.CreateRibbon("ribbon",
{pathArray: myNewPath, instance: ribbon});
选项 | 价值 | 默认值 |
---|---|---|
pathArray | (Vector3[][]) Vector3 数组数组,路径数组REQUIRED | |
closeArray | (布尔值) 强制功能区加入其最后和第一条路径 | 错误的 |
closePath | (布尔值) 强制每个功能区路径连接其最后一个点和第一个点 | 错误的 |
offset | (数字) 如果 pathArray 只有一个路径使用 | 路径长度的一半 |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
sideOrientation | (数字)侧向 | 默认侧 |
frontUVs | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
backUVs | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
instance | (LineMesh)要更新的功能区实例 | 无效的 |
invertUV | (布尔值)在几何构造时交换 U 和 V 坐标(纹理旋转 90°) | 错误的 |
mesh:
const ribbon = BABYLON.Mesh.CreateRibbon("ribbon",
pathArray, closeArray, closePath, offset, scene);
const ribbon = BABYLON.Mesh.CreateRibbon("ribbon",
pathArray, closeArray, closePath, offset, scene,
updatable, sideOrientation, instance);
五、管子
const options = {//vec3 array,
updatable: true
}
let tube = BABYLON.MeshBuilder.CreateTube("tube", options, scene);
options.path[0].x +=6;
options.instance = tube;
tube = BABYLON.MeshBuilder.CreateTubes("tube", options);
选项 | 价值 | 默认值 |
---|---|---|
path | (Vector3[]) Vector3 的数组,管子的路径REQUIRED | |
radius | (number) 管的半径 | 1 |
tessellation | (number) 径向段数 | 64 |
radiusFunction | ( function(index, distance) ) 从(index, distance)参数返回半径值的函数 | 无效的 |
cap | (编号)管帽:NO_CAP、CAP_START、CAP_END、CAP_ALL | NO_CAP |
arc | (number)管周长在 0 和 1 之间的比率 | 1 |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
sideOrientation | (数字)侧向 | 默认侧 |
frontUVs | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
backUVs | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
backUVs | (LineMesh)要更新的管的实例 | 无效的 |
invertUV | (布尔值)在几何构造时交换 U 和 V 坐标(纹理旋转 90°) | 错误的 |
mesh:
let tube = BABYLON.Mesh.CreateTube("tube", path, radius,
tesselation, optional radiusFunction, cap, scene);
let tube = BABYLON.Mesh.CreateTube("tube", path, radius,
tesselation, optional radiusFunction, cap, scene,
updatable, sideOrientation, instance);
六、挤压形状
1、挤压
const options = {
shape: myPoints, //z=0的三维空间数组
path: myPath, //3维空间数组
updatable: true
}
let extruded = BABYLON.MeshBuilder.ExtrudeShape("ext", options, scene);
options.shape = newShape;
options.path = newPath;
options.instance = extruded;
extruded = BABYLON.MeshBuilder.ExtrudeShape("ext", options);
选项 | 价值 | 默认值 |
---|---|---|
shape | (Vector3[]) Vector3 数组,你要拉伸的形状需要 | |
path | (Vector3[]) Vector3 的数组,需要拉伸轴 | |
scale | (数字) 缩放形状的值 | 1 |
rotation | (数字) 沿着路径每一步旋转形状的值 | 0 |
cap | (数量)挤压帽:NO_CAP, CAP_START, CAP_END, CAP_ALL | NO_CAP |
closeShape | (boolean)关闭形状,无需将 shape[0] 推入形状数组 | 错误的 |
closePath | (boolean)关闭路径,无需将 path[0] 推入路径数组 | 错误的 |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
sideOrientation | (数字)侧向 | 默认侧 |
frontUVs | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
backUVs | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
instance | (LineMesh)要更新的拉伸形状的实例 | 无效的 |
invertUV | (布尔值)在几何构造时交换 U 和 V 坐标(纹理旋转 90°) | 错误的 |
mesh:
let extrusion = BABYLON.Mesh.ExtrudeShape(name, shape, path,
scale, rotation, cap, scene);
let extrusion = BABYLON.Mesh.ExtrudeShape(name, shape, path,
scale, rotation, cap, scene, updatable, sideOrientation, instance);
2、定制挤压方式
const options = {
shape: myPoints,
path: myPath,
rotationFunction: rotFn,
scaleFunction: scaleFn,
updatable: true,
};
let extruded = BABYLON.MeshBuilder.ExtrudeShapeCustom("ext", options, scene);
options.shape = newShape;
options.path = newPath;
options.instance = extruded;
options.rotationFunction = newRotFn;
options.scaleFunction = newScaleFn;
extruded = BABYLON.MeshBuilder.ExtrudeShapeCustom("ext", options);
选项 | 价值 | 默认值 |
---|---|---|
shape | (Vector3[]) Vector3 数组,你要拉伸的形状需要 | |
path | (Vector3[]) Vector3的数组,需要拉伸轴 | |
scaleFunction | ( function(i, distance) )从(i, distance)参数返回比例值的函数 | {返回 1;} |
rotationFunction | ( function(i, distance) )从(i, distance)参数返回旋转值的函数 | {返回 0;} |
closeShape | (boolean)关闭形状,替换ribbonClosePath | 错误的 |
closePath | (boolean)关闭路径,替换ribbonCloseArray | 错误的 |
ribbonClosePath | (布尔值)底层功能区closePath参数值已弃用 | 错误的 |
ribbonCloseArray | (布尔值)底层功能区closeArray参数值已弃用 | 错误的 |
cap | (数量)挤压帽:NO_CAP, CAP_START, CAP_END, CAP_ALL | NO_CAP |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
sideOrientation | (数字)侧向 | 默认侧 |
frontUVs | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
backUVs | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
instance | (LineMesh)要更新的拉伸形状的实例 | 无效的 |
invertUV | (布尔值)在几何构造时交换 U 和 V 坐标(纹理旋转 90°) | 错误的 |
mesh:
let extrusion = BABYLON.Mesh.ExtrudeShapeCustom("extrusion", shape,
path, scaleFunction, rotateFunction, ribbonCloseArray,
ribbonClosePath, cap, scene);
let extrusion = BABYLON.Mesh.ExtrudeShapeCustom("extrusion", shape,
path, scaleFunction, rotateFunction, ribbonCloseArray,
ribbonClosePath, cap, scene, updatable, sideOrientation, instance);
let extrusion = BABYLON.Mesh.ExtrudeShapeCustom(
"extrusion",
shape,
path,
() => {
return 1;
},
() => {
return 0;
},
ribbonCloseArray,
ribbonClosePath,
cap,
scene,
);
七、车床
const lathe = BABYLON.MeshBuilder.CreateLathe("lathe", options, scene);
选项 | 价值 | 默认值 |
---|---|---|
shape | (Vector3[]) Vector3的数组,你要转的形状REQUIRED | |
radius | (数字) 车床半径值 | 1 |
tessellation | (number) 围绕车床的迭代次数,车床边数 | 64 |
arc | (数字)圆周率在 0 和 1 之间。取比例值 | 1 |
cap | (编号)管帽:NO_CAP、CAP_START、CAP_END、CAP_ALL | NO_CAP |
closed | (boolean)false 打开/关闭车床圆周,使用时应设置为arc | 真的 |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
sideOrientation | (数字)侧向 | 默认侧 |
fRontUVS | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
backUVS | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
insertUV | (布尔值)在几何构造时交换 U 和 V 坐标(纹理旋转 90°) | 错误的 |
mesh:
let lathe = BABYLON.Mesh.CreateLathe("lathe", shape, radius,
tessellation, scene);
let lathe = BABYLON.Mesh.CreateLathe("lathe", shape, radius,
tessellation, scene, updatable, sideOrientation);
八、不规则多边形
const polygon = BABYLON.MeshBuilder.CreatePolygon("polygon", options, scene);
选项 | 价值 | 默认值 |
---|---|---|
shape | (Vector3[]) Vector3 数组,你要构建的形状需要 | |
holes | (Vector3[][]) 孔数组,每个孔是一个连续的 Vector3 数组 | [] |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
sideOrientation | (数字)侧向 | 默认侧 |
frontUVS | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
backUVS | (Vector4) 仅当 sideOrientation:BABYLON.Mesh.DOUBLESIDE 是一个选项时 | Vector4(0,0, 1,1) |
mesh:
let polygon = BABYLON.Mesh.CreatePolygon("polygon", shape, scene);
let polygon = BABYLON.Mesh.CreatePolygon("polygon", shape,
scene, holes, updatable, sideOrientation);
九、不规则多边形挤出
1、正常挤出
const extrudedPolygon = BABYLON.MeshBuilder.ExtrudePolygon(
"polygon", options, scene);
选项 | 价值 | 默认值 |
---|---|---|
shape | (Vector3[]) Vector3的数组,你要转的形状REQUIRED | |
depth | (数字) 挤压深度要求 | |
faceColors | (Color4[]) 3 个Color4的数组,每个盒子面一个 | 每边的 Color4(1, 1, 1, 1) |
faceUV | (Vector4[]) 3 个Vector4的数组,每个盒子面一个 | 每边的 UV(0, 0, 1, 1) |
wrap | (布尔值)当错误纹理映射到每个单独的侧面时,使用 faceUV[1] 将纹理映射到侧面,当真实包裹在所有侧面时 | 错误的 |
holes | (Vector3[][]) 孔数组,每个孔是一个连续的 Vector3 数组 | [] |
updatable | (布尔值)如果网格是可更新的,则为真 | 错误的 |
sideOrientation | (数字)侧向 | 默认侧 |
mesh:
let polygon = BABYLON.Mesh.CreatePolygon("polygon", shape,
depth, scene);
let polygon = BABYLON.Mesh.CreatePolygon("polygon", shape,
depth, scene, holes, updatable, sideOrientation);
2、多边形网格生成器
const polygon_triangulation = new BABYLON.PolygonMeshBuilder(
"name", vector2 array, scene);
const polygon = polygon_triangulation.build();
var polygon_triangulation = new BABYLON.PolygonMeshBuilder(
"name", Path2, scene);
var polygon = polygon_triangulation.build(false, 3);
添加孔:
polygon_triangulation.addHole(hole1);
polygon_triangulation.addHole(hole2);
polygon_triangulation.addHole(hole3);
var polygon = polygon_triangulation.build(true, 1.4);