3DMLoader.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  1. import {
  2. BufferGeometryLoader,
  3. CanvasTexture,
  4. ClampToEdgeWrapping,
  5. Color,
  6. DirectionalLight,
  7. DoubleSide,
  8. FileLoader,
  9. LinearFilter,
  10. Line,
  11. LineBasicMaterial,
  12. Loader,
  13. Matrix4,
  14. Mesh,
  15. MeshPhysicalMaterial,
  16. MeshStandardMaterial,
  17. Object3D,
  18. PointLight,
  19. Points,
  20. PointsMaterial,
  21. RectAreaLight,
  22. RepeatWrapping,
  23. SpotLight,
  24. Sprite,
  25. SpriteMaterial,
  26. TextureLoader
  27. } from 'three';
  28. import { EXRLoader } from '../loaders/EXRLoader.js';
  29. const _taskCache = new WeakMap();
  30. class Rhino3dmLoader extends Loader {
  31. constructor( manager ) {
  32. super( manager );
  33. this.libraryPath = '';
  34. this.libraryPending = null;
  35. this.libraryBinary = null;
  36. this.libraryConfig = {};
  37. this.url = '';
  38. this.workerLimit = 4;
  39. this.workerPool = [];
  40. this.workerNextTaskID = 1;
  41. this.workerSourceURL = '';
  42. this.workerConfig = {};
  43. this.materials = [];
  44. this.warnings = [];
  45. }
  46. setLibraryPath( path ) {
  47. this.libraryPath = path;
  48. return this;
  49. }
  50. setWorkerLimit( workerLimit ) {
  51. this.workerLimit = workerLimit;
  52. return this;
  53. }
  54. load( url, onLoad, onProgress, onError ) {
  55. const loader = new FileLoader( this.manager );
  56. loader.setPath( this.path );
  57. loader.setResponseType( 'arraybuffer' );
  58. loader.setRequestHeader( this.requestHeader );
  59. this.url = url;
  60. loader.load( url, ( buffer ) => {
  61. // Check for an existing task using this buffer. A transferred buffer cannot be transferred
  62. // again from this thread.
  63. if ( _taskCache.has( buffer ) ) {
  64. const cachedTask = _taskCache.get( buffer );
  65. return cachedTask.promise.then( onLoad ).catch( onError );
  66. }
  67. this.decodeObjects( buffer, url )
  68. .then( result => {
  69. result.userData.warnings = this.warnings;
  70. onLoad( result );
  71. } )
  72. .catch( e => onError( e ) );
  73. }, onProgress, onError );
  74. }
  75. debug() {
  76. console.log( 'Task load: ', this.workerPool.map( ( worker ) => worker._taskLoad ) );
  77. }
  78. decodeObjects( buffer, url ) {
  79. let worker;
  80. let taskID;
  81. const taskCost = buffer.byteLength;
  82. const objectPending = this._getWorker( taskCost )
  83. .then( ( _worker ) => {
  84. worker = _worker;
  85. taskID = this.workerNextTaskID ++;
  86. return new Promise( ( resolve, reject ) => {
  87. worker._callbacks[ taskID ] = { resolve, reject };
  88. worker.postMessage( { type: 'decode', id: taskID, buffer }, [ buffer ] );
  89. // this.debug();
  90. } );
  91. } )
  92. .then( ( message ) => this._createGeometry( message.data ) )
  93. .catch( e => {
  94. throw e;
  95. } );
  96. // Remove task from the task list.
  97. // Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
  98. objectPending
  99. .catch( () => true )
  100. .then( () => {
  101. if ( worker && taskID ) {
  102. this._releaseTask( worker, taskID );
  103. //this.debug();
  104. }
  105. } );
  106. // Cache the task result.
  107. _taskCache.set( buffer, {
  108. url: url,
  109. promise: objectPending
  110. } );
  111. return objectPending;
  112. }
  113. parse( data, onLoad, onError ) {
  114. this.decodeObjects( data, '' )
  115. .then( result => {
  116. result.userData.warnings = this.warnings;
  117. onLoad( result );
  118. } )
  119. .catch( e => onError( e ) );
  120. }
  121. _compareMaterials( material ) {
  122. const mat = {};
  123. mat.name = material.name;
  124. mat.color = {};
  125. mat.color.r = material.color.r;
  126. mat.color.g = material.color.g;
  127. mat.color.b = material.color.b;
  128. mat.type = material.type;
  129. mat.vertexColors = material.vertexColors;
  130. const json = JSON.stringify( mat );
  131. for ( let i = 0; i < this.materials.length; i ++ ) {
  132. const m = this.materials[ i ];
  133. const _mat = {};
  134. _mat.name = m.name;
  135. _mat.color = {};
  136. _mat.color.r = m.color.r;
  137. _mat.color.g = m.color.g;
  138. _mat.color.b = m.color.b;
  139. _mat.type = m.type;
  140. _mat.vertexColors = m.vertexColors;
  141. if ( JSON.stringify( _mat ) === json ) {
  142. return m;
  143. }
  144. }
  145. this.materials.push( material );
  146. return material;
  147. }
  148. _createMaterial( material, renderEnvironment ) {
  149. if ( material === undefined ) {
  150. return new MeshStandardMaterial( {
  151. color: new Color( 1, 1, 1 ),
  152. metalness: 0.8,
  153. name: Loader.DEFAULT_MATERIAL_NAME,
  154. side: DoubleSide
  155. } );
  156. }
  157. //console.log(material)
  158. const mat = new MeshPhysicalMaterial( {
  159. color: new Color( material.diffuseColor.r / 255.0, material.diffuseColor.g / 255.0, material.diffuseColor.b / 255.0 ),
  160. emissive: new Color( material.emissionColor.r, material.emissionColor.g, material.emissionColor.b ),
  161. flatShading: material.disableLighting,
  162. ior: material.indexOfRefraction,
  163. name: material.name,
  164. reflectivity: material.reflectivity,
  165. opacity: 1.0 - material.transparency,
  166. side: DoubleSide,
  167. specularColor: material.specularColor,
  168. transparent: material.transparency > 0 ? true : false
  169. } );
  170. mat.userData.id = material.id;
  171. if ( material.pbrSupported ) {
  172. const pbr = material.pbr;
  173. mat.anisotropy = pbr.anisotropic;
  174. mat.anisotropyRotation = pbr.anisotropicRotation;
  175. mat.color = new Color( pbr.baseColor.r, pbr.baseColor.g, pbr.baseColor.b );
  176. mat.clearcoat = pbr.clearcoat;
  177. mat.clearcoatRoughness = pbr.clearcoatRoughness;
  178. mat.metalness = pbr.metallic;
  179. mat.transmission = 1 - pbr.opacity;
  180. mat.roughness = pbr.roughness;
  181. mat.sheen = pbr.sheen;
  182. mat.specularIntensity = pbr.specular;
  183. mat.thickness = pbr.subsurface;
  184. }
  185. if ( material.pbrSupported && material.pbr.opacity === 0 && material.transparency === 1 ) {
  186. //some compromises
  187. mat.opacity = 0.2;
  188. mat.transmission = 1.00;
  189. }
  190. const textureLoader = new TextureLoader();
  191. for ( let i = 0; i < material.textures.length; i ++ ) {
  192. const texture = material.textures[ i ];
  193. if ( texture.image !== null ) {
  194. const map = textureLoader.load( texture.image );
  195. //console.log(texture.type )
  196. switch ( texture.type ) {
  197. case 'Bump':
  198. mat.bumpMap = map;
  199. break;
  200. case 'Diffuse':
  201. mat.map = map;
  202. break;
  203. case 'Emap':
  204. mat.envMap = map;
  205. break;
  206. case 'Opacity':
  207. mat.transmissionMap = map;
  208. break;
  209. case 'Transparency':
  210. mat.alphaMap = map;
  211. mat.transparent = true;
  212. break;
  213. case 'PBR_Alpha':
  214. mat.alphaMap = map;
  215. mat.transparent = true;
  216. break;
  217. case 'PBR_AmbientOcclusion':
  218. mat.aoMap = map;
  219. break;
  220. case 'PBR_Anisotropic':
  221. mat.anisotropyMap = map;
  222. break;
  223. case 'PBR_BaseColor':
  224. mat.map = map;
  225. break;
  226. case 'PBR_Clearcoat':
  227. mat.clearcoatMap = map;
  228. break;
  229. case 'PBR_ClearcoatBump':
  230. mat.clearcoatNormalMap = map;
  231. break;
  232. case 'PBR_ClearcoatRoughness':
  233. mat.clearcoatRoughnessMap = map;
  234. break;
  235. case 'PBR_Displacement':
  236. mat.displacementMap = map;
  237. break;
  238. case 'PBR_Emission':
  239. mat.emissiveMap = map;
  240. break;
  241. case 'PBR_Metallic':
  242. mat.metalnessMap = map;
  243. break;
  244. case 'PBR_Roughness':
  245. mat.roughnessMap = map;
  246. break;
  247. case 'PBR_Sheen':
  248. mat.sheenColorMap = map;
  249. break;
  250. case 'PBR_Specular':
  251. mat.specularColorMap = map;
  252. break;
  253. case 'PBR_Subsurface':
  254. mat.thicknessMap = map;
  255. break;
  256. default:
  257. this.warnings.push( {
  258. message: `THREE.3DMLoader: No conversion exists for 3dm ${texture.type}.`,
  259. type: 'no conversion'
  260. } );
  261. break;
  262. }
  263. map.wrapS = texture.wrapU === 0 ? RepeatWrapping : ClampToEdgeWrapping;
  264. map.wrapT = texture.wrapV === 0 ? RepeatWrapping : ClampToEdgeWrapping;
  265. if ( texture.repeat ) {
  266. map.repeat.set( texture.repeat[ 0 ], texture.repeat[ 1 ] );
  267. }
  268. }
  269. }
  270. if ( renderEnvironment ) {
  271. new EXRLoader().load( renderEnvironment.image, function ( texture ) {
  272. texture.mapping = THREE.EquirectangularReflectionMapping;
  273. mat.envMap = texture;
  274. } );
  275. }
  276. return mat;
  277. }
  278. _createGeometry( data ) {
  279. const object = new Object3D();
  280. const instanceDefinitionObjects = [];
  281. const instanceDefinitions = [];
  282. const instanceReferences = [];
  283. object.userData[ 'layers' ] = data.layers;
  284. object.userData[ 'groups' ] = data.groups;
  285. object.userData[ 'settings' ] = data.settings;
  286. object.userData.settings[ 'renderSettings' ] = data.renderSettings;
  287. object.userData[ 'objectType' ] = 'File3dm';
  288. object.userData[ 'materials' ] = null;
  289. object.name = this.url;
  290. let objects = data.objects;
  291. const materials = data.materials;
  292. for ( let i = 0; i < objects.length; i ++ ) {
  293. const obj = objects[ i ];
  294. const attributes = obj.attributes;
  295. switch ( obj.objectType ) {
  296. case 'InstanceDefinition':
  297. instanceDefinitions.push( obj );
  298. break;
  299. case 'InstanceReference':
  300. instanceReferences.push( obj );
  301. break;
  302. default:
  303. let matId = null;
  304. switch ( attributes.materialSource.name ) {
  305. case 'ObjectMaterialSource_MaterialFromLayer':
  306. //check layer index
  307. if ( attributes.layerIndex >= 0 ) {
  308. matId = data.layers[ attributes.layerIndex ].renderMaterialIndex;
  309. }
  310. break;
  311. case 'ObjectMaterialSource_MaterialFromObject':
  312. if ( attributes.materialIndex >= 0 ) {
  313. matId = attributes.materialIndex;
  314. }
  315. break;
  316. }
  317. let material = null;
  318. if ( matId >= 0 ) {
  319. const rMaterial = materials[ matId ];
  320. material = this._createMaterial( rMaterial, data.renderEnvironment );
  321. }
  322. const _object = this._createObject( obj, material );
  323. if ( _object === undefined ) {
  324. continue;
  325. }
  326. const layer = data.layers[ attributes.layerIndex ];
  327. _object.visible = layer ? data.layers[ attributes.layerIndex ].visible : true;
  328. if ( attributes.isInstanceDefinitionObject ) {
  329. instanceDefinitionObjects.push( _object );
  330. } else {
  331. object.add( _object );
  332. }
  333. break;
  334. }
  335. }
  336. for ( let i = 0; i < instanceDefinitions.length; i ++ ) {
  337. const iDef = instanceDefinitions[ i ];
  338. objects = [];
  339. for ( let j = 0; j < iDef.attributes.objectIds.length; j ++ ) {
  340. const objId = iDef.attributes.objectIds[ j ];
  341. for ( let p = 0; p < instanceDefinitionObjects.length; p ++ ) {
  342. const idoId = instanceDefinitionObjects[ p ].userData.attributes.id;
  343. if ( objId === idoId ) {
  344. objects.push( instanceDefinitionObjects[ p ] );
  345. }
  346. }
  347. }
  348. // Currently clones geometry and does not take advantage of instancing
  349. for ( let j = 0; j < instanceReferences.length; j ++ ) {
  350. const iRef = instanceReferences[ j ];
  351. if ( iRef.geometry.parentIdefId === iDef.attributes.id ) {
  352. const iRefObject = new Object3D();
  353. const xf = iRef.geometry.xform.array;
  354. const matrix = new Matrix4();
  355. matrix.set( ...xf );
  356. iRefObject.applyMatrix4( matrix );
  357. for ( let p = 0; p < objects.length; p ++ ) {
  358. iRefObject.add( objects[ p ].clone( true ) );
  359. }
  360. object.add( iRefObject );
  361. }
  362. }
  363. }
  364. object.userData[ 'materials' ] = this.materials;
  365. object.name = '';
  366. return object;
  367. }
  368. _createObject( obj, mat ) {
  369. const loader = new BufferGeometryLoader();
  370. const attributes = obj.attributes;
  371. let geometry, material, _color, color;
  372. switch ( obj.objectType ) {
  373. case 'Point':
  374. case 'PointSet':
  375. geometry = loader.parse( obj.geometry );
  376. if ( geometry.attributes.hasOwnProperty( 'color' ) ) {
  377. material = new PointsMaterial( { vertexColors: true, sizeAttenuation: false, size: 2 } );
  378. } else {
  379. _color = attributes.drawColor;
  380. color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 );
  381. material = new PointsMaterial( { color: color, sizeAttenuation: false, size: 2 } );
  382. }
  383. material = this._compareMaterials( material );
  384. const points = new Points( geometry, material );
  385. points.userData[ 'attributes' ] = attributes;
  386. points.userData[ 'objectType' ] = obj.objectType;
  387. if ( attributes.name ) {
  388. points.name = attributes.name;
  389. }
  390. return points;
  391. case 'Mesh':
  392. case 'Extrusion':
  393. case 'SubD':
  394. case 'Brep':
  395. if ( obj.geometry === null ) return;
  396. geometry = loader.parse( obj.geometry );
  397. if ( mat === null ) {
  398. mat = this._createMaterial();
  399. }
  400. if ( geometry.attributes.hasOwnProperty( 'color' ) ) {
  401. mat.vertexColors = true;
  402. }
  403. mat = this._compareMaterials( mat );
  404. const mesh = new Mesh( geometry, mat );
  405. mesh.castShadow = attributes.castsShadows;
  406. mesh.receiveShadow = attributes.receivesShadows;
  407. mesh.userData[ 'attributes' ] = attributes;
  408. mesh.userData[ 'objectType' ] = obj.objectType;
  409. if ( attributes.name ) {
  410. mesh.name = attributes.name;
  411. }
  412. return mesh;
  413. case 'Curve':
  414. geometry = loader.parse( obj.geometry );
  415. _color = attributes.drawColor;
  416. color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 );
  417. material = new LineBasicMaterial( { color: color } );
  418. material = this._compareMaterials( material );
  419. const lines = new Line( geometry, material );
  420. lines.userData[ 'attributes' ] = attributes;
  421. lines.userData[ 'objectType' ] = obj.objectType;
  422. if ( attributes.name ) {
  423. lines.name = attributes.name;
  424. }
  425. return lines;
  426. case 'TextDot':
  427. geometry = obj.geometry;
  428. const ctx = document.createElement( 'canvas' ).getContext( '2d' );
  429. const font = `${geometry.fontHeight}px ${geometry.fontFace}`;
  430. ctx.font = font;
  431. const width = ctx.measureText( geometry.text ).width + 10;
  432. const height = geometry.fontHeight + 10;
  433. const r = window.devicePixelRatio;
  434. ctx.canvas.width = width * r;
  435. ctx.canvas.height = height * r;
  436. ctx.canvas.style.width = width + 'px';
  437. ctx.canvas.style.height = height + 'px';
  438. ctx.setTransform( r, 0, 0, r, 0, 0 );
  439. ctx.font = font;
  440. ctx.textBaseline = 'middle';
  441. ctx.textAlign = 'center';
  442. color = attributes.drawColor;
  443. ctx.fillStyle = `rgba(${color.r},${color.g},${color.b},${color.a})`;
  444. ctx.fillRect( 0, 0, width, height );
  445. ctx.fillStyle = 'white';
  446. ctx.fillText( geometry.text, width / 2, height / 2 );
  447. const texture = new CanvasTexture( ctx.canvas );
  448. texture.minFilter = LinearFilter;
  449. texture.wrapS = ClampToEdgeWrapping;
  450. texture.wrapT = ClampToEdgeWrapping;
  451. material = new SpriteMaterial( { map: texture, depthTest: false } );
  452. const sprite = new Sprite( material );
  453. sprite.position.set( geometry.point[ 0 ], geometry.point[ 1 ], geometry.point[ 2 ] );
  454. sprite.scale.set( width / 10, height / 10, 1.0 );
  455. sprite.userData[ 'attributes' ] = attributes;
  456. sprite.userData[ 'objectType' ] = obj.objectType;
  457. if ( attributes.name ) {
  458. sprite.name = attributes.name;
  459. }
  460. return sprite;
  461. case 'Light':
  462. geometry = obj.geometry;
  463. let light;
  464. switch ( geometry.lightStyle.name ) {
  465. case 'LightStyle_WorldPoint':
  466. light = new PointLight();
  467. light.castShadow = attributes.castsShadows;
  468. light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
  469. light.shadow.normalBias = 0.1;
  470. break;
  471. case 'LightStyle_WorldSpot':
  472. light = new SpotLight();
  473. light.castShadow = attributes.castsShadows;
  474. light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
  475. light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
  476. light.angle = geometry.spotAngleRadians;
  477. light.shadow.normalBias = 0.1;
  478. break;
  479. case 'LightStyle_WorldRectangular':
  480. light = new RectAreaLight();
  481. const width = Math.abs( geometry.width[ 2 ] );
  482. const height = Math.abs( geometry.length[ 0 ] );
  483. light.position.set( geometry.location[ 0 ] - ( height / 2 ), geometry.location[ 1 ], geometry.location[ 2 ] - ( width / 2 ) );
  484. light.height = height;
  485. light.width = width;
  486. light.lookAt( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
  487. break;
  488. case 'LightStyle_WorldDirectional':
  489. light = new DirectionalLight();
  490. light.castShadow = attributes.castsShadows;
  491. light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
  492. light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
  493. light.shadow.normalBias = 0.1;
  494. break;
  495. case 'LightStyle_WorldLinear':
  496. // no conversion exists, warning has already been printed to the console
  497. break;
  498. default:
  499. break;
  500. }
  501. if ( light ) {
  502. light.intensity = geometry.intensity;
  503. _color = geometry.diffuse;
  504. color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 );
  505. light.color = color;
  506. light.userData[ 'attributes' ] = attributes;
  507. light.userData[ 'objectType' ] = obj.objectType;
  508. }
  509. return light;
  510. }
  511. }
  512. _initLibrary() {
  513. if ( ! this.libraryPending ) {
  514. // Load rhino3dm wrapper.
  515. const jsLoader = new FileLoader( this.manager );
  516. jsLoader.setPath( this.libraryPath );
  517. const jsContent = new Promise( ( resolve, reject ) => {
  518. jsLoader.load( 'rhino3dm.js', resolve, undefined, reject );
  519. } );
  520. // Load rhino3dm WASM binary.
  521. const binaryLoader = new FileLoader( this.manager );
  522. binaryLoader.setPath( this.libraryPath );
  523. binaryLoader.setResponseType( 'arraybuffer' );
  524. const binaryContent = new Promise( ( resolve, reject ) => {
  525. binaryLoader.load( 'rhino3dm.wasm', resolve, undefined, reject );
  526. } );
  527. this.libraryPending = Promise.all( [ jsContent, binaryContent ] )
  528. .then( ( [ jsContent, binaryContent ] ) => {
  529. //this.libraryBinary = binaryContent;
  530. this.libraryConfig.wasmBinary = binaryContent;
  531. const fn = Rhino3dmWorker.toString();
  532. const body = [
  533. '/* rhino3dm.js */',
  534. jsContent,
  535. '/* worker */',
  536. fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
  537. ].join( '\n' );
  538. this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
  539. } );
  540. }
  541. return this.libraryPending;
  542. }
  543. _getWorker( taskCost ) {
  544. return this._initLibrary().then( () => {
  545. if ( this.workerPool.length < this.workerLimit ) {
  546. const worker = new Worker( this.workerSourceURL );
  547. worker._callbacks = {};
  548. worker._taskCosts = {};
  549. worker._taskLoad = 0;
  550. worker.postMessage( {
  551. type: 'init',
  552. libraryConfig: this.libraryConfig
  553. } );
  554. worker.onmessage = e => {
  555. const message = e.data;
  556. switch ( message.type ) {
  557. case 'warning':
  558. this.warnings.push( message.data );
  559. console.warn( message.data );
  560. break;
  561. case 'decode':
  562. worker._callbacks[ message.id ].resolve( message );
  563. break;
  564. case 'error':
  565. worker._callbacks[ message.id ].reject( message );
  566. break;
  567. default:
  568. console.error( 'THREE.Rhino3dmLoader: Unexpected message, "' + message.type + '"' );
  569. }
  570. };
  571. this.workerPool.push( worker );
  572. } else {
  573. this.workerPool.sort( function ( a, b ) {
  574. return a._taskLoad > b._taskLoad ? - 1 : 1;
  575. } );
  576. }
  577. const worker = this.workerPool[ this.workerPool.length - 1 ];
  578. worker._taskLoad += taskCost;
  579. return worker;
  580. } );
  581. }
  582. _releaseTask( worker, taskID ) {
  583. worker._taskLoad -= worker._taskCosts[ taskID ];
  584. delete worker._callbacks[ taskID ];
  585. delete worker._taskCosts[ taskID ];
  586. }
  587. dispose() {
  588. for ( let i = 0; i < this.workerPool.length; ++ i ) {
  589. this.workerPool[ i ].terminate();
  590. }
  591. this.workerPool.length = 0;
  592. return this;
  593. }
  594. }
  595. /* WEB WORKER */
  596. function Rhino3dmWorker() {
  597. let libraryPending;
  598. let libraryConfig;
  599. let rhino;
  600. let taskID;
  601. onmessage = function ( e ) {
  602. const message = e.data;
  603. switch ( message.type ) {
  604. case 'init':
  605. libraryConfig = message.libraryConfig;
  606. const wasmBinary = libraryConfig.wasmBinary;
  607. let RhinoModule;
  608. libraryPending = new Promise( function ( resolve ) {
  609. /* Like Basis Loader */
  610. RhinoModule = { wasmBinary, onRuntimeInitialized: resolve };
  611. rhino3dm( RhinoModule ); // eslint-disable-line no-undef
  612. } ).then( () => {
  613. rhino = RhinoModule;
  614. } );
  615. break;
  616. case 'decode':
  617. taskID = message.id;
  618. const buffer = message.buffer;
  619. libraryPending.then( () => {
  620. try {
  621. const data = decodeObjects( rhino, buffer );
  622. self.postMessage( { type: 'decode', id: message.id, data } );
  623. } catch ( error ) {
  624. self.postMessage( { type: 'error', id: message.id, error } );
  625. }
  626. } );
  627. break;
  628. }
  629. };
  630. function decodeObjects( rhino, buffer ) {
  631. const arr = new Uint8Array( buffer );
  632. const doc = rhino.File3dm.fromByteArray( arr );
  633. const objects = [];
  634. const materials = [];
  635. const layers = [];
  636. const views = [];
  637. const namedViews = [];
  638. const groups = [];
  639. const strings = [];
  640. //Handle objects
  641. const objs = doc.objects();
  642. const cnt = objs.count;
  643. for ( let i = 0; i < cnt; i ++ ) {
  644. const _object = objs.get( i );
  645. const object = extractObjectData( _object, doc );
  646. _object.delete();
  647. if ( object ) {
  648. objects.push( object );
  649. }
  650. }
  651. // Handle instance definitions
  652. // console.log( `Instance Definitions Count: ${doc.instanceDefinitions().count()}` );
  653. for ( let i = 0; i < doc.instanceDefinitions().count; i ++ ) {
  654. const idef = doc.instanceDefinitions().get( i );
  655. const idefAttributes = extractProperties( idef );
  656. idefAttributes.objectIds = idef.getObjectIds();
  657. objects.push( { geometry: null, attributes: idefAttributes, objectType: 'InstanceDefinition' } );
  658. }
  659. // Handle materials
  660. const textureTypes = [
  661. // rhino.TextureType.Bitmap,
  662. rhino.TextureType.Diffuse,
  663. rhino.TextureType.Bump,
  664. rhino.TextureType.Transparency,
  665. rhino.TextureType.Opacity,
  666. rhino.TextureType.Emap
  667. ];
  668. const pbrTextureTypes = [
  669. rhino.TextureType.PBR_BaseColor,
  670. rhino.TextureType.PBR_Subsurface,
  671. rhino.TextureType.PBR_SubsurfaceScattering,
  672. rhino.TextureType.PBR_SubsurfaceScatteringRadius,
  673. rhino.TextureType.PBR_Metallic,
  674. rhino.TextureType.PBR_Specular,
  675. rhino.TextureType.PBR_SpecularTint,
  676. rhino.TextureType.PBR_Roughness,
  677. rhino.TextureType.PBR_Anisotropic,
  678. rhino.TextureType.PBR_Anisotropic_Rotation,
  679. rhino.TextureType.PBR_Sheen,
  680. rhino.TextureType.PBR_SheenTint,
  681. rhino.TextureType.PBR_Clearcoat,
  682. rhino.TextureType.PBR_ClearcoatBump,
  683. rhino.TextureType.PBR_ClearcoatRoughness,
  684. rhino.TextureType.PBR_OpacityIor,
  685. rhino.TextureType.PBR_OpacityRoughness,
  686. rhino.TextureType.PBR_Emission,
  687. rhino.TextureType.PBR_AmbientOcclusion,
  688. rhino.TextureType.PBR_Displacement
  689. ];
  690. for ( let i = 0; i < doc.materials().count; i ++ ) {
  691. const _material = doc.materials().get( i );
  692. const material = extractProperties( _material );
  693. const textures = [];
  694. textures.push( ...extractTextures( _material, textureTypes, doc ) );
  695. material.pbrSupported = _material.physicallyBased().supported;
  696. if ( material.pbrSupported ) {
  697. textures.push( ...extractTextures( _material, pbrTextureTypes, doc ) );
  698. material.pbr = extractProperties( _material.physicallyBased() );
  699. }
  700. material.textures = textures;
  701. materials.push( material );
  702. _material.delete();
  703. }
  704. // Handle layers
  705. for ( let i = 0; i < doc.layers().count; i ++ ) {
  706. const _layer = doc.layers().get( i );
  707. const layer = extractProperties( _layer );
  708. layers.push( layer );
  709. _layer.delete();
  710. }
  711. // Handle views
  712. for ( let i = 0; i < doc.views().count; i ++ ) {
  713. const _view = doc.views().get( i );
  714. const view = extractProperties( _view );
  715. views.push( view );
  716. _view.delete();
  717. }
  718. // Handle named views
  719. for ( let i = 0; i < doc.namedViews().count; i ++ ) {
  720. const _namedView = doc.namedViews().get( i );
  721. const namedView = extractProperties( _namedView );
  722. namedViews.push( namedView );
  723. _namedView.delete();
  724. }
  725. // Handle groups
  726. for ( let i = 0; i < doc.groups().count; i ++ ) {
  727. const _group = doc.groups().get( i );
  728. const group = extractProperties( _group );
  729. groups.push( group );
  730. _group.delete();
  731. }
  732. // Handle settings
  733. const settings = extractProperties( doc.settings() );
  734. //TODO: Handle other document stuff like dimstyles, instance definitions, bitmaps etc.
  735. // Handle dimstyles
  736. // console.log( `Dimstyle Count: ${doc.dimstyles().count()}` );
  737. // Handle bitmaps
  738. // console.log( `Bitmap Count: ${doc.bitmaps().count()}` );
  739. // Handle strings
  740. // console.log( `Document Strings Count: ${doc.strings().count()}` );
  741. // Note: doc.strings().documentUserTextCount() counts any doc.strings defined in a section
  742. // console.log( `Document User Text Count: ${doc.strings().documentUserTextCount()}` );
  743. const strings_count = doc.strings().count;
  744. for ( let i = 0; i < strings_count; i ++ ) {
  745. strings.push( doc.strings().get( i ) );
  746. }
  747. // Handle Render Environments for Material Environment
  748. // get the id of the active render environment skylight, which we'll use for environment texture
  749. const reflectionId = doc.settings().renderSettings().renderEnvironments.reflectionId;
  750. const rc = doc.renderContent();
  751. let renderEnvironment = null;
  752. for ( let i = 0; i < rc.count; i ++ ) {
  753. const content = rc.get( i );
  754. switch ( content.kind ) {
  755. case 'environment':
  756. const id = content.id;
  757. // there could be multiple render environments in a 3dm file
  758. if ( id !== reflectionId ) break;
  759. const renderTexture = content.findChild( 'texture' );
  760. const fileName = renderTexture.fileName;
  761. for ( let j = 0; j < doc.embeddedFiles().count; j ++ ) {
  762. const _fileName = doc.embeddedFiles().get( j ).fileName;
  763. if ( fileName === _fileName ) {
  764. const background = doc.getEmbeddedFileAsBase64( fileName );
  765. const backgroundImage = 'data:image/png;base64,' + background;
  766. renderEnvironment = { type: 'renderEnvironment', image: backgroundImage, name: fileName };
  767. }
  768. }
  769. break;
  770. }
  771. }
  772. // Handle Render Settings
  773. const renderSettings = {
  774. ambientLight: doc.settings().renderSettings().ambientLight,
  775. backgroundColorTop: doc.settings().renderSettings().backgroundColorTop,
  776. backgroundColorBottom: doc.settings().renderSettings().backgroundColorBottom,
  777. useHiddenLights: doc.settings().renderSettings().useHiddenLights,
  778. depthCue: doc.settings().renderSettings().depthCue,
  779. flatShade: doc.settings().renderSettings().flatShade,
  780. renderBackFaces: doc.settings().renderSettings().renderBackFaces,
  781. renderPoints: doc.settings().renderSettings().renderPoints,
  782. renderCurves: doc.settings().renderSettings().renderCurves,
  783. renderIsoParams: doc.settings().renderSettings().renderIsoParams,
  784. renderMeshEdges: doc.settings().renderSettings().renderMeshEdges,
  785. renderAnnotations: doc.settings().renderSettings().renderAnnotations,
  786. useViewportSize: doc.settings().renderSettings().useViewportSize,
  787. scaleBackgroundToFit: doc.settings().renderSettings().scaleBackgroundToFit,
  788. transparentBackground: doc.settings().renderSettings().transparentBackground,
  789. imageDpi: doc.settings().renderSettings().imageDpi,
  790. shadowMapLevel: doc.settings().renderSettings().shadowMapLevel,
  791. namedView: doc.settings().renderSettings().namedView,
  792. snapShot: doc.settings().renderSettings().snapShot,
  793. specificViewport: doc.settings().renderSettings().specificViewport,
  794. groundPlane: extractProperties( doc.settings().renderSettings().groundPlane ),
  795. safeFrame: extractProperties( doc.settings().renderSettings().safeFrame ),
  796. dithering: extractProperties( doc.settings().renderSettings().dithering ),
  797. skylight: extractProperties( doc.settings().renderSettings().skylight ),
  798. linearWorkflow: extractProperties( doc.settings().renderSettings().linearWorkflow ),
  799. renderChannels: extractProperties( doc.settings().renderSettings().renderChannels ),
  800. sun: extractProperties( doc.settings().renderSettings().sun ),
  801. renderEnvironments: extractProperties( doc.settings().renderSettings().renderEnvironments ),
  802. postEffects: extractProperties( doc.settings().renderSettings().postEffects ),
  803. };
  804. doc.delete();
  805. return { objects, materials, layers, views, namedViews, groups, strings, settings, renderSettings, renderEnvironment };
  806. }
  807. function extractTextures( m, tTypes, d ) {
  808. const textures = [];
  809. for ( let i = 0; i < tTypes.length; i ++ ) {
  810. const _texture = m.getTexture( tTypes[ i ] );
  811. if ( _texture ) {
  812. let textureType = tTypes[ i ].constructor.name;
  813. textureType = textureType.substring( 12, textureType.length );
  814. const texture = extractTextureData( _texture, textureType, d );
  815. textures.push( texture );
  816. _texture.delete();
  817. }
  818. }
  819. return textures;
  820. }
  821. function extractTextureData( t, tType, d ) {
  822. const texture = { type: tType };
  823. const image = d.getEmbeddedFileAsBase64( t.fileName );
  824. texture.wrapU = t.wrapU;
  825. texture.wrapV = t.wrapV;
  826. texture.wrapW = t.wrapW;
  827. const uvw = t.uvwTransform.toFloatArray( true );
  828. texture.repeat = [ uvw[ 0 ], uvw[ 5 ] ];
  829. if ( image ) {
  830. texture.image = 'data:image/png;base64,' + image;
  831. } else {
  832. self.postMessage( { type: 'warning', id: taskID, data: {
  833. message: `THREE.3DMLoader: Image for ${tType} texture not embedded in file.`,
  834. type: 'missing resource'
  835. }
  836. } );
  837. texture.image = null;
  838. }
  839. return texture;
  840. }
  841. function extractObjectData( object, doc ) {
  842. const _geometry = object.geometry();
  843. const _attributes = object.attributes();
  844. let objectType = _geometry.objectType;
  845. let geometry, attributes, position, data, mesh;
  846. // skip instance definition objects
  847. //if( _attributes.isInstanceDefinitionObject ) { continue; }
  848. // TODO: handle other geometry types
  849. switch ( objectType ) {
  850. case rhino.ObjectType.Curve:
  851. const pts = curveToPoints( _geometry, 100 );
  852. position = {};
  853. attributes = {};
  854. data = {};
  855. position.itemSize = 3;
  856. position.type = 'Float32Array';
  857. position.array = [];
  858. for ( let j = 0; j < pts.length; j ++ ) {
  859. position.array.push( pts[ j ][ 0 ] );
  860. position.array.push( pts[ j ][ 1 ] );
  861. position.array.push( pts[ j ][ 2 ] );
  862. }
  863. attributes.position = position;
  864. data.attributes = attributes;
  865. geometry = { data };
  866. break;
  867. case rhino.ObjectType.Point:
  868. const pt = _geometry.location;
  869. position = {};
  870. const color = {};
  871. attributes = {};
  872. data = {};
  873. position.itemSize = 3;
  874. position.type = 'Float32Array';
  875. position.array = [ pt[ 0 ], pt[ 1 ], pt[ 2 ] ];
  876. const _color = _attributes.drawColor( doc );
  877. color.itemSize = 3;
  878. color.type = 'Float32Array';
  879. color.array = [ _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 ];
  880. attributes.position = position;
  881. attributes.color = color;
  882. data.attributes = attributes;
  883. geometry = { data };
  884. break;
  885. case rhino.ObjectType.PointSet:
  886. case rhino.ObjectType.Mesh:
  887. geometry = _geometry.toThreejsJSON();
  888. break;
  889. case rhino.ObjectType.Brep:
  890. const faces = _geometry.faces();
  891. mesh = new rhino.Mesh();
  892. for ( let faceIndex = 0; faceIndex < faces.count; faceIndex ++ ) {
  893. const face = faces.get( faceIndex );
  894. const _mesh = face.getMesh( rhino.MeshType.Any );
  895. if ( _mesh ) {
  896. mesh.append( _mesh );
  897. _mesh.delete();
  898. }
  899. face.delete();
  900. }
  901. if ( mesh.faces().count > 0 ) {
  902. mesh.compact();
  903. geometry = mesh.toThreejsJSON();
  904. faces.delete();
  905. }
  906. mesh.delete();
  907. break;
  908. case rhino.ObjectType.Extrusion:
  909. mesh = _geometry.getMesh( rhino.MeshType.Any );
  910. if ( mesh ) {
  911. geometry = mesh.toThreejsJSON();
  912. mesh.delete();
  913. }
  914. break;
  915. case rhino.ObjectType.TextDot:
  916. geometry = extractProperties( _geometry );
  917. break;
  918. case rhino.ObjectType.Light:
  919. geometry = extractProperties( _geometry );
  920. if ( geometry.lightStyle.name === 'LightStyle_WorldLinear' ) {
  921. self.postMessage( { type: 'warning', id: taskID, data: {
  922. message: `THREE.3DMLoader: No conversion exists for ${objectType.constructor.name} ${geometry.lightStyle.name}`,
  923. type: 'no conversion',
  924. guid: _attributes.id
  925. }
  926. } );
  927. }
  928. break;
  929. case rhino.ObjectType.InstanceReference:
  930. geometry = extractProperties( _geometry );
  931. geometry.xform = extractProperties( _geometry.xform );
  932. geometry.xform.array = _geometry.xform.toFloatArray( true );
  933. break;
  934. case rhino.ObjectType.SubD:
  935. // TODO: precalculate resulting vertices and faces and warn on excessive results
  936. _geometry.subdivide( 3 );
  937. mesh = rhino.Mesh.createFromSubDControlNet( _geometry, false );
  938. if ( mesh ) {
  939. geometry = mesh.toThreejsJSON();
  940. mesh.delete();
  941. }
  942. break;
  943. /*
  944. case rhino.ObjectType.Annotation:
  945. case rhino.ObjectType.Hatch:
  946. case rhino.ObjectType.ClipPlane:
  947. */
  948. default:
  949. self.postMessage( { type: 'warning', id: taskID, data: {
  950. message: `THREE.3DMLoader: Conversion not implemented for ${objectType.constructor.name}`,
  951. type: 'not implemented',
  952. guid: _attributes.id
  953. }
  954. } );
  955. break;
  956. }
  957. if ( geometry ) {
  958. attributes = extractProperties( _attributes );
  959. attributes.geometry = extractProperties( _geometry );
  960. if ( _attributes.groupCount > 0 ) {
  961. attributes.groupIds = _attributes.getGroupList();
  962. }
  963. if ( _attributes.userStringCount > 0 ) {
  964. attributes.userStrings = _attributes.getUserStrings();
  965. }
  966. if ( _geometry.userStringCount > 0 ) {
  967. attributes.geometry.userStrings = _geometry.getUserStrings();
  968. }
  969. if ( _attributes.decals().count > 0 ) {
  970. self.postMessage( { type: 'warning', id: taskID, data: {
  971. message: 'THREE.3DMLoader: No conversion exists for the decals associated with this object.',
  972. type: 'no conversion',
  973. guid: _attributes.id
  974. }
  975. } );
  976. }
  977. attributes.drawColor = _attributes.drawColor( doc );
  978. objectType = objectType.constructor.name;
  979. objectType = objectType.substring( 11, objectType.length );
  980. return { geometry, attributes, objectType };
  981. } else {
  982. self.postMessage( { type: 'warning', id: taskID, data: {
  983. message: `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.`,
  984. type: 'missing mesh',
  985. guid: _attributes.id
  986. }
  987. } );
  988. }
  989. }
  990. function extractProperties( object ) {
  991. const result = {};
  992. for ( const property in object ) {
  993. const value = object[ property ];
  994. if ( typeof value !== 'function' ) {
  995. if ( typeof value === 'object' && value !== null && value.hasOwnProperty( 'constructor' ) ) {
  996. result[ property ] = { name: value.constructor.name, value: value.value };
  997. } else if ( typeof value === 'object' && value !== null ) {
  998. result[ property ] = extractProperties( value );
  999. } else {
  1000. result[ property ] = value;
  1001. }
  1002. } else {
  1003. // these are functions that could be called to extract more data.
  1004. //console.log( `${property}: ${object[ property ].constructor.name}` );
  1005. }
  1006. }
  1007. return result;
  1008. }
  1009. function curveToPoints( curve, pointLimit ) {
  1010. let pointCount = pointLimit;
  1011. let rc = [];
  1012. const ts = [];
  1013. if ( curve instanceof rhino.LineCurve ) {
  1014. return [ curve.pointAtStart, curve.pointAtEnd ];
  1015. }
  1016. if ( curve instanceof rhino.PolylineCurve ) {
  1017. pointCount = curve.pointCount;
  1018. for ( let i = 0; i < pointCount; i ++ ) {
  1019. rc.push( curve.point( i ) );
  1020. }
  1021. return rc;
  1022. }
  1023. if ( curve instanceof rhino.PolyCurve ) {
  1024. const segmentCount = curve.segmentCount;
  1025. for ( let i = 0; i < segmentCount; i ++ ) {
  1026. const segment = curve.segmentCurve( i );
  1027. const segmentArray = curveToPoints( segment, pointCount );
  1028. rc = rc.concat( segmentArray );
  1029. segment.delete();
  1030. }
  1031. return rc;
  1032. }
  1033. if ( curve instanceof rhino.ArcCurve ) {
  1034. pointCount = Math.floor( curve.angleDegrees / 5 );
  1035. pointCount = pointCount < 2 ? 2 : pointCount;
  1036. // alternative to this hardcoded version: https://stackoverflow.com/a/18499923/2179399
  1037. }
  1038. if ( curve instanceof rhino.NurbsCurve && curve.degree === 1 ) {
  1039. const pLine = curve.tryGetPolyline();
  1040. for ( let i = 0; i < pLine.count; i ++ ) {
  1041. rc.push( pLine.get( i ) );
  1042. }
  1043. pLine.delete();
  1044. return rc;
  1045. }
  1046. const domain = curve.domain;
  1047. const divisions = pointCount - 1.0;
  1048. for ( let j = 0; j < pointCount; j ++ ) {
  1049. const t = domain[ 0 ] + ( j / divisions ) * ( domain[ 1 ] - domain[ 0 ] );
  1050. if ( t === domain[ 0 ] || t === domain[ 1 ] ) {
  1051. ts.push( t );
  1052. continue;
  1053. }
  1054. const tan = curve.tangentAt( t );
  1055. const prevTan = curve.tangentAt( ts.slice( - 1 )[ 0 ] );
  1056. // Duplicated from THREE.Vector3
  1057. // How to pass imports to worker?
  1058. const tS = tan[ 0 ] * tan[ 0 ] + tan[ 1 ] * tan[ 1 ] + tan[ 2 ] * tan[ 2 ];
  1059. const ptS = prevTan[ 0 ] * prevTan[ 0 ] + prevTan[ 1 ] * prevTan[ 1 ] + prevTan[ 2 ] * prevTan[ 2 ];
  1060. const denominator = Math.sqrt( tS * ptS );
  1061. let angle;
  1062. if ( denominator === 0 ) {
  1063. angle = Math.PI / 2;
  1064. } else {
  1065. const theta = ( tan.x * prevTan.x + tan.y * prevTan.y + tan.z * prevTan.z ) / denominator;
  1066. angle = Math.acos( Math.max( - 1, Math.min( 1, theta ) ) );
  1067. }
  1068. if ( angle < 0.1 ) continue;
  1069. ts.push( t );
  1070. }
  1071. rc = ts.map( t => curve.pointAt( t ) );
  1072. return rc;
  1073. }
  1074. }
  1075. export { Rhino3dmLoader };