Three.js Source Note (76) extras/geometries/spheregeometry.js

Source: Internet
Author: User

Commercial Territory (http://blog.csdn.net/omni360/)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.


I was just beginning to learn, a lot of things are definitely wrong and please forgive me.

The following code is a comment for the extras/geometries/spheregeometry.js file in the three.js source file.

More updates in: Https://github.com/omni360/three.js.sourcecode


/** * @author mrdoob/http://mrdoob.com/*//*///spheregeometry is used to create a sphere object within a three-dimensional space.//////usage: var geometry = new three. Spheregeometry (5,32,32);///var material = new three. Meshbasicmaterial ({color:0x00ff00});///var sphere = new three. Mesh (geometry,material);////Scene.add (sphere); *////<summary>spheregeometry</summary>///<param Name = "radius" type= "float" > Sphere body radius </param>///<param name = "Widthsegments" type= "int" > Sphere width Subdivision segment number, should be Meridian bar </param>///<param name = "Heightsegments" type= "int" > Sphere height Subdivision segment number, should be the latitude bar </param>///<param name = " Phistart "type=" float "> Sphere equatorial Line starting point radian </param>///<param name =" Philength "type=" float "> arc length of sphere equatorial line </ Param>///<param name = "Thetastart" type= "float" > Sphere warp starting point radian </param>///<param name = "Thetalength" Type= "float" > Sphere meridian arc length </param>three. Spheregeometry = function (radius, widthsegments, heightsegments, Phistart, Philength, Thetastart, thetalength) {THREE.G Eometry.call (this); this.parameters = {radius:radius,//Sphere body radius widthsegments:widthsegments,//Sphere Width Subdivision segment number, should be warp bar heightsegments:heightsegments,//Sphere Height Subdivision segment number , it should be latitude. phistart:phistart,//The starting point of the equatorial line of the sphere philength:philength,//the arc length thetastart:thetastart of the sphere Equator line,// Sphere Warp Start point radian thetalength:thetalength//Sphere meridian arc Length};radius = Radius | | 50;//sphere body radius, default initialized to 50.widthSegments = Math.max (3, Math.floor (widthsegments) | | 8);//Sphere width subdivision segment number, should be Meridian Bar,  Default initialized to 8heightSegments = Math.max (2, Math.floor (heightsegments) | | 6);//Sphere height subdivision segment number, should be the latitude bar, default initialized to 6phiStart = Phistart!== Undefined?  phistart:0; The arc of the starting point of the sphere's equatorial line, initialized by default to 0phiLength = Philength!== undefined? PhiLength:Math.PI * 2;//Sphere Equatorial Line arc length, default initialized to twice times the pi,360 degree thetastart = thetastart!== undefined? thetastart:0; The arc of the starting point of the Sphere meridian, initialized by default to 0thetaLength = Thetalength!== undefined? ThetaLength:Math.PI;  The sphere has an arc length that is initialized to pi,180 degrees by default. var x, y, vertices = [], Uvs = [];//compute vertex data, press into vertices array. for (y = 0; y <= heightsegments; y + +) {var verticesrow = [];var uvsrow = [];for (x = 0; x <= widthsegments; x + +) {var u = x/widthsEgments;var v = y/heightsegments;var vertex = new three.  Vector3 (); vertex.x =-radius * Math.Cos (phistart + u * philength) * Math.sin (Thetastart + v * thetalength); vertex.y = RADIUS * Math.Cos (Thetastart + v * thetalength), vertex.z = Radius * Math.sin (phistart + u * philength) * Math.sin (th Etastart + v * thetalength); This.vertices.push (vertex); Verticesrow.push (this.vertices.length-1); Uvsrow.push (New TH REE. Vector2 (U, 1-v));} Vertices.push (Verticesrow); Uvs.push (Uvsrow);}  Compute triangular faces, and map uv.for (y = 0; y < heightsegments; y + +) {for (x = 0; x < widthsegments; x + +) {var v1 = vertices[y [x + 1];var v2 = vertices[y] [x];var v3 = vertices[y + 1] [x];var v4 = vertices[y + 1] [x + 1];var n1 = this. vertices[v1].clone (). Normalize (), var n2 = this.vertices[v2].clone (). normalize (); var n3 = this.vertices[v3].clone (). N Ormalize (); var N4 = this.vertices[v4].clone (). normalize (); var uv1 = uvs[y [x + 1].clone (); var uv2 = uvs[y] [x].cl One (); var UV3 = uvs[y + 1 [x].clone (); var uv4 = uvs[y + 1] [x + 1].clone (); if (Math.Abs (this.vertices[v1].y) = = = radius) {uv1.x = (uv1.x + uv2.x)/2;this.faces.push (new three. Face3 (v1, v3, v4, [N1, N3, N4]); this.facevertexuvs[0].push ([Uv1, Uv3, uv4]);} else if (Math.Abs (this.vertices[v3].y) = = = radius) {uv3.x = (uv3.x + uv4.x)/2;this.faces.push (new three. Face3 (v1, v2, v3, [N1, N2, N3]); this.facevertexuvs[0].push ([Uv1, Uv2, Uv3]);} else {This.faces.push (new three. Face3 (v1, v2, v4, [N1, N2, N4]); this.facevertexuvs[0].push ([Uv1, Uv2, uv4]); This.faces.push (new three. Face3 (v2, v3, v4, [N2.clone (), N3, N4.clone ()])); this.facevertexuvs[0].push ([Uv2.clone (), Uv3, Uv4.clone ()]);} }}this.computefacenormals ();//Calculates the normals of a polygon. This.boundingsphere = new three. Sphere (new three. Vector3 (), RADIUS);//Calculate sphere bounds.};/ The following is a method property definition for the Spheregeometry object, inherited from the Geometry object. **************** ***************************/three. Spheregeometry.prototype = Object.create (three. Geometry.prototype);


Commercial Territory (http://blog.csdn.net/omni360/)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.


The following code is a comment for the extras/geometries/spheregeometry.js file in the three.js source file.

More updates in: Https://github.com/omni360/three.js.sourcecode

Three.js Source Note (76) extras/geometries/spheregeometry.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.