Add model previews on upload #27
@@ -5,15 +5,30 @@
|
|||||||
* @param {Event} e
|
* @param {Event} e
|
||||||
*/
|
*/
|
||||||
checkForGltf = function (e) {
|
checkForGltf = function (e) {
|
||||||
fileName = e.target.value
|
const fileInfo = e.target.files[0]
|
||||||
if (fileName.match(/(.gl(?:b|(?:tf))$)/)) {
|
if (fileInfo.name.match(/(.gl(?:b|(?:tf))$)/) && fileInfo.type == 'model/gltf-binary') {
|
||||||
const mvPreview = document.createElement('model-viewer')
|
const mvPreview = document.createElement('model-viewer')
|
||||||
mvPreview.style['width'] = '180px'
|
mvPreview.style['width'] = '180px'
|
||||||
mvPreview.style['height'] = '180px'
|
mvPreview.style['height'] = '180px'
|
||||||
|
|
||||||
|
const dThumbCap = document.createElement('div')
|
||||||
|
dThumbCap.classList.add('thumbcaption')
|
||||||
|
|
||||||
|
const dThumbName = document.createElement('div')
|
||||||
|
dThumbName.classList.add('filename')
|
||||||
|
dThumbName.innerHTML = fileInfo.name
|
||||||
|
|
||||||
|
const dThumbInfo = document.createElement('div')
|
||||||
|
dThumbInfo.classList.add('fileinfo')
|
||||||
|
dThumbInfo.innerHTML = (fileInfo.size / 1024 / 1024).toFixed(1) + 'MB'
|
||||||
|
|
||||||
|
dThumbCap.appendChild(dThumbName)
|
||||||
|
dThumbCap.appendChild(dThumbInfo)
|
||||||
|
|
||||||
const dThumbIn = document.createElement('div')
|
const dThumbIn = document.createElement('div')
|
||||||
dThumbIn.classList.add('thumbinner')
|
dThumbIn.classList.add('thumbinner')
|
||||||
dThumbIn.appendChild(mvPreview)
|
dThumbIn.appendChild(mvPreview)
|
||||||
|
dThumbIn.appendChild(dThumbCap)
|
||||||
|
|
||||||
const dThumb = document.createElement('div')
|
const dThumb = document.createElement('div')
|
||||||
dThumb.id = 'glmv-upload-thumbnail'
|
dThumb.id = 'glmv-upload-thumbnail'
|
||||||
@@ -28,7 +43,7 @@ checkForGltf = function (e) {
|
|||||||
$('model-viewer').attr('auto-rotate-delay',3000)
|
$('model-viewer').attr('auto-rotate-delay',3000)
|
||||||
$('model-viewer')[0].toggleAttribute('auto-rotate')
|
$('model-viewer')[0].toggleAttribute('auto-rotate')
|
||||||
},{once: true})
|
},{once: true})
|
||||||
reader.readAsDataURL(e.target.files[0])
|
reader.readAsDataURL(fileInfo)
|
||||||
} else {
|
} else {
|
||||||
$('#glmv-upload-thumbnail').remove()
|
$('#glmv-upload-thumbnail').remove()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user