index.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. const highlightRegExp = new RegExp( v.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ), 'gi' );
  207. // Search through all categories
  208. const results = [];
  209. for ( const category in searchData ) {
  210. const items = searchData[ category ];
  211. for ( const item of items ) {
  212. if ( item.title.match( regExp ) ) {
  213. results.push( { ...item, category } );
  214. }
  215. }
  216. }
  217. // Display results
  218. if ( results.length > 0 ) {
  219. // Group results by class
  220. const grouped = {};
  221. results.forEach( item => {
  222. const parts = item.title.split( /[#~]/ );
  223. const className = parts[ 0 ];
  224. const memberName = parts[ 1 ];
  225. if ( ! grouped[ className ] ) {
  226. grouped[ className ] = {
  227. class: null,
  228. members: [],
  229. category: item.category
  230. };
  231. }
  232. // Convert title to hash: "BoxHelper#update" -> "BoxHelper.update"
  233. const fullHash = item.title.replace( /[#~]/g, '.' );
  234. if ( memberName ) {
  235. if ( memberName.match( regExp ) ) {
  236. grouped[ className ].members.push( {
  237. name: memberName,
  238. hash: fullHash,
  239. kind: item.kind
  240. } );
  241. }
  242. } else {
  243. grouped[ className ].class = {
  244. name: className,
  245. hash: fullHash
  246. };
  247. }
  248. } );
  249. // Helper function to highlight matching text
  250. function highlightMatch( text, regExp ) {
  251. return text.replace( regExp, match => `<strong>${match}</strong>` );
  252. }
  253. // Group by category
  254. const byCategory = {};
  255. for ( const className in grouped ) {
  256. const group = grouped[ className ];
  257. const category = group.category || 'Other';
  258. if ( ! byCategory[ category ] ) {
  259. byCategory[ category ] = {};
  260. }
  261. byCategory[ category ][ className ] = group;
  262. }
  263. // Render grouped results with category headers
  264. const currentHash = window.location.hash.substring( 1 );
  265. let html = '';
  266. const categories = Object.keys( searchData );
  267. for ( const category of categories ) {
  268. if ( ! byCategory[ category ] ) continue;
  269. html += `<h2>${category}</h2>`;
  270. for ( const className in byCategory[ category ] ) {
  271. const group = byCategory[ category ][ className ];
  272. if ( group.class ) {
  273. html += '<div class="search-result-group">';
  274. const selectedClass = group.class.hash === currentHash ? ' selected' : '';
  275. const highlightedName = highlightMatch( group.class.name, highlightRegExp );
  276. html += `<a href="#${group.class.hash}" class="search-result-class${selectedClass}">${highlightedName}</a>`;
  277. }
  278. if ( group.members.length > 0 ) {
  279. if ( ! group.class ) {
  280. html += '<div class="search-result-group">';
  281. html += `<a href="#${className}" class="search-result-class">${className}</a>`;
  282. }
  283. group.members.forEach( member => {
  284. const selectedClass = member.hash === currentHash ? ' selected' : '';
  285. const highlightedName = highlightMatch( member.name, highlightRegExp );
  286. const suffix = member.kind === 'function' ? '()' : '';
  287. html += `<a href="#${member.hash}" class="search-result-member${selectedClass}">.${highlightedName}${suffix}</a>`;
  288. } );
  289. }
  290. if ( group.class || group.members.length > 0 ) {
  291. html += '</div>';
  292. }
  293. }
  294. }
  295. searchResults.innerHTML = html;
  296. // Add click handlers to update selection
  297. searchResults.querySelectorAll( 'a' ).forEach( link => {
  298. link.addEventListener( 'click', function () {
  299. // Remove selected class from all links
  300. searchResults.querySelectorAll( 'a' ).forEach( item => {
  301. item.classList.remove( 'selected' );
  302. } );
  303. // Add selected class to clicked link
  304. link.classList.add( 'selected' );
  305. } );
  306. } );
  307. } else {
  308. searchResults.innerHTML = '<div style="padding: 16px; color: #999;">No results found.</div>';
  309. }
  310. } else {
  311. window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
  312. // Hide search results, show navigation
  313. searchResults.style.display = 'none';
  314. content.style.display = 'block';
  315. // Highlight and scroll to current page in navigation
  316. const currentHash = window.location.hash.substring( 1 );
  317. if ( currentHash ) {
  318. // Extract the base page name (before the first dot for members)
  319. const basePage = currentHash.split( '.' )[ 0 ];
  320. // Find and highlight the link in navigation
  321. const pageInfo = pageLinks[ basePage ];
  322. if ( pageInfo ) {
  323. // Remove selected class from all links
  324. navigation.querySelectorAll( 'a' ).forEach( function ( item ) {
  325. item.classList.remove( 'selected' );
  326. } );
  327. // Add selected class to current page
  328. pageInfo.linkElement.classList.add( 'selected' );
  329. // Scroll the link into view
  330. scrollIntoViewVertical( pageInfo.linkElement );
  331. }
  332. }
  333. }
  334. }
  335. // Routing
  336. function createNewIframe() {
  337. const hash = window.location.hash.substring( 1 );
  338. // Parse hash: "global.Break" -> pageName: "global", anchor: "#Break"
  339. // or "BoxHelper" -> pageName: "BoxHelper", anchor: ""
  340. let pageName, anchor;
  341. const dotIndex = hash.indexOf( '.' );
  342. if ( dotIndex !== - 1 ) {
  343. pageName = hash.substring( 0, dotIndex );
  344. anchor = '#' + hash.substring( dotIndex + 1 );
  345. } else {
  346. pageName = hash;
  347. anchor = '';
  348. }
  349. let subtitle = '';
  350. const oldIframe = iframe;
  351. iframe = oldIframe.cloneNode();
  352. iframe.style.display = 'none';
  353. // Try to find the page link - first with full hash (e.g., "global.Break"), then without anchor
  354. const fullPageName = hash;
  355. let pageLink = pageLinks[ fullPageName ] || pageLinks[ pageName ];
  356. // If not found and hash doesn't contain a dot, try TSL.{hash} or global.{hash}
  357. if ( ! pageLink && dotIndex === - 1 && hash ) {
  358. pageLink = pageLinks[ 'TSL.' + hash ] || pageLinks[ 'global.' + hash ];
  359. // Update the hash to the full path
  360. if ( pageLink ) {
  361. const prefix = pageLinks[ 'TSL.' + hash ] ? 'TSL' : 'global';
  362. window.history.replaceState( {}, '', window.location.pathname + window.location.search + '#' + prefix + '.' + hash );
  363. }
  364. }
  365. if ( hash && pageLink ) {
  366. iframe.onload = function () {
  367. iframe.style.display = 'unset';
  368. // Intercept clicks on internal documentation links in the iframe
  369. setupIframeLinks();
  370. };
  371. // Use the stored anchor if available, otherwise use the parsed one
  372. const iframeAnchor = pageLink.anchor || anchor;
  373. iframe.src = pageLink.pageURL + iframeAnchor;
  374. subtitle = hash + ' – ';
  375. // Update navigation selection and scroll into view
  376. navigation.querySelectorAll( 'a' ).forEach( function ( item ) {
  377. item.classList.remove( 'selected' );
  378. } );
  379. if ( pageLink.linkElement ) {
  380. pageLink.linkElement.classList.add( 'selected' );
  381. // Only scroll if this is not a user click (user clicks handle their own smooth scrolling)
  382. if ( ! isUserClick ) {
  383. scrollIntoViewVertical( pageLink.linkElement );
  384. }
  385. isUserClick = false;
  386. }
  387. } else {
  388. iframe.src = '';
  389. subtitle = '';
  390. }
  391. document.body.replaceChild( iframe, oldIframe );
  392. document.title = subtitle + 'three.js docs';
  393. }
  394. function setupIframeLinks() {
  395. try {
  396. // Get the iframe's document
  397. const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
  398. // Find all links in the iframe
  399. const links = iframeDoc.querySelectorAll( 'a' );
  400. links.forEach( function ( link ) {
  401. link.addEventListener( 'click', function ( event ) {
  402. const href = link.getAttribute( 'href' );
  403. // Only handle relative links to .html files (with or without anchors)
  404. if ( href && ! href.startsWith( 'http' ) && href.includes( '.html' ) ) {
  405. event.preventDefault();
  406. // Parse href: "global.html#Break" -> "global.Break" or "Light.html" -> "Light"
  407. const match = href.match( /^([^#]+\.html)(#.*)?$/ );
  408. if ( match ) {
  409. const htmlFile = match[ 1 ];
  410. const anchor = match[ 2 ] || '';
  411. const pageName = htmlFile.replace( /\.html$/, '' );
  412. // Convert to dot notation: "global.html#Break" -> "global.Break"
  413. const fullHash = pageName + anchor.replace( '#', '.' );
  414. // Update the parent page's hash
  415. window.location.hash = fullHash;
  416. }
  417. }
  418. } );
  419. } );
  420. } catch ( e ) {
  421. // Ignore cross-origin errors
  422. console.error( 'Could not set up iframe links:', e );
  423. }
  424. }
  425. //
  426. console.log( [
  427. ' __ __',
  428. ' __/ __\\ / __\\__ ____ _____ _____',
  429. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  430. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  431. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  432. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  433. ' / __/ / \\__ \\',
  434. ' \\/____/\\/_____/'
  435. ].join( '\n' ) );
  436. </script>
  437. </body>
  438. </html>
粤ICP备19079148号