index.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js / editor</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link rel="apple-touch-icon" href="images/icon.png">
  8. <link rel="manifest" href="manifest.json">
  9. <link rel="shortcut icon" href="../files/favicon.ico" />
  10. </head>
  11. <body ontouchstart="">
  12. <link rel="stylesheet" href="css/main.css">
  13. <script src="../examples/js/libs/jszip.min.js"></script>
  14. <link rel="stylesheet" href="js/libs/codemirror/codemirror.css">
  15. <link rel="stylesheet" href="js/libs/codemirror/theme/monokai.css">
  16. <script src="js/libs/codemirror/codemirror.js"></script>
  17. <script src="js/libs/codemirror/mode/javascript.js"></script>
  18. <script src="js/libs/codemirror/mode/glsl.js"></script>
  19. <script src="js/libs/esprima.js"></script>
  20. <script src="js/libs/jsonlint.js"></script>
  21. <script src="js/libs/glslprep.min.js"></script>
  22. <link rel="stylesheet" href="js/libs/codemirror/addon/dialog.css">
  23. <link rel="stylesheet" href="js/libs/codemirror/addon/show-hint.css">
  24. <link rel="stylesheet" href="js/libs/codemirror/addon/tern.css">
  25. <script src="js/libs/codemirror/addon/dialog.js"></script>
  26. <script src="js/libs/codemirror/addon/show-hint.js"></script>
  27. <script src="js/libs/codemirror/addon/tern.js"></script>
  28. <script src="js/libs/acorn/acorn.js"></script>
  29. <script src="js/libs/acorn/acorn_loose.js"></script>
  30. <script src="js/libs/acorn/walk.js"></script>
  31. <script src="js/libs/ternjs/polyfill.js"></script>
  32. <script src="js/libs/ternjs/signal.js"></script>
  33. <script src="js/libs/ternjs/tern.js"></script>
  34. <script src="js/libs/ternjs/def.js"></script>
  35. <script src="js/libs/ternjs/comment.js"></script>
  36. <script src="js/libs/ternjs/infer.js"></script>
  37. <script src="js/libs/ternjs/doc_comment.js"></script>
  38. <script src="js/libs/tern-threejs/threejs.js"></script>
  39. <script src="js/libs/signals.min.js"></script>
  40. <script type="module">
  41. import * as THREE from '../build/three.module.js';
  42. import { Editor } from './js/Editor.js';
  43. import { Viewport } from './js/Viewport.js';
  44. import { Toolbar } from './js/Toolbar.js';
  45. import { Script } from './js/Script.js';
  46. import { Player } from './js/Player.js';
  47. import { Sidebar } from './js/Sidebar.js';
  48. import { Menubar } from './js/Menubar.js';
  49. window.URL = window.URL || window.webkitURL;
  50. window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
  51. Number.prototype.format = function () {
  52. return this.toString().replace( /(\d)(?=(\d{3})+(?!\d))/g, "$1," );
  53. };
  54. //
  55. var editor = new Editor();
  56. window.editor = editor; // Expose editor to Console
  57. window.THREE = THREE; // Expose THREE to APP Scripts and Console
  58. var viewport = new Viewport( editor );
  59. document.body.appendChild( viewport.dom );
  60. var toolbar = new Toolbar( editor );
  61. document.body.appendChild( toolbar.dom );
  62. var script = new Script( editor );
  63. document.body.appendChild( script.dom );
  64. var player = new Player( editor );
  65. document.body.appendChild( player.dom );
  66. var sidebar = new Sidebar( editor );
  67. document.body.appendChild( sidebar.dom );
  68. var menubar = new Menubar( editor );
  69. document.body.appendChild( menubar.dom );
  70. //
  71. editor.storage.init( function () {
  72. editor.storage.get( function ( state ) {
  73. if ( isLoadingFromHash ) return;
  74. if ( state !== undefined ) {
  75. editor.fromJSON( state );
  76. }
  77. var selected = editor.config.getKey( 'selected' );
  78. if ( selected !== undefined ) {
  79. editor.selectByUuid( selected );
  80. }
  81. } );
  82. //
  83. var timeout;
  84. function saveState() {
  85. if ( editor.config.getKey( 'autosave' ) === false ) {
  86. return;
  87. }
  88. clearTimeout( timeout );
  89. timeout = setTimeout( function () {
  90. editor.signals.savingStarted.dispatch();
  91. timeout = setTimeout( function () {
  92. editor.storage.set( editor.toJSON() );
  93. editor.signals.savingFinished.dispatch();
  94. }, 100 );
  95. }, 1000 );
  96. }
  97. var signals = editor.signals;
  98. signals.geometryChanged.add( saveState );
  99. signals.objectAdded.add( saveState );
  100. signals.objectChanged.add( saveState );
  101. signals.objectRemoved.add( saveState );
  102. signals.materialChanged.add( saveState );
  103. signals.sceneBackgroundChanged.add( saveState );
  104. signals.sceneFogChanged.add( saveState );
  105. signals.sceneGraphChanged.add( saveState );
  106. signals.scriptChanged.add( saveState );
  107. signals.historyChanged.add( saveState );
  108. } );
  109. //
  110. document.addEventListener( 'dragover', function ( event ) {
  111. event.preventDefault();
  112. event.dataTransfer.dropEffect = 'copy';
  113. }, false );
  114. document.addEventListener( 'drop', function ( event ) {
  115. event.preventDefault();
  116. editor.loader.loadFiles( event.dataTransfer.files );
  117. }, false );
  118. function onWindowResize() {
  119. editor.signals.windowResize.dispatch();
  120. }
  121. window.addEventListener( 'resize', onWindowResize, false );
  122. onWindowResize();
  123. //
  124. var isLoadingFromHash = false;
  125. var hash = window.location.hash;
  126. if ( hash.substr( 1, 5 ) === 'file=' ) {
  127. var file = hash.substr( 6 );
  128. if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
  129. var loader = new THREE.FileLoader();
  130. loader.crossOrigin = '';
  131. loader.load( file, function ( text ) {
  132. editor.clear();
  133. editor.fromJSON( JSON.parse( text ) );
  134. } );
  135. isLoadingFromHash = true;
  136. }
  137. }
  138. // ServiceWorker
  139. if ( 'serviceWorker' in navigator ) {
  140. try {
  141. navigator.serviceWorker.register( 'sw.js' );
  142. } catch ( error ) {
  143. }
  144. }
  145. /*
  146. window.addEventListener( 'message', function ( event ) {
  147. editor.clear();
  148. editor.fromJSON( event.data );
  149. }, false );
  150. */
  151. </script>
  152. </body>
  153. </html>