3DMLoader.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  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.generateMipmaps = false;
  450. texture.wrapS = ClampToEdgeWrapping;
  451. texture.wrapT = ClampToEdgeWrapping;
  452. material = new SpriteMaterial( { map: texture, depthTest: false } );
  453. const sprite = new Sprite( material );
  454. sprite.position.set( geometry.point[ 0 ], geometry.point[ 1 ], geometry.point[ 2 ] );
  455. sprite.scale.set( width / 10, height / 10, 1.0 );
  456. sprite.userData[ 'attributes' ] = attributes;
  457. sprite.userData[ 'objectType' ] = obj.objectType;
  458. if ( attributes.name ) {
  459. sprite.name = attributes.name;
  460. }
  461. return sprite;
  462. case 'Light':
  463. geometry = obj.geometry;
  464. let light;
  465. switch ( geometry.lightStyle.name ) {
  466. case 'LightStyle_WorldPoint':
  467. light = new PointLight();
  468. light.castShadow = attributes.castsShadows;
  469. light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
  470. light.shadow.normalBias = 0.1;
  471. break;
  472. case 'LightStyle_WorldSpot':
  473. light = new SpotLight();
  474. light.castShadow = attributes.castsShadows;
  475. light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
  476. light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
  477. light.angle = geometry.spotAngleRadians;
  478. light.shadow.normalBias = 0.1;
  479. break;
  480. case 'LightStyle_WorldRectangular':
  481. light = new RectAreaLight();
  482. const width = Math.abs( geometry.width[ 2 ] );
  483. const height = Math.abs( geometry.length[ 0 ] );
  484. light.position.set( geometry.location[ 0 ] - ( height / 2 ), geometry.location[ 1 ], geometry.location[ 2 ] - ( width / 2 ) );
  485. light.height = height;
  486. light.width = width;
  487. light.lookAt( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
  488. break;
  489. case 'LightStyle_WorldDirectional':
  490. light = new DirectionalLight();
  491. light.castShadow = attributes.castsShadows;
  492. light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
  493. light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
  494. light.shadow.normalBias = 0.1;
  495. break;
  496. case 'LightStyle_WorldLinear':
  497. // no conversion exists, warning has already been printed to the console
  498. break;
  499. default:
  500. break;
  501. }
  502. if ( light ) {
  503. light.intensity = geometry.intensity;
  504. _color = geometry.diffuse;
  505. color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 );
  506. light.color = color;
  507. light.userData[ 'attributes' ] = attributes;
  508. light.userData[ 'objectType' ] = obj.objectType;
  509. }
  510. return light;
  511. }
  512. }
  513. _initLibrary() {
  514. if ( ! this.libraryPending ) {
  515. // Load rhino3dm wrapper.
  516. const jsLoader = new FileLoader( this.manager );
  517. jsLoader.setPath( this.libraryPath );
  518. const jsContent = new Promise( ( resolve, reject ) => {
  519. jsLoader.load( 'rhino3dm.js', resolve, undefined, reject );
  520. } );
  521. // Load rhino3dm WASM binary.
  522. const binaryLoader = new FileLoader( this.manager );
  523. binaryLoader.setPath( this.libraryPath );
  524. binaryLoader.setResponseType( 'arraybuffer' );
  525. const binaryContent = new Promise( ( resolve, reject ) => {
  526. binaryLoader.load( 'rhino3dm.wasm', resolve, undefined, reject );
  527. } );
  528. this.libraryPending = Promise.all( [ jsContent, binaryContent ] )
  529. .then( ( [ jsContent, binaryContent ] ) => {
  530. //this.libraryBinary = binaryContent;
  531. this.libraryConfig.wasmBinary = binaryContent;
  532. const fn = Rhino3dmWorker.toString();
  533. const body = [
  534. '/* rhino3dm.js */',
  535. jsContent,
  536. '/* worker */',
  537. fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
  538. ].join( '\n' );
  539. this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
  540. } );
  541. }
  542. return this.libraryPending;
  543. }
  544. _getWorker( taskCost ) {
  545. return this._initLibrary().then( () => {
  546. if ( this.workerPool.length < this.workerLimit ) {
  547. const worker = new Worker( this.workerSourceURL );
  548. worker._callbacks = {};
  549. worker._taskCosts = {};
  550. worker._taskLoad = 0;
  551. worker.postMessage( {
  552. type: 'init',
  553. libraryConfig: this.libraryConfig
  554. } );
  555. worker.onmessage = e => {
  556. const message = e.data;
  557. switch ( message.type ) {
  558. case 'warning':
  559. this.warnings.push( message.data );
  560. console.warn( message.data );
  561. break;
  562. case 'decode':
  563. worker._callbacks[ message.id ].resolve( message );
  564. break;
  565. case 'error':
  566. worker._callbacks[ message.id ].reject( message );
  567. break;
  568. default:
  569. console.error( 'THREE.Rhino3dmLoader: Unexpected message, "' + message.type + '"' );
  570. }
  571. };
  572. this.workerPool.push( worker );
  573. } else {
  574. this.workerPool.sort( function ( a, b ) {
  575. return a._taskLoad > b._taskLoad ? - 1 : 1;
  576. } );
  577. }
  578. const worker = this.workerPool[ this.workerPool.length - 1 ];
  579. worker._taskLoad += taskCost;
  580. return worker;
  581. } );
  582. }
  583. _releaseTask( worker, taskID ) {
  584. worker._taskLoad -= worker._taskCosts[ taskID ];
  585. delete worker._callbacks[ taskID ];
  586. delete worker._taskCosts[ taskID ];
  587. }
  588. dispose() {
  589. for ( let i = 0; i < this.workerPool.length; ++ i ) {
  590. this.workerPool[ i ].terminate();
  591. }
  592. this.workerPool.length = 0;
  593. return this;
  594. }
  595. }
  596. /* WEB WORKER */
  597. function Rhino3dmWorker() {
  598. let libraryPending;
  599. let libraryConfig;
  600. let rhino;
  601. let taskID;
  602. onmessage = function ( e ) {
  603. const message = e.data;
  604. switch ( message.type ) {
  605. case 'init':
  606. libraryConfig = message.libraryConfig;
  607. const wasmBinary = libraryConfig.wasmBinary;
  608. let RhinoModule;
  609. libraryPending = new Promise( function ( resolve ) {
  610. /* Like Basis Loader */
  611. RhinoModule = { wasmBinary, onRuntimeInitialized: resolve };
  612. rhino3dm( RhinoModule ); // eslint-disable-line no-undef
  613. } ).then( () => {
  614. rhino = RhinoModule;
  615. } );
  616. break;
  617. case 'decode':
  618. taskID = message.id;
  619. const buffer = message.buffer;
  620. libraryPending.then( () => {
  621. try {
  622. const data = decodeObjects( rhino, buffer );
  623. self.postMessage( { type: 'decode', id: message.id, data } );
  624. } catch ( error ) {
  625. self.postMessage( { type: 'error', id: message.id, error } );
  626. }
  627. } );
  628. break;
  629. }
  630. };
  631. function decodeObjects( rhino, buffer ) {
  632. const arr = new Uint8Array( buffer );
  633. const doc = rhino.File3dm.fromByteArray( arr );
  634. const objects = [];
  635. const materials = [];
  636. const layers = [];
  637. const views = [];
  638. const namedViews = [];
  639. const groups = [];
  640. const strings = [];
  641. //Handle objects
  642. const objs = doc.objects();
  643. const cnt = objs.count;
  644. for ( let i = 0; i < cnt; i ++ ) {
  645. const _object = objs.get( i );
  646. const object = extractObjectData( _object, doc );
  647. _object.delete();
  648. if ( object ) {
  649. objects.push( object );
  650. }
  651. }
  652. // Handle instance definitions
  653. // console.log( `Instance Definitions Count: ${doc.instanceDefinitions().count()}` );
  654. for ( let i = 0; i < doc.instanceDefinitions().count; i ++ ) {
  655. const idef = doc.instanceDefinitions().get( i );
  656. const idefAttributes = extractProperties( idef );
  657. idefAttributes.objectIds = idef.getObjectIds();
  658. objects.push( { geometry: null, attributes: idefAttributes, objectType: 'InstanceDefinition' } );
  659. }
  660. // Handle materials
  661. const textureTypes = [
  662. // rhino.TextureType.Bitmap,
  663. rhino.TextureType.Diffuse,
  664. rhino.TextureType.Bump,
  665. rhino.TextureType.Transparency,
  666. rhino.TextureType.Opacity,
  667. rhino.TextureType.Emap
  668. ];
  669. const pbrTextureTypes = [
  670. rhino.TextureType.PBR_BaseColor,
  671. rhino.TextureType.PBR_Subsurface,
  672. rhino.TextureType.PBR_SubsurfaceScattering,
  673. rhino.TextureType.PBR_SubsurfaceScatteringRadius,
  674. rhino.TextureType.PBR_Metallic,
  675. rhino.TextureType.PBR_Specular,
  676. rhino.TextureType.PBR_SpecularTint,
  677. rhino.TextureType.PBR_Roughness,
  678. rhino.TextureType.PBR_Anisotropic,
  679. rhino.TextureType.PBR_Anisotropic_Rotation,
  680. rhino.TextureType.PBR_Sheen,
  681. rhino.TextureType.PBR_SheenTint,
  682. rhino.TextureType.PBR_Clearcoat,
  683. rhino.TextureType.PBR_ClearcoatBump,
  684. rhino.TextureType.PBR_ClearcoatRoughness,
  685. rhino.TextureType.PBR_OpacityIor,
  686. rhino.TextureType.PBR_OpacityRoughness,
  687. rhino.TextureType.PBR_Emission,
  688. rhino.TextureType.PBR_AmbientOcclusion,
  689. rhino.TextureType.PBR_Displacement
  690. ];
  691. for ( let i = 0; i < doc.materials().count; i ++ ) {
  692. const _material = doc.materials().get( i );
  693. const material = extractProperties( _material );
  694. const textures = [];
  695. textures.push( ...extractTextures( _material, textureTypes, doc ) );
  696. material.pbrSupported = _material.physicallyBased().supported;
  697. if ( material.pbrSupported ) {
  698. textures.push( ...extractTextures( _material, pbrTextureTypes, doc ) );
  699. material.pbr = extractProperties( _material.physicallyBased() );
  700. }
  701. material.textures = textures;
  702. materials.push( material );
  703. _material.delete();
  704. }
  705. // Handle layers
  706. for ( let i = 0; i < doc.layers().count; i ++ ) {
  707. const _layer = doc.layers().get( i );
  708. const layer = extractProperties( _layer );
  709. layers.push( layer );
  710. _layer.delete();
  711. }
  712. // Handle views
  713. for ( let i = 0; i < doc.views().count; i ++ ) {
  714. const _view = doc.views().get( i );
  715. const view = extractProperties( _view );
  716. views.push( view );
  717. _view.delete();
  718. }
  719. // Handle named views
  720. for ( let i = 0; i < doc.namedViews().count; i ++ ) {
  721. const _namedView = doc.namedViews().get( i );
  722. const namedView = extractProperties( _namedView );
  723. namedViews.push( namedView );
  724. _namedView.delete();
  725. }
  726. // Handle groups
  727. for ( let i = 0; i < doc.groups().count; i ++ ) {
  728. const _group = doc.groups().get( i );
  729. const group = extractProperties( _group );
  730. groups.push( group );
  731. _group.delete();
  732. }
  733. // Handle settings
  734. const settings = extractProperties( doc.settings() );
  735. //TODO: Handle other document stuff like dimstyles, instance definitions, bitmaps etc.
  736. // Handle dimstyles
  737. // console.log( `Dimstyle Count: ${doc.dimstyles().count()}` );
  738. // Handle bitmaps
  739. // console.log( `Bitmap Count: ${doc.bitmaps().count()}` );
  740. // Handle strings
  741. // console.log( `Document Strings Count: ${doc.strings().count()}` );
  742. // Note: doc.strings().documentUserTextCount() counts any doc.strings defined in a section
  743. // console.log( `Document User Text Count: ${doc.strings().documentUserTextCount()}` );
  744. const strings_count = doc.strings().count;
  745. for ( let i = 0; i < strings_count; i ++ ) {
  746. strings.push( doc.strings().get( i ) );
  747. }
  748. // Handle Render Environments for Material Environment
  749. // get the id of the active render environment skylight, which we'll use for environment texture
  750. const reflectionId = doc.settings().renderSettings().renderEnvironments.reflectionId;
  751. const rc = doc.renderContent();
  752. let renderEnvironment = null;
  753. for ( let i = 0; i < rc.count; i ++ ) {
  754. const content = rc.get( i );
  755. switch ( content.kind ) {
  756. case 'environment':
  757. const id = content.id;
  758. // there could be multiple render environments in a 3dm file
  759. if ( id !== reflectionId ) break;
  760. const renderTexture = content.findChild( 'texture' );
  761. const fileName = renderTexture.fileName;
  762. for ( let j = 0; j < doc.embeddedFiles().count; j ++ ) {
  763. const _fileName = doc.embeddedFiles().get( j ).fileName;
  764. if ( fileName === _fileName ) {
  765. const background = doc.getEmbeddedFileAsBase64( fileName );
  766. const backgroundImage = 'data:image/png;base64,' + background;
  767. renderEnvironment = { type: 'renderEnvironment', image: backgroundImage, name: fileName };
  768. }
  769. }
  770. break;
  771. }
  772. }
  773. // Handle Render Settings
  774. const renderSettings = {
  775. ambientLight: doc.settings().renderSettings().ambientLight,
  776. backgroundColorTop: doc.settings().renderSettings().backgroundColorTop,
  777. backgroundColorBottom: doc.settings().renderSettings().backgroundColorBottom,
  778. useHiddenLights: doc.settings().renderSettings().useHiddenLights,
  779. depthCue: doc.settings().renderSettings().depthCue,
  780. flatShade: doc.settings().renderSettings().flatShade,
  781. renderBackFaces: doc.settings().renderSettings().renderBackFaces,
  782. renderPoints: doc.settings().renderSettings().renderPoints,
  783. renderCurves: doc.settings().renderSettings().renderCurves,
  784. renderIsoParams: doc.settings().renderSettings().renderIsoParams,
  785. renderMeshEdges: doc.settings().renderSettings().renderMeshEdges,
  786. renderAnnotations: doc.settings().renderSettings().renderAnnotations,
  787. useViewportSize: doc.settings().renderSettings().useViewportSize,
  788. scaleBackgroundToFit: doc.settings().renderSettings().scaleBackgroundToFit,
  789. transparentBackground: doc.settings().renderSettings().transparentBackground,
  790. imageDpi: doc.settings().renderSettings().imageDpi,
  791. shadowMapLevel: doc.settings().renderSettings().shadowMapLevel,
  792. namedView: doc.settings().renderSettings().namedView,
  793. snapShot: doc.settings().renderSettings().snapShot,
  794. specificViewport: doc.settings().renderSettings().specificViewport,
  795. groundPlane: extractProperties( doc.settings().renderSettings().groundPlane ),
  796. safeFrame: extractProperties( doc.settings().renderSettings().safeFrame ),
  797. dithering: extractProperties( doc.settings().renderSettings().dithering ),
  798. skylight: extractProperties( doc.settings().renderSettings().skylight ),
  799. linearWorkflow: extractProperties( doc.settings().renderSettings().linearWorkflow ),
  800. renderChannels: extractProperties( doc.settings().renderSettings().renderChannels ),
  801. sun: extractProperties( doc.settings().renderSettings().sun ),
  802. renderEnvironments: extractProperties( doc.settings().renderSettings().renderEnvironments ),
  803. postEffects: extractProperties( doc.settings().renderSettings().postEffects ),
  804. };
  805. doc.delete();
  806. return { objects, materials, layers, views, namedViews, groups, strings, settings, renderSettings, renderEnvironment };
  807. }
  808. function extractTextures( m, tTypes, d ) {
  809. const textures = [];
  810. for ( let i = 0; i < tTypes.length; i ++ ) {
  811. const _texture = m.getTexture( tTypes[ i ] );
  812. if ( _texture ) {
  813. let textureType = tTypes[ i ].constructor.name;
  814. textureType = textureType.substring( 12, textureType.length );
  815. const texture = extractTextureData( _texture, textureType, d );
  816. textures.push( texture );
  817. _texture.delete();
  818. }
  819. }
  820. return textures;
  821. }
  822. function extractTextureData( t, tType, d ) {
  823. const texture = { type: tType };
  824. const image = d.getEmbeddedFileAsBase64( t.fileName );
  825. texture.wrapU = t.wrapU;
  826. texture.wrapV = t.wrapV;
  827. texture.wrapW = t.wrapW;
  828. const uvw = t.uvwTransform.toFloatArray( true );
  829. texture.repeat = [ uvw[ 0 ], uvw[ 5 ] ];
  830. if ( image ) {
  831. texture.image = 'data:image/png;base64,' + image;
  832. } else {
  833. self.postMessage( { type: 'warning', id: taskID, data: {
  834. message: `THREE.3DMLoader: Image for ${tType} texture not embedded in file.`,
  835. type: 'missing resource'
  836. }
  837. } );
  838. texture.image = null;
  839. }
  840. return texture;
  841. }
  842. function extractObjectData( object, doc ) {
  843. const _geometry = object.geometry();
  844. const _attributes = object.attributes();
  845. let objectType = _geometry.objectType;
  846. let geometry, attributes, position, data, mesh;
  847. // skip instance definition objects
  848. //if( _attributes.isInstanceDefinitionObject ) { continue; }
  849. // TODO: handle other geometry types
  850. switch ( objectType ) {
  851. case rhino.ObjectType.Curve:
  852. const pts = curveToPoints( _geometry, 100 );
  853. position = {};
  854. attributes = {};
  855. data = {};
  856. position.itemSize = 3;
  857. position.type = 'Float32Array';
  858. position.array = [];
  859. for ( let j = 0; j < pts.length; j ++ ) {
  860. position.array.push( pts[ j ][ 0 ] );
  861. position.array.push( pts[ j ][ 1 ] );
  862. position.array.push( pts[ j ][ 2 ] );
  863. }
  864. attributes.position = position;
  865. data.attributes = attributes;
  866. geometry = { data };
  867. break;
  868. case rhino.ObjectType.Point:
  869. const pt = _geometry.location;
  870. position = {};
  871. const color = {};
  872. attributes = {};
  873. data = {};
  874. position.itemSize = 3;
  875. position.type = 'Float32Array';
  876. position.array = [ pt[ 0 ], pt[ 1 ], pt[ 2 ] ];
  877. const _color = _attributes.drawColor( doc );
  878. color.itemSize = 3;
  879. color.type = 'Float32Array';
  880. color.array = [ _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 ];
  881. attributes.position = position;
  882. attributes.color = color;
  883. data.attributes = attributes;
  884. geometry = { data };
  885. break;
  886. case rhino.ObjectType.PointSet:
  887. case rhino.ObjectType.Mesh:
  888. geometry = _geometry.toThreejsJSON();
  889. break;
  890. case rhino.ObjectType.Brep:
  891. const faces = _geometry.faces();
  892. mesh = new rhino.Mesh();
  893. for ( let faceIndex = 0; faceIndex < faces.count; faceIndex ++ ) {
  894. const face = faces.get( faceIndex );
  895. const _mesh = face.getMesh( rhino.MeshType.Any );
  896. if ( _mesh ) {
  897. mesh.append( _mesh );
  898. _mesh.delete();
  899. }
  900. face.delete();
  901. }
  902. if ( mesh.faces().count > 0 ) {
  903. mesh.compact();
  904. geometry = mesh.toThreejsJSON();
  905. faces.delete();
  906. }
  907. mesh.delete();
  908. break;
  909. case rhino.ObjectType.Extrusion:
  910. mesh = _geometry.getMesh( rhino.MeshType.Any );
  911. if ( mesh ) {
  912. geometry = mesh.toThreejsJSON();
  913. mesh.delete();
  914. }
  915. break;
  916. case rhino.ObjectType.TextDot:
  917. geometry = extractProperties( _geometry );
  918. break;
  919. case rhino.ObjectType.Light:
  920. geometry = extractProperties( _geometry );
  921. if ( geometry.lightStyle.name === 'LightStyle_WorldLinear' ) {
  922. self.postMessage( { type: 'warning', id: taskID, data: {
  923. message: `THREE.3DMLoader: No conversion exists for ${objectType.constructor.name} ${geometry.lightStyle.name}`,
  924. type: 'no conversion',
  925. guid: _attributes.id
  926. }
  927. } );
  928. }
  929. break;
  930. case rhino.ObjectType.InstanceReference:
  931. geometry = extractProperties( _geometry );
  932. geometry.xform = extractProperties( _geometry.xform );
  933. geometry.xform.array = _geometry.xform.toFloatArray( true );
  934. break;
  935. case rhino.ObjectType.SubD:
  936. // TODO: precalculate resulting vertices and faces and warn on excessive results
  937. _geometry.subdivide( 3 );
  938. mesh = rhino.Mesh.createFromSubDControlNet( _geometry, false );
  939. if ( mesh ) {
  940. geometry = mesh.toThreejsJSON();
  941. mesh.delete();
  942. }
  943. break;
  944. /*
  945. case rhino.ObjectType.Annotation:
  946. case rhino.ObjectType.Hatch:
  947. case rhino.ObjectType.ClipPlane:
  948. */
  949. default:
  950. self.postMessage( { type: 'warning', id: taskID, data: {
  951. message: `THREE.3DMLoader: Conversion not implemented for ${objectType.constructor.name}`,
  952. type: 'not implemented',
  953. guid: _attributes.id
  954. }
  955. } );
  956. break;
  957. }
  958. if ( geometry ) {
  959. attributes = extractProperties( _attributes );
  960. attributes.geometry = extractProperties( _geometry );
  961. if ( _attributes.groupCount > 0 ) {
  962. attributes.groupIds = _attributes.getGroupList();
  963. }
  964. if ( _attributes.userStringCount > 0 ) {
  965. attributes.userStrings = _attributes.getUserStrings();
  966. }
  967. if ( _geometry.userStringCount > 0 ) {
  968. attributes.geometry.userStrings = _geometry.getUserStrings();
  969. }
  970. if ( _attributes.decals().count > 0 ) {
  971. self.postMessage( { type: 'warning', id: taskID, data: {
  972. message: 'THREE.3DMLoader: No conversion exists for the decals associated with this object.',
  973. type: 'no conversion',
  974. guid: _attributes.id
  975. }
  976. } );
  977. }
  978. attributes.drawColor = _attributes.drawColor( doc );
  979. objectType = objectType.constructor.name;
  980. objectType = objectType.substring( 11, objectType.length );
  981. return { geometry, attributes, objectType };
  982. } else {
  983. self.postMessage( { type: 'warning', id: taskID, data: {
  984. message: `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.`,
  985. type: 'missing mesh',
  986. guid: _attributes.id
  987. }
  988. } );
  989. }
  990. }
  991. function extractProperties( object ) {
  992. const result = {};
  993. for ( const property in object ) {
  994. const value = object[ property ];
  995. if ( typeof value !== 'function' ) {
  996. if ( typeof value === 'object' && value !== null && value.hasOwnProperty( 'constructor' ) ) {
  997. result[ property ] = { name: value.constructor.name, value: value.value };
  998. } else if ( typeof value === 'object' && value !== null ) {
  999. result[ property ] = extractProperties( value );
  1000. } else {
  1001. result[ property ] = value;
  1002. }
  1003. } else {
  1004. // these are functions that could be called to extract more data.
  1005. //console.log( `${property}: ${object[ property ].constructor.name}` );
  1006. }
  1007. }
  1008. return result;
  1009. }
  1010. function curveToPoints( curve, pointLimit ) {
  1011. let pointCount = pointLimit;
  1012. let rc = [];
  1013. const ts = [];
  1014. if ( curve instanceof rhino.LineCurve ) {
  1015. return [ curve.pointAtStart, curve.pointAtEnd ];
  1016. }
  1017. if ( curve instanceof rhino.PolylineCurve ) {
  1018. pointCount = curve.pointCount;
  1019. for ( let i = 0; i < pointCount; i ++ ) {
  1020. rc.push( curve.point( i ) );
  1021. }
  1022. return rc;
  1023. }
  1024. if ( curve instanceof rhino.PolyCurve ) {
  1025. const segmentCount = curve.segmentCount;
  1026. for ( let i = 0; i < segmentCount; i ++ ) {
  1027. const segment = curve.segmentCurve( i );
  1028. const segmentArray = curveToPoints( segment, pointCount );
  1029. rc = rc.concat( segmentArray );
  1030. segment.delete();
  1031. }
  1032. return rc;
  1033. }
  1034. if ( curve instanceof rhino.ArcCurve ) {
  1035. pointCount = Math.floor( curve.angleDegrees / 5 );
  1036. pointCount = pointCount < 2 ? 2 : pointCount;
  1037. // alternative to this hardcoded version: https://stackoverflow.com/a/18499923/2179399
  1038. }
  1039. if ( curve instanceof rhino.NurbsCurve && curve.degree === 1 ) {
  1040. const pLine = curve.tryGetPolyline();
  1041. for ( let i = 0; i < pLine.count; i ++ ) {
  1042. rc.push( pLine.get( i ) );
  1043. }
  1044. pLine.delete();
  1045. return rc;
  1046. }
  1047. const domain = curve.domain;
  1048. const divisions = pointCount - 1.0;
  1049. for ( let j = 0; j < pointCount; j ++ ) {
  1050. const t = domain[ 0 ] + ( j / divisions ) * ( domain[ 1 ] - domain[ 0 ] );
  1051. if ( t === domain[ 0 ] || t === domain[ 1 ] ) {
  1052. ts.push( t );
  1053. continue;
  1054. }
  1055. const tan = curve.tangentAt( t );
  1056. const prevTan = curve.tangentAt( ts.slice( - 1 )[ 0 ] );
  1057. // Duplicated from THREE.Vector3
  1058. // How to pass imports to worker?
  1059. const tS = tan[ 0 ] * tan[ 0 ] + tan[ 1 ] * tan[ 1 ] + tan[ 2 ] * tan[ 2 ];
  1060. const ptS = prevTan[ 0 ] * prevTan[ 0 ] + prevTan[ 1 ] * prevTan[ 1 ] + prevTan[ 2 ] * prevTan[ 2 ];
  1061. const denominator = Math.sqrt( tS * ptS );
  1062. let angle;
  1063. if ( denominator === 0 ) {
  1064. angle = Math.PI / 2;
  1065. } else {
  1066. const theta = ( tan.x * prevTan.x + tan.y * prevTan.y + tan.z * prevTan.z ) / denominator;
  1067. angle = Math.acos( Math.max( - 1, Math.min( 1, theta ) ) );
  1068. }
  1069. if ( angle < 0.1 ) continue;
  1070. ts.push( t );
  1071. }
  1072. rc = ts.map( t => curve.pointAt( t ) );
  1073. return rc;
  1074. }
  1075. }
  1076. export { Rhino3dmLoader };
粤ICP备19079148号