index.html 18 KB

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