index.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <html>
  2. <head>
  3. <title>three.js gui</title>
  4. <style>
  5. @font-face {
  6. font-family: 'Inconsolata';
  7. src: url('files/inconsolata.woff') format('woff');
  8. font-weight: normal;
  9. font-style: normal;
  10. }
  11. body {
  12. margin: 0;
  13. overflow: hidden;
  14. }
  15. button {
  16. cursor: pointer;
  17. }
  18. pre {
  19. font-family: 'Inconsolata';
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <script type="text/javascript" src="../build/Three.js"></script>
  25. <script type="text/javascript" src="js/libs/signals.min.js"></script>
  26. <script type="text/javascript" src="js/UI.js"></script>
  27. <script type="text/javascript" src="js/UI.Viewports.js"></script>
  28. <script type="text/javascript" src="js/UI.Toolbar.js"></script>
  29. <script type="text/javascript" src="js/Code.js"></script>
  30. <script type="text/javascript" src="js/Code.Templates.js"></script>
  31. <script>
  32. var Signal = signals.Signal;
  33. var signals = {
  34. added: new Signal(),
  35. updated: new Signal()
  36. };
  37. var ui = new UI();
  38. document.body.appendChild( ui.getDOMElement() );
  39. var code = new Code()
  40. document.body.appendChild( code.getDOMElement() );
  41. var xhalf = 0.7;
  42. var xr = document.createElement( 'div' );
  43. xr.style.position = 'absolute';
  44. xr.style.top = '0px';
  45. xr.style.width = '1px';
  46. xr.style.borderLeft = '1px solid #e0e0e0';
  47. // xr.style.backgroundColor = '#ffffff';
  48. xr.style.cursor = 'col-resize';
  49. xr.addEventListener( 'mousedown', function ( event ) {
  50. event.preventDefault();
  51. document.body.style.cursor = 'col-resize';
  52. document.addEventListener( 'mousemove', onMouseMove, false );
  53. document.addEventListener( 'mouseup', onMouseUp, false );
  54. function onMouseMove( event ) {
  55. event.preventDefault();
  56. xhalf = Math.max( 0, Math.min( 1, event.clientX / window.innerWidth ) );
  57. update();
  58. }
  59. function onMouseUp( event ) {
  60. document.body.style.cursor = 'auto';
  61. document.removeEventListener( 'mousemove', onMouseMove, false );
  62. document.removeEventListener( 'mouseup', onMouseUp, false );
  63. }
  64. }, false );
  65. xr.addEventListener( 'dblclick', function ( event ) {
  66. xhalf = 0.7;
  67. update();
  68. }, false );
  69. document.body.appendChild( xr );
  70. // Add Sphere
  71. var geometry = new THREE.SphereGeometry( 75, 20, 10 );
  72. var material = new THREE.MeshBasicMaterial( { color: 0xffffff } );
  73. var mesh = new THREE.Mesh( geometry, material );
  74. signals.added.dispatch( mesh );
  75. //
  76. update();
  77. window.addEventListener( 'resize', function ( event ) { update() }, false );
  78. function update() {
  79. ui.setSize( window.innerWidth * xhalf, window.innerHeight );
  80. code.setPosition( window.innerWidth * xhalf, 0 );
  81. code.setSize( window.innerWidth - ( window.innerWidth * xhalf ), window.innerHeight );
  82. xr.style.left = ( window.innerWidth * xhalf ) + 'px';
  83. xr.style.height = window.innerHeight + 'px';
  84. }
  85. </script>
  86. </body>
  87. </html>