mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-27 04:21:46 +08:00
Add gltf binary export option
This commit is contained in:
parent
e7fcf8245e
commit
390da38f2f
@ -376,7 +376,11 @@ Object.assign(Blockbench, {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
//text or binary
|
//text or binary
|
||||||
fs.writeFileSync(file_path, options.content)
|
let content = options.content;
|
||||||
|
if (content instanceof ArrayBuffer) {
|
||||||
|
content = Buffer.from(content);
|
||||||
|
}
|
||||||
|
fs.writeFileSync(file_path, content)
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb(file_path)
|
cb(file_path)
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,11 @@ function buildAnimationTracks(do_quaternions = true) {
|
|||||||
var codec = new Codec('gltf', {
|
var codec = new Codec('gltf', {
|
||||||
name: 'GLTF Model',
|
name: 'GLTF Model',
|
||||||
extension: 'gltf',
|
extension: 'gltf',
|
||||||
async compile(options = 0) {
|
export_options: {
|
||||||
|
encoding: {type: 'select', label: 'Encoding', options: {ascii: 'ASCII (glTF)', binary: 'Binary (glb)'}},
|
||||||
|
animations: {label: 'codec.fbx.export_animations', type: 'checkbox', value: true}
|
||||||
|
},
|
||||||
|
async compile(options = this.getExportOptions()) {
|
||||||
let scope = this;
|
let scope = this;
|
||||||
let exporter = new THREE.GLTFExporter();
|
let exporter = new THREE.GLTFExporter();
|
||||||
let animations = [];
|
let animations = [];
|
||||||
@ -186,11 +190,12 @@ var codec = new Codec('gltf', {
|
|||||||
if (options.animations !== false) {
|
if (options.animations !== false) {
|
||||||
animations = buildAnimationTracks();
|
animations = buildAnimationTracks();
|
||||||
}
|
}
|
||||||
let json = await new Promise((resolve, reject) => {
|
let result = await new Promise((resolve, reject) => {
|
||||||
exporter.parse(gl_scene, resolve, {
|
exporter.parse(gl_scene, resolve, {
|
||||||
animations,
|
animations,
|
||||||
onlyVisible: false,
|
onlyVisible: false,
|
||||||
trs: true,
|
trs: true,
|
||||||
|
binary: options.encoding == 'binary',
|
||||||
truncateDrawRange: false,
|
truncateDrawRange: false,
|
||||||
forcePowerOfTwoTextures: true,
|
forcePowerOfTwoTextures: true,
|
||||||
scale_factor: 1/Settings.get('model_export_scale'),
|
scale_factor: 1/Settings.get('model_export_scale'),
|
||||||
@ -199,29 +204,32 @@ var codec = new Codec('gltf', {
|
|||||||
})
|
})
|
||||||
scene.add(Project.model_3d);
|
scene.add(Project.model_3d);
|
||||||
|
|
||||||
scope.dispatchEvent('compile', {model: json, options});
|
scope.dispatchEvent('compile', {model: result, options});
|
||||||
return JSON.stringify(json);
|
if (options.encoding == 'binary') {
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return JSON.stringify(result);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
scene.add(Project.model_3d);
|
scene.add(Project.model_3d);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
export() {
|
async export() {
|
||||||
var scope = codec;
|
await this.promptExportOptions();
|
||||||
scope.compile().then(content => {
|
let content = await this.compile();
|
||||||
setTimeout(_ => {
|
await new Promise(r => setTimeout(r, 20));
|
||||||
Blockbench.export({
|
console.log(content)
|
||||||
resource_id: 'gltf',
|
Blockbench.export({
|
||||||
type: scope.name,
|
resource_id: 'gltf',
|
||||||
extensions: [scope.extension],
|
type: this.name,
|
||||||
name: scope.fileName(),
|
extensions: [this.getExportOptions().encoding == 'binary' ? 'glb' : 'gltf'],
|
||||||
startpath: scope.startPath(),
|
name: this.fileName(),
|
||||||
content,
|
startpath: this.startPath(),
|
||||||
custom_writer: isApp ? (a, b) => scope.write(a, b) : null,
|
content,
|
||||||
}, path => scope.afterDownload(path))
|
custom_writer: isApp ? (a, b) => this.write(a, b) : null,
|
||||||
}, 20)
|
}, path => this.afterDownload(path));
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user