123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- import { Uint16BufferAttribute, Uint32BufferAttribute } from '../../core/BufferAttribute';
- import { arrayMax } from '../../utils';
- import { WebGLGeometries } from './WebGLGeometries';
- function WebGLObjects( gl, attributes, properties, info ) {
- var geometries = new WebGLGeometries( gl, attributes, properties, info );
- //
- function update( object ) {
- // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
- var geometry = geometries.get( object );
- if ( object.geometry.isGeometry ) {
- geometry.updateFromObject( object );
- }
- var index = geometry.index;
- var geometryAttributes = geometry.attributes;
- if ( index !== null ) {
- attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
- }
- for ( var name in geometryAttributes ) {
- attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
- }
- // morph targets
- var morphAttributes = geometry.morphAttributes;
- for ( var name in morphAttributes ) {
- var array = morphAttributes[ name ];
- for ( var i = 0, l = array.length; i < l; i ++ ) {
- attributes.update( array[ i ], gl.ARRAY_BUFFER );
- }
- }
- return geometry;
- }
- function getWireframeAttribute( geometry ) {
- var property = properties.get( geometry );
- if ( property.wireframe !== undefined ) {
- return property.wireframe;
- }
- var indices = [];
- var geometryIndex = geometry.index;
- var geometryAttributes = geometry.attributes;
- // console.time( 'wireframe' );
- if ( geometryIndex !== null ) {
- var array = geometryIndex.array;
- for ( var i = 0, l = array.length; i < l; i += 3 ) {
- var a = array[ i + 0 ];
- var b = array[ i + 1 ];
- var c = array[ i + 2 ];
- indices.push( a, b, b, c, c, a );
- }
- } else {
- var array = geometryAttributes.position.array;
- for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
- var a = i + 0;
- var b = i + 1;
- var c = i + 2;
- indices.push( a, b, b, c, c, a );
- }
- }
- // console.timeEnd( 'wireframe' );
- var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
- attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
- property.wireframe = attribute;
- return attribute;
- }
- return {
- getWireframeAttribute: getWireframeAttribute,
- update: update
- };
- }
- export { WebGLObjects };
|