Three.js Source Note (77) Extras/geometries/lathegeometry.js

Source: Internet
Author: User
Tags sin

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/lathegeometry.js file in the three.js source file.

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


/** * @author astrodud/http://astrodud.isgreat.org/* @author zz85/https://github.com/zz85 * @author bhouston/http:/ The/exocortex.com *//*///lathegeometry class creates rotational geometry from a section vertex array (points).//////usage:///var points = [];///for (var i = 0; i <; I + +) {///points.push (new three). Vector3 (Math.sin (i * 0.2) * + 0, (i-5) * 2));///}///var geometry = new three. Lathegeometry (points);///var material = new three. Meshbasicmaterial ({color:0xffff00});///var lathe = new three. Mesh (geometry, material);///scene.add (lathe); *////<summary>lathegeometry</summary>///<param name = "Points" type= "float" > Rotating body section vertex array </param>///<param name = "segments" type= "int" > Subdivision segment number of rotation circle of rotating body </ Param>///<param name = "Phistart" type= "float" > The starting point of the rotation body </param>///<param name = "Philength" type= " Float "> Arc length </param>//points-to Create a closed torus, one must use a set of points//create a closed torus,//Like so : [A, B, C, D, a], see first was the same as last.For example [A,b,c,d,a], the first vertex must be the same as the last vertex.//segments-the number of circumference segments to create//rotation circle segments//phistart-th E starting Radian//rotation section starting point, default initialization 0.//philength-the radian (0 to 2*pi) range of the lathed section//2*pi is a Clos Ed lathe, less than 2PI is a portion. The arc length of the rotation is initialized to 2*PI by default. Three. Lathegeometry = function (points, segments, Phistart, Philength) {three. Geometry.call (this); segments = Segments | | 12;phistart = Phistart | | 0;philength = Philength | | 2 * Math.pi;var Inversepointlength = 1.0/(points.length-1); var inversesegments = 1.0/segments;//The rotation body section vertex array is rotated to get all The array of vertices. for (var i = 0, il = segments; i <= il; i + +) {var phi = Phistart + i * inversesegments * philength;var c = Mat  H.cos (phi), S = Math.sin (phi), for (var j = 0, JL = points.length; J < JL; J + +) {var pt = points[J];var vertex = New three. Vector3 (); vertex.x = c * pt.x-s * pt.y;vertex.y = s * pt.x + c * pt.y;vertex.z = Pt.z;this.vertices.push (vertex);}} var np = points.length;//willAll vertex calculations generate triangular polygons and calculate the uvfor of the triangular polygon map (var i = 0, il = segments; i < il; i + +) {for (var j = 0, JL = points.length-1; J &lt ; Jl J + +) {var base = j + NP * I;var a = Base;var B = base + Np;var c = base + 1 + np;var D = base + 1;var u0 = i * Inversese  Gments;var V0 = J * Inversepointlength;var u1 = u0 + Inversesegments;var v1 = v0 + inversepointlength;this.faces.push (new Three. Face3 (A, B, D)); this.facevertexuvs[0].push ([new three. Vector2 (u0, V0), new three. Vector2 (U1, V0), new three. Vector2 (u0, v1)]); This.faces.push (new three. Face3 (b, C, D)); this.facevertexuvs[0].push ([new three. Vector2 (U1, V0), new three. Vector2 (U1, v1), new three. Vector2 (u0, v1)]);}} This.mergevertices ();//merge vertices, delete extra vertices this.computefacenormals ();//calculate normals of triangular faces this.computevertexnormals ();//calculate normals of vertices };/***************************************************** The following is the method property definition for the Lathegeometry object, inherited from the Geometry object. ************** /three. Lathegeometry.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/lathegeometry.js file in the three.js source file.

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

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