index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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="../examples/#webgl_animation_keyframes">examples</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. <select id="language">
  32. <option value="en">en</option>
  33. <option value="ar">ar</option>
  34. <option value="ko">한국어</option>
  35. <option value="zh">中文</option>
  36. <option value="ja">日本語</option>
  37. <option value="it">it</option>
  38. <option value="pt-br">pt-br</option>
  39. <option value="fr">fr</option>
  40. <option value="ru">ru</option>
  41. </select>
  42. </div>
  43. <div id="content"></div>
  44. </div>
  45. </div>
  46. <iframe name="viewer"></iframe>
  47. <script>
  48. const panel = document.getElementById( 'panel' );
  49. const content = document.getElementById( 'content' );
  50. const expandButton = document.getElementById( 'expandButton' );
  51. const clearSearchButton = document.getElementById( 'clearSearchButton' );
  52. const panelScrim = document.getElementById( 'panelScrim' );
  53. const filterInput = document.getElementById( 'filterInput' );
  54. let iframe = document.querySelector( 'iframe' );
  55. const sectionLink = document.querySelector( '#sections > a' );
  56. const sectionDefaultHref = sectionLink.href;
  57. const pageProperties = {};
  58. const titles = {};
  59. const categoryElements = [];
  60. let navigation;
  61. init();
  62. async function init() {
  63. const list = await ( await fetch( 'list.json' ) ).json();
  64. // *BufferGeometry to *Geometry
  65. if ( /Instanced/.exec( window.location.hash ) === null && /([\w]+)BufferGeometry$/.exec( window.location.hash ) ) {
  66. window.location.hash = window.location.hash.replace( 'BufferGeometry', 'Geometry' );
  67. }
  68. const hash = window.location.hash.substring( 1 );
  69. // Localisation
  70. let language = 'en';
  71. if ( /^(api|manual|examples)/.test( hash ) ) {
  72. const hashLanguage = /^(api|manual|examples)\/(en|ar|ko|zh|ja|it|pt-br|fr|ru)\//.exec( hash );
  73. if ( hashLanguage === null ) {
  74. // Route old non-localised api links
  75. window.location.hash = hash.replace( /^(api|manual|examples)/, '$1/en' );
  76. } else {
  77. language = hashLanguage[ 2 ];
  78. }
  79. }
  80. const languageSelect = document.getElementById( 'language' );
  81. languageSelect.value = language;
  82. languageSelect.addEventListener( 'change', function () {
  83. setLanguage( this.value );
  84. } );
  85. function setLanguage( value ) {
  86. language = value;
  87. createNavigation( list, language );
  88. updateFilter();
  89. autoChangeUrlLanguage( language );
  90. }
  91. // Functionality for hamburger button (on small devices)
  92. expandButton.onclick = function ( event ) {
  93. event.preventDefault();
  94. panel.classList.toggle( 'open' );
  95. };
  96. panelScrim.onclick = function ( event ) {
  97. event.preventDefault();
  98. panel.classList.toggle( 'open' );
  99. };
  100. // Functionality for search/filter input field
  101. filterInput.onfocus = function () {
  102. panel.classList.add( 'searchFocused' );
  103. };
  104. filterInput.onblur = function () {
  105. if ( filterInput.value === '' ) {
  106. panel.classList.remove( 'searchFocused' );
  107. }
  108. };
  109. filterInput.oninput = function () {
  110. updateFilter();
  111. };
  112. clearSearchButton.onclick = function () {
  113. filterInput.value = '';
  114. updateFilter();
  115. filterInput.focus();
  116. };
  117. // Activate content and title change on browser navigation
  118. window.onpopstate = createNewIframe;
  119. // Create the navigation panel and configure the iframe
  120. createNavigation( list, language );
  121. createNewIframe();
  122. // Handle search query
  123. filterInput.value = extractQuery();
  124. if ( filterInput.value !== '' ) {
  125. panel.classList.add( 'searchFocused' );
  126. updateFilter();
  127. } else {
  128. updateLink( '' );
  129. }
  130. }
  131. // Navigation Panel
  132. function createLink( pageName, pageURL ) {
  133. const link = document.createElement( 'a' );
  134. link.href = pageURL + '.html';
  135. link.textContent = pageName;
  136. link.setAttribute( 'target', 'viewer' );
  137. link.addEventListener( 'click', function ( event ) {
  138. if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
  139. window.location.hash = pageURL;
  140. panel.classList.remove( 'open' );
  141. content.querySelectorAll( 'a' ).forEach( function ( item ) {
  142. item.classList.remove( 'selected' );
  143. } );
  144. link.classList.add( 'selected' );
  145. } );
  146. return link;
  147. }
  148. function createNavigation( list, language ) {
  149. if ( navigation !== undefined ) {
  150. content.removeChild( navigation );
  151. }
  152. // Create the navigation panel using data from list.js
  153. navigation = document.createElement( 'div' );
  154. content.appendChild( navigation );
  155. if ( language === 'ar' ) {
  156. navigation.style.direction = 'rtl';
  157. }
  158. const localList = list[ language ];
  159. const selectedPage = window.location.hash.substring( 1 );
  160. for ( const section in localList ) {
  161. // Create sections
  162. const categories = localList[ section ];
  163. const sectionHead = document.createElement( 'h2' );
  164. sectionHead.textContent = section;
  165. navigation.appendChild( sectionHead );
  166. for ( const category in categories ) {
  167. // Create categories
  168. const pages = categories[ category ];
  169. const categoryContainer = document.createElement( 'div' );
  170. navigation.appendChild( categoryContainer );
  171. const categoryHead = document.createElement( 'h3' );
  172. categoryHead.textContent = category;
  173. categoryContainer.appendChild( categoryHead );
  174. const categoryContent = document.createElement( 'ul' );
  175. categoryContainer.appendChild( categoryContent );
  176. for ( const pageName in pages ) {
  177. // Create page links
  178. const pageURL = pages[ pageName ];
  179. // Localisation
  180. const listElement = document.createElement( 'li' );
  181. categoryContent.appendChild( listElement );
  182. const linkElement = createLink( pageName, pageURL );
  183. listElement.appendChild( linkElement );
  184. // select current page
  185. if ( pageURL === selectedPage ) {
  186. linkElement.classList.add( 'selected' );
  187. }
  188. // Gather the main properties for the current subpage
  189. pageProperties[ pageName ] = {
  190. section: section,
  191. category: category,
  192. pageURL: pageURL,
  193. linkElement: linkElement
  194. };
  195. // Gather the document titles (used for easy access on browser navigation)
  196. titles[ pageURL ] = pageName;
  197. }
  198. // Gather the category elements for easy access on filtering
  199. categoryElements.push( categoryContent );
  200. }
  201. }
  202. }
  203. // Auto change language url. If a reader open a document in English, when they click "zh", the document they read will auto change into Chinese version
  204. function autoChangeUrlLanguage( language ) {
  205. const hash = location.hash;
  206. if ( hash === '' ) return;
  207. const docType = hash.slice( 0, hash.indexOf( '/' ) + 1 );
  208. let docLink = hash.slice( hash.indexOf( '/' ) + 1 );
  209. docLink = docLink.slice( docLink.indexOf( '/' ) );
  210. location.href = docType + language + docLink;
  211. }
  212. // Filtering
  213. function extractQuery() {
  214. const search = window.location.search;
  215. if ( search.indexOf( '?q=' ) !== - 1 ) {
  216. return decodeURI( search.slice( 3 ) );
  217. }
  218. return '';
  219. }
  220. function escapeRegExp( string ) {
  221. string = string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
  222. return '(?=.*' + string.split( ' ' ).join( ')(?=.*' ) + ')'; // match all words, in any order
  223. }
  224. function updateFilter() {
  225. let v = filterInput.value.trim();
  226. v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one
  227. if ( v !== '' ) {
  228. window.history.replaceState( {}, '', '?q=' + v + window.location.hash );
  229. } else {
  230. window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
  231. }
  232. //
  233. const regExp = new RegExp( escapeRegExp( v ), 'gi' );
  234. for ( let pageName in pageProperties ) {
  235. const linkElement = pageProperties[ pageName ].linkElement;
  236. const categoryClassList = linkElement.parentElement.classList;
  237. const filterResults = pageName.match( regExp );
  238. if ( filterResults !== null && filterResults.length > 0 ) {
  239. pageName = pageName.replaceAll( regExp, '<b>$&</b>' );
  240. categoryClassList.remove( 'hidden' );
  241. linkElement.innerHTML = pageName;
  242. } else {
  243. // Hide all non-matching page names
  244. categoryClassList.add( 'hidden' );
  245. }
  246. }
  247. displayFilteredPanel();
  248. updateLink( v );
  249. }
  250. function updateLink( search ) {
  251. // update examples link
  252. if ( search ) {
  253. const link = sectionLink.href.split( /[?#]/ )[ 0 ];
  254. sectionLink.href = `${link}?q=${search}`;
  255. } else {
  256. sectionLink.href = sectionDefaultHref;
  257. }
  258. }
  259. function displayFilteredPanel() {
  260. // Show/hide categories depending on their content
  261. // First check if at least one page in this category is not hidden
  262. categoryElements.forEach( function ( category ) {
  263. const pages = category.children;
  264. const pagesLength = pages.length;
  265. const sectionClassList = category.parentElement.classList;
  266. let hideCategory = true;
  267. for ( let i = 0; i < pagesLength; i ++ ) {
  268. const pageClassList = pages[ i ].classList;
  269. if ( ! pageClassList.contains( 'hidden' ) ) {
  270. hideCategory = false;
  271. }
  272. }
  273. // If and only if all page names are hidden, hide the whole category
  274. if ( hideCategory ) {
  275. sectionClassList.add( 'hidden' );
  276. } else {
  277. sectionClassList.remove( 'hidden' );
  278. }
  279. } );
  280. }
  281. // Routing
  282. function setUrlFragment( pageName ) { // eslint-disable-line no-unused-vars
  283. // Handle navigation from the subpages (iframes):
  284. // First separate the member (if existing) from the page name,
  285. // then identify the subpage's URL and set it as URL fragment (re-adding the member)
  286. const pageURL = getPageURL( pageName );
  287. if ( pageURL ) {
  288. window.location.hash = pageURL;
  289. createNewIframe();
  290. }
  291. }
  292. function getPageURL( pageName ) {
  293. const splitPageName = decomposePageName( pageName, '.', '.' );
  294. const currentProperties = pageProperties[ splitPageName[ 0 ] ];
  295. if ( currentProperties ) {
  296. return currentProperties.pageURL + splitPageName[ 1 ];
  297. } else {
  298. return null;
  299. }
  300. }
  301. function createNewIframe() {
  302. // Change the content displayed in the iframe
  303. // First separate the member part of the fragment (if existing)
  304. const hash = window.location.hash.substring( 1 );
  305. const splitHash = decomposePageName( hash, '.', '#' );
  306. // Creating a new Iframe instead of assigning a new src is
  307. // a cross-browser solution to allow normal browser navigation;
  308. // - only assigning a new src would result in two history states each time.
  309. // Note: iframe.contentWindow.location.replace(hash) should work, too,
  310. // but it doesn't work in Edge with links from the subpages!
  311. let subtitle;
  312. const oldIframe = iframe;
  313. iframe = oldIframe.cloneNode();
  314. if ( hash && titles[ splitHash[ 0 ] ] ) {
  315. iframe.src = splitHash[ 0 ] + '.html' + splitHash[ 1 ];
  316. subtitle = titles[ splitHash[ 0 ] ] + splitHash[ 1 ] + ' – ';
  317. iframe.style.display = 'unset';
  318. } else {
  319. iframe.src = '';
  320. subtitle = '';
  321. iframe.style.display = 'none';
  322. }
  323. document.body.replaceChild( iframe, oldIframe );
  324. document.title = subtitle + 'three.js docs';
  325. }
  326. function decomposePageName( pageName, oldDelimiter, newDelimiter ) {
  327. // Helper function for separating the member (if existing) from the pageName
  328. // For example: 'Geometry.morphTarget' can be converted to
  329. // ['Geometry', '.morphTarget'] or ['Geometry', '#morphTarget']
  330. // Note: According RFC 3986 no '#' allowed inside of an URL fragment!
  331. let parts = [];
  332. const dotIndex = pageName.indexOf( oldDelimiter );
  333. if ( dotIndex !== - 1 ) {
  334. parts = pageName.split( oldDelimiter );
  335. parts[ 1 ] = newDelimiter + parts[ 1 ];
  336. } else {
  337. parts[ 0 ] = pageName;
  338. parts[ 1 ] = '';
  339. }
  340. return parts;
  341. }
  342. //
  343. console.log( [
  344. ' __ __',
  345. ' __/ __\\ / __\\__ ____ _____ _____',
  346. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  347. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  348. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  349. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  350. ' / __/ / \\__ \\',
  351. ' \\/____/\\/_____/'
  352. ].join( '\n' ) );
  353. </script>
  354. </body>
  355. </html>