mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-01-31 03:53:13 -05:00
Better buffer handling
This commit is contained in:
parent
998dcfe649
commit
cf27c8b69d
24
lib/gltf.js
24
lib/gltf.js
@ -144,9 +144,9 @@ function createGltf(objData) {
|
||||
}
|
||||
|
||||
var vertexBuffers = [];
|
||||
var vertexByteOffset = 0;
|
||||
var vertexBufferByteOffset = 0;
|
||||
var indexBuffers = [];
|
||||
var indexBuffersByteOffset = 0;
|
||||
var indexBufferByteOffset = 0;
|
||||
var accessorCount = 0;
|
||||
|
||||
function addVertexAttribute(array, components) {
|
||||
@ -157,7 +157,7 @@ function createGltf(objData) {
|
||||
var type = (components === 3 ? 'VEC3' : 'VEC2');
|
||||
var accessor = {
|
||||
bufferView : vertexBufferViewId,
|
||||
byteOffset : vertexByteOffset,
|
||||
byteOffset : vertexBufferByteOffset,
|
||||
byteStride : 0,
|
||||
componentType : WebGLConstants.FLOAT,
|
||||
count : count,
|
||||
@ -166,7 +166,7 @@ function createGltf(objData) {
|
||||
type : type
|
||||
};
|
||||
|
||||
vertexByteOffset += buffer.length;
|
||||
vertexBufferByteOffset += buffer.length;
|
||||
vertexBuffers.push(buffer);
|
||||
var accessorId = 'accessor_' + accessorCount++;
|
||||
gltf.accessors[accessorId] = accessor;
|
||||
@ -180,7 +180,7 @@ function createGltf(objData) {
|
||||
var minMax = array.getMinMax(1);
|
||||
var accessor = {
|
||||
bufferView : indexBufferViewId,
|
||||
byteOffset : indexBuffersByteOffset,
|
||||
byteOffset : indexBufferByteOffset,
|
||||
byteStride : 0,
|
||||
componentType : componentType,
|
||||
count : length,
|
||||
@ -189,7 +189,7 @@ function createGltf(objData) {
|
||||
type : 'SCALAR'
|
||||
};
|
||||
|
||||
indexBuffersByteOffset += buffer.length;
|
||||
indexBufferByteOffset += buffer.length;
|
||||
indexBuffers.push(buffer);
|
||||
|
||||
var accessorId = 'accessor_' + accessorCount++;
|
||||
@ -300,9 +300,9 @@ function createGltf(objData) {
|
||||
}
|
||||
}
|
||||
|
||||
var vertexBuffer = Buffer.concat(vertexBuffers);
|
||||
var indexBuffer = Buffer.concat(indexBuffers);
|
||||
var buffer = Buffer.concat([vertexBuffer, indexBuffer]);
|
||||
var buffers = [];
|
||||
buffers = buffers.concat(vertexBuffers, indexBuffers);
|
||||
var buffer = Buffer.concat(buffers);
|
||||
|
||||
// Buffers larger than ~192MB cannot be base64 encoded due to a NodeJS limitation. Source: https://github.com/nodejs/node/issues/4266
|
||||
var bufferUri;
|
||||
@ -317,15 +317,15 @@ function createGltf(objData) {
|
||||
|
||||
gltf.bufferViews[vertexBufferViewId] = {
|
||||
buffer : bufferId,
|
||||
byteLength : vertexBuffer.length,
|
||||
byteLength : vertexBufferByteOffset,
|
||||
byteOffset : 0,
|
||||
target : WebGLConstants.ARRAY_BUFFER
|
||||
};
|
||||
|
||||
gltf.bufferViews[indexBufferViewId] = {
|
||||
buffer : bufferId,
|
||||
byteLength : indexBuffer.length,
|
||||
byteOffset : vertexBuffer.length,
|
||||
byteLength : indexBufferByteOffset,
|
||||
byteOffset : vertexBufferByteOffset,
|
||||
target : WebGLConstants.ELEMENT_ARRAY_BUFFER
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user