//添加一个圆柱体
addRegularPrism(center, segment, height, radius,object3Dlayer) {
var topColor = [0.26, 1, 1, 0.9]; //上三角面
var topFaceColor = [0.26, 1, 1, 0.9];
var bottomColor = [0.26, 0.3, 1, 0.9];//下三角面
this.cylinder = new AMap.Object3D.Mesh();
var geometry = this.cylinder.geometry;
var verticesLength = segment * 2;
var path = []
for (var i = 0; i < segment; i += 1) {
var angle = 2 * Math.PI * i / segment;
var x = center.x + Math.cos(angle) * radius;
var y = center.y + Math.sin(angle) * radius;
path.push([x, y]);
geometry.vertices.push(x, y, -5000); //底部顶点
var x1 = center.x + Math.cos(angle) * 1000;
var y1 = center.y + Math.sin(angle) * 1000;
// path.push([x1, y1]);
geometry.vertices.push(x1, y1, -height); //顶部顶点
geometry.vertexColors.push.apply(geometry.vertexColors, bottomColor); //底部颜色
geometry.vertexColors.push.apply(geometry.vertexColors, topColor); //顶部颜色
var bottomIndex = i * 2;
var topIndex = bottomIndex + 1;
var nextBottomIndex = (bottomIndex + 2) % verticesLength;
var nextTopIndex = (bottomIndex + 3) % verticesLength;
geometry.faces.push(bottomIndex, topIndex, nextTopIndex); //侧面三角形1
geometry.faces.push(bottomIndex, nextTopIndex, nextBottomIndex); //侧面三角形2
}
// 构建顶面三角形,为了区分顶面点和侧面点使用不一样的颜色,所以需要独立的顶点
for (var i = 0; i < segment; i += 1) {
geometry.vertices.push.apply(geometry.vertices, geometry.vertices.slice(i * 6 + 3, i * 6 + 6)); //底部顶点
geometry.vertexColors.push.apply(geometry.vertexColors, topFaceColor);
}
var triangles = AMap.GeometryUtil.triangulateShape(path);
var offset = segment * 2;
for (var v = 0; v < triangles.length; v += 3) {
geometry.faces.push(triangles[v] + offset, triangles[v + 2] + offset, triangles[v + 1] + offset);
}
this.cylinder.transparent = true; // 如果使用了透明颜色,请设置true
this.cylinderArr.push(this.cylinder)
//this.object3Dlayer.add(this.cylinder);
}```
知识点1. var topColor = [0.26, 1, 1, 0.9]; //上三角面
var topFaceColor = [0.26, 1, 1, 0.9];
var bottomColor = [0.26, 0.3, 1, 0.9];//下三角面
3d立体构成是由上顶点下定点 中间部分是上下延申的三角组合成中间面,
知识点2 geometry.vertices.push(x, y, -5000); //底部顶点
-5000是柱子靠外面 所以....且必须设置
知识点3.[0.26, 0.3, 1, 0.9]
是Matlab(yuv)的颜色需要 与RGB转换 最后一个是透明度 必须设置
高德地图3D立体颜色设置
于 2022-04-02 17:32:40 首次发布