Advertisement
yskang

threejs-minecraft-44

May 4th, 2020
2,271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //修改 index.js
  2.  
  3. function save( blob, filename ) {
  4.     const url = URL.createObjectURL( blob );
  5.     const link = document.createElement( 'a' );
  6.     link.href = url;
  7.     link.download = filename || 'data.json';
  8.     link.style = 'display: none';
  9.     document.body.appendChild( link );
  10.     link.click();
  11.     URL.revokeObjectURL( url );
  12.     document.body.removeChild( link );
  13. }
  14.  
  15. function saveArrayBuffer( buffer, filename ) {
  16.     save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename );
  17. }
  18.  
  19. function saveString( text, filename ) {
  20.     save( new Blob( [ text ], { type: 'text/plain' } ), filename );
  21. }
  22.  
  23. const exportBtn = document.getElementById( 'export' );
  24. exportBtn.addEventListener( 'click', function() {
  25.     let output = scene.toJSON();
  26.     output = JSON.stringify( output, null, '\t' );
  27.     output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
  28.  
  29.     saveString( output, 'scene.json' );
  30. });
  31.  
  32. // 修改 index.css
  33.  
  34. button#export {
  35.     z-index: 10;
  36.     position: absolute;
  37.     left: 120px;
  38. }
  39.  
  40. // 修改 index.html
  41.  
  42. <button type="button" id="export">Export</button>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement