USDZExporter.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. import {
  2. NoColorSpace,
  3. DoubleSide,
  4. Color,
  5. } from 'three';
  6. import {
  7. strToU8,
  8. zipSync,
  9. } from '../libs/fflate.module.js';
  10. class USDZExporter {
  11. constructor() {
  12. this.textureUtils = null;
  13. }
  14. setTextureUtils( utils ) {
  15. this.textureUtils = utils;
  16. }
  17. parse( scene, onDone, onError, options ) {
  18. this.parseAsync( scene, options ).then( onDone ).catch( onError );
  19. }
  20. async parseAsync( scene, options = {} ) {
  21. options = Object.assign( {
  22. ar: {
  23. anchoring: { type: 'plane' },
  24. planeAnchoring: { alignment: 'horizontal' }
  25. },
  26. includeAnchoringProperties: true,
  27. quickLookCompatible: false,
  28. maxTextureSize: 1024,
  29. }, options );
  30. const files = {};
  31. const modelFileName = 'model.usda';
  32. // model file should be first in USDZ archive so we init it here
  33. files[ modelFileName ] = null;
  34. let output = buildHeader();
  35. output += buildSceneStart( options );
  36. const materials = {};
  37. const textures = {};
  38. scene.traverseVisible( ( object ) => {
  39. if ( object.isMesh ) {
  40. const geometry = object.geometry;
  41. const material = object.material;
  42. if ( material.isMeshStandardMaterial ) {
  43. const geometryFileName = 'geometries/Geometry_' + geometry.id + '.usda';
  44. if ( ! ( geometryFileName in files ) ) {
  45. const meshObject = buildMeshObject( geometry );
  46. files[ geometryFileName ] = buildUSDFileAsString( meshObject );
  47. }
  48. if ( ! ( material.uuid in materials ) ) {
  49. materials[ material.uuid ] = material;
  50. }
  51. output += buildXform( object, geometry, material );
  52. } else {
  53. console.warn( 'THREE.USDZExporter: Unsupported material type (USDZ only supports MeshStandardMaterial)', object );
  54. }
  55. } else if ( object.isCamera ) {
  56. output += buildCamera( object );
  57. }
  58. } );
  59. output += buildSceneEnd();
  60. output += buildMaterials( materials, textures, options.quickLookCompatible );
  61. files[ modelFileName ] = strToU8( output );
  62. output = null;
  63. for ( const id in textures ) {
  64. let texture = textures[ id ];
  65. if ( texture.isCompressedTexture === true ) {
  66. if ( this.textureUtils === null ) {
  67. throw new Error( 'THREE.USDZExporter: setTextureUtils() must be called to process compressed textures.' );
  68. } else {
  69. texture = await this.textureUtils.decompress( texture );
  70. }
  71. }
  72. const canvas = imageToCanvas( texture.image, texture.flipY, options.maxTextureSize );
  73. const blob = await new Promise( resolve => canvas.toBlob( resolve, 'image/png', 1 ) );
  74. files[ `textures/Texture_${ id }.png` ] = new Uint8Array( await blob.arrayBuffer() );
  75. }
  76. // 64 byte alignment
  77. // https://github.com/101arrowz/fflate/issues/39#issuecomment-777263109
  78. let offset = 0;
  79. for ( const filename in files ) {
  80. const file = files[ filename ];
  81. const headerSize = 34 + filename.length;
  82. offset += headerSize;
  83. const offsetMod64 = offset & 63;
  84. if ( offsetMod64 !== 4 ) {
  85. const padLength = 64 - offsetMod64;
  86. const padding = new Uint8Array( padLength );
  87. files[ filename ] = [ file, { extra: { 12345: padding } } ];
  88. }
  89. offset = file.length;
  90. }
  91. return zipSync( files, { level: 0 } );
  92. }
  93. }
  94. function imageToCanvas( image, flipY, maxTextureSize ) {
  95. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  96. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  97. ( typeof OffscreenCanvas !== 'undefined' && image instanceof OffscreenCanvas ) ||
  98. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  99. const scale = maxTextureSize / Math.max( image.width, image.height );
  100. const canvas = document.createElement( 'canvas' );
  101. canvas.width = image.width * Math.min( 1, scale );
  102. canvas.height = image.height * Math.min( 1, scale );
  103. const context = canvas.getContext( '2d' );
  104. // TODO: We should be able to do this in the UsdTransform2d?
  105. if ( flipY === true ) {
  106. context.translate( 0, canvas.height );
  107. context.scale( 1, - 1 );
  108. }
  109. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  110. return canvas;
  111. } else {
  112. throw new Error( 'THREE.USDZExporter: No valid image data found. Unable to process texture.' );
  113. }
  114. }
  115. //
  116. const PRECISION = 7;
  117. function buildHeader() {
  118. return `#usda 1.0
  119. (
  120. customLayerData = {
  121. string creator = "Three.js USDZExporter"
  122. }
  123. defaultPrim = "Root"
  124. metersPerUnit = 1
  125. upAxis = "Y"
  126. )
  127. `;
  128. }
  129. function buildSceneStart( options ) {
  130. const alignment = options.includeAnchoringProperties === true ? `
  131. token preliminary:anchoring:type = "${options.ar.anchoring.type}"
  132. token preliminary:planeAnchoring:alignment = "${options.ar.planeAnchoring.alignment}"
  133. ` : '';
  134. return `def Xform "Root"
  135. {
  136. def Scope "Scenes" (
  137. kind = "sceneLibrary"
  138. )
  139. {
  140. def Xform "Scene" (
  141. customData = {
  142. bool preliminary_collidesWithEnvironment = 0
  143. string sceneName = "Scene"
  144. }
  145. sceneName = "Scene"
  146. )
  147. {${alignment}
  148. `;
  149. }
  150. function buildSceneEnd() {
  151. return `
  152. }
  153. }
  154. }
  155. `;
  156. }
  157. function buildUSDFileAsString( dataToInsert ) {
  158. let output = buildHeader();
  159. output += dataToInsert;
  160. return strToU8( output );
  161. }
  162. // Xform
  163. function buildXform( object, geometry, material ) {
  164. const name = 'Object_' + object.id;
  165. const transform = buildMatrix( object.matrixWorld );
  166. if ( object.matrixWorld.determinant() < 0 ) {
  167. console.warn( 'THREE.USDZExporter: USDZ does not support negative scales', object );
  168. }
  169. return `def Xform "${ name }" (
  170. prepend references = @./geometries/Geometry_${ geometry.id }.usda@</Geometry>
  171. prepend apiSchemas = ["MaterialBindingAPI"]
  172. )
  173. {
  174. matrix4d xformOp:transform = ${ transform }
  175. uniform token[] xformOpOrder = ["xformOp:transform"]
  176. rel material:binding = </Materials/Material_${ material.id }>
  177. }
  178. `;
  179. }
  180. function buildMatrix( matrix ) {
  181. const array = matrix.elements;
  182. return `( ${ buildMatrixRow( array, 0 ) }, ${ buildMatrixRow( array, 4 ) }, ${ buildMatrixRow( array, 8 ) }, ${ buildMatrixRow( array, 12 ) } )`;
  183. }
  184. function buildMatrixRow( array, offset ) {
  185. return `(${ array[ offset + 0 ] }, ${ array[ offset + 1 ] }, ${ array[ offset + 2 ] }, ${ array[ offset + 3 ] })`;
  186. }
  187. // Mesh
  188. function buildMeshObject( geometry ) {
  189. const mesh = buildMesh( geometry );
  190. return `
  191. def "Geometry"
  192. {
  193. ${mesh}
  194. }
  195. `;
  196. }
  197. function buildMesh( geometry ) {
  198. const name = 'Geometry';
  199. const attributes = geometry.attributes;
  200. const count = attributes.position.count;
  201. return `
  202. def Mesh "${ name }"
  203. {
  204. int[] faceVertexCounts = [${ buildMeshVertexCount( geometry ) }]
  205. int[] faceVertexIndices = [${ buildMeshVertexIndices( geometry ) }]
  206. normal3f[] normals = [${ buildVector3Array( attributes.normal, count )}] (
  207. interpolation = "vertex"
  208. )
  209. point3f[] points = [${ buildVector3Array( attributes.position, count )}]
  210. ${ buildPrimvars( attributes ) }
  211. uniform token subdivisionScheme = "none"
  212. }
  213. `;
  214. }
  215. function buildMeshVertexCount( geometry ) {
  216. const count = geometry.index !== null ? geometry.index.count : geometry.attributes.position.count;
  217. return Array( count / 3 ).fill( 3 ).join( ', ' );
  218. }
  219. function buildMeshVertexIndices( geometry ) {
  220. const index = geometry.index;
  221. const array = [];
  222. if ( index !== null ) {
  223. for ( let i = 0; i < index.count; i ++ ) {
  224. array.push( index.getX( i ) );
  225. }
  226. } else {
  227. const length = geometry.attributes.position.count;
  228. for ( let i = 0; i < length; i ++ ) {
  229. array.push( i );
  230. }
  231. }
  232. return array.join( ', ' );
  233. }
  234. function buildVector3Array( attribute, count ) {
  235. if ( attribute === undefined ) {
  236. console.warn( 'USDZExporter: Normals missing.' );
  237. return Array( count ).fill( '(0, 0, 0)' ).join( ', ' );
  238. }
  239. const array = [];
  240. for ( let i = 0; i < attribute.count; i ++ ) {
  241. const x = attribute.getX( i );
  242. const y = attribute.getY( i );
  243. const z = attribute.getZ( i );
  244. array.push( `(${ x.toPrecision( PRECISION ) }, ${ y.toPrecision( PRECISION ) }, ${ z.toPrecision( PRECISION ) })` );
  245. }
  246. return array.join( ', ' );
  247. }
  248. function buildVector2Array( attribute ) {
  249. const array = [];
  250. for ( let i = 0; i < attribute.count; i ++ ) {
  251. const x = attribute.getX( i );
  252. const y = attribute.getY( i );
  253. array.push( `(${ x.toPrecision( PRECISION ) }, ${ 1 - y.toPrecision( PRECISION ) })` );
  254. }
  255. return array.join( ', ' );
  256. }
  257. function buildPrimvars( attributes ) {
  258. let string = '';
  259. for ( let i = 0; i < 4; i ++ ) {
  260. const id = ( i > 0 ? i : '' );
  261. const attribute = attributes[ 'uv' + id ];
  262. if ( attribute !== undefined ) {
  263. string += `
  264. texCoord2f[] primvars:st${ id } = [${ buildVector2Array( attribute )}] (
  265. interpolation = "vertex"
  266. )`;
  267. }
  268. }
  269. // vertex colors
  270. const colorAttribute = attributes.color;
  271. if ( colorAttribute !== undefined ) {
  272. const count = colorAttribute.count;
  273. string += `
  274. color3f[] primvars:displayColor = [${buildVector3Array( colorAttribute, count )}] (
  275. interpolation = "vertex"
  276. )`;
  277. }
  278. return string;
  279. }
  280. // Materials
  281. function buildMaterials( materials, textures, quickLookCompatible = false ) {
  282. const array = [];
  283. for ( const uuid in materials ) {
  284. const material = materials[ uuid ];
  285. array.push( buildMaterial( material, textures, quickLookCompatible ) );
  286. }
  287. return `def "Materials"
  288. {
  289. ${ array.join( '' ) }
  290. }
  291. `;
  292. }
  293. function buildMaterial( material, textures, quickLookCompatible = false ) {
  294. // https://graphics.pixar.com/usd/docs/UsdPreviewSurface-Proposal.html
  295. const pad = ' ';
  296. const inputs = [];
  297. const samplers = [];
  298. function buildTexture( texture, mapType, color ) {
  299. const id = texture.source.id + '_' + texture.flipY;
  300. textures[ id ] = texture;
  301. const uv = texture.channel > 0 ? 'st' + texture.channel : 'st';
  302. const WRAPPINGS = {
  303. 1000: 'repeat', // RepeatWrapping
  304. 1001: 'clamp', // ClampToEdgeWrapping
  305. 1002: 'mirror' // MirroredRepeatWrapping
  306. };
  307. const repeat = texture.repeat.clone();
  308. const offset = texture.offset.clone();
  309. const rotation = texture.rotation;
  310. // rotation is around the wrong point. after rotation we need to shift offset again so that we're rotating around the right spot
  311. const xRotationOffset = Math.sin( rotation );
  312. const yRotationOffset = Math.cos( rotation );
  313. // texture coordinates start in the opposite corner, need to correct
  314. offset.y = 1 - offset.y - repeat.y;
  315. // turns out QuickLook is buggy and interprets texture repeat inverted/applies operations in a different order.
  316. // Apple Feedback: FB10036297 and FB11442287
  317. if ( quickLookCompatible ) {
  318. // This is NOT correct yet in QuickLook, but comes close for a range of models.
  319. // It becomes more incorrect the bigger the offset is
  320. offset.x = offset.x / repeat.x;
  321. offset.y = offset.y / repeat.y;
  322. offset.x += xRotationOffset / repeat.x;
  323. offset.y += yRotationOffset - 1;
  324. } else {
  325. // results match glTF results exactly. verified correct in usdview.
  326. offset.x += xRotationOffset * repeat.x;
  327. offset.y += ( 1 - yRotationOffset ) * repeat.y;
  328. }
  329. return `
  330. def Shader "PrimvarReader_${ mapType }"
  331. {
  332. uniform token info:id = "UsdPrimvarReader_float2"
  333. float2 inputs:fallback = (0.0, 0.0)
  334. token inputs:varname = "${ uv }"
  335. float2 outputs:result
  336. }
  337. def Shader "Transform2d_${ mapType }"
  338. {
  339. uniform token info:id = "UsdTransform2d"
  340. token inputs:in.connect = </Materials/Material_${ material.id }/PrimvarReader_${ mapType }.outputs:result>
  341. float inputs:rotation = ${ ( rotation * ( 180 / Math.PI ) ).toFixed( PRECISION ) }
  342. float2 inputs:scale = ${ buildVector2( repeat ) }
  343. float2 inputs:translation = ${ buildVector2( offset ) }
  344. float2 outputs:result
  345. }
  346. def Shader "Texture_${ texture.id }_${ mapType }"
  347. {
  348. uniform token info:id = "UsdUVTexture"
  349. asset inputs:file = @textures/Texture_${ id }.png@
  350. float2 inputs:st.connect = </Materials/Material_${ material.id }/Transform2d_${ mapType }.outputs:result>
  351. ${ color !== undefined ? 'float4 inputs:scale = ' + buildColor4( color ) : '' }
  352. token inputs:sourceColorSpace = "${ texture.colorSpace === NoColorSpace ? 'raw' : 'sRGB' }"
  353. token inputs:wrapS = "${ WRAPPINGS[ texture.wrapS ] }"
  354. token inputs:wrapT = "${ WRAPPINGS[ texture.wrapT ] }"
  355. float outputs:r
  356. float outputs:g
  357. float outputs:b
  358. float3 outputs:rgb
  359. ${ material.transparent || material.alphaTest > 0.0 ? 'float outputs:a' : '' }
  360. }`;
  361. }
  362. if ( material.side === DoubleSide ) {
  363. console.warn( 'THREE.USDZExporter: USDZ does not support double sided materials', material );
  364. }
  365. if ( material.map !== null ) {
  366. inputs.push( `${ pad }color3f inputs:diffuseColor.connect = </Materials/Material_${ material.id }/Texture_${ material.map.id }_diffuse.outputs:rgb>` );
  367. if ( material.transparent ) {
  368. inputs.push( `${ pad }float inputs:opacity.connect = </Materials/Material_${ material.id }/Texture_${ material.map.id }_diffuse.outputs:a>` );
  369. } else if ( material.alphaTest > 0.0 ) {
  370. inputs.push( `${ pad }float inputs:opacity.connect = </Materials/Material_${ material.id }/Texture_${ material.map.id }_diffuse.outputs:a>` );
  371. inputs.push( `${ pad }float inputs:opacityThreshold = ${material.alphaTest}` );
  372. }
  373. samplers.push( buildTexture( material.map, 'diffuse', material.color ) );
  374. } else {
  375. inputs.push( `${ pad }color3f inputs:diffuseColor = ${ buildColor( material.color ) }` );
  376. }
  377. if ( material.emissiveMap !== null ) {
  378. inputs.push( `${ pad }color3f inputs:emissiveColor.connect = </Materials/Material_${ material.id }/Texture_${ material.emissiveMap.id }_emissive.outputs:rgb>` );
  379. samplers.push( buildTexture( material.emissiveMap, 'emissive', new Color( material.emissive.r * material.emissiveIntensity, material.emissive.g * material.emissiveIntensity, material.emissive.b * material.emissiveIntensity ) ) );
  380. } else if ( material.emissive.getHex() > 0 ) {
  381. inputs.push( `${ pad }color3f inputs:emissiveColor = ${ buildColor( material.emissive ) }` );
  382. }
  383. if ( material.normalMap !== null ) {
  384. inputs.push( `${ pad }normal3f inputs:normal.connect = </Materials/Material_${ material.id }/Texture_${ material.normalMap.id }_normal.outputs:rgb>` );
  385. samplers.push( buildTexture( material.normalMap, 'normal' ) );
  386. }
  387. if ( material.aoMap !== null ) {
  388. inputs.push( `${ pad }float inputs:occlusion.connect = </Materials/Material_${ material.id }/Texture_${ material.aoMap.id }_occlusion.outputs:r>` );
  389. samplers.push( buildTexture( material.aoMap, 'occlusion', new Color( material.aoMapIntensity, material.aoMapIntensity, material.aoMapIntensity ) ) );
  390. }
  391. if ( material.roughnessMap !== null ) {
  392. inputs.push( `${ pad }float inputs:roughness.connect = </Materials/Material_${ material.id }/Texture_${ material.roughnessMap.id }_roughness.outputs:g>` );
  393. samplers.push( buildTexture( material.roughnessMap, 'roughness', new Color( material.roughness, material.roughness, material.roughness ) ) );
  394. } else {
  395. inputs.push( `${ pad }float inputs:roughness = ${ material.roughness }` );
  396. }
  397. if ( material.metalnessMap !== null ) {
  398. inputs.push( `${ pad }float inputs:metallic.connect = </Materials/Material_${ material.id }/Texture_${ material.metalnessMap.id }_metallic.outputs:b>` );
  399. samplers.push( buildTexture( material.metalnessMap, 'metallic', new Color( material.metalness, material.metalness, material.metalness ) ) );
  400. } else {
  401. inputs.push( `${ pad }float inputs:metallic = ${ material.metalness }` );
  402. }
  403. if ( material.alphaMap !== null ) {
  404. inputs.push( `${pad}float inputs:opacity.connect = </Materials/Material_${material.id}/Texture_${material.alphaMap.id}_opacity.outputs:r>` );
  405. inputs.push( `${pad}float inputs:opacityThreshold = 0.0001` );
  406. samplers.push( buildTexture( material.alphaMap, 'opacity' ) );
  407. } else {
  408. inputs.push( `${pad}float inputs:opacity = ${material.opacity}` );
  409. }
  410. if ( material.isMeshPhysicalMaterial ) {
  411. if ( material.clearcoatMap !== null ) {
  412. inputs.push( `${pad}float inputs:clearcoat.connect = </Materials/Material_${material.id}/Texture_${material.clearcoatMap.id}_clearcoat.outputs:r>` );
  413. samplers.push( buildTexture( material.clearcoatMap, 'clearcoat', new Color( material.clearcoat, material.clearcoat, material.clearcoat ) ) );
  414. } else {
  415. inputs.push( `${pad}float inputs:clearcoat = ${material.clearcoat}` );
  416. }
  417. if ( material.clearcoatRoughnessMap !== null ) {
  418. inputs.push( `${pad}float inputs:clearcoatRoughness.connect = </Materials/Material_${material.id}/Texture_${material.clearcoatRoughnessMap.id}_clearcoatRoughness.outputs:g>` );
  419. samplers.push( buildTexture( material.clearcoatRoughnessMap, 'clearcoatRoughness', new Color( material.clearcoatRoughness, material.clearcoatRoughness, material.clearcoatRoughness ) ) );
  420. } else {
  421. inputs.push( `${pad}float inputs:clearcoatRoughness = ${material.clearcoatRoughness}` );
  422. }
  423. inputs.push( `${ pad }float inputs:ior = ${ material.ior }` );
  424. }
  425. return `
  426. def Material "Material_${ material.id }"
  427. {
  428. def Shader "PreviewSurface"
  429. {
  430. uniform token info:id = "UsdPreviewSurface"
  431. ${ inputs.join( '\n' ) }
  432. int inputs:useSpecularWorkflow = 0
  433. token outputs:surface
  434. }
  435. token outputs:surface.connect = </Materials/Material_${ material.id }/PreviewSurface.outputs:surface>
  436. ${ samplers.join( '\n' ) }
  437. }
  438. `;
  439. }
  440. function buildColor( color ) {
  441. return `(${ color.r }, ${ color.g }, ${ color.b })`;
  442. }
  443. function buildColor4( color ) {
  444. return `(${ color.r }, ${ color.g }, ${ color.b }, 1.0)`;
  445. }
  446. function buildVector2( vector ) {
  447. return `(${ vector.x }, ${ vector.y })`;
  448. }
  449. function buildCamera( camera ) {
  450. const name = camera.name ? camera.name : 'Camera_' + camera.id;
  451. const transform = buildMatrix( camera.matrixWorld );
  452. if ( camera.matrixWorld.determinant() < 0 ) {
  453. console.warn( 'THREE.USDZExporter: USDZ does not support negative scales', camera );
  454. }
  455. if ( camera.isOrthographicCamera ) {
  456. return `def Camera "${name}"
  457. {
  458. matrix4d xformOp:transform = ${ transform }
  459. uniform token[] xformOpOrder = ["xformOp:transform"]
  460. float2 clippingRange = (${ camera.near.toPrecision( PRECISION ) }, ${ camera.far.toPrecision( PRECISION ) })
  461. float horizontalAperture = ${ ( ( Math.abs( camera.left ) + Math.abs( camera.right ) ) * 10 ).toPrecision( PRECISION ) }
  462. float verticalAperture = ${ ( ( Math.abs( camera.top ) + Math.abs( camera.bottom ) ) * 10 ).toPrecision( PRECISION ) }
  463. token projection = "orthographic"
  464. }
  465. `;
  466. } else {
  467. return `def Camera "${name}"
  468. {
  469. matrix4d xformOp:transform = ${ transform }
  470. uniform token[] xformOpOrder = ["xformOp:transform"]
  471. float2 clippingRange = (${ camera.near.toPrecision( PRECISION ) }, ${ camera.far.toPrecision( PRECISION ) })
  472. float focalLength = ${ camera.getFocalLength().toPrecision( PRECISION ) }
  473. float focusDistance = ${ camera.focus.toPrecision( PRECISION ) }
  474. float horizontalAperture = ${ camera.getFilmWidth().toPrecision( PRECISION ) }
  475. token projection = "perspective"
  476. float verticalAperture = ${ camera.getFilmHeight().toPrecision( PRECISION ) }
  477. }
  478. `;
  479. }
  480. }
  481. export { USDZExporter };
粤ICP备19079148号