Three.js Source Note (60) objects/line.js

Source: Internet
Author: User
Tags polyline

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

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


/** * @author mrdoob/http://mrdoob.com/*//*///line object, create a line, or a group of lines.//usage: var geometry = new three. Geometry ();//Create Geometry object//var material = new three. Linebasicmaterial ({color:0xffff00});//Create material object, there is a material object specifically for the line object linebasicmaterial.///Geometry.verteces.push ( New three. Vector3 ( -10,0,0),//Add verteces vertex data///new three for Geometry objects. Vector3 (0,10,0),///new three. Vector3 (10,0,0)////var line = new three. Mesh (geometry, Material,three. Linestrip);//create a line of material material, type Three.linestrip (non-closed polyline) through geometry vertex data.//Scene.add (line); Add lines to the scene. *////<summary>line</summary>///<param name = "Geometry" type= "three. Geometry ">geometry object (frame of lantern) </param>///<param name =" Material "type=" three. Material ">material object (Material object) </param>///<param name =" type "type=" line type constant "> line type constant, with unclosed polyline (three. Linestrip), multiple sets of two-vertex segments (three. linepieces) </param>///<returns type= "Mesh" > Return to Line Object </returns>three. line = function (geometry, material, type) {three. Object3d.call (this);//Call OThe call method of the Bject3d object, the method that originally belongs to Object3d is given to the current object line to use. This.geometry = Geometry!== undefined? Geometry:new three. Geometry ();//Assign the parameter Geometry to the Geometry property of the Line object this.material = material!== undefined? Material:new three. Linebasicmaterial ({color:Math.random () * 0XFFFFFF}),//assigns the parameter material to the material property of the line object and creates a random color material if the material parameter is not passed , assign to the current mesh object This.type = (type!== undefined)? Type:three. linestrip;//assigns the parameter type to the Type property of the line pair, and if the type parameter is not passed, the default is initialized to the Three.linestrip type.}; Three. Linestrip = 0;//non-closed polyline three.linepieces = 1;//Multiple sets of double-vertex segments//todo: three.lineloop//closed polyline is missing./******************************** The following is the method property definition for the line object, inherited from Object3d**************************************************/three. Line.prototype = Object.create (three. Object3d.prototype); The/*///raycast method is used to obtain the intersection of the current object and the ray (parameter raycaster). Raycaster.intersectobject calls this method. Mainly used for collision detection,///When selecting objects in the scene, it is often used to determine whether the current mouse is coincident with the object to select the object.///Note:raycast method The parameter intersects parameter is used to store the collection of intersections, in the following format:// Intersects.push ({//////distance:distance,///point:intersectionpoint,///face:null,///faceindex:null,///object:this//////});///*////<summary>raycast</summary>///< param name = "Raycaster" type= "three. Raycaster "> Ray object </param>///<param name =" intersects "type=" Objectarray "> Intersection of Attribute Collection </param>/// <returns type= the attribute collection </returns>three for the "Objectarray" > Intersection. Line.prototype.raycast = (function () {var Inversematrix = new three. Matrix4 (); var ray = new three. Ray (); var sphere = new three. Sphere (); return function (Raycaster, intersects) {var precision = precision factor of intersection of raycaster.lineprecision;//Ray and line object. var precisionsq = precision * precision;//precision factor squared var geometry = this.geometry;if (Geometry.boundingsphere = = = null) geom Etry.computeboundingsphere ();//Ensure that the Boundingsphere property is not null//Checking boundingsphere distance to ray// Check the sphere bounds of the segment to the distance of the Ray Sphere.copy (Geometry.boundingsphere); sphere.applymatrix4 (This.matrixworld); if (    Raycaster.ray.isIntersectionSphere (Sphere) = = = False) {//If the sphere bounds of the geometry and the ray do not want to be delivered to return; Return to}inversematrix.getinverse ( This.matrixworld);//Gets the inverse matrix ray.copy (Raycaster.ray) of the This.matrixworld property of the current object. APPLYMATRIX4 (Inversematrix);// Gives the origin of the Ray object, the direction, multiplied by the inverse matrix,/* if (geometry instanceof three. Buffergeometry) {} else */if (geometry instanceof three. Geometry) {var vertices = Geometry.vertices;var Nbvertices = Vertices.length;var intersegment = new three. Vector3 (); var interray = new three. Vector3 (); var step = This.type = = = Three. Linestrip? 1:2;for (var i = 0; i < nbVertices-1; i = i + step) {//If it is a non-closed polyline, each argument +1, if it is multiple sets of two-vertex segments, the argument is +2var distsq = Ray.distan Cesqtosegment (vertices[i], vertices[i + 1], Interray, intersegment);//distancesqtosegment method will return parameter vertices[i], vert ices[i + 1] The minimum distance from the line segment to the current Ray. Interray, Intersegment, respectively, for storing perpendicular if (distsq > Precisionsq) on the Ray and on the online segment continue;//if the minimum distance is greater than the fine Degree factor, exiting the loop. var distance = Ray.origin.distanceTo (Interray);//The distance from the origin of the ray to the perpendicular of the line segment. if (Distance < Raycaster.near | | distanc E > Raycaster.far) continue;//If the distance is less than the near end of the ray, or is greater than the far side of the Ray, jump out of the loop Intersects.push ({//will intersect the object, vertex index, distance, intersection save tointersects attribute array in distance:distance,//distance//What does we want? Intersection point on the ray or on the segment?? What we want, the intersection on the ray or on the line//point:raycaster.ray.at (distance), if you want to on the ray, that will raycaster.ray.at (distance) assignment to Pointpoint: Intersegment.clone (). APPLYMATRIX4 (This.matrixworld),//If you want to get the intersection in the position of the segment, Intersegment.clone (). APPLYMATRIX4 ( This.matrixworld) Assign to the index object:this//object in the attribute array where the pointface:null,//polygon faceindex:null,//Face});}};} ());/*clone method///clone method clones a line mesh object. *////<summary>clone</summary>///<param name = "Object" Type= " Object3d "> receives the cloned Object3d object </param>///<returns type=" Ray "> returns the line Mesh object. </returns>three. Line.prototype.clone = function (object) {if (object = = = undefined) object = new three. Line (This.geometry, this.material, This.type); Three. Object3D.prototype.clone.call (this, object);//Inherits Object3d's Clone method return object;//returns mesh Mesh object.};


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

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

Three.js Source Note (60) objects/line.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.