mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-27 10:30:16 -05:00
Fix image uris and use better naming for separate resources
This commit is contained in:
parent
462c80fbc0
commit
139f473785
@ -104,7 +104,7 @@ function createGltf(data, inputPath, modelName, done) {
|
||||
vertexByteStride = sizeOfFloat32 * 3;
|
||||
}
|
||||
|
||||
var bufferId = 'buffer_' + modelName;
|
||||
var bufferId = modelName + '_buffer';
|
||||
var bufferViewVertexId = 'bufferView_vertex';
|
||||
var bufferViewIndexId = 'bufferView_index';
|
||||
var accessorPositionId = 'accessor_position';
|
||||
@ -131,7 +131,7 @@ function createGltf(data, inputPath, modelName, done) {
|
||||
}
|
||||
|
||||
function getImageId(image) {
|
||||
return 'image_' + path.basename(image).substr(0, image.lastIndexOf('.'));
|
||||
return path.basename(image, path.extname(image));
|
||||
}
|
||||
|
||||
var gltf = {
|
||||
|
28
lib/image.js
28
lib/image.js
@ -19,19 +19,39 @@ function getChannels(colorType) {
|
||||
}
|
||||
}
|
||||
|
||||
function getUriType(extension) {
|
||||
switch (extension) {
|
||||
case 'png':
|
||||
return 'data:image/png';
|
||||
case 'jpg':
|
||||
return 'data:image/jpeg';
|
||||
case 'jpeg':
|
||||
return 'data:image/jpeg';
|
||||
case 'gif':
|
||||
return 'data:image/gif';
|
||||
default:
|
||||
return 'data:image/' + extension;
|
||||
}
|
||||
}
|
||||
|
||||
function loadImage(imagePath, done) {
|
||||
fs.readFile(imagePath, function(error, data) {
|
||||
if (error) {
|
||||
throw(error);
|
||||
}
|
||||
|
||||
var extension = path.extname(imagePath).slice(1);
|
||||
var uriType = getUriType(extension);
|
||||
var uri = uriType + ';base64,' + data.toString('base64');
|
||||
|
||||
var info = {
|
||||
transparent : false,
|
||||
channels : 3,
|
||||
data : data
|
||||
transparent: false,
|
||||
channels: 3,
|
||||
data: data,
|
||||
uri: uri
|
||||
};
|
||||
|
||||
if (path.extname(imagePath) === '.png') {
|
||||
if (path.extname(imagePath) === 'png') {
|
||||
// Color type is encoded in the 25th bit of the png
|
||||
var colorType = data[25];
|
||||
var channels = getChannels(colorType);
|
||||
|
@ -268,12 +268,7 @@ function getImages(inputPath, materials, done) {
|
||||
imagePath = path.join(inputPath, image);
|
||||
}
|
||||
loadImage(imagePath, function(info) {
|
||||
var uri = 'data:application/octet-stream;base64,' + info.data.toString('base64');
|
||||
imagesInfo[image] = {
|
||||
transparent : info.transparent,
|
||||
channels : info.channels,
|
||||
uri : uri
|
||||
};
|
||||
imagesInfo[image] = info;
|
||||
callback();
|
||||
});
|
||||
}, function (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user