ObjectLoader.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. import {
  2. UVMapping,
  3. CubeReflectionMapping,
  4. CubeRefractionMapping,
  5. EquirectangularReflectionMapping,
  6. EquirectangularRefractionMapping,
  7. CubeUVReflectionMapping,
  8. CubeUVRefractionMapping,
  9. RepeatWrapping,
  10. ClampToEdgeWrapping,
  11. MirroredRepeatWrapping,
  12. NearestFilter,
  13. NearestMipmapNearestFilter,
  14. NearestMipmapLinearFilter,
  15. LinearFilter,
  16. LinearMipmapNearestFilter,
  17. LinearMipmapLinearFilter
  18. } from '../constants.js';
  19. import { BufferAttribute } from '../core/BufferAttribute.js';
  20. import { Color } from '../math/Color.js';
  21. import { Object3D } from '../core/Object3D.js';
  22. import { Group } from '../objects/Group.js';
  23. import { InstancedMesh } from '../objects/InstancedMesh.js';
  24. import { Sprite } from '../objects/Sprite.js';
  25. import { Points } from '../objects/Points.js';
  26. import { Line } from '../objects/Line.js';
  27. import { LineLoop } from '../objects/LineLoop.js';
  28. import { LineSegments } from '../objects/LineSegments.js';
  29. import { LOD } from '../objects/LOD.js';
  30. import { Mesh } from '../objects/Mesh.js';
  31. import { Shape } from '../extras/core/Shape.js';
  32. import { Fog } from '../scenes/Fog.js';
  33. import { FogExp2 } from '../scenes/FogExp2.js';
  34. import { HemisphereLight } from '../lights/HemisphereLight.js';
  35. import { SpotLight } from '../lights/SpotLight.js';
  36. import { PointLight } from '../lights/PointLight.js';
  37. import { DirectionalLight } from '../lights/DirectionalLight.js';
  38. import { AmbientLight } from '../lights/AmbientLight.js';
  39. import { RectAreaLight } from '../lights/RectAreaLight.js';
  40. import { LightProbe } from '../lights/LightProbe.js';
  41. import { OrthographicCamera } from '../cameras/OrthographicCamera.js';
  42. import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
  43. import { Scene } from '../scenes/Scene.js';
  44. import { CubeTexture } from '../textures/CubeTexture.js';
  45. import { Texture } from '../textures/Texture.js';
  46. import { ImageLoader } from './ImageLoader.js';
  47. import { LoadingManager } from './LoadingManager.js';
  48. import { AnimationClip } from '../animation/AnimationClip.js';
  49. import { MaterialLoader } from './MaterialLoader.js';
  50. import { LoaderUtils } from './LoaderUtils.js';
  51. import { BufferGeometryLoader } from './BufferGeometryLoader.js';
  52. import { Loader } from './Loader.js';
  53. import { FileLoader } from './FileLoader.js';
  54. import * as Geometries from '../geometries/Geometries.js';
  55. import * as Curves from '../extras/curves/Curves.js';
  56. class ObjectLoader extends Loader {
  57. constructor( manager ) {
  58. super( manager );
  59. }
  60. load( url, onLoad, onProgress, onError ) {
  61. const scope = this;
  62. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  63. this.resourcePath = this.resourcePath || path;
  64. const loader = new FileLoader( scope.manager );
  65. loader.setPath( this.path );
  66. loader.setRequestHeader( this.requestHeader );
  67. loader.load( url, function ( text ) {
  68. let json = null;
  69. try {
  70. json = JSON.parse( text );
  71. } catch ( error ) {
  72. if ( onError !== undefined ) onError( error );
  73. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  74. return;
  75. }
  76. const metadata = json.metadata;
  77. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  78. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  79. return;
  80. }
  81. scope.parse( json, onLoad );
  82. }, onProgress, onError );
  83. }
  84. parse( json, onLoad ) {
  85. const shapes = this.parseShape( json.shapes );
  86. const geometries = this.parseGeometries( json.geometries, shapes );
  87. const images = this.parseImages( json.images, function () {
  88. if ( onLoad !== undefined ) onLoad( object );
  89. } );
  90. const textures = this.parseTextures( json.textures, images );
  91. const materials = this.parseMaterials( json.materials, textures );
  92. const object = this.parseObject( json.object, geometries, materials );
  93. if ( json.animations ) {
  94. object.animations = this.parseAnimations( json.animations );
  95. }
  96. if ( json.images === undefined || json.images.length === 0 ) {
  97. if ( onLoad !== undefined ) onLoad( object );
  98. }
  99. return object;
  100. }
  101. parseShape( json ) {
  102. const shapes = {};
  103. if ( json !== undefined ) {
  104. for ( let i = 0, l = json.length; i < l; i ++ ) {
  105. const shape = new Shape().fromJSON( json[ i ] );
  106. shapes[ shape.uuid ] = shape;
  107. }
  108. }
  109. return shapes;
  110. }
  111. parseGeometries( json, shapes ) {
  112. const geometries = {};
  113. let geometryShapes;
  114. if ( json !== undefined ) {
  115. const bufferGeometryLoader = new BufferGeometryLoader();
  116. for ( let i = 0, l = json.length; i < l; i ++ ) {
  117. let geometry;
  118. const data = json[ i ];
  119. switch ( data.type ) {
  120. case 'PlaneGeometry':
  121. case 'PlaneBufferGeometry':
  122. geometry = new Geometries[ data.type ](
  123. data.width,
  124. data.height,
  125. data.widthSegments,
  126. data.heightSegments
  127. );
  128. break;
  129. case 'BoxGeometry':
  130. case 'BoxBufferGeometry':
  131. case 'CubeGeometry': // backwards compatible
  132. geometry = new Geometries[ data.type ](
  133. data.width,
  134. data.height,
  135. data.depth,
  136. data.widthSegments,
  137. data.heightSegments,
  138. data.depthSegments
  139. );
  140. break;
  141. case 'CircleGeometry':
  142. case 'CircleBufferGeometry':
  143. geometry = new Geometries[ data.type ](
  144. data.radius,
  145. data.segments,
  146. data.thetaStart,
  147. data.thetaLength
  148. );
  149. break;
  150. case 'CylinderGeometry':
  151. case 'CylinderBufferGeometry':
  152. geometry = new Geometries[ data.type ](
  153. data.radiusTop,
  154. data.radiusBottom,
  155. data.height,
  156. data.radialSegments,
  157. data.heightSegments,
  158. data.openEnded,
  159. data.thetaStart,
  160. data.thetaLength
  161. );
  162. break;
  163. case 'ConeGeometry':
  164. case 'ConeBufferGeometry':
  165. geometry = new Geometries[ data.type ](
  166. data.radius,
  167. data.height,
  168. data.radialSegments,
  169. data.heightSegments,
  170. data.openEnded,
  171. data.thetaStart,
  172. data.thetaLength
  173. );
  174. break;
  175. case 'SphereGeometry':
  176. case 'SphereBufferGeometry':
  177. geometry = new Geometries[ data.type ](
  178. data.radius,
  179. data.widthSegments,
  180. data.heightSegments,
  181. data.phiStart,
  182. data.phiLength,
  183. data.thetaStart,
  184. data.thetaLength
  185. );
  186. break;
  187. case 'DodecahedronGeometry':
  188. case 'DodecahedronBufferGeometry':
  189. case 'IcosahedronGeometry':
  190. case 'IcosahedronBufferGeometry':
  191. case 'OctahedronGeometry':
  192. case 'OctahedronBufferGeometry':
  193. case 'TetrahedronGeometry':
  194. case 'TetrahedronBufferGeometry':
  195. geometry = new Geometries[ data.type ](
  196. data.radius,
  197. data.detail
  198. );
  199. break;
  200. case 'RingGeometry':
  201. case 'RingBufferGeometry':
  202. geometry = new Geometries[ data.type ](
  203. data.innerRadius,
  204. data.outerRadius,
  205. data.thetaSegments,
  206. data.phiSegments,
  207. data.thetaStart,
  208. data.thetaLength
  209. );
  210. break;
  211. case 'TorusGeometry':
  212. case 'TorusBufferGeometry':
  213. geometry = new Geometries[ data.type ](
  214. data.radius,
  215. data.tube,
  216. data.radialSegments,
  217. data.tubularSegments,
  218. data.arc
  219. );
  220. break;
  221. case 'TorusKnotGeometry':
  222. case 'TorusKnotBufferGeometry':
  223. geometry = new Geometries[ data.type ](
  224. data.radius,
  225. data.tube,
  226. data.tubularSegments,
  227. data.radialSegments,
  228. data.p,
  229. data.q
  230. );
  231. break;
  232. case 'TubeGeometry':
  233. case 'TubeBufferGeometry':
  234. // This only works for built-in curves (e.g. CatmullRomCurve3).
  235. // User defined curves or instances of CurvePath will not be deserialized.
  236. geometry = new Geometries[ data.type ](
  237. new Curves[ data.path.type ]().fromJSON( data.path ),
  238. data.tubularSegments,
  239. data.radius,
  240. data.radialSegments,
  241. data.closed
  242. );
  243. break;
  244. case 'LatheGeometry':
  245. case 'LatheBufferGeometry':
  246. geometry = new Geometries[ data.type ](
  247. data.points,
  248. data.segments,
  249. data.phiStart,
  250. data.phiLength
  251. );
  252. break;
  253. case 'PolyhedronGeometry':
  254. case 'PolyhedronBufferGeometry':
  255. geometry = new Geometries[ data.type ](
  256. data.vertices,
  257. data.indices,
  258. data.radius,
  259. data.details
  260. );
  261. break;
  262. case 'ShapeGeometry':
  263. case 'ShapeBufferGeometry':
  264. geometryShapes = [];
  265. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  266. const shape = shapes[ data.shapes[ j ] ];
  267. geometryShapes.push( shape );
  268. }
  269. geometry = new Geometries[ data.type ](
  270. geometryShapes,
  271. data.curveSegments
  272. );
  273. break;
  274. case 'ExtrudeGeometry':
  275. case 'ExtrudeBufferGeometry':
  276. geometryShapes = [];
  277. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  278. const shape = shapes[ data.shapes[ j ] ];
  279. geometryShapes.push( shape );
  280. }
  281. const extrudePath = data.options.extrudePath;
  282. if ( extrudePath !== undefined ) {
  283. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  284. }
  285. geometry = new Geometries[ data.type ](
  286. geometryShapes,
  287. data.options
  288. );
  289. break;
  290. case 'BufferGeometry':
  291. case 'InstancedBufferGeometry':
  292. geometry = bufferGeometryLoader.parse( data );
  293. break;
  294. case 'Geometry':
  295. console.error( 'THREE.ObjectLoader: Loading "Geometry" is not supported anymore.' );
  296. break;
  297. default:
  298. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  299. continue;
  300. }
  301. geometry.uuid = data.uuid;
  302. if ( data.name !== undefined ) geometry.name = data.name;
  303. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  304. geometries[ data.uuid ] = geometry;
  305. }
  306. }
  307. return geometries;
  308. }
  309. parseMaterials( json, textures ) {
  310. const cache = {}; // MultiMaterial
  311. const materials = {};
  312. if ( json !== undefined ) {
  313. const loader = new MaterialLoader();
  314. loader.setTextures( textures );
  315. for ( let i = 0, l = json.length; i < l; i ++ ) {
  316. const data = json[ i ];
  317. if ( data.type === 'MultiMaterial' ) {
  318. // Deprecated
  319. const array = [];
  320. for ( let j = 0; j < data.materials.length; j ++ ) {
  321. const material = data.materials[ j ];
  322. if ( cache[ material.uuid ] === undefined ) {
  323. cache[ material.uuid ] = loader.parse( material );
  324. }
  325. array.push( cache[ material.uuid ] );
  326. }
  327. materials[ data.uuid ] = array;
  328. } else {
  329. if ( cache[ data.uuid ] === undefined ) {
  330. cache[ data.uuid ] = loader.parse( data );
  331. }
  332. materials[ data.uuid ] = cache[ data.uuid ];
  333. }
  334. }
  335. }
  336. return materials;
  337. }
  338. parseAnimations( json ) {
  339. const animations = [];
  340. for ( let i = 0; i < json.length; i ++ ) {
  341. const data = json[ i ];
  342. const clip = AnimationClip.parse( data );
  343. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  344. animations.push( clip );
  345. }
  346. return animations;
  347. }
  348. parseImages( json, onLoad ) {
  349. const scope = this;
  350. const images = {};
  351. let loader;
  352. function loadImage( url ) {
  353. scope.manager.itemStart( url );
  354. return loader.load( url, function () {
  355. scope.manager.itemEnd( url );
  356. }, undefined, function () {
  357. scope.manager.itemError( url );
  358. scope.manager.itemEnd( url );
  359. } );
  360. }
  361. if ( json !== undefined && json.length > 0 ) {
  362. const manager = new LoadingManager( onLoad );
  363. loader = new ImageLoader( manager );
  364. loader.setCrossOrigin( this.crossOrigin );
  365. for ( let i = 0, il = json.length; i < il; i ++ ) {
  366. const image = json[ i ];
  367. const url = image.url;
  368. if ( Array.isArray( url ) ) {
  369. // load array of images e.g CubeTexture
  370. images[ image.uuid ] = [];
  371. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  372. const currentUrl = url[ j ];
  373. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  374. images[ image.uuid ].push( loadImage( path ) );
  375. }
  376. } else {
  377. // load single image
  378. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  379. images[ image.uuid ] = loadImage( path );
  380. }
  381. }
  382. }
  383. return images;
  384. }
  385. parseTextures( json, images ) {
  386. function parseConstant( value, type ) {
  387. if ( typeof value === 'number' ) return value;
  388. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  389. return type[ value ];
  390. }
  391. const textures = {};
  392. if ( json !== undefined ) {
  393. for ( let i = 0, l = json.length; i < l; i ++ ) {
  394. const data = json[ i ];
  395. if ( data.image === undefined ) {
  396. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  397. }
  398. if ( images[ data.image ] === undefined ) {
  399. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  400. }
  401. let texture;
  402. if ( Array.isArray( images[ data.image ] ) ) {
  403. texture = new CubeTexture( images[ data.image ] );
  404. } else {
  405. texture = new Texture( images[ data.image ] );
  406. }
  407. texture.needsUpdate = true;
  408. texture.uuid = data.uuid;
  409. if ( data.name !== undefined ) texture.name = data.name;
  410. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  411. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  412. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  413. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  414. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  415. if ( data.wrap !== undefined ) {
  416. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  417. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  418. }
  419. if ( data.format !== undefined ) texture.format = data.format;
  420. if ( data.type !== undefined ) texture.type = data.type;
  421. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  422. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  423. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  424. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  425. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  426. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  427. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  428. textures[ data.uuid ] = texture;
  429. }
  430. }
  431. return textures;
  432. }
  433. parseObject( data, geometries, materials ) {
  434. let object;
  435. function getGeometry( name ) {
  436. if ( geometries[ name ] === undefined ) {
  437. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  438. }
  439. return geometries[ name ];
  440. }
  441. function getMaterial( name ) {
  442. if ( name === undefined ) return undefined;
  443. if ( Array.isArray( name ) ) {
  444. const array = [];
  445. for ( let i = 0, l = name.length; i < l; i ++ ) {
  446. const uuid = name[ i ];
  447. if ( materials[ uuid ] === undefined ) {
  448. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  449. }
  450. array.push( materials[ uuid ] );
  451. }
  452. return array;
  453. }
  454. if ( materials[ name ] === undefined ) {
  455. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  456. }
  457. return materials[ name ];
  458. }
  459. let geometry, material;
  460. switch ( data.type ) {
  461. case 'Scene':
  462. object = new Scene();
  463. if ( data.background !== undefined ) {
  464. if ( Number.isInteger( data.background ) ) {
  465. object.background = new Color( data.background );
  466. }
  467. }
  468. if ( data.fog !== undefined ) {
  469. if ( data.fog.type === 'Fog' ) {
  470. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  471. } else if ( data.fog.type === 'FogExp2' ) {
  472. object.fog = new FogExp2( data.fog.color, data.fog.density );
  473. }
  474. }
  475. break;
  476. case 'PerspectiveCamera':
  477. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  478. if ( data.focus !== undefined ) object.focus = data.focus;
  479. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  480. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  481. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  482. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  483. break;
  484. case 'OrthographicCamera':
  485. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  486. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  487. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  488. break;
  489. case 'AmbientLight':
  490. object = new AmbientLight( data.color, data.intensity );
  491. break;
  492. case 'DirectionalLight':
  493. object = new DirectionalLight( data.color, data.intensity );
  494. break;
  495. case 'PointLight':
  496. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  497. break;
  498. case 'RectAreaLight':
  499. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  500. break;
  501. case 'SpotLight':
  502. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  503. break;
  504. case 'HemisphereLight':
  505. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  506. break;
  507. case 'LightProbe':
  508. object = new LightProbe().fromJSON( data );
  509. break;
  510. case 'SkinnedMesh':
  511. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  512. case 'Mesh':
  513. geometry = getGeometry( data.geometry );
  514. material = getMaterial( data.material );
  515. object = new Mesh( geometry, material );
  516. break;
  517. case 'InstancedMesh':
  518. geometry = getGeometry( data.geometry );
  519. material = getMaterial( data.material );
  520. const count = data.count;
  521. const instanceMatrix = data.instanceMatrix;
  522. object = new InstancedMesh( geometry, material, count );
  523. object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  524. break;
  525. case 'LOD':
  526. object = new LOD();
  527. break;
  528. case 'Line':
  529. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  530. break;
  531. case 'LineLoop':
  532. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  533. break;
  534. case 'LineSegments':
  535. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  536. break;
  537. case 'PointCloud':
  538. case 'Points':
  539. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  540. break;
  541. case 'Sprite':
  542. object = new Sprite( getMaterial( data.material ) );
  543. break;
  544. case 'Group':
  545. object = new Group();
  546. break;
  547. default:
  548. object = new Object3D();
  549. }
  550. object.uuid = data.uuid;
  551. if ( data.name !== undefined ) object.name = data.name;
  552. if ( data.matrix !== undefined ) {
  553. object.matrix.fromArray( data.matrix );
  554. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  555. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  556. } else {
  557. if ( data.position !== undefined ) object.position.fromArray( data.position );
  558. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  559. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  560. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  561. }
  562. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  563. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  564. if ( data.shadow ) {
  565. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  566. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  567. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  568. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  569. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  570. }
  571. if ( data.visible !== undefined ) object.visible = data.visible;
  572. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  573. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  574. if ( data.userData !== undefined ) object.userData = data.userData;
  575. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  576. if ( data.children !== undefined ) {
  577. const children = data.children;
  578. for ( let i = 0; i < children.length; i ++ ) {
  579. object.add( this.parseObject( children[ i ], geometries, materials ) );
  580. }
  581. }
  582. if ( data.type === 'LOD' ) {
  583. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  584. const levels = data.levels;
  585. for ( let l = 0; l < levels.length; l ++ ) {
  586. const level = levels[ l ];
  587. const child = object.getObjectByProperty( 'uuid', level.object );
  588. if ( child !== undefined ) {
  589. object.addLevel( child, level.distance );
  590. }
  591. }
  592. }
  593. return object;
  594. }
  595. }
  596. const TEXTURE_MAPPING = {
  597. UVMapping: UVMapping,
  598. CubeReflectionMapping: CubeReflectionMapping,
  599. CubeRefractionMapping: CubeRefractionMapping,
  600. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  601. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  602. CubeUVReflectionMapping: CubeUVReflectionMapping,
  603. CubeUVRefractionMapping: CubeUVRefractionMapping
  604. };
  605. const TEXTURE_WRAPPING = {
  606. RepeatWrapping: RepeatWrapping,
  607. ClampToEdgeWrapping: ClampToEdgeWrapping,
  608. MirroredRepeatWrapping: MirroredRepeatWrapping
  609. };
  610. const TEXTURE_FILTER = {
  611. NearestFilter: NearestFilter,
  612. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  613. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  614. LinearFilter: LinearFilter,
  615. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  616. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  617. };
  618. export { ObjectLoader };