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/torusgeometry.js file in the three.js source file.
More updates in: Https://github.com/omni360/three.js.sourcecode
/** * @author Oosmoxiecode * @author mrdoob/http://mrdoob.com/* based on http://code.google.com/p/away3d/source/browse/ trunk/fp10/away3dlite/src/away3dlite/primitives/torus.as?r=2888 *//*///torusgeometry is used to create a torus object within a three-dimensional space.//////usage: var geometry = new three. Torusgeometry (3,1,12,18);///var material = new three. Meshbasicmaterial ({color:0x00ff00});///var torus = new three. Mesh (geometry,material);///Scene.add (torus); *////<summary>torusgeometry</summary>///<param name = "Radius" type= "float" > Torus radius </param>///<param name = "Tube" type= "float" > Ring elbow RADIUS </param>///< param name = "radialsegments" type= "int" > segment number of segments on torus </param>///<param name = "Tubularsegments" type= "int" > Number of subdivision segments on ring elbow circumference </param>///<param name = "arc" type= "float" > Torus circumference arc length, default initialized to Math.PI * 2</param> Three. Torusgeometry = function (radius, tube, radialsegments, tubularsegments, ARC) {three. Geometry.call (this);//Call method of the Geometry object is called, and the method that originally belongs to Geometry is given to the current object TorusgeOmetry to use. this.parameters = {radius:radius,//Ring body radius tube:tube,//Ring bend radius radialsegments:radialsegments,// Number of segments segment on torus circumference tubularsegments:tubularsegments,//segment number of segments on ring elbow circumference ARC:ARC//torus circumference arc length, default initialized to Math.PI * 2};radius = RADIUS | | 100;//torus radius, if parameter is not set, initialize to 100.tube = Tube | | 40; Ring bend radius, if parameter is not set, initialize to 40.radialSegments = Radialsegments | | 8; Number of segments segment on torus circumference, if parameter is not set, initialize to 8.tubularSegments = Tubularsegments | | 6;//the number of subdivision segments on the ring bend circumference, if the parameter is not set, initialized to 6.arc = Arc | | Math.PI * 2;//Circular arc length, default initialized to Math.PI * 2var Center = new three. Vector3 (), Uvs = [], normals = [];//compute vertex data, press into vertices array. for (var j = 0; J <= Radialsegments; j + +) {for (var i = 0; I <= tubularsegments; i + +) {var u = i/tubularsegments * Arc;var v = j/radialsegments * Math.PI * 2;center.x = radius * Math.Cos (u); cente R.y = radius * Math.sin (U), var vertex = new three. Vector3 (); vertex.x = (radius + Tube * Math.Cos (v)) * Math.Cos (u); vertex.y = (radius + Tube * Math.Cos (v)) * Math . Sin (u); vertex.z = Tube * Math.sin (v); this.vertices. push (vertex); Uvs.push (new three. Vector2 (i/tubularsegments, j/radialsegments)); Normals.push (Vertex.clone (). Sub (center). normalize ());}} Compute triangular faces, and map uv.for (var j = 1; J <= Radialsegments; j + +) {for (var i = 1; I <= tubularsegments; i + +) {var a = (tubularsegments + 1) * j + i-1;var B = (tubularsegments + 1) * (j-1) + i-1;var C = (tubularsegments + 1) * (j-1) + i;var D = (tubularsegments + 1) * j + i;var face = new three. Face3 (A, B, D, [normals[a].clone (), normals[b].clone (), normals[D].clone ()]); This.faces.push (face); This.faceve rtexuvs[0].push ([uvs[a].clone (), uvs[b].clone (), uvs[D].clone ()]); face = new three. Face3 (b, C, D, [normals[b].clone (), normals[C].clone (), normals[D].clone ()]); This.faces.push (face); This.faceve rtexuvs[0].push ([uvs[b].clone (), uvs[C].clone (), uvs[D].clone ()]);}} This.computefacenormals ();//The normal};/***************************************************** of the computed surface The following is the method property of the Torusgeometry objectThe geometry object, inherited from the. **************************************************/three. Torusgeometry.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/torusgeometry.js file in the three.js source file.
More updates in: Https://github.com/omni360/three.js.sourcecode
Three.js Source Note (79) Extras/geometries/torusgeometry.js