index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>three.js docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link rel="shortcut icon" href="../files/favicon_white.ico" media="(prefers-color-scheme: dark)"/>
  8. <link rel="shortcut icon" href="../files/favicon.ico" media="(prefers-color-scheme: light)" />
  9. <link rel="stylesheet" type="text/css" href="../files/main.css">
  10. <!-- console sandbox -->
  11. <script type="module">
  12. import * as THREE from '../build/three.module.js';
  13. window.THREE = THREE;
  14. </script>
  15. </head>
  16. <body>
  17. <div id="panel" translate="no">
  18. <div id="header">
  19. <h1><a href="https://threejs.org">three.js</a></h1>
  20. <div id="sections">
  21. <span class="selected">docs</span>
  22. <a href="../manual/">manual</a>
  23. </div>
  24. <div id="expandButton"></div>
  25. </div>
  26. <div id="panelScrim"></div>
  27. <div id="contentWrapper">
  28. <div id="inputWrapper">
  29. <input placeholder="" type="text" id="filterInput" autocorrect="off" autocapitalize="off" spellcheck="false" />
  30. <div id="clearSearchButton"></div>
  31. </div>
  32. <div id="searchResults" style="display: none;"></div>
  33. <div id="content">
  34. <!--NAV_PLACEHOLDER-->
  35. </div>
  36. </div>
  37. </div>
  38. <iframe name="viewer"></iframe>
  39. <script>
  40. // Handle legacy URLs from old documentation structure
  41. ( function handleLegacyURLs() {
  42. const hash = window.location.hash;
  43. if ( hash.startsWith( '#api/' ) || hash.startsWith( '#examples/' ) ) {
  44. const mappings = {
  45. '3DMLoader': 'Rhino3dmLoader',
  46. 'BufferGeometryUtils': 'module-BufferGeometryUtils',
  47. 'CameraUtils': 'module-CameraUtils',
  48. 'SceneUtils': 'module-SceneUtils',
  49. 'SkeletonUtils': 'module-SkeletonUtils',
  50. 'UniformsUtils': 'module-UniformsUtils',
  51. 'DefaultLoadingManager': 'LoadingManager',
  52. 'Interpolations': 'module-Interpolations',
  53. 'Animation': 'global',
  54. 'BufferAttributeUsage': 'global',
  55. 'Core': 'global',
  56. 'CustomBlendingEquations': 'global',
  57. 'Materials': 'global',
  58. 'Textures': 'global'
  59. };
  60. const parts = hash.split( '/' );
  61. let className = parts[ parts.length - 1 ];
  62. if ( className ) {
  63. if ( className in mappings ) className = mappings[ className ];
  64. window.location.hash = className;
  65. }
  66. }
  67. } )();
  68. const panel = document.getElementById( 'panel' );
  69. const content = document.getElementById( 'content' );
  70. const expandButton = document.getElementById( 'expandButton' );
  71. const clearSearchButton = document.getElementById( 'clearSearchButton' );
  72. const panelScrim = document.getElementById( 'panelScrim' );
  73. const filterInput = document.getElementById( 'filterInput' );
  74. let iframe = document.getElementsByName( 'viewer' )[ 0 ];
  75. const pageLinks = {};
  76. let navigation;
  77. let isUserClick = false;
  78. let searchData;
  79. fetch( 'search.json' )
  80. .then( response => response.json() )
  81. .then( data => {
  82. searchData = data;
  83. if ( filterInput.value !== '' ) {
  84. updateFilter();
  85. }
  86. } )
  87. .catch( err => console.error( 'Failed to load search data:', err ) );
  88. init();
  89. function init() {
  90. expandButton.onclick = function ( event ) {
  91. event.preventDefault();
  92. panel.classList.toggle( 'open' );
  93. };
  94. panelScrim.onclick = function ( event ) {
  95. event.preventDefault();
  96. panel.classList.toggle( 'open' );
  97. };
  98. filterInput.onfocus = function () {
  99. panel.classList.add( 'searchFocused' );
  100. };
  101. filterInput.onblur = function () {
  102. if ( filterInput.value === '' ) {
  103. panel.classList.remove( 'searchFocused' );
  104. }
  105. };
  106. filterInput.oninput = function () {
  107. updateFilter();
  108. };
  109. clearSearchButton.onclick = function () {
  110. filterInput.value = '';
  111. updateFilter();
  112. filterInput.focus();
  113. };
  114. window.onpopstate = createNewIframe;
  115. setupNavigation();
  116. createNewIframe();
  117. filterInput.value = extractQuery();
  118. if ( filterInput.value !== '' ) {
  119. panel.classList.add( 'searchFocused' );
  120. }
  121. }
  122. // Navigation Panel
  123. function setupNavigation() {
  124. navigation = content;
  125. const selectedPage = window.location.hash.substring( 1 );
  126. const links = navigation.querySelectorAll( 'a' );
  127. links.forEach( link => {
  128. const href = link.getAttribute( 'href' );
  129. if ( href && href.includes( '.html' ) ) {
  130. const match = href.match( /^([^#]+\.html)(#.*)?$/ );
  131. if ( ! match ) return;
  132. const htmlFile = match[ 1 ];
  133. const anchor = match[ 2 ] || '';
  134. const pageName = htmlFile.replace( /\.html$/, '' );
  135. const fullPageName = pageName + anchor.replace( '#', '.' );
  136. const pageURL = 'pages/' + htmlFile;
  137. link.setAttribute( 'href', pageURL + anchor );
  138. link.setAttribute( 'target', 'viewer' );
  139. link.addEventListener( 'click', function ( event ) {
  140. if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
  141. event.preventDefault();
  142. isUserClick = true;
  143. window.location.hash = fullPageName;
  144. panel.classList.remove( 'open' );
  145. navigation.querySelectorAll( 'a' ).forEach( function ( item ) {
  146. item.classList.remove( 'selected' );
  147. } );
  148. link.classList.add( 'selected' );
  149. } );
  150. pageLinks[ fullPageName ] = {
  151. linkElement: link,
  152. pageURL: pageURL,
  153. anchor: anchor,
  154. href: href
  155. };
  156. if ( ! pageLinks[ pageName ] ) {
  157. pageLinks[ pageName ] = {
  158. linkElement: link,
  159. pageURL: pageURL,
  160. anchor: '',
  161. href: htmlFile
  162. };
  163. }
  164. if ( fullPageName === selectedPage || pageName === selectedPage ) {
  165. link.classList.add( 'selected' );
  166. scrollIntoViewVertical( link );
  167. }
  168. }
  169. } );
  170. }
  171. function scrollIntoViewVertical( element ) {
  172. const container = document.getElementById( 'content' );
  173. const elementTop = element.offsetTop;
  174. const elementHeight = element.offsetHeight;
  175. const viewportHeight = window.innerHeight;
  176. // Scroll to center the element vertically using viewport height
  177. const scrollTop = elementTop - ( viewportHeight / 2 ) + ( elementHeight / 2 );
  178. container.scrollTop = scrollTop;
  179. }
  180. function extractQuery() {
  181. const search = window.location.search;
  182. if ( search.indexOf( '?q=' ) !== - 1 ) {
  183. return decodeURI( search.slice( 3 ) );
  184. }
  185. return '';
  186. }
  187. function escapeRegExp( string ) {
  188. string = string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
  189. return '(?=.*' + string.split( ' ' ).join( ')(?=.*' ) + ')';
  190. }
  191. function updateFilter() {
  192. let v = filterInput.value.trim();
  193. v = v.replace( /\s+/gi, ' ' );
  194. const searchResults = document.getElementById( 'searchResults' );
  195. const content = document.getElementById( 'content' );
  196. if ( v !== '' ) {
  197. window.history.replaceState( {}, '', '?q=' + v + window.location.hash );
  198. // Show search results, hide navigation
  199. searchResults.style.display = 'block';
  200. content.style.display = 'none';
  201. if ( searchData === undefined ) {
  202. searchResults.innerHTML = '<div style="padding: 16px; color: #999;">Loading search data...</div>';
  203. return;
  204. }
  205. const regExp = new RegExp( escapeRegExp( v ), 'gi' );
  206. // Create highlight regex that matches any of the search words
  207. const words = v.split( ' ' ).map( word => word.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ) ).join( '|' );
  208. const highlightRegExp = new RegExp( words, 'gi' );
  209. // Search through all categories
  210. const results = [];
  211. for ( const category in searchData ) {
  212. const items = searchData[ category ];
  213. for ( const item of items ) {
  214. // Match against combined category and title for multi-word searches
  215. const searchText = category + ' ' + item.title;
  216. if ( searchText.match( regExp ) ) {
  217. results.push( { ...item, category } );
  218. }
  219. }
  220. }
  221. // Display results
  222. if ( results.length > 0 ) {
  223. // Group results by class
  224. const grouped = {};
  225. results.forEach( item => {
  226. const parts = item.title.split( /[#~]/ );
  227. const className = parts[ 0 ];
  228. const memberName = parts[ 1 ];
  229. if ( ! grouped[ className ] ) {
  230. grouped[ className ] = {
  231. class: null,
  232. members: [],
  233. category: item.category
  234. };
  235. }
  236. // Convert title to hash: "BoxHelper#update" -> "BoxHelper.update"
  237. const fullHash = item.title.replace( /[#~]/g, '.' );
  238. if ( memberName ) {
  239. if ( memberName.match( regExp ) ) {
  240. grouped[ className ].members.push( {
  241. name: memberName,
  242. hash: fullHash,
  243. kind: item.kind
  244. } );
  245. }
  246. } else {
  247. grouped[ className ].class = {
  248. name: className,
  249. hash: fullHash
  250. };
  251. }
  252. } );
  253. // Helper function to highlight matching text
  254. function highlightMatch( text, regExp ) {
  255. return text.replace( regExp, match => `<strong>${match}</strong>` );
  256. }
  257. // Group by category
  258. const byCategory = {};
  259. for ( const className in grouped ) {
  260. const group = grouped[ className ];
  261. const category = group.category || 'Other';
  262. if ( ! byCategory[ category ] ) {
  263. byCategory[ category ] = {};
  264. }
  265. byCategory[ category ][ className ] = group;
  266. }
  267. // Render grouped results with category headers
  268. const currentHash = window.location.hash.substring( 1 );
  269. let html = '';
  270. const categories = Object.keys( searchData );
  271. for ( const category of categories ) {
  272. if ( ! byCategory[ category ] ) continue;
  273. const highlightedCategory = highlightMatch( category, highlightRegExp );
  274. html += `<h2>${highlightedCategory}</h2>`;
  275. for ( const className in byCategory[ category ] ) {
  276. const group = byCategory[ category ][ className ];
  277. if ( group.class ) {
  278. html += '<div class="search-result-group">';
  279. const selectedClass = group.class.hash === currentHash ? ' selected' : '';
  280. const highlightedName = highlightMatch( group.class.name, highlightRegExp );
  281. html += `<a href="#${group.class.hash}" class="search-result-class${selectedClass}">${highlightedName}</a>`;
  282. }
  283. if ( group.members.length > 0 ) {
  284. if ( ! group.class ) {
  285. html += '<div class="search-result-group">';
  286. html += `<a href="#${className}" class="search-result-class">${className}</a>`;
  287. }
  288. group.members.forEach( member => {
  289. const selectedClass = member.hash === currentHash ? ' selected' : '';
  290. const highlightedName = highlightMatch( member.name, highlightRegExp );
  291. const suffix = member.kind === 'function' ? '()' : '';
  292. html += `<a href="#${member.hash}" class="search-result-member${selectedClass}">.${highlightedName}${suffix}</a>`;
  293. } );
  294. }
  295. if ( group.class || group.members.length > 0 ) {
  296. html += '</div>';
  297. }
  298. }
  299. }
  300. searchResults.innerHTML = html;
  301. // Add click handlers to update selection
  302. searchResults.querySelectorAll( 'a' ).forEach( link => {
  303. link.addEventListener( 'click', function () {
  304. // Remove selected class from all links
  305. searchResults.querySelectorAll( 'a' ).forEach( item => {
  306. item.classList.remove( 'selected' );
  307. } );
  308. // Add selected class to clicked link
  309. link.classList.add( 'selected' );
  310. } );
  311. } );
  312. } else {
  313. searchResults.innerHTML = '<div style="padding: 16px; color: #999;">No results found.</div>';
  314. }
  315. } else {
  316. window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
  317. // Hide search results, show navigation
  318. searchResults.style.display = 'none';
  319. content.style.display = 'block';
  320. // Highlight and scroll to current page in navigation
  321. const currentHash = window.location.hash.substring( 1 );
  322. if ( currentHash ) {
  323. // Extract the base page name (before the first dot for members)
  324. const basePage = currentHash.split( '.' )[ 0 ];
  325. // Find and highlight the link in navigation
  326. const pageInfo = pageLinks[ basePage ];
  327. if ( pageInfo ) {
  328. // Remove selected class from all links
  329. navigation.querySelectorAll( 'a' ).forEach( function ( item ) {
  330. item.classList.remove( 'selected' );
  331. } );
  332. // Add selected class to current page
  333. pageInfo.linkElement.classList.add( 'selected' );
  334. // Scroll the link into view
  335. scrollIntoViewVertical( pageInfo.linkElement );
  336. }
  337. }
  338. }
  339. }
  340. // Routing
  341. function createNewIframe() {
  342. const hash = window.location.hash.substring( 1 );
  343. // Parse hash: "global.Break" -> pageName: "global", anchor: "#Break"
  344. // or "BoxHelper" -> pageName: "BoxHelper", anchor: ""
  345. let pageName, anchor;
  346. const dotIndex = hash.indexOf( '.' );
  347. if ( dotIndex !== - 1 ) {
  348. pageName = hash.substring( 0, dotIndex );
  349. anchor = '#' + hash.substring( dotIndex + 1 );
  350. } else {
  351. pageName = hash;
  352. anchor = '';
  353. }
  354. let subtitle = '';
  355. const oldIframe = iframe;
  356. iframe = oldIframe.cloneNode();
  357. iframe.style.display = 'none';
  358. // Try to find the page link - first with full hash (e.g., "global.Break"), then without anchor
  359. const fullPageName = hash;
  360. let pageLink = pageLinks[ fullPageName ] || pageLinks[ pageName ];
  361. // If not found and hash doesn't contain a dot, try TSL.{hash} or global.{hash}
  362. if ( ! pageLink && dotIndex === - 1 && hash ) {
  363. pageLink = pageLinks[ 'TSL.' + hash ] || pageLinks[ 'global.' + hash ];
  364. // Update the hash to the full path
  365. if ( pageLink ) {
  366. const prefix = pageLinks[ 'TSL.' + hash ] ? 'TSL' : 'global';
  367. window.history.replaceState( {}, '', window.location.pathname + window.location.search + '#' + prefix + '.' + hash );
  368. }
  369. }
  370. if ( hash && pageLink ) {
  371. iframe.onload = function () {
  372. iframe.style.display = 'unset';
  373. // Intercept clicks on internal documentation links in the iframe
  374. setupIframeLinks();
  375. };
  376. // Use the stored anchor if available, otherwise use the parsed one
  377. const iframeAnchor = pageLink.anchor || anchor;
  378. iframe.src = pageLink.pageURL + iframeAnchor;
  379. subtitle = hash + ' – ';
  380. // Update navigation selection and scroll into view
  381. navigation.querySelectorAll( 'a' ).forEach( function ( item ) {
  382. item.classList.remove( 'selected' );
  383. } );
  384. if ( pageLink.linkElement ) {
  385. pageLink.linkElement.classList.add( 'selected' );
  386. // Only scroll if this is not a user click (user clicks handle their own smooth scrolling)
  387. if ( ! isUserClick ) {
  388. scrollIntoViewVertical( pageLink.linkElement );
  389. }
  390. isUserClick = false;
  391. }
  392. } else {
  393. iframe.src = '';
  394. subtitle = '';
  395. }
  396. document.body.replaceChild( iframe, oldIframe );
  397. document.title = subtitle + 'three.js docs';
  398. }
  399. function setupIframeLinks() {
  400. try {
  401. // Get the iframe's document
  402. const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
  403. // Find all links in the iframe
  404. const links = iframeDoc.querySelectorAll( 'a' );
  405. links.forEach( function ( link ) {
  406. link.addEventListener( 'click', function ( event ) {
  407. const href = link.getAttribute( 'href' );
  408. // Only handle relative links to .html files (with or without anchors)
  409. if ( href && ! href.startsWith( 'http' ) && href.includes( '.html' ) ) {
  410. event.preventDefault();
  411. // Parse href: "global.html#Break" -> "global.Break" or "Light.html" -> "Light"
  412. const match = href.match( /^([^#]+\.html)(#.*)?$/ );
  413. if ( match ) {
  414. const htmlFile = match[ 1 ];
  415. const anchor = match[ 2 ] || '';
  416. const pageName = htmlFile.replace( /\.html$/, '' );
  417. // Convert to dot notation: "global.html#Break" -> "global.Break"
  418. const fullHash = pageName + anchor.replace( '#', '.' );
  419. // Update the parent page's hash
  420. window.location.hash = fullHash;
  421. }
  422. }
  423. } );
  424. } );
  425. } catch ( e ) {
  426. // Ignore cross-origin errors
  427. console.error( 'Could not set up iframe links:', e );
  428. }
  429. }
  430. //
  431. console.log( [
  432. ' __ __',
  433. ' __/ __\\ / __\\__ ____ _____ _____',
  434. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  435. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  436. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  437. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  438. ' / __/ / \\__ \\',
  439. ' \\/____/\\/_____/'
  440. ].join( '\n' ) );
  441. </script>
  442. </body>
  443. </html>
粤ICP备19079148号