Three.js Source Note (84) extras/geometries/parametricgeometry.js

Source: Internet
Author: User
Tags diff

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

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


/** * @author zz85/https://github.com/zz85 * Parametric surfaces Geometry * Based on the brilliant article by @prideout HTTP://PRIDEOUT.NET/BLOG/?P=44 * * New three. Parametricgeometry (Parametricfunction, usegments, ysegements); * *//*///parametricgeometry is used to create a geometry within a three-dimensional space through the definition of the parameter func. With this object, all the collections you want, play your math talent.//////usage://var func = function ( U,V) {///var point = new three. Vector3 ();///point.x = + math.cos (u);///point.y = + Math.sin (v);///return point;///};///var geometry = new THR Ee. Parametricgeometry (func,8,8);///var material = new three. Meshbasicmaterial ({color:0x00ff00});///var param = new three. Mesh (geometry,material);////Scene.add (param); *////<summary>parametricgeometry</summary>///<param Name = "Func" type= "Funciton" > function function, must accept parameter u,v, return vector3</param>///<param name = "slices" type= "int" > The number of subdivision segments in the u direction </param>///<param name = "Stacks" type= "int" >v the number of segments in the direction of </param>three. Parametricgeometry = function (func, slices, stACKs) {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 parametricgeometry to use. var verts = this.vertices; var faces = This.faces;var Uvs = this.facevertexuvs[0];var i, IL, J, P;var u, v;var stackcount = stacks + 1;var Slicecou NT = slices + 1;//calculates vertex data and presses into vertices array. for (i = 0; I <= stacks; i + +) {v = i/stacks;for (j = 0; J <= Slices; j + +) {u = j/slices;p = func (U, v); Verts.push (P);}} var A, B, C, D;var UVA, UVB, UVC, uvd;//compute triangular faces, and map uv.for (i = 0; i < stacks; I + +) {for (j = 0; J < slices; J + +) {a = i * slicecount + j;b = i * slicecount + j + 1;c = (i + 1) * Slicecount + j + 1;d = (i + 1) * Slicecount + J;uva = n EW three. Vector2 (J/slices, i/stacks); UVB = new three. Vector2 ((j + 1)/slices, i/stacks), UVC = new three. Vector2 ((j + 1)/slices, (i + 1)/stacks); UVD = new three. Vector2 (J/slices, (i + 1)/stacks); Faces.push (new three. Face3 (A, B, D)); Uvs.push ([UVA, UVB, UVD]); Faces.push (new three. Face3 (b, C, d)); Uvs.push ([Uvb.clone (), UVC, Uvd.clone ()]);}} Console.log (this);//Magic bullet//var diff = this.mergevertices ();//Console.log (' Removed ', diff, ' vertices by Merg ing '); this.computefacenormals ();//Calculates the normals of the Face This.computevertexnormals ();//calculates vertex normals};/******************************* The following is a method property definition for the Parametricgeometry object, inherited from the Geometry object. ******************************************* /three. Parametricgeometry.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/parametricgeometry.js file in the three.js source file.

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

Three.js Source Note (84) extras/geometries/parametricgeometry.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.