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;
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);
geometry.faces.push(bottomIndex, nextTopIndex, nextBottomIndex);
}
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;
this.cylinderArr.push(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转换 最后一个是透明度 必须设置
|