Skip to content
Open
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
28 changes: 20 additions & 8 deletions src/g3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ class Attribute {
}

// Converts a VIM attribute into a typed array from its raw data
static castData (
bytes: Uint8Array,
dataType: string
): Uint8Array | Int16Array | Int32Array | Float32Array | Float64Array {
// This is a UInt8 array

static castData (bytes: Uint8Array, dataType: string): TypedArray {
switch (dataType) {
case 'float32':
return new Float32Array(
Expand All @@ -89,6 +84,7 @@ class Attribute {
bytes.byteOffset,
bytes.byteLength / 8
)
case 'uint8':
case 'int8':
return bytes
case 'int16':
Expand All @@ -97,15 +93,31 @@ class Attribute {
bytes.byteOffset,
bytes.byteLength / 2
)
case 'uint16':
return new Uint16Array(
bytes.buffer,
bytes.byteOffset,
bytes.byteLength / 2
)
case 'int32':
return new Int32Array(
bytes.buffer,
bytes.byteOffset,
bytes.byteLength / 4
)
// case "int64": return new Int64Array(data.buffer, data.byteOffset, data.byteLength / 8);
case 'uint32':
return new Uint32Array(
bytes.buffer,
bytes.byteOffset,
bytes.byteLength / 4
)

case 'int64':
case 'uint64':
console.error('G3d: 64-bit buffers unsuported')
return
default:
throw new Error('Unrecognized attribute data type ' + dataType)
console.error('Unrecognized attribute data type ' + dataType)
}
}
}
Expand Down