提交 a65dd861 编写于 作者: M Mr.doob

Sprite: Removed geometry.

上级 309aa386
......@@ -339,32 +339,40 @@ THREE.Projector = function () {
_renderData.objects.length = 0;
_renderData.lights.length = 0;
function addObject( object ) {
_object = getNextObjectInPool();
_object.id = object.id;
_object.object = object;
_vector3.setFromMatrixPosition( object.matrixWorld );
_vector3.applyProjection( _viewProjectionMatrix );
_object.z = _vector3.z;
_object.renderOrder = object.renderOrder;
_renderData.objects.push( _object );
}
scene.traverseVisible( function ( object ) {
if ( object instanceof THREE.Light ) {
_renderData.lights.push( object );
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Sprite ) {
var material = object.material;
if ( material.visible === false ) return;
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line ) {
if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
if ( object.material.visible === false ) return;
if ( object.frustumCulled === true && _frustum.intersectsObject( object ) === false ) return;
_object = getNextObjectInPool();
_object.id = object.id;
_object.object = object;
addObject( object );
_vector3.setFromMatrixPosition( object.matrixWorld );
_vector3.applyProjection( _viewProjectionMatrix );
_object.z = _vector3.z;
_object.renderOrder = object.renderOrder;
} else if ( object instanceof THREE.Sprite ) {
_renderData.objects.push( _object );
if ( object.material.visible === false ) return;
if ( object.frustumCulled === true && _frustum.intersectsSprite( object ) === false ) return;
}
addObject( object );
}
......
......@@ -86,10 +86,27 @@ THREE.Frustum.prototype = {
var geometry = object.geometry;
if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
if ( geometry.boundingSphere === null )
geometry.computeBoundingSphere();
sphere.copy( geometry.boundingSphere );
sphere.applyMatrix4( object.matrixWorld );
sphere.copy( geometry.boundingSphere )
.applyMatrix4( object.matrixWorld );
return this.intersectsSphere( sphere );
};
}(),
intersectsSprite: function () {
var sphere = new THREE.Sphere();
return function ( sprite ) {
sphere.center.set( 0, 0, 0 );
sphere.radius = 0.7071067811865476;
sphere.applyMatrix4( sprite.matrixWorld );
return this.intersectsSphere( sphere );
......
......@@ -3,29 +3,15 @@
* @author alteredq / http://alteredqualia.com/
*/
THREE.Sprite = ( function () {
THREE.Sprite = function ( material ) {
var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
THREE.Object3D.call( this );
var geometry = new THREE.BufferGeometry();
geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
this.type = 'Sprite';
return function Sprite( material ) {
this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
THREE.Object3D.call( this );
this.type = 'Sprite';
this.geometry = geometry;
this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
};
} )();
};
THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
THREE.Sprite.prototype.constructor = THREE.Sprite;
......
......@@ -1356,6 +1356,8 @@ THREE.WebGLRenderer = function ( parameters ) {
}
// TODO Duplicated code (Frustum)
function isObjectViewable( object ) {
var geometry = object.geometry;
......@@ -1363,9 +1365,24 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( geometry.boundingSphere === null )
geometry.computeBoundingSphere();
var sphere = _sphere.
copy( geometry.boundingSphere ).
applyMatrix4( object.matrixWorld );
_sphere.copy( geometry.boundingSphere ).
applyMatrix4( object.matrixWorld );
return isSphereViewable( _sphere );
}
function isSpriteViewable( sprite ) {
_sphere.center.set( 0, 0, 0 );
_sphere.radius = 0.7071067811865476;
_sphere.applyMatrix4( sprite.matrixWorld );
return isSphereViewable( _sphere );
}
function isSphereViewable( sphere ) {
if ( ! _frustum.intersectsSphere( sphere ) ) return false;
......@@ -1402,7 +1419,7 @@ THREE.WebGLRenderer = function ( parameters ) {
} else if ( object instanceof THREE.Sprite ) {
if ( object.frustumCulled === false || isObjectViewable( object ) === true ) {
if ( object.frustumCulled === false || isSpriteViewable( object ) === true ) {
sprites.push( object );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册