Three.js Source Note (82) Extras/geometries/ringgeometry.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/ringgeometry.js file in the three.js source file.

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


/** * @author Kaleb Murphy *//*///ringgeometry is used to create a two-dimensional torus object within a three-dimensional space.//////usage: var geometry = new three. Ringgeometry (1,5,32);///var material = new three. Meshbasicmaterial ({color:0x00ff00});///var Ring = new three. Mesh (geometry,material);///Scene.add (Ring); *////<summary>torusgeometry</summary>///<param name = " Innerradius "type=" float "> Torus inner circle radius, default initialized to 0</param>///<param name =" Outerradius "type=" float "> Torus outer Circle radius , the default is initialized to 50</param>///<param name = "Thetasegments" type= "int" > The number of subdivision segments on the torus circumference, which represents the roundness of the ring, the lowest is 3. The default value is 8</param>///<param name = "Phisegments" type= "int" > The number of segments in the circle to the outer circle of the torus, the lowest is 1. The default value is 8</param>///<param name = "Thetastart" type= "float" > The starting angle of the torus, which is initialized by default to 0</param>///<param name = "Thetalength" type= "float" > Torus circumference arc length, default initialized to Math.PI * 2</param>three. Ringgeometry = function (Innerradius, Outerradius, Thetasegments, Phisegments, Thetastart, thetalength) {THREE. Geometry.call (this);//Call method that calls the Geometry object, the method that originally belongs to GeometryGiven to the current object ringgeometry to use. Innerradius = Innerradius | | 0;//Circle radius within the torus, default initialized to 0outerRadius = Outerradius | | 50;//Circle radius, default initialized to 50thetaStart = Thetastart!== undefined? thetastart:0;//the starting angle of the torus, by default initialized to 0thetaLength = Thetalength!== undefined? ThetaLength:Math.PI * 2;//Circular arc length, default initialized to Math.PI * 2thetaSegments = thetasegments!== undefined? Math.max (3, thetasegments): The number of subdivision segments on the circumference of the 8;//torus, representing the roundness of the ring, the lowest is 3. The default value is 8phiSegments = phisegments!== undefined? Math.max (1, phisegments): The number of subdivision segments in the circle to the outer circle of the 8;//torus, the lowest is 1. The default value is 8var I, O, Uvs = [], radius = Innerradius, Radiusstep = ((Outerradius-innerradius)/phisegments);//compute vertex data, press into Ver  Tices Array. for (i = 0; i < phisegments + 1; i + +) {//Concentric circles inside ringfor (o = 0; o < thetasegments + 1; O + +) {//number of segments per circle circumference, var vertex = new three. Vector3 (); var segment = Thetastart + o/thetasegments * thetalength;vertex.x = Radius * Math.Cos (segment); vertex.y = RA Dius * Math.sin (segment); This.vertices.push (vertex); uVs.push (new three. Vector2 ((Vertex.x/outerradius + 1)/2, (Vertex.y/outerradius + 1)/2));} Radius + = Radiusstep;} var n = new three. Vector3 (0, 0, 1);//compute triangular face, and map uv.for (i = 0; i < phisegments; i + +) {//Concentric circles inside Ringvar thetasegm ent = i * (thetasegments + 1); for (o = 0; o < thetasegments; O + +) {//number of segments per circle circle of segments Var seg ment = o + Thetasegment;var v1 = Segment;var v2 = segment + thetasegments + 1;var v3 = segment + thetasegments + 2;THIS.FA Ces.push (new three. Face3 (v1, v2, v3, [N.clone (), N.clone (), N.clone ()])); this.facevertexuvs[0].push ([uvs[v1].clone (), uvs[v2].cl One (), uvs[v3].clone ()), V1 = SEGMENT;V2 = segment + thetasegments + 2;v3 = segment + 1;this.faces.push (new three. Face3 (v1, v2, v3, [N.clone (), N.clone (), N.clone ()])); this.facevertexuvs[0].push ([uvs[v1].clone (), uvs[v2].cl One (), uvs[v3].clone ()]);}} This.computefacenormals ();//Calculates the face's normal this.boundingsphere = new three. Sphere (NewThree. Vector3 (), RADIUS);//Calculate sphere boundary};/***************************************************** The following is the method property definition for the Ringgeometry object, Inherits from the Geometry object. **************************************************/three. Ringgeometry.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/ringgeometry.js file in the three.js source file.

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

Three.js Source Note (82) Extras/geometries/ringgeometry.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.