Skip to content

Commit

Permalink
fix getAccessorBytes byteOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Oct 6, 2024
1 parent 598d84e commit fbf2adb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions deps/zigltf/src/GltfBuffer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ pub fn getAccessorBytes(self: *@This(), T: type, accessor_index: u32) ![]const T
if (accessor.bufferView) |bufferView_index| {
const bufferViewBytes = try self.getBufferViewBytes(bufferView_index);
const bufferView = self.gltf.bufferViews[bufferView_index];
const begin = accessor.byteOffset;
const end = accessor.byteOffset + accessor.count * accessor.stride();
const bytes = bufferViewBytes[begin..end];

const same_stride = if (bufferView.byteStride) |stride|
stride == accessor.stride()
else
true;

if (same_stride) {
const begin = accessor.byteOffset;
const end = accessor.byteOffset + accessor.count * accessor.stride();
const bytes = bufferViewBytes[begin..end];
return @alignCast(std.mem.bytesAsSlice(T, bytes));
} else {
var buffer = try self.allocator.alloc(T, accessor.count);
var p = &bufferViewBytes[0];
var p = &bytes[0];
const stride = bufferView.byteStride.?;
for (0..accessor.count) |vertex_index| {
const ptr: *const T = @ptrCast(@alignCast(p));
Expand Down

0 comments on commit fbf2adb

Please sign in to comment.