computeBoundingSphere method

void computeBoundingSphere()
override

Computes the bounding sphere of the skinned mesh, and updates {@link SkinnedMesh#boundingSphere}. The bounding sphere is automatically computed by the engine once when it is needed, e.g., for ray casting and view frustum culling. If the skinned mesh is animated, the bounding sphere should be recomputed per frame in order to reflect the current animation state.

Implementation

void computeBoundingSphere() {
		final geometry = this.geometry;

		if ( this.boundingSphere == null ) {
			this.boundingSphere = new BoundingSphere();
		}

		this.boundingSphere?.empty();

		final positionAttribute = geometry?.getAttributeFromString( 'position' );

		for (int i = 0; i < positionAttribute.count; i ++ ) {
			this.getVertexPosition( i, _vertex );
			this.boundingSphere?.expandByPoint( _vertex );
		}
	}