Three.js Source Note (67) Objects/pointcloud.js

Source: Internet
Author: User

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

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


/** * @author alteredq/http://alteredqualia.com/*//*///pointcloud Point Cloud Object, in the scene to easily change a large number of point sprite object size, position and other properties. *////<summary >pointcloud</summary>///<param name = "Geometry" type= "three. Geometry the point collection in the >geometry object Point cloud object </param>///<param name = "Material" type= "three". Pointcloudmaterial ">pointcloudmaterial object (Point cloud Material object) </param>///<returns type=" Pointcloud "> Return Mesh Object </returns>three. Pointcloud = function (geometry, material) {three. Object3d.call (this);//Call method of the Object3d object is called, the method that originally belongs to Object3d is given to the current object Pointcloud to use. This.geometry = Geometry!== Undefined? Geometry:new three. Geometry ();////assigns the parameter Geometry to the Geometry property of the Mesh object this.material = material!== undefined? Material:new three. Pointcloudmaterial ({color:Math.random () * 0XFFFFFF}),//assigns the parameter material to the material property of the Pointcloud object, if no material parameter is passed, A random color material is created, assigned to the current Pointcloud object this.sortparticles = false;//set to sort particles?? The Todo:sortparticles attribute is not understood and has time to come back for processing.};/ Here are the methods of the Pointcloud objectThe definition of sex, inherited from Object3d**************************************************/three. Pointcloud.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,///indices: [A, B, C],///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. PointCloud.prototype.raycast = (function () {var Inversematrix = new three. MATRIX4 ();//declares a 4x4 matrix, which is used to place the inverse matrix var ray = new three. Ray ();//Declare Global Ray object return function (Raycaster, intersects) {var object = This;var geometry = Object.geometry;var threshold = Raycaster.params.PointCloud.threshold;inversematrix.getinverse (This.matrixworld); Ray.copy (Raycaster.ray). APPLYMATRIX4 (InverseMatrix) if (Geometry.boundingbox!== null) {if (Ray.isintersectionbox (geometry.boundingbox) = = = False) {return;}} var localthreshold = threshold/((this.scale.x + this.scale.y + this.scale.z)/3); var position = new three. Vector3 ();//Check the specific implementation of the ray and point cloud element collision. var testpoint = function (point, index) {var raypointdistance = Ray.distancetopoint (poin t); if (Raypointdistance < localthreshold) {var intersectpoint = Ray.closestpointtopoint (point); intersectpoint.appl YMATRIX4 (Object.matrixworld), var distance = Raycaster.ray.origin.distanceTo (intersectpoint); Intersects.push ({ Distance:distance,distancetoray:raypointdistance,point:intersectpoint.clone (), Index:index,face:null,object: Object});}};/ /If the Geometry object is an Buffergeometry object if (geometry instanceof three. Buffergeometry) {var attributes = Geometry.attributes;var positions = attributes.position.array;//face three data formats PoinDetects the elements of the Tcloud object. if (attributes.index!== undefined) {var indices = Attributes.index.array;var offsets = geometry.offsets if (offsets.length = = = 0) {var offset = {Start:0,count:indices.length,index:0};offsets = [offset];} for (var oi = 0, ol = offsets.length; oi < ol; ++oi) {var start = offsets[Oi].start;var count = offsets[Oi].count var index = offsets[Oi].index;for (var i = start, il = start + count; i < il; i + +) {var a = index + indices[i]; Position.set (positions[A * 3],positions[A * 3 + 1],positions[A * 3 + 2]); TestPoint (position, a);}} else {var pointcount = positions.length/3;for (var i = 0; i < pointcount; i + +) {Position.set (positions[3 * I],po sitions[3 * i + 1],positions[3 * i + 2]); TestPoint (position, i);}} else {var vertices = this.geometry.vertices;for (var i = 0; i < vertices.length; i + +) {TestPoint (vertices[i], i) ;}}};} ());/*clone method///clone method clones a Pointcloud point cloud object. *////<summary>clone</summary>///<paraM name = "Object" type= "Pointcloud" > Receive cloned Object3d object </param>///<returns type= "Pointcloud" > Returns the Pointcloud object. </returns>three. PointCloud.prototype.clone = function (object) {if (object = = = undefined) object = new three. Pointcloud (This.geometry, this.material); object.sortparticles = This.sortparticles; Three. Object3D.prototype.clone.call (this, object);//Inherits Object3d's Clone method return object;//returns the cloned Pointcloud object};//backwards Compatibility backward compatible, particle system bai point cloud object substitution. Use the same as Three.pointcloud objects. Three.particlesystem = function (geometry, material) { Console.warn (' three. Particlesystem have been renamed to three. Pointcloud. '); return new three. Pointcloud (geometry, material);};


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

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

Three.js Source Note (67) Objects/pointcloud.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.