Last active
January 21, 2021 12:56
-
-
Save AdaRoseCannon/cb3564ef874cdd90aadb9e8c496d52f9 to your computer and use it in GitHub Desktop.
GLTF Exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create a new bookmark and use the below was the URL: | |
javascript:(function()%7Bs%3Ddocument.createElement('script')%3B%0As.setAttribute('type'%2C%20'module')%3B%0As.innerHTML%20%3D%20%60import%20%7BGLTFExporter%7D%20from%20'https%3A%2F%2Frawcdn.githack.com%2Fmrdoob%2Fthree.js%2Fcf04fca253477f40e04488229cfcaf0f280e448b%2Fexamples%2Fjsm%2Fexporters%2FGLTFExporter.js'%3B%0Aif%20(!window.scene)%20%7B%0A%20%20alert('No%20window.scene')%3B%0A%7D%20else%20%7B%0A%20%20const%20exporter%20%3D%20new%20GLTFExporter()%3B%0A%20%20exporter.parse(%20scene%2C%20function%20(%20gltf%20)%20%7B%0A%20%20%20%20const%20blob%20%3D%20new%20Blob(%20%5B%20gltf%20%5D%2C%20%7B%20type%3A%20'application%2Foctet-stream'%20%7D%20)%3B%0A%20%20%20%20const%20link%20%3D%20document.createElement(%20'a'%20)%3B%0A%20%20%20%20link.style.display%20%3D%20'none'%3B%0A%20%20%20%20document.body.appendChild(%20link%20)%3B%0A%20%20%20%20link.href%20%3D%20URL.createObjectURL(%20blob%20)%3B%0A%20%20%20%20link.download%20%3D%20'scene.glb'%3B%0A%20%20%20%20link.click()%3B%0A%20%20%7D%2C%20%7B%0A%20%20%20%20binary%3A%20true%0A%20%20%7D%20)%3B%0A%7D%0A%60%3B%0Adocument.body.appendChild(s)%3B%7D)()%3B |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assemble into the above bookmarklet using https://caiorss.github.io/bookmarklet-maker/ | |
s=document.createElement('script'); | |
s.setAttribute('type', 'module'); | |
s.innerHTML = `import {GLTFExporter} from 'https://rawcdn.githack.com/mrdoob/three.js/cf04fca253477f40e04488229cfcaf0f280e448b/examples/jsm/exporters/GLTFExporter.js'; | |
if (!window.scene) { | |
alert('No window.scene'); | |
} else { | |
const exporter = new GLTFExporter(); | |
exporter.parse( scene, function ( gltf ) { | |
const blob = new Blob( [ gltf ], { type: 'application/octet-stream' } ); | |
const link = document.createElement( 'a' ); | |
link.style.display = 'none'; | |
document.body.appendChild( link ); | |
link.href = URL.createObjectURL( blob ); | |
link.download = 'scene.glb'; | |
link.click(); | |
}, { | |
binary: true | |
} ); | |
} | |
`; | |
document.body.appendChild(s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment