-
Notifications
You must be signed in to change notification settings - Fork 0
/
polarGrid.js
39 lines (33 loc) · 1.39 KB
/
polarGrid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as THREE from "three";
export function createPolarGrid(
radius = 20, // size of grid
radials = 16, // number of radial lines (ie "spokes")
circles = 10, // number of concentric cirles
divisions = 64, // number of segments per concentric circle, higher => rounder
color = 0x3d3d3d,
opacity = 0.1
) {
const material = new THREE.LineBasicMaterial({ color, opacity});
const geometry = new THREE.BufferGeometry();
const vertices = [];
// Create radials
for (let i = 0; i <= radials; i++) {
const theta = (i / radials) * Math.PI * 2;
vertices.push(0, 0, 0);
vertices.push(Math.cos(theta) * radius, 0, Math.sin(theta) * radius);
}
// Create concentric circles
for (let i = 0; i <= circles; i++) {
const r = (radius / circles) * i;
for (let j = 0; j < divisions; j++) {
const theta1 = (j / divisions) * Math.PI * 2;
const theta2 = ((j + 1) / divisions) * Math.PI * 2;
vertices.push(Math.cos(theta1) * r, 0, Math.sin(theta1) * r);
vertices.push(Math.cos(theta2) * r, 0, Math.sin(theta2) * r);
}
}
geometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
//const line = new THREE.LineSegments(geometry, material);
//scene.add(line);
return new THREE.LineSegments(geometry, material);
}