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/torusknotgeometry.js file in the three.js source file.
More updates in: Https://github.com/omni360/three.js.sourcecode
/** * @author Oosmoxiecode * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/ primitives/torusknot.as?spec=svn2473&r=2473 *//*/// Torusknotgeometryy is used to create a torus or ring knot object in a three-dimensional space. It is an extended three-dimensional geometry formed by the ring body, often used to make tubular, twining. A shape with a cyst.//For geometrical characteristics of ring knots, refer to:// en.wikipedia.org/wiki/torus_knot///all kinds of beautiful demo:http://katlas.math.toronto.edu/wiki/36_torus_knots//////usage: var Geometry = new three. Torusknotgeometry (5,32,32);///var material = new three. Meshbasicmaterial ({color:0x00ff00});///var sphere = new three. Mesh (geometry,material);////Scene.add (sphere); *////<summary>torusknotgeometry</summary>///<param Name = "radius" type= "float" > Ring junction RADIUS </param>///<param name = "Tube" type= "float" > Annular junction Bend Radius </param>// /<param name = "Radialsegments" type= "int" > segment number of segments on ring circumference </param>///<param name = "Tubularsegments" type= " The number of subdivision segments on the circumference of the int "> Ring Bend Tube </param>///<param name =" P "type=" float ">p\q: Effective for knot (nodal) Form, controlling the number of loops winding in the curve path, P determines the parameters in the vertical direction. </param≫///<param name = "Q" type= "float" >p\q: Effective for the knot (Nodal) Form, control the number of laps of the curve path, Q determines the horizontal direction of the parameter. </param>///<param Name = "Heightscale" type= "float" > scale in the high direction of the ring junction. The default value is 1</param>three. Torusknotgeometry = function (radius, tube, radialsegments, tubularsegments, p, Q, Heightscale) {three. Geometry.call (this);//Call method of the Geometry object is called, the method that originally belongs to Geometry is given to the current object torusknotgeometry to use. This.parameters = {radius: radius,//annular Junction radius tube:tube,//annular Junction Bend RADIUS radialsegments:radialsegments,//segment number segment on ring circumference tubularsegments:tubularsegments,// Number of subdivision segments on the circumference of a ring-bend tube p:p,//p\q: Effective for knot (nodal) Form, controlling the number of loops winding in the curve path, and p determining the parameters of the vertical direction. Q:q,//p\q: Effective for knot (knots), the number of loops that control curve path winding, Q determines the horizontal direction of the parameter. heightscale:heightscale//scaling in the high direction of the ring junction. The default value is 1};radius = Radius | | 100;//Ring junction RADIUS, default initialized to 100tube = Tube | | 40;//Ring Knot Bend radius, default initialized to 40radialSegments = Radialsegments | | 64;//segment number of segments on the ring circle, default initialized to 64tubularSegments = Tubularsegments | | Number of subdivision segments on the circumference of the 8;//ring Bend tube, default initialized to 8p = P | | 2;//p\q: Effective for knot (nodal) Form, controlling the number of loops around the curve path, and p determining parameters in the vertical direction. Default initialized to 2q = Q | | 3;//p\q: Effective for the knot (nodal) Form, the number of loops that control the curve path, Q determines the parameters of the horizontal direction. Default initialized to 3heightScale = Heightscale | | 1;//the scaling in the high direction of the ring junction. The default value is 1var Grid = new Array (radialsegments); var tang = new three. Vector3 (); var n = new three. Vector3 (); var Bitan = new three. Vector3 ();//compute vertex data, press into vertices array for (var i = 0; i < radialsegments; + + i) {grid[i] = new Array (tubularsegments); VA R u = i/radialsegments * 2 * p * Math.pi;var p1 = getPos (u, Q, p, radius, heightscale); var p2 = getPos (U + 0.01, q, p , radius, Heightscale); Tang.subvectors (P2, p1); N.addvectors (P2, p1); Bitan.crossvectors (Tang, n); N.crossvectors (bit An, Tang); Bitan.normalize (); N.normalize (); for (var j = 0; J < tubularsegments; + + j) {var v = j/tubularsegments * 2 * Math.pi;var CX =-Tube * Math.Cos (v); TODO:Hack:Negating it so it faces outside.var cy = Tube * Math.sin (v); var pos = new Three. Vector3 ();p os.x = p1.x + cx * n.x + cy * bitan.x;pos.y = p1.y + cx * N.Y + cy * bitan.y;pos.z = p1.z + cx * n.z + cy * bit an.z;grid[I [j] = This.vertices.push (POS)-1;}} Compute triangular faces, and map uvfor (var i = 0; I < radialsegments; + + i) {for (var j = 0; J < tubularsegments; + + j) {var ip = (i + 1)% Radialsegments;var JP = (j + 1)% Tubulars Egments;var a = grid[I [j];var b = grid[IP] [j];var c = grid[IP] [jp];var d = grid[i] [jp];var UVA = new thre E.vector2 (i/radialsegments, j/tubularsegments); var UVB = new three. Vector2 ((i + 1)/radialsegments, j/tubularsegments); var UVC = new three. Vector2 ((i + 1)/radialsegments, (j + 1)/tubularsegments), var uvd = new three. Vector2 (I/radialsegments, (j + 1)/tubularsegments); This.faces.push (new three. Face3 (A, B, D)); this.facevertexuvs[0].push ([UVA, UVB, UVD]); This.faces.push (new three. Face3 (b, C, D)); this.facevertexuvs[0].push ([Uvb.clone (), UVC, Uvd.clone ()]);}} This.computefacenormals ();//Calculate the normal this.computevertexnormals () of the plane,//calculate the vertex normals/*///getpos method, known U,in_q,in_p,radius, Heightscale, the specific implementation of vertex coordinates is obtained. *////<summary>getpos</summary>///<param name = "U" type= "float" > segments on the circumference, The current segment occupies the total length ofThe distance of the point. </param>///<param name = "In_p" type= "float" >p\q: Valid for knot (nodal) Form, control the number of laps of the curve path, p determines the parameters in the vertical direction. </param >///<param name = "In_q" type= "float" >p\q: Valid for knot (nodal) Form, control the number of laps of the curve path, Q determines the parameters of the horizontal direction. </param>///<param Name = "radius" type= "float" > Ring junction RADIUS </param>///<param name = "Heightscale" type= "float" > Zoom on the ring junction height. </ Param>function getPos (U, in_q, in_p, radius, heightscale) {var cu = Math.Cos (u); var su = Math.sin (u); var quoverp = In_q/in_p * U;var cs = Math.Cos (QUOVERP); var tx = Radius * (2 + CS) * 0.5 * Cu;var ty = radius * (2 + CS) * Su * 0.5;var TZ = Heightscale * radius * Math.sin (QUOVERP) * 0.5;return new three. Vector3 (TX, Ty, TZ);}};/ The following is a method property definition for the Torusknotgeometry object, inherited from the Geometry object. ************* /three. Torusknotgeometry.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/torusknotgeometry.js file in the three.js source file.
More updates in: Https://github.com/omni360/three.js.sourcecode
Three.js Source Note (83) Extras/geometries/torusknotgeometry.js