Three. js source code comments (17th) objects/PointCloud. js, pointcloud

Source: Internet
Author: User

Three. js source code comments (17th) objects/PointCloud. js, pointcloud

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 objects/PointCloud. JS file in the THREE. js source code file.

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


/*** @ Author alteredq/http://alteredqualia.com/* // PointCloud point cloud object, in the scene easily change a large number of point genie object size, location and other attributes. * //// <summary> PointCloud </summary> /// <param name = "geometry" type = "THREE. geometry "> point set in the point cloud object of the Geometry 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 the call method of the Object3D object and hand over the method originally belonging to Object3D to the current object PointCloud for use. this. geometry = geometry! = Undefined? Geometry: new THREE. Geometry (); // assign the geometry parameter to the geometry attribute of the mesh object. this. material = material! = Undefined? Material: new THREE. pointCloudMaterial ({color: Math. random () * 0 xffffff}); // assign the material parameter to the material attribute of the PointCloud object. If the material parameter is not passed, a random color material is created, assigned to the current PointCloud object this. sortparticipant = false; // set whether to sort particles ?? // TODO .}; /*************************************** * ************ the method attribute definition of the PointCloud object is as follows, 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 (raycaster parameter. raycaster. intersectObject calls this method. It is mainly used for collision detection. // It is often used when you select an object in a scenario. It is used to determine whether the current mouse matches the object and select an object. /// NOTE: The intersects parameter in the raycast method is used to store the set of intersections. The format is as follows: // 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 "> Set of vertex attributes </param> /// <returns type = "ObjectArray"> THREE. pointCloud. prototype. raycast = (function () {var inverseMatrix = new THREE. matrix4 (); // declare a 4x4 matrix to place the inverse matrix var ray = new THREE. ray (); // declare the 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 whether the rays collide with the point cloud elements. var testPoint = function (point, index) {var rayPointDistance = ray. distanceToPoint (point); if (rayPointDistance <localThreshold) {var intersectPoint = ray. closestPoin TToPoint (point); intersectPoint. applyMatrix4 (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 a BufferGeometry object if (geometry instanceof THREE. bufferGeometry) {var attributes = geometry. attributes; var po Sitions = attributes. position. array; // The elements of pointCloud objects in three data formats are detected. 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, );}}} else {var pointCount = positions. length/3; for (var I = 0; I <pointCount; I ++) {position. set (positions [3 * I], positions [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 to clone a PointCloud point cloud object. * //// <summary> clone </summary> /// <param name = "object" type = "PointCloud"> receives the 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. sortparticipant = this. sortparticipant; THREE. object3D. prototype. clone. call (this, object); // inherit the Object3D clone method return object; // return the cloned PointCloud object}; // Backwards compatibility is backward compatible, and the particle system replaces the point cloud object. usage and THREE. pointCloud objects are the same. THREE. particle System = function (geometry, material) {console. warn ('Three. particle System has been renamed to THREE. pointCloud. '); return new THREE. pointCloud (geometry, material );};


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 objects/PointCloud. JS file in the THREE. js source code file.

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

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.