index.html 14 KB

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