Skip to content

Instantly share code, notes, and snippets.

@pushmatrix
Last active June 10, 2020 13:24
Show Gist options
  • Save pushmatrix/2884722da2c8b3256f933473c137b747 to your computer and use it in GitHub Desktop.
Save pushmatrix/2884722da2c8b3256f933473c137b747 to your computer and use it in GitHub Desktop.
Creating a usdz cube of any size
let fs = require('fs');
function createUSDZ(length, width, height) {
// Offset where the x, y, z scale properties are set
const byteOffset = 1344;
fs.readFile('cube.usdz', null, function (err, data) {
let view = new DataView(data.buffer);
// Set the scale for the x, y, z axis
view.setFloat32(byteOffset, length, true);
view.setFloat32(byteOffset + 4, width, true);
view.setFloat32(byteOffset + 8, height, true);
fs.writeFile('new_cube.usdz', view, function (err, data) {
if (err) {
return console.log(err);
}
});
});
}
// Example usage
createUSDZ(1, 1, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment