Comparing version 1.1.0 to 1.1.1
@@ -1,9 +0,9 @@ | ||
var fs = require('fs-extra'); | ||
var objParser = require('./objParser'); | ||
var packFormat = require('./packFormat'); | ||
var getBounds = require('./getBounds'); | ||
const fs = require('fs-extra'); | ||
const objParser = require('./objParser'); | ||
const packFormat = require('./packFormat'); | ||
const getBounds = require('./getBounds'); | ||
const path = require('path'); | ||
// load a model | ||
var createBatch = function() | ||
const createBatch = function () | ||
{ | ||
@@ -18,12 +18,12 @@ const mega = { | ||
return mega; | ||
} | ||
}; | ||
var createManifest = function() | ||
const createManifest = function () | ||
{ | ||
const manifest = { | ||
geometry:[] | ||
geometry: [], | ||
}; | ||
return manifest; | ||
} | ||
}; | ||
@@ -33,57 +33,57 @@ const maxSize = 0xFFFF; | ||
var finish = function(currentBatch, manifest, out) | ||
const finish = function (currentBatch, manifest, out) | ||
{ | ||
const bufferFilePath = out + idCount + '.gb-buffer'; | ||
const bufferFilePath = `${out + idCount}.gb-buffer`; | ||
manifest.size = currentBatch.buffer.length; | ||
manifest.indexSize = currentBatch.indexBuffer.length; | ||
manifest.buffer = path.basename(bufferFilePath);//'buffer' + idCount + '.gb-buffer'; | ||
var buffer = new Buffer( (currentBatch.buffer.length * 4) + (currentBatch.indexBuffer.length * 2) ); | ||
for(var i = 0; i < currentBatch.buffer.length; i++) | ||
manifest.buffer = path.basename(bufferFilePath);// 'buffer' + idCount + '.gb-buffer'; | ||
const buffer = new Buffer((currentBatch.buffer.length * 4) + (currentBatch.indexBuffer.length * 2)); | ||
for (var i = 0; i < currentBatch.buffer.length; i++) | ||
{ | ||
buffer.writeFloatLE( currentBatch.buffer[i], i * 4 ); | ||
buffer.writeFloatLE(currentBatch.buffer[i], i * 4); | ||
} | ||
const offset = currentBatch.buffer.length * 4; | ||
for(var i = 0; i < currentBatch.indexBuffer.length; i++) | ||
for (var i = 0; i < currentBatch.indexBuffer.length; i++) | ||
{ | ||
buffer.writeUInt16LE( currentBatch.indexBuffer[i] | 0, offset + (i * 2) ); | ||
buffer.writeUInt16LE(currentBatch.indexBuffer[i] | 0, offset + (i * 2)); | ||
} | ||
//var wstream = fs.createWriteStream(out + idCount + '.gbd'); | ||
//wstream.write(buffer); | ||
//wstream.end(); | ||
// var wstream = fs.createWriteStream(out + idCount + '.gbd'); | ||
// wstream.write(buffer); | ||
// wstream.end(); | ||
fs.outputFileSync(bufferFilePath, buffer); | ||
fs.outputFileSync(out + idCount + '.gb-map', JSON.stringify(manifest, null, 4)); | ||
fs.outputFileSync(`${out + idCount}.gb-map`, JSON.stringify(manifest, null, 4)); | ||
idCount++; | ||
} | ||
}; | ||
var convertObjsToGBOBatch = function(objs, out)//objSource, out) | ||
const convertObjsToGBOBatch = function (objs, out)// objSource, out) | ||
{ | ||
if(!objs.length)return; | ||
if (!objs.length) return; | ||
count = 0; | ||
let currentBatch = createBatch(); | ||
let manifest = createManifest(); | ||
var allBatchs = [manifest]; | ||
const allBatchs = [manifest]; | ||
//console.log(objs) | ||
objs.forEach(geometry => { | ||
// console.log(objs) | ||
objs.forEach((geometry) => | ||
{ | ||
const source = geometry.original; | ||
var data = fs.readFileSync(source, 'utf8'); | ||
var objData = objParser(data); | ||
const data = fs.readFileSync(source, 'utf8'); | ||
const objData = objParser(data); | ||
if (currentBatch.index + objData.indices.length > maxSize) | ||
@@ -96,10 +96,8 @@ { | ||
manifest = createManifest(); | ||
allBatchs.push(manifest); | ||
} | ||
const statVert = currentBatch.vertIndex / 8; | ||
const attribStart = currentBatch.vertIndex / 8; | ||
const megaData = currentBatch.buffer; | ||
@@ -128,3 +126,3 @@ const megaIndexData = currentBatch.indexBuffer; | ||
{ | ||
megaIndexData[i + start] = objData.indices[i] + statVert; | ||
megaIndexData[i + start] = objData.indices[i] + attribStart; | ||
} | ||
@@ -134,6 +132,6 @@ | ||
const geometryFrag = { file:geometry.outputFile, start, size: objData.indices.length }; | ||
manifest.geometry.push(geometryFrag) | ||
const geometryFrag = { file: geometry.outputFile, attribStart, attribSize: count, start, size: objData.indices.length }; | ||
}) | ||
manifest.geometry.push(geometryFrag); | ||
}); | ||
@@ -143,6 +141,5 @@ finish(currentBatch, manifest, out); | ||
return allBatchs; | ||
} | ||
}; | ||
module.exports = convertObjsToGBOBatch; | ||
module.exports = convertObjsToGBOBatch | ||
{ | ||
"name": "gbo-parser", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A reader for goodboys gbo file format.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
761
13