Three. js source code annotation (14th) extras/geometries/ParametricGeometry. 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/ParametricGeometry. JS file in the THREE. js source code 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 generate a ry by defining the parameter func in a 3D space. with this object, you can bring your mathematical talents into full use as a collection of all the things you want. //// usage: // var func = function (u, v) {// var point = new THREE. vector3 (); // point. x = 100 + Math. cos (u); // point. y = 100 + Math. sin (v); // return point; //}; // var geometry = new THREE. 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, the u, v, returns Vector3 </param> /// <param name = "slices" type = "int"> Number of segments in the u direction </param> /// <param name = "stacks" type = "int"> Number of segments in the v direction </param> THREE. parametricGeometry = function (func, slices, stacks) {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 ParametricGeometry for 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 sliceCount = slices + 1; // calculate vertex data, press into the 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 ultraviolet a, ultraviolet B, uvc, uvd; // calculate the triangle surface and texture 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; UV = new THREE. vector2 (j/slices, I/stacks); ultraviolet B = 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 ([ultraviolet A, ultraviolet B, uvd]); faces. push (new THREE. face3 (B, c, d); uvs. push ([ultraviolet B. clone (), uvc, uvd. clone ()]) ;}// console. log (this); // magic bullet // var diff = this. mergeVertices (); // console. log ('removed', diff, 'vertices by merging '); this. computeFaceNormals (); // calculate the surface normal this. computeVertexNormals (); // calculate the vertex normal }; /*************************************** * ************ the method attribute definition of the ParametricGeometry object is as follows, it inherits from the Geometry object. **************************************** * *********/THREE. parametricGeometry. 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/ParametricGeometry. JS file in the THREE. js source code file.
More updates in: https://github.com/omni360/three.js.sourcecode