123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js / editor</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link rel="apple-touch-icon" href="images/icon.png">
- <link rel="manifest" href="manifest.json">
- <link rel="shortcut icon" href="../files/favicon.ico" />
- </head>
- <body ontouchstart="">
- <link rel="stylesheet" href="css/main.css">
- <script src="../examples/js/libs/jszip.min.js"></script>
- <link rel="stylesheet" href="js/libs/codemirror/codemirror.css">
- <link rel="stylesheet" href="js/libs/codemirror/theme/monokai.css">
- <script src="js/libs/codemirror/codemirror.js"></script>
- <script src="js/libs/codemirror/mode/javascript.js"></script>
- <script src="js/libs/codemirror/mode/glsl.js"></script>
- <script src="js/libs/esprima.js"></script>
- <script src="js/libs/jsonlint.js"></script>
- <script src="js/libs/glslprep.min.js"></script>
- <link rel="stylesheet" href="js/libs/codemirror/addon/dialog.css">
- <link rel="stylesheet" href="js/libs/codemirror/addon/show-hint.css">
- <link rel="stylesheet" href="js/libs/codemirror/addon/tern.css">
- <script src="js/libs/codemirror/addon/dialog.js"></script>
- <script src="js/libs/codemirror/addon/show-hint.js"></script>
- <script src="js/libs/codemirror/addon/tern.js"></script>
- <script src="js/libs/acorn/acorn.js"></script>
- <script src="js/libs/acorn/acorn_loose.js"></script>
- <script src="js/libs/acorn/walk.js"></script>
- <script src="js/libs/ternjs/polyfill.js"></script>
- <script src="js/libs/ternjs/signal.js"></script>
- <script src="js/libs/ternjs/tern.js"></script>
- <script src="js/libs/ternjs/def.js"></script>
- <script src="js/libs/ternjs/comment.js"></script>
- <script src="js/libs/ternjs/infer.js"></script>
- <script src="js/libs/ternjs/doc_comment.js"></script>
- <script src="js/libs/tern-threejs/threejs.js"></script>
- <script src="js/libs/signals.min.js"></script>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { Editor } from './js/Editor.js';
- import { Viewport } from './js/Viewport.js';
- import { Toolbar } from './js/Toolbar.js';
- import { Script } from './js/Script.js';
- import { Player } from './js/Player.js';
- import { Sidebar } from './js/Sidebar.js';
- import { Menubar } from './js/Menubar.js';
- window.URL = window.URL || window.webkitURL;
- window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
- Number.prototype.format = function () {
- return this.toString().replace( /(\d)(?=(\d{3})+(?!\d))/g, "$1," );
- };
- //
- var editor = new Editor();
- window.editor = editor; // Expose editor to Console
- window.THREE = THREE; // Expose THREE to APP Scripts and Console
- var viewport = new Viewport( editor );
- document.body.appendChild( viewport.dom );
- var toolbar = new Toolbar( editor );
- document.body.appendChild( toolbar.dom );
- var script = new Script( editor );
- document.body.appendChild( script.dom );
- var player = new Player( editor );
- document.body.appendChild( player.dom );
- var sidebar = new Sidebar( editor );
- document.body.appendChild( sidebar.dom );
- var menubar = new Menubar( editor );
- document.body.appendChild( menubar.dom );
- //
- editor.storage.init( function () {
- editor.storage.get( function ( state ) {
- if ( isLoadingFromHash ) return;
- if ( state !== undefined ) {
- editor.fromJSON( state );
- }
- var selected = editor.config.getKey( 'selected' );
- if ( selected !== undefined ) {
- editor.selectByUuid( selected );
- }
- } );
- //
- var timeout;
- function saveState() {
- if ( editor.config.getKey( 'autosave' ) === false ) {
- return;
- }
- clearTimeout( timeout );
- timeout = setTimeout( function () {
- editor.signals.savingStarted.dispatch();
- timeout = setTimeout( function () {
- editor.storage.set( editor.toJSON() );
- editor.signals.savingFinished.dispatch();
- }, 100 );
- }, 1000 );
- }
- var signals = editor.signals;
- signals.geometryChanged.add( saveState );
- signals.objectAdded.add( saveState );
- signals.objectChanged.add( saveState );
- signals.objectRemoved.add( saveState );
- signals.materialChanged.add( saveState );
- signals.sceneBackgroundChanged.add( saveState );
- signals.sceneFogChanged.add( saveState );
- signals.sceneGraphChanged.add( saveState );
- signals.scriptChanged.add( saveState );
- signals.historyChanged.add( saveState );
- } );
- //
- document.addEventListener( 'dragover', function ( event ) {
- event.preventDefault();
- event.dataTransfer.dropEffect = 'copy';
- }, false );
- document.addEventListener( 'drop', function ( event ) {
- event.preventDefault();
- editor.loader.loadFiles( event.dataTransfer.files );
- }, false );
- function onWindowResize() {
- editor.signals.windowResize.dispatch();
- }
- window.addEventListener( 'resize', onWindowResize, false );
- onWindowResize();
- //
- var isLoadingFromHash = false;
- var hash = window.location.hash;
- if ( hash.substr( 1, 5 ) === 'file=' ) {
- var file = hash.substr( 6 );
- if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
- var loader = new THREE.FileLoader();
- loader.crossOrigin = '';
- loader.load( file, function ( text ) {
- editor.clear();
- editor.fromJSON( JSON.parse( text ) );
- } );
- isLoadingFromHash = true;
- }
- }
- // ServiceWorker
- if ( 'serviceWorker' in navigator ) {
- try {
- navigator.serviceWorker.register( 'sw.js' );
- } catch ( error ) {
- }
- }
- /*
- window.addEventListener( 'message', function ( event ) {
- editor.clear();
- editor.fromJSON( event.data );
- }, false );
- */
- </script>
- </body>
- </html>
|