Three. js source code annotation (19th) extras/geometries/CircleGeometry. js, three. jsgeometries

Source: Internet
Author: User

Three. js source code annotation (19th) extras/geometries/CircleGeometry. 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/CircleGeometry. JS file in the THREE. js source code file.

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


/*** @ Author hughes * // CircleGeometry is used to create a circular object in a three-dimensional space, A circular object is a polygon object that is formed by splicing triangles specified by the segments parameter around the center of a circle. ///// usage: var radius = 5, segments = 32; // var geometry = new THREE. circleGeometry (radius, segments); // var material = new THREE. meshBasicMaterial ({color: 0x00ff00}); // var circle = new THREE. mesh (geometry, material); // scene. add (circle); * // <summary> CircleGeometry </summary> // <param name = "Radius" type = "float"> radius of a circular (polygon) object, the default value is 50. </param> // <param name = "segments" type = "int"> optional. The number of line segments (edges) of a circle (polygon ), the default value is 8 </param> /// <param name = "thetaStart" type = "int"> (optional) the starting point of the circle (polygon, the default value is 0 </param> /// <param name = "thetaLength" type = "int"> (optional) indicates the end point of the circle (polygon). The default value is Math. PI * 2 </param> THREE. circleGeometry = function (radius, segments, thetaStart, thetaLength) {THREE. geometry. call (this); this. parameters = {Radius: radius, segments: segments, thetaStart: thetaStart, thetaLength: thetaLength}; radius = radius | 50; // circle (polygon) radius. The default value is 50. segments = segments! = Undefined? Math. max (3, segments): 8; // number of segments in a circle or polygon. The minimum value is 3. If the segments attribute is not set, the value is initialized to 8. thetaStart = thetaStart! = Undefined? ThetaStart: 0; // the starting point of the circle or polygon. The default value is 0. thetaLength = thetaLength! = Undefined? ThetaLength: Math. PI * 2; // the end point of the circle (polygon). The default value is Math. PI * 2 // the following code generates uv coordinates and point information for the circle (polygon. var I, uvs = [], center = new THREE. vector3 (), centerUV = new THREE. vector2 (0.5, 0.5); this. vertices. push (center); uvs. push (centerUV); for (I = 0; I <= segments; I ++) {// traverse to form a circle (polygon) var vertex = new THREE. vector3 (); var segment = thetaStart + I/segments * thetaLength; // obtain the vertex angle that forms the circular (polygon) side or line segment. x = radius * Math. cos (segment); // calculate the x coordinate vertex Based on the radius and angle values. y = radius * Math. sin (segment); // calculate the y coordinate based on the radius and angle value. this. vertices. push (vertex); // Add to vertex array. uvs. push (new THREE. vector2 (vertex. x/radius + 1)/2, (vertex. y/radius + 1)/2); // Add the uvs coordinate information} var n = new THREE. vector3 (0, 0, 1); for (I = 1; I <= segments; I ++) {// traverse a circle (polygon) this. faces. push (new THREE. face3 (I, I + 1, 0, [n. clone (), n. clone (), n. clone ()]); // generate the triangle vertex index this. faceVertexUvs [0]. push ([uvs [I]. clone (), uvs [I + 1]. clone (), centerUV. clone ()]); // generate The uvs coordinates of the triangle surface in the same order as the vertex index of the triangle surface} this. computeFaceNormals (); // calculate the surface normal this. boundingSphere = new THREE. sphere (new THREE. vector3 (), radius); // generates the spherical boundary of the circular (polygon) object .}; /*************************************** * ************ the method attribute definition of the CircleGeometry object is as follows, it inherits from the Geometry object. **************************************** * *********/THREE. circleGeometry. 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/CircleGeometry. 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.