index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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. if ( selectedPage === '' ) {
  127. panel.classList.add( 'open' );
  128. }
  129. const links = navigation.querySelectorAll( 'a' );
  130. links.forEach( link => {
  131. const href = link.getAttribute( 'href' );
  132. if ( href && href.includes( '.html' ) ) {
  133. const match = href.match( /^([^#]+\.html)(#.*)?$/ );
  134. if ( ! match ) return;
  135. const htmlFile = match[ 1 ];
  136. const anchor = match[ 2 ] || '';
  137. const pageName = htmlFile.replace( /\.html$/, '' );
  138. const fullPageName = pageName + anchor.replace( '#', '.' );
  139. const pageURL = 'pages/' + htmlFile;
  140. link.setAttribute( 'href', pageURL + anchor );
  141. link.setAttribute( 'target', 'viewer' );
  142. link.addEventListener( 'click', function ( event ) {
  143. if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
  144. event.preventDefault();
  145. isUserClick = true;
  146. window.location.hash = fullPageName;
  147. panel.classList.remove( 'open' );
  148. navigation.querySelectorAll( 'a' ).forEach( function ( item ) {
  149. item.classList.remove( 'selected' );
  150. } );
  151. link.classList.add( 'selected' );
  152. } );
  153. pageLinks[ fullPageName ] = {
  154. linkElement: link,
  155. pageURL: pageURL,
  156. anchor: anchor,
  157. href: href
  158. };
  159. if ( ! pageLinks[ pageName ] ) {
  160. pageLinks[ pageName ] = {
  161. linkElement: link,
  162. pageURL: pageURL,
  163. anchor: '',
  164. href: htmlFile
  165. };
  166. }
  167. if ( fullPageName === selectedPage || pageName === selectedPage ) {
  168. link.classList.add( 'selected' );
  169. scrollIntoViewVertical( link );
  170. }
  171. }
  172. } );
  173. }
  174. function scrollIntoViewVertical( element ) {
  175. const container = document.getElementById( 'content' );
  176. const elementTop = element.offsetTop;
  177. const elementHeight = element.offsetHeight;
  178. const viewportHeight = window.innerHeight;
  179. // Scroll to center the element vertically using viewport height
  180. const scrollTop = elementTop - ( viewportHeight / 2 ) + ( elementHeight / 2 );
  181. container.scrollTop = scrollTop;
  182. }
  183. function extractQuery() {
  184. const search = window.location.search;
  185. if ( search.indexOf( '?q=' ) !== - 1 ) {
  186. return decodeURI( search.slice( 3 ) );
  187. }
  188. return '';
  189. }
  190. function escapeRegExp( string ) {
  191. string = string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
  192. return '(?=.*' + string.split( ' ' ).join( ')(?=.*' ) + ')';
  193. }
  194. function updateFilter() {
  195. let v = filterInput.value.trim();
  196. v = v.replace( /\s+/gi, ' ' );
  197. const searchResults = document.getElementById( 'searchResults' );
  198. const content = document.getElementById( 'content' );
  199. if ( v !== '' ) {
  200. window.history.replaceState( {}, '', '?q=' + v + window.location.hash );
  201. // Show search results, hide navigation
  202. searchResults.style.display = 'block';
  203. content.style.display = 'none';
  204. if ( searchData === undefined ) {
  205. searchResults.innerHTML = '<div style="padding: 16px; color: #999;">Loading search data...</div>';
  206. return;
  207. }
  208. const regExp = new RegExp( escapeRegExp( v ), 'gi' );
  209. // Create highlight regex that matches any of the search words
  210. const words = v.split( ' ' ).map( word => word.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ) ).join( '|' );
  211. const highlightRegExp = new RegExp( words, 'gi' );
  212. // Search through all categories
  213. const results = [];
  214. for ( const category in searchData ) {
  215. const items = searchData[ category ];
  216. for ( const item of items ) {
  217. // Match against combined category and title for multi-word searches
  218. const searchText = category + ' ' + item.title;
  219. if ( searchText.match( regExp ) ) {
  220. results.push( { ...item, category } );
  221. }
  222. }
  223. }
  224. // Display results
  225. if ( results.length > 0 ) {
  226. // Group results by class
  227. const grouped = {};
  228. results.forEach( item => {
  229. const parts = item.title.split( /[#~]/ );
  230. const className = parts[ 0 ];
  231. const memberName = parts[ 1 ];
  232. if ( ! grouped[ className ] ) {
  233. grouped[ className ] = {
  234. class: null,
  235. members: [],
  236. category: item.category
  237. };
  238. }
  239. // Convert title to hash: "BoxHelper#update" -> "BoxHelper.update"
  240. const fullHash = item.title.replace( /[#~]/g, '.' );
  241. if ( memberName ) {
  242. if ( memberName.match( regExp ) ) {
  243. grouped[ className ].members.push( {
  244. name: memberName,
  245. hash: fullHash,
  246. kind: item.kind
  247. } );
  248. }
  249. } else {
  250. grouped[ className ].class = {
  251. name: className,
  252. hash: fullHash
  253. };
  254. }
  255. } );
  256. // Helper function to highlight matching text
  257. function highlightMatch( text, regExp ) {
  258. return text.replace( regExp, match => `<strong>${match}</strong>` );
  259. }
  260. // Group by category
  261. const byCategory = {};
  262. for ( const className in grouped ) {
  263. const group = grouped[ className ];
  264. const category = group.category || 'Other';
  265. if ( ! byCategory[ category ] ) {
  266. byCategory[ category ] = {};
  267. }
  268. byCategory[ category ][ className ] = group;
  269. }
  270. // Render grouped results with category headers
  271. const currentHash = window.location.hash.substring( 1 );
  272. let html = '';
  273. const categories = Object.keys( searchData );
  274. for ( const category of categories ) {
  275. if ( ! byCategory[ category ] ) continue;
  276. const highlightedCategory = highlightMatch( category, highlightRegExp );
  277. html += `<h2>${highlightedCategory}</h2>`;
  278. for ( const className in byCategory[ category ] ) {
  279. const group = byCategory[ category ][ className ];
  280. if ( group.class ) {
  281. html += '<div class="search-result-group">';
  282. const selectedClass = group.class.hash === currentHash ? ' selected' : '';
  283. const highlightedName = highlightMatch( group.class.name, highlightRegExp );
  284. html += `<a href="#${group.class.hash}" class="search-result-class${selectedClass}">${highlightedName}</a>`;
  285. }
  286. if ( group.members.length > 0 ) {
  287. if ( ! group.class ) {
  288. html += '<div class="search-result-group">';
  289. html += `<a href="#${className}" class="search-result-class">${className}</a>`;
  290. }
  291. group.members.forEach( member => {
  292. const selectedClass = member.hash === currentHash ? ' selected' : '';
  293. const highlightedName = highlightMatch( member.name, highlightRegExp );
  294. const suffix = member.kind === 'function' ? '()' : '';
  295. html += `<a href="#${member.hash}" class="search-result-member${selectedClass}">.${highlightedName}${suffix}</a>`;
  296. } );
  297. }
  298. if ( group.class || group.members.length > 0 ) {
  299. html += '</div>';
  300. }
  301. }
  302. }
  303. searchResults.innerHTML = html;
  304. // Add click handlers to update selection
  305. searchResults.querySelectorAll( 'a' ).forEach( link => {
  306. link.addEventListener( 'click', function () {
  307. // Remove selected class from all links
  308. searchResults.querySelectorAll( 'a' ).forEach( item => {
  309. item.classList.remove( 'selected' );
  310. } );
  311. // Add selected class to clicked link
  312. link.classList.add( 'selected' );
  313. } );
  314. } );
  315. } else {
  316. searchResults.innerHTML = '<div style="padding: 16px; color: #999;">No results found.</div>';
  317. }
  318. } else {
  319. window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
  320. // Hide search results, show navigation
  321. searchResults.style.display = 'none';
  322. content.style.display = 'block';
  323. // Highlight and scroll to current page in navigation
  324. const currentHash = window.location.hash.substring( 1 );
  325. if ( currentHash ) {
  326. // Extract the base page name (before the first dot for members)
  327. const basePage = currentHash.split( '.' )[ 0 ];
  328. // Find and highlight the link in navigation
  329. const pageInfo = pageLinks[ basePage ];
  330. if ( pageInfo ) {
  331. // Remove selected class from all links
  332. navigation.querySelectorAll( 'a' ).forEach( function ( item ) {
  333. item.classList.remove( 'selected' );
  334. } );
  335. // Add selected class to current page
  336. pageInfo.linkElement.classList.add( 'selected' );
  337. // Scroll the link into view
  338. scrollIntoViewVertical( pageInfo.linkElement );
  339. }
  340. }
  341. }
  342. }
  343. // Routing
  344. function createNewIframe() {
  345. const hash = window.location.hash.substring( 1 );
  346. // Parse hash: "global.Break" -> pageName: "global", anchor: "#Break"
  347. // or "BoxHelper" -> pageName: "BoxHelper", anchor: ""
  348. let pageName, anchor;
  349. const dotIndex = hash.indexOf( '.' );
  350. if ( dotIndex !== - 1 ) {
  351. pageName = hash.substring( 0, dotIndex );
  352. anchor = '#' + hash.substring( dotIndex + 1 );
  353. } else {
  354. pageName = hash;
  355. anchor = '';
  356. }
  357. let subtitle = '';
  358. const oldIframe = iframe;
  359. iframe = oldIframe.cloneNode();
  360. iframe.style.display = 'none';
  361. // Try to find the page link - first with full hash (e.g., "global.Break"), then without anchor
  362. const fullPageName = hash;
  363. let pageLink = pageLinks[ fullPageName ] || pageLinks[ pageName ];
  364. // If not found and hash doesn't contain a dot, try TSL.{hash} or global.{hash}
  365. if ( ! pageLink && dotIndex === - 1 && hash ) {
  366. pageLink = pageLinks[ 'TSL.' + hash ] || pageLinks[ 'global.' + hash ];
  367. // Update the hash to the full path
  368. if ( pageLink ) {
  369. const prefix = pageLinks[ 'TSL.' + hash ] ? 'TSL' : 'global';
  370. window.history.replaceState( {}, '', window.location.pathname + window.location.search + '#' + prefix + '.' + hash );
  371. }
  372. }
  373. if ( hash && pageLink ) {
  374. iframe.onload = function () {
  375. iframe.style.display = 'unset';
  376. // Intercept clicks on internal documentation links in the iframe
  377. setupIframeLinks();
  378. };
  379. // Use the stored anchor if available, otherwise use the parsed one
  380. const iframeAnchor = pageLink.anchor || anchor;
  381. iframe.src = pageLink.pageURL + iframeAnchor;
  382. subtitle = hash + ' – ';
  383. // Update navigation selection and scroll into view
  384. navigation.querySelectorAll( 'a' ).forEach( function ( item ) {
  385. item.classList.remove( 'selected' );
  386. } );
  387. if ( pageLink.linkElement ) {
  388. pageLink.linkElement.classList.add( 'selected' );
  389. // Only scroll if this is not a user click (user clicks handle their own smooth scrolling)
  390. if ( ! isUserClick ) {
  391. scrollIntoViewVertical( pageLink.linkElement );
  392. }
  393. isUserClick = false;
  394. }
  395. } else {
  396. iframe.src = '';
  397. subtitle = '';
  398. }
  399. document.body.replaceChild( iframe, oldIframe );
  400. document.title = subtitle + 'three.js docs';
  401. }
  402. function setupIframeLinks() {
  403. try {
  404. // Get the iframe's document
  405. const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
  406. // Find all links in the iframe
  407. const links = iframeDoc.querySelectorAll( 'a' );
  408. links.forEach( function ( link ) {
  409. link.addEventListener( 'click', function ( event ) {
  410. const href = link.getAttribute( 'href' );
  411. // Only handle relative links to .html files (with or without anchors)
  412. if ( href && ! href.startsWith( 'http' ) && href.includes( '.html' ) ) {
  413. event.preventDefault();
  414. // Parse href: "global.html#Break" -> "global.Break" or "Light.html" -> "Light"
  415. const match = href.match( /^([^#]+\.html)(#.*)?$/ );
  416. if ( match ) {
  417. const htmlFile = match[ 1 ];
  418. const anchor = match[ 2 ] || '';
  419. const pageName = htmlFile.replace( /\.html$/, '' );
  420. // Convert to dot notation: "global.html#Break" -> "global.Break"
  421. const fullHash = pageName + anchor.replace( '#', '.' );
  422. // Update the parent page's hash
  423. window.location.hash = fullHash;
  424. }
  425. }
  426. } );
  427. } );
  428. } catch ( e ) {
  429. // Ignore cross-origin errors
  430. console.error( 'Could not set up iframe links:', e );
  431. }
  432. }
  433. //
  434. console.log( [
  435. ' __ __',
  436. ' __/ __\\ / __\\__ ____ _____ _____',
  437. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  438. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  439. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  440. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  441. ' / __/ / \\__ \\',
  442. ' \\/____/\\/_____/'
  443. ].join( '\n' ) );
  444. </script>
  445. </body>
  446. </html>
粤ICP备19079148号