Add catch for issues in glTF exporter

This commit is contained in:
JannisX11 2021-12-30 13:15:29 +01:00
parent 2d160ef179
commit 01545e940e
2 changed files with 22 additions and 17 deletions

View File

@ -158,7 +158,7 @@ function buildAnimationTracks(do_quaternions = true) {
var codec = new Codec('gltf', {
name: 'GLTF Model',
extension: 'gltf',
compile(options = 0, callback) {
async compile(options = 0) {
let scope = this;
let exporter = new THREE.GLTFExporter();
let animations = [];
@ -172,25 +172,31 @@ var codec = new Codec('gltf', {
if (options.animations !== false) {
animations = buildAnimationTracks();
}
exporter.parse(gl_scene, (json) => {
scope.dispatchEvent('compile', {model: json, options});
callback(JSON.stringify(json));
try {
let json = await new Promise((resolve, reject) => {
exporter.parse(gl_scene, resolve, {
animations,
onlyVisible: false,
trs: true,
truncateDrawRange: false,
forcePowerOfTwoTextures: true,
scale_factor: 1/16,
exportFaceColors: false,
});
})
scene.add(Project.model_3d);
}, {
animations,
onlyVisible: false,
trs: true,
truncateDrawRange: false,
forcePowerOfTwoTextures: true,
scale_factor: 1/16,
exportFaceColors: false,
});
scope.dispatchEvent('compile', {model: json, options});
return JSON.stringify(json);
} catch (err) {
scene.add(Project.model_3d);
throw err;
}
},
export() {
var scope = codec;
scope.compile(0, content => {
scope.compile().then(content => {
setTimeout(_ => {
Blockbench.export({
resource_id: 'gltf',

View File

@ -1307,7 +1307,6 @@ GLTFExporter.prototype = {
if (mesh.material instanceof Array) {
let group = mesh.geometry.groups.find(group => Math.floor(i/2) >= group.start && Math.floor(i/2) < (group.start + group.count));
console.log(group, mesh.geometry)
if (group) material = mesh.material[group.materialIndex];
} else {
material = mesh.material;