mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-23 08:34:14 -05:00
Merge pull request #3 from AnalyticalGraphicsInc/embed
Rename combine to embed
This commit is contained in:
commit
e1bee3b587
@ -19,7 +19,7 @@ Run `node bin/obj2gltf.js` and pass it the path to an OBJ file.
|
||||
|----|-----------|--------|
|
||||
|`-i`|Path to the input OBJ file.| :white_check_mark: Yes|
|
||||
|`-o`|Directory or filename for the exported glTF file.|No|
|
||||
|`-c`|Combine glTF resources, including images, into the exported glTF file.|No, default `false`|
|
||||
|`-e`|Embed glTF resources, including images, into the exported glTF file.|No, default `false`|
|
||||
|`-t`|Shading technique. Possible values are `lambert`, `phong`, `blinn`, and `constant`. The shading technique is typically determined by the MTL file, but this allows more explicit control.|No|
|
||||
|`-h`|Display help|No|
|
||||
|
||||
|
@ -16,7 +16,7 @@ if (process.argv.length < 3 || defined(argv.h) || defined(argv.help)) {
|
||||
console.log(' -i, --input Path to obj file');
|
||||
console.log(' -o, --output Directory or filename for the exported glTF file');
|
||||
console.log(' -b, --binary Output binary glTF');
|
||||
console.log(' -c, --combine Combine glTF resources into a single file');
|
||||
console.log(' -e, --embed Embed glTF resources into a single file');
|
||||
console.log(' -t, --technique Shading technique. Possible values are lambert, phong, blinn, constant');
|
||||
console.log(' -h, --help Display this help');
|
||||
process.exit(0);
|
||||
@ -25,7 +25,7 @@ if (process.argv.length < 3 || defined(argv.h) || defined(argv.help)) {
|
||||
var objFile = defaultValue(argv._[0], defaultValue(argv.i, argv.input));
|
||||
var outputPath = defaultValue(argv._[1], defaultValue(argv.o, argv.output));
|
||||
var binary = defaultValue(defaultValue(argv.b, argv.binary), false);
|
||||
var combine = defaultValue(defaultValue(argv.c, argv.combine), false);
|
||||
var embed = defaultValue(defaultValue(argv.e, argv.embed), false);
|
||||
var technique = defaultValue(argv.t, argv.technique);
|
||||
|
||||
if (!defined(objFile)) {
|
||||
@ -59,7 +59,7 @@ fs.mkdir(outputPath, function(){
|
||||
parseObj(objFile, inputPath, function(data) {
|
||||
console.timeEnd('Parse Obj');
|
||||
console.time('Create glTF');
|
||||
createGltf(data, modelName, inputPath, outputPath, binary, combine, technique, function() {
|
||||
createGltf(data, modelName, inputPath, outputPath, binary, embed, technique, function() {
|
||||
console.timeEnd('Create glTF');
|
||||
console.timeEnd('Total');
|
||||
});
|
||||
|
14
lib/gltf.js
14
lib/gltf.js
@ -13,7 +13,7 @@ var modelMaterialsCommon = require('./modelMaterialsCommon');
|
||||
|
||||
module.exports = createGltf;
|
||||
|
||||
function getImages(inputPath, outputPath, combine, materials, done) {
|
||||
function getImages(inputPath, outputPath, embed, materials, done) {
|
||||
var images = [];
|
||||
|
||||
for (var name in materials) {
|
||||
@ -44,7 +44,7 @@ function getImages(inputPath, outputPath, combine, materials, done) {
|
||||
var copyPath = path.join(outputPath, baseName);
|
||||
imageInfo(imagePath, function(info) {
|
||||
var uri;
|
||||
if (combine) {
|
||||
if (embed) {
|
||||
uri = 'data:application/octet-stream;base64,' + info.data.toString('base64');
|
||||
} else {
|
||||
uri = baseName;
|
||||
@ -56,7 +56,7 @@ function getImages(inputPath, outputPath, combine, materials, done) {
|
||||
uri : uri
|
||||
};
|
||||
|
||||
if (combine) {
|
||||
if (embed) {
|
||||
callback();
|
||||
} else if (path.relative(imagePath, copyPath) !== '') {
|
||||
fsExtra.copy(imagePath, copyPath, {clobber : true}, function (err) {
|
||||
@ -75,7 +75,7 @@ function getImages(inputPath, outputPath, combine, materials, done) {
|
||||
});
|
||||
}
|
||||
|
||||
function createGltf(data, modelName, inputPath, outputPath, binary, combine, technique, done) {
|
||||
function createGltf(data, modelName, inputPath, outputPath, binary, embed, technique, done) {
|
||||
var vertexCount = data.vertexCount;
|
||||
var vertexArray = data.vertexArray;
|
||||
var positionMin = data.positionMin;
|
||||
@ -84,7 +84,7 @@ function createGltf(data, modelName, inputPath, outputPath, binary, combine, tec
|
||||
var materialGroups = data.materialGroups;
|
||||
var materials = data.materials;
|
||||
|
||||
getImages(inputPath, outputPath, combine, materials, function(images) {
|
||||
getImages(inputPath, outputPath, embed, materials, function(images) {
|
||||
var i, j, name;
|
||||
|
||||
var sizeOfFloat32 = 4;
|
||||
@ -228,7 +228,7 @@ function createGltf(data, modelName, inputPath, outputPath, binary, combine, tec
|
||||
gltf.samplers[samplerId] = {}; // Use default values
|
||||
|
||||
var bufferUri;
|
||||
if (combine) {
|
||||
if (embed) {
|
||||
bufferUri = 'data:application/octet-stream;base64,' + buffer.toString('base64');
|
||||
} else {
|
||||
bufferUri = binaryRelPath;
|
||||
@ -417,7 +417,7 @@ function createGltf(data, modelName, inputPath, outputPath, binary, combine, tec
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
if (combine) {
|
||||
if (embed) {
|
||||
done();
|
||||
} else {
|
||||
// Save .bin file
|
||||
|
Loading…
Reference in New Issue
Block a user