我正在使用Three JS
,并且可以使用GridHelper将网格添加到场景中。是否有类似的功能可以产生极坐标网格?
这是生成2D笛卡尔平面(source)的几何的方式:
var geometry = new THREE.Geometry();
var material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
this.color1 = new THREE.Color(0x444444);
this.color2 = new THREE.Color(0x888888);
for (var i = -size; i <= size; i += step) {
geometry.vertices.push(
new THREE.Vector3(-size, 0, i), new THREE.Vector3(size, 0, i),
new THREE.Vector3(i, 0, -size), new THREE.Vector3(i, 0, size)
);
var color = i === 0 ? this.color1 : this.color2;
geometry.colors.push(color, color, color, color);
}
THREE.LineSegments.call(this, geometry, material);
我尝试将其重写如下:
var segments = 64;
var material = new THREE.LineBasicMaterial({ color: 0x1976D2 });
//Somehow below didn't work...
//var material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
var geometry = new THREE.Geometry();
this.color1 = new THREE.Color(0x444444);
this.color2 = new THREE.Color(0x888888);
for (var i = -size; i <= size; i += step) {
var circle = new THREE.CircleGeometry(i, segments);
// Remove center vertex
circle.vertices.shift();
geometry.merge(circle);
var color = i === 0 ? this.color1 : this.color2;
geometry.colors.push(color, color, color, color);
}
THREE.LineSegments.call(this, geometry, material);
但是不知何故,线是虚线...
最佳答案
试试这样:
THREE.PolarHelper = function(radius, rStep, aStep, color) {
var helper = new THREE.Mesh();
function line(r, a, color) {
var material = new THREE.LineBasicMaterial({ color: color });
var geometry = new THREE.Geometry();
geometry.vertices.push(
new THREE.Vector3( Math.cos(a)*r, Math.sin(a)*r, 0 ),
new THREE.Vector3( -Math.cos(a)*r, -Math.sin(a)*r, 0 )
);
return new THREE.Line( geometry, material );
}
function circle(r, color) {
var curve = new THREE.EllipseCurve( 0, 0, r, r, 0, 2 * Math.PI, false, 0 );
var path = new THREE.Path( curve.getPoints( 72 ) );
var geometry = path.createPointsGeometry( 72 );
var material = new THREE.LineBasicMaterial( { color : color } );
return new THREE.Line( geometry, material );
}
var d = radius/rStep;
for (var r=1; r<=rStep; r++) {
helper.add(circle(r*d, color));
}
d = Math.PI/aStep;
for (var a=0; a<aStep; a++) {
helper.add( line(radius, a*d, color) );
}
return helper;
}
[https://jsfiddle.net/tzsd5cre/]
关于javascript - 三个JS Gridhelper Polar可能吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35398896/