3DMLoader.js 37 KB

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