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

BufferGeometryLoader: CRLF to LF

上级 d0d0f68b
/** /**
* @author mrdoob / http://mrdoob.com/ * @author mrdoob / http://mrdoob.com/
*/ */
THREE.BufferGeometryLoader = function ( manager ) { THREE.BufferGeometryLoader = function ( manager ) {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
}; };
THREE.BufferGeometryLoader.prototype = { THREE.BufferGeometryLoader.prototype = {
constructor: THREE.BufferGeometryLoader, constructor: THREE.BufferGeometryLoader,
load: function ( url, onLoad, onProgress, onError ) { load: function ( url, onLoad, onProgress, onError ) {
var scope = this; var scope = this;
var loader = new THREE.XHRLoader( scope.manager ); var loader = new THREE.XHRLoader( scope.manager );
loader.load( url, function ( text ) { loader.load( url, function ( text ) {
onLoad( scope.parse( JSON.parse( text ) ) ); onLoad( scope.parse( JSON.parse( text ) ) );
}, onProgress, onError ); }, onProgress, onError );
}, },
parse: function ( json ) { parse: function ( json ) {
var geometry = new THREE.BufferGeometry(); var geometry = new THREE.BufferGeometry();
var index = json.data.index; var index = json.data.index;
if ( index !== undefined ) { if ( index !== undefined ) {
var typedArray = new self[ index.type ]( index.array ); var typedArray = new self[ index.type ]( index.array );
geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) ); geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
} }
var attributes = json.data.attributes; var attributes = json.data.attributes;
for ( var key in attributes ) { for ( var key in attributes ) {
var attribute = attributes[ key ]; var attribute = attributes[ key ];
var typedArray = new self[ attribute.type ]( attribute.array ); var typedArray = new self[ attribute.type ]( attribute.array );
geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) ); geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
} }
var groups = json.data.groups || json.data.drawcalls || json.data.offsets; var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
if ( groups !== undefined ) { if ( groups !== undefined ) {
for ( var i = 0, n = groups.length; i !== n; ++ i ) { for ( var i = 0, n = groups.length; i !== n; ++ i ) {
var group = groups[ i ]; var group = groups[ i ];
geometry.addGroup( group.start, group.count, group.materialIndex ); geometry.addGroup( group.start, group.count, group.materialIndex );
} }
} }
var boundingSphere = json.data.boundingSphere; var boundingSphere = json.data.boundingSphere;
if ( boundingSphere !== undefined ) { if ( boundingSphere !== undefined ) {
var center = new THREE.Vector3(); var center = new THREE.Vector3();
if ( boundingSphere.center !== undefined ) { if ( boundingSphere.center !== undefined ) {
center.fromArray( boundingSphere.center ); center.fromArray( boundingSphere.center );
} }
geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius ); geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
} }
return geometry; return geometry;
} }
}; };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册