2017-10-27 01:00:52 +08:00
|
|
|
(function() {
|
2018-10-18 01:50:25 +08:00
|
|
|
$.getScript("lib/file_saver.js");
|
2019-01-09 22:54:35 +08:00
|
|
|
$.getScript('https://rawgit.com/nodeca/pako/master/dist/pako.js', function() {
|
|
|
|
window.zlib = pako
|
|
|
|
})
|
2017-10-27 01:00:52 +08:00
|
|
|
})()
|
|
|
|
|
2018-10-18 01:50:25 +08:00
|
|
|
$(document).ready(function() {
|
|
|
|
$('.open-in-browser').click((event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
window.open(event.target.href, '_blank');
|
|
|
|
});
|
|
|
|
})
|
2019-04-08 00:53:33 +08:00
|
|
|
/*setInterval(function() {
|
|
|
|
Prop.zoom = Math.round(devicePixelRatio*100)
|
|
|
|
}, 500)*/
|
2018-03-29 02:48:11 +08:00
|
|
|
|
2017-10-27 01:00:52 +08:00
|
|
|
function tryLoadPOSTModel() {
|
2018-10-18 01:50:25 +08:00
|
|
|
if ($('#post_model').text() !== '') {
|
|
|
|
if ($('#post_textures').text() !== '') {
|
|
|
|
Project.dataURLTextures = true
|
|
|
|
}
|
|
|
|
loadModel($('#post_model').text(), 'model')
|
|
|
|
//$('#post_model').remove()
|
|
|
|
if ($('#post_textures').text() !== '') {
|
|
|
|
var data = JSON.parse( $('#post_textures').text() )
|
|
|
|
for (var key in data) {
|
2019-02-04 04:09:35 +08:00
|
|
|
var tex = textures.findInArray('id', key+'');
|
|
|
|
if (tex) {
|
|
|
|
tex.img.src = ''
|
|
|
|
tex.source = 'data:image/png;base64,'+data[key]
|
2018-10-18 01:50:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
textures.forEach(function(tex) {
|
|
|
|
tex.load()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return true;
|
2017-10-27 01:00:52 +08:00
|
|
|
} else {
|
2018-10-18 01:50:25 +08:00
|
|
|
return false
|
2017-10-27 01:00:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Saver
|
2018-10-24 03:49:04 +08:00
|
|
|
function writeFileObj() {
|
2018-12-03 02:37:06 +08:00
|
|
|
var delay = 40
|
2018-10-18 01:50:25 +08:00
|
|
|
var content = buildOBJModel('model')
|
|
|
|
//OBJECT
|
|
|
|
var blob_obj = new Blob([content.obj], {type: "text/plain;charset=utf-8"});
|
2018-10-24 03:49:04 +08:00
|
|
|
var obj_saver = saveAs(blob_obj, 'model.obj', {autoBOM: true})
|
2018-10-18 01:50:25 +08:00
|
|
|
|
2018-12-03 02:37:06 +08:00
|
|
|
setTimeout(function() {
|
2018-10-18 01:50:25 +08:00
|
|
|
//MATERIAL
|
|
|
|
var blob_mtl = new Blob([content.mtl], {type: "text/plain;charset=utf-8"});
|
2018-12-03 02:37:06 +08:00
|
|
|
saveAs(blob_mtl, 'model.mtl', {autoBOM: true})
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2018-10-18 01:50:25 +08:00
|
|
|
if (settings.obj_textures.value === true) {
|
|
|
|
var tex_i = 0
|
|
|
|
function saveTex() {
|
|
|
|
if (textures[tex_i] && content.images.hasOwnProperty(textures[tex_i].id)) {
|
|
|
|
var image_data = atob(textures[tex_i].source.split(',')[1]);
|
|
|
|
var arraybuffer = new ArrayBuffer(image_data.length);
|
|
|
|
var view = new Uint8Array(arraybuffer);
|
|
|
|
for (var i=0; i<image_data.length; i++) {
|
|
|
|
view[i] = image_data.charCodeAt(i) & 0xff;
|
|
|
|
}
|
|
|
|
var blob = new Blob([arraybuffer], {type: 'application/octet-stream'})
|
|
|
|
var img_saver = saveAs(blob, textures[tex_i].name)
|
2018-12-03 02:37:06 +08:00
|
|
|
setTimeout(function() {
|
2018-10-18 01:50:25 +08:00
|
|
|
tex_i++
|
|
|
|
saveTex()
|
2018-12-03 02:37:06 +08:00
|
|
|
}, delay)
|
2018-10-18 01:50:25 +08:00
|
|
|
} else if (textures[tex_i]) {
|
|
|
|
tex_i++
|
|
|
|
saveTex()
|
|
|
|
} else {
|
|
|
|
Blockbench.showQuickMessage(tl('message.save_obj'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveTex()
|
|
|
|
} else {
|
|
|
|
Blockbench.showQuickMessage(tl('message.save_obj'))
|
|
|
|
}
|
2018-12-03 02:37:06 +08:00
|
|
|
}, delay)
|
|
|
|
}, delay)
|
2017-10-27 01:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveFile() {
|
2018-12-27 21:03:04 +08:00
|
|
|
if (Blockbench.entity_mode === false) {
|
|
|
|
BarItems.export_blockmodel.trigger()
|
|
|
|
} else {
|
|
|
|
BarItems.export_entity.trigger()
|
|
|
|
}
|
2017-10-27 01:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//Misc
|
|
|
|
window.onbeforeunload = function() {
|
2018-03-29 02:48:11 +08:00
|
|
|
if (Prop.project_saved === false && elements.length > 0) {
|
2018-10-18 01:50:25 +08:00
|
|
|
return true;
|
2019-04-13 04:39:53 +08:00
|
|
|
} else {
|
|
|
|
EditSession.quit()
|
2017-10-27 01:00:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function showSaveDialog(close) {
|
2018-10-18 01:50:25 +08:00
|
|
|
var unsaved_textures = 0;
|
|
|
|
textures.forEach(function(t) {
|
|
|
|
if (!t.saved) {
|
|
|
|
unsaved_textures++;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if ((Prop.project_saved === false && elements.length > 0) || unsaved_textures) {
|
|
|
|
|
|
|
|
var answer = confirm(tl('message.close_warning.web'))
|
|
|
|
if (answer == true) {
|
|
|
|
if (close) {
|
|
|
|
//preventClosing = false
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-27 01:00:52 +08:00
|
|
|
}
|