three.jsソース注釈(六十七)objects/PointCloud.js


商域無疆(http://blog.csdn.net/omni360/)
本稿では、「署名-非商業用途-一貫性の維持」に従って、共通のプロトコルを作成します.
商域无疆- このブログは 敏捷な開発と移動と物連設備の研究:データ可視化、GOLANG、Html 5、WEB GL、THREE.JS、さもなくば、本ブログからの文章は転載あるいは再転載を拒否して、協力に感謝します.
私もちょうど学习を始めるので、多くの地方はきっと间违っています
以下のコードはTHREE.JSソースファイルのobjects/PointCloud.jsファイルの注釈である.
更新内容: https://github.com/omni360/three.js.sourcecode
/**
 * @author alteredq / http://alteredqualia.com/
 */

/*
///PointCloud    ,                   ,     .
*/
///PointCloud
///Geometry           
///PointCloudMaterial  (      )
///  Mesh  
THREE.PointCloud = function ( geometry, material ) {

	THREE.Object3D.call( this );	//  Object3D   call  ,     Object3D         PointCloud   .

	this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();	//	//   geometry   mesh   geometry  
	this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );		//   material   PointCloud   material  ,      material  ,         ,     PointCloud  

	this.sortParticles = false;	//        ??
								//TODO:sortParticles       ,       .

};
/*************************************************
****   PointCloud         ,   Object3D
**************************************************/
THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );

/*
///raycast             (  raycaster)   .raycaster.intersectObject       。           ,
///                ,                   .
/// NOTE:raycast     intersects           ,    
///	intersects.push( {
///
///				distance: distance,
///				point: intersectionPoint,
///				indices: [ a, b, c ],
///				face: null,
///				faceIndex: null,
///				object: this
///
///			} );
///
*////raycast
///    
///       
///       
THREE.PointCloud.prototype.raycast = ( function () {

	var inverseMatrix = new THREE.Matrix4();	//    4x4  ,       
	var ray = new THREE.Ray();			//        

	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();
		//                  .
		var testPoint = function ( point, index ) {

			var rayPointDistance = ray.distanceToPoint( point );

			if ( rayPointDistance < localThreshold ) {

				var intersectPoint = ray.closestPointToPoint( 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

				} );

			}

		};
		//  geometry   BufferGeometry  
		if ( geometry instanceof THREE.BufferGeometry ) {

			var attributes = geometry.attributes;
			var positions = attributes.position.array;
			//          pointCloud         .
			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 ],
						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  
///clone      PointCloud    .
*/
///clone
///     Object3D  
///  PointCloud  .	
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 );	//  Object3D clone  

	return object;	//     PointCloud  

};

// Backwards compatibility     ,           .   THREE.PointCloud    .

THREE.ParticleSystem = function ( geometry, material ) {

	console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
	return new THREE.PointCloud( geometry, material );

};

商域無疆(http://blog.csdn.net/omni360/)
本稿では、「署名-非商業用途-一貫性の維持」に従って、共通のプロトコルを作成します.
商域无疆- このブログは 敏捷な開発と移動と物連設備の研究:データ可視化、GOLANG、Html 5、WEB GL、THREE.JS、さもなくば、本ブログからの文章は転載あるいは再転載を拒否して、協力に感謝します.
以下のコードはTHREE.JSソースファイルのobjects/PointCloud.jsファイルの注釈である.
更新内容: https://github.com/omni360/three.js.sourcecode