Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created accessor bufferViews should be byte aligned #421

Merged
merged 4 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log
### 2.0.1 - ????

* Fixed a bug where the buffer `byteOffset` was not set properly when updating 1.0 accessor types to 2.0 allowed values. [#418](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/418)
* Fixed a bug where bufferViews were not properly byte aligned when updating accessors from 1.0 to 2.0. [#421](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/421)
* Fixed a bug in `removePipelineExtras` when run in the browser. [#422](https://github.com/AnalyticalGraphicsInc/gltf-pipeline/pull/422)

### 2.0.0 - 2018-08-14
Expand Down
6 changes: 4 additions & 2 deletions lib/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ function moveByteStrideToBufferView(gltf) {
var accessorByteLength = accessor.count * accessorByteStride;
delete accessor.byteStride;

var nextAccessorByteStride = (i < accessorsLength - 1) ? computeAccessorByteStride(gltf, accessors[i + 1]) : undefined;
var hasNextAccessor = (i < accessorsLength - 1);
var nextAccessorByteStride = hasNextAccessor ? computeAccessorByteStride(gltf, accessors[i + 1]) : undefined;
if (accessorByteStride !== nextAccessorByteStride) {
var newBufferView = clone(bufferView, true);
if (bufferViewHasVertexAttributes[bufferViewId]) {
Expand All @@ -804,7 +805,8 @@ function moveByteStrideToBufferView(gltf) {
accessor.bufferView = newBufferViewId;
accessor.byteOffset = accessor.byteOffset - currentByteOffset;
}
currentByteOffset = accessorByteOffset + accessorByteLength;
// Set current byte offset to next accessor's byte offset
currentByteOffset = hasNextAccessor ? accessors[i + 1].byteOffset : undefined;
currentIndex = i + 1;
}
}
Expand Down
20 changes: 10 additions & 10 deletions specs/lib/updateVersionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,15 @@ describe('updateVersion', function() {
},
accessor_normal: {
bufferView: 'bufferViewAttributes',
byteOffset: 36,
componentType: WebGLConstants.FLOAT,
byteOffset: 42,
componentType: WebGLConstants.BYTE,
count: 3,
type: 'VEC3'
type: 'VEC2'
},
accessor_texcoord: {
bufferView: 'bufferViewAttributes',
byteOffset: 72,
componentType: WebGLConstants.FLOAT,
byteOffset: 50,
componentType: WebGLConstants.BYTE,
count: 3,
type: 'VEC2'
},
Expand Down Expand Up @@ -722,14 +722,14 @@ describe('updateVersion', function() {
var positionBufferView = gltf.bufferViews[positionAccessor.bufferView];
var texcoordBufferView = gltf.bufferViews[texcoordAccessor.bufferView];
expect(positionAccessor.bufferView).toBe(1);
expect(normalAccessor.bufferView).toBe(1);
expect(normalAccessor.bufferView).toBe(2);
expect(texcoordAccessor.bufferView).toBe(2);
expect(positionBufferView.byteLength).toBe(72);
expect(positionBufferView.byteLength).toBe(36);
expect(positionBufferView.byteOffset).toBe(12); // First unrelated buffer view is 12 bytes
expect(positionBufferView.byteStride).toBe(12);
expect(texcoordBufferView.byteLength).toBe(24);
expect(texcoordBufferView.byteOffset).toBe(72 + 12); // First unrelated buffer view is 12 bytes
expect(texcoordBufferView.byteStride).toBe(8);
expect(texcoordBufferView.byteLength).toBe(50 - 42 + 6); // Padding to next buffer view
expect(texcoordBufferView.byteOffset).toBe(42 + 12); // Byte offset of previous accessor plus byte length
expect(texcoordBufferView.byteStride).toBe(2);
expect(positionAccessor.byteStride).toBeUndefined();
expect(normalAccessor.byteStride).toBeUndefined();
expect(texcoordAccessor.byteStride).toBeUndefined();
Expand Down