index.html 16 KB

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