mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-18 15:26:19 +08:00
Add catch for issues in glTF exporter
This commit is contained in:
parent
2d160ef179
commit
01545e940e
@ -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',
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user