Three. js source code annotation (719th) extras/geometries/TorusGeometry. js, three. jsgeometries

Source: Internet
Author: User

Three. js source code annotation (719th) extras/geometries/TorusGeometry. js, three. jsgeometries

Wuji (http://blog.csdn.net/omni360)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.


I also just started learning. Sorry for the errors in many places.

The following code is a comment on the extras/geometries/TorusGeometry. JS file in the THREE. js source code 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 ring object in 3D 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"> ring radius </param> /// <param name = "tube" type = "float"> bend radius </param> // <param name = "radialSegments" type = "int"> subdivision on the circumference of the ring number of line segments </param> /// <param name = "tubularSegments" type = "int"> Number of segments on the circumference of a ring bend </param> // <param name = "arc" type = "float"> circle arc length, math is initialized by default. PI * 2 </param> THREE. torusGeometry = function (radius, tube, radialSegments, tubularSegments, arc) {THREE. geometry. call (this); // call the call method of the Geometry object and hand over the method originally belonging to the Geometry to the current object TorusGeometry for use. this. parameters = {radius: radius, // Ring Body radius tube: tube, // ring bend radius radialSegments: radialSegments, // number of segments on the Ring Body circumference tubularSegments: tubularSegments, // number of segments on the circumference of a ring bend. arc: arc // The arc Length of the circumference of the Ring Body. The default value is Math. PI * 2}; radius = radius | 100; // circle body radius. If the parameter is not set, the initialization is 100. tube = tube | 40; // radius of the ring bend. If the parameter is not set, the value is initialized to 40. radialSegments = radialSegments | 8; // number of segments on the circumference of the ring. If the parameter is not set, the value is initialized to 8. tubularSegments = tubularSegments | 6; // number of segments in the circumference of a ring bend. If the parameter is not set, initialize it to 6.arc = arc | Math. PI * 2; // The circumference arc length of the ring, initialized as Math by default. PI * 2var center = new THREE. vector3 (), uvs = [], normals = []; // calculate vertex data and press it into the 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); center. 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 () ;}/// calculate the triangle surface and texture 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. faceVertexUvs [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. faceVertexUvs [0]. push ([uvs [B]. clone (), uvs [c]. clone (), uvs [d]. clone ()]) ;}} this. computeFaceNormals (); // calculates the plane's normal }; /*************************************** * ************ the method attribute definition of the TorusGeometry object is as follows, it inherits from the Geometry object. **************************************** * *********/THREE. torusGeometry. prototype = Object. create (THREE. geometry. prototype );


Wuji (http://blog.csdn.net/omni360)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.


The following code is a comment on the extras/geometries/TorusGeometry. JS file in the THREE. js source code file.

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

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.