index.js
function _drawSphere(pos, r, color) {
        var p = new Primitive();
        p.color = toColor(color);

        // Decreasing these angles will increase complexity of sphere.
        var dtheta = 35; var dphi = 35;

        for (var theta = -90; theta <= (90 - dtheta); theta += dtheta) {
            for (var phi = 0; phi <= (360 - dphi); phi += dphi) {
                p.vertices.push(new THREE.Vector3(
                    pos.x + r * Math.cos(theta * DEG_TO_RAD) * Math.cos(phi * DEG_TO_RAD),
                    pos.y + r * Math.cos(theta * DEG_TO_RAD) * Math.sin(phi * DEG_TO_RAD),
                    pos.z + r * Math.sin(theta * DEG_TO_RAD)
                ));

                p.vertices.push(new THREE.Vector3(
                    pos.x + r * Math.cos((theta + dtheta) * DEG_TO_RAD) * Math.cos(phi * DEG_TO_RAD),
                    pos.y + r * Math.cos((theta + dtheta) * DEG_TO_RAD) * Math.sin(phi * DEG_TO_RAD),
                    pos.z + r * Math.sin((theta + dtheta) * DEG_TO_RAD)
                ));

                p.vertices.push(new THREE.Vector3(
                    pos.x + r * Math.cos((theta + dtheta) * DEG_TO_RAD) * Math.cos((phi + dphi) * DEG_TO_RAD),
                    pos.y + r * Math.cos((theta + dtheta) * DEG_TO_RAD) * Math.sin((phi + dphi) * DEG_TO_RAD),
                    pos.z + r * Math.sin((theta + dtheta) * DEG_TO_RAD)
                ));

                if ((theta > -90) && (theta < 90)) {
                    p.vertices.push(new THREE.Vector3(
                        pos.x + r * Math.cos(theta * DEG_TO_RAD) * Math.cos((phi + dphi) * DEG_TO_RAD),
                        pos.y + r * Math.cos(theta * DEG_TO_RAD) * Math.sin((phi + dphi) * DEG_TO_RAD),
                        pos.z + r * Math.sin(theta * DEG_TO_RAD)
                    ));
                }
            }
        }

        renderer.addPrimitive(p);
    }
function _drawSphere(pos, r, color) {
        var p = new Primitive();
        p.color = toColor(color);

        // Decreasing these angles will increase complexity of sphere.
        var dtheta = 35; var dphi = 35;

        for (var theta = -90; theta <= (90 - dtheta); theta += dtheta) {
            for (var phi = 0; phi <= (360 - dphi); phi += dphi) {
                p.vertices.push(new THREE.Vector3(
                    pos.x + r * Math.cos(theta * DEG_TO_RAD) * Math.cos(phi * DEG_TO_RAD),
                    pos.y + r * Math.cos(theta * DEG_TO_RAD) * Math.sin(phi * DEG_TO_RAD),
                    pos.z + r * Math.sin(theta * DEG_TO_RAD)
                ));

                p.vertices.push(new THREE.Vector3(
                    pos.x + r * Math.cos((theta + dtheta) * DEG_TO_RAD) * Math.cos(phi * DEG_TO_RAD),
                    pos.y + r * Math.cos((theta + dtheta) * DEG_TO_RAD) * Math.sin(phi * DEG_TO_RAD),
                    pos.z + r * Math.sin((theta + dtheta) * DEG_TO_RAD)
                ));

                p.vertices.push(new THREE.Vector3(
                    pos.x + r * Math.cos((theta + dtheta) * DEG_TO_RAD) * Math.cos((phi + dphi) * DEG_TO_RAD),
                    pos.y + r * Math.cos((theta + dtheta) * DEG_TO_RAD) * Math.sin((phi + dphi) * DEG_TO_RAD),
                    pos.z + r * Math.sin((theta + dtheta) * DEG_TO_RAD)
                ));

                if ((theta > -90) && (theta < 90)) {
                    p.vertices.push(new THREE.Vector3(
                        pos.x + r * Math.cos(theta * DEG_TO_RAD) * Math.cos((phi + dphi) * DEG_TO_RAD),
                        pos.y + r * Math.cos(theta * DEG_TO_RAD) * Math.sin((phi + dphi) * DEG_TO_RAD),
                        pos.z + r * Math.sin(theta * DEG_TO_RAD)
                    ));
                }
            }
        }

        renderer.addPrimitive(p);
    }
function _drawSphere ( pos , r , color ) { var p = new Primitive ( ) ; p . color = toColor ( color ) ; // Decreasing these angles will increase complexity of sphere. var dtheta = 35 ; var dphi = 35 ; for ( var theta = - 90 ; theta <= ( 90 - dtheta ) ; theta += dtheta ) { for ( var phi = 0 ; phi <= ( 360 - dphi ) ; phi += dphi ) { p . vertices . push ( new THREE . Vector3 ( pos . x + r * Math . cos ( theta * DEG_TO_RAD ) * Math . cos ( phi * DEG_TO_RAD ) , pos . y + r * Math . cos ( theta * DEG_TO_RAD ) * Math . sin ( phi * DEG_TO_RAD ) , pos . z + r * Math . sin ( theta * DEG_TO_RAD ) ) ) ; p . vertices . push ( new THREE . Vector3 ( pos . x + r * Math . cos ( ( theta + dtheta ) * DEG_TO_RAD ) * Math . cos ( phi * DEG_TO_RAD ) , pos . y + r * Math . cos ( ( theta + dtheta ) * DEG_TO_RAD ) * Math . sin ( phi * DEG_TO_RAD ) , pos . z + r * Math . sin ( ( theta + dtheta ) * DEG_TO_RAD ) ) ) ; p . vertices . push ( new THREE . Vector3 ( pos . x + r * Math . cos ( ( theta + dtheta ) * DEG_TO_RAD ) * Math . cos ( ( phi + dphi ) * DEG_TO_RAD ) , pos . y + r * Math . cos ( ( theta + dtheta ) * DEG_TO_RAD ) * Math . sin ( ( phi + dphi ) * DEG_TO_RAD ) , pos . z + r * Math . sin ( ( theta + dtheta ) * DEG_TO_RAD ) ) ) ; if ( ( theta > - 90 ) && ( theta < 90 ) ) { p . vertices . push ( new THREE . Vector3 ( pos . x + r * Math . cos ( theta * DEG_TO_RAD ) * Math . cos ( ( phi + dphi ) * DEG_TO_RAD ) , pos . y + r * Math . cos ( theta * DEG_TO_RAD ) * Math . sin ( ( phi + dphi ) * DEG_TO_RAD ) , pos . z + r * Math . sin ( theta * DEG_TO_RAD ) ) ) ; } } } renderer . addPrimitive ( p ) ; }
Draw a sphere at pos with radius r.
Draw a sphere at pos with radius r .