Export gltf models in block instead of pixel units

This commit is contained in:
JannisX11 2020-12-25 21:58:29 +01:00
parent 4e1fe04e99
commit 52657c084f
3 changed files with 22 additions and 2 deletions

View File

@ -162,7 +162,8 @@ var codec = new Codec('gltf', {
trs: true,
truncateDrawRange: false,
forcePowerOfTwoTextures: true,
exportFaceColors: false
scale_factor: 1/16,
exportFaceColors: false,
});
},
export() {

View File

@ -21,7 +21,12 @@ var codec = new Codec('obj', {
if (!options) options = 0;
var old_scene_position = new THREE.Vector3().copy(scene.position);
scene.position.set(0,0,0)
scene.position.set(0,0,0);
/**
Based on: three.js obj exporter, MIT license
https://github.com/mrdoob/three.js/blob/dev/examples/js/exporters/OBJExporter.js
*/
var output = '# Made in Blockbench '+appVersion+'\n';
var materials = {};

View File

@ -1305,6 +1305,17 @@ GLTFExporter.prototype = {
}
})
}
if ( options.scale_factor && attributeName === 'POSITION' ) {
// Blockbench: Scaled export
modifiedAttribute = new BufferAttribute( new Float32Array( array ), attribute.itemSize, attribute.normalized );
modifiedAttribute.array.forEach((v, i) => {
modifiedAttribute.array[i] *= options.scale_factor;
})
}
var accessor = processAccessor( modifiedAttribute || attribute, geometry );
if ( accessor !== null ) {
@ -1833,6 +1844,9 @@ GLTFExporter.prototype = {
if ( ! equalArray( position, [ 0, 0, 0 ] ) ) {
if (options.scale_factor) {
position = position.map(v => v * options.scale_factor);
}
gltfNode.translation = position;
}