Last active
June 10, 2020 13:24
-
-
Save pushmatrix/2884722da2c8b3256f933473c137b747 to your computer and use it in GitHub Desktop.
Creating a usdz cube of any size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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