I’ve been messing around with using Model I/O to load 3D assets and have run into an issue with getting/setting the vector data type.Specifically I’ve been trying to use vector_float3 and vector_int2 and I’m not getting back correct values.
In the case of vector_float3, I’m trying to read back the bounds of the MDLAsset.boundingBox.
I’ve created a Declare and a Structure that roughly looks like:
[code]Declare Function boundingBox Lib “ModelIO” Selector “boundingBox” (id As Integer) As MDLAxisAlignedBoundingBox
Struct MDLAxisAlignedBoundingBox
MaxBounds As vector_float3
MinBounds As vector_float3
Struct vector_float3
X As Single
Y As Single
Z As Single
[/code]
When I go to read the MDLAsset’s bounding box, the MaxBounds reads correctly but the MinBounds are off by 4 bytes, with Y holding what should be the X value, Z the Y value. I’ve tried things such as
- adding a StructureAlignment attribute of 16 for vector_float3
- adding another Single value at the end of vector_float3 to act as padding
- returning a Ptr for the Declare to try and retrieve it as a MemoryBlock
but in all cases and configurations I’ve tried so far the debug outright crashes when run.
In the case of vector_int2, I’m trying to create a MDLCheckerboardTexture but cannot get/set the MDLTexture.dimensions. The values I read back are not even remotely close to what they should be, unlike vector_float3 which gives me some of the correct values. The structure I’ve used is
Struct vector_int2
X As Int32
Y As Int32
And again I’ve messed around with both Declare and struct configurations to no avail, similar to what I’ve described for vector_float3
Digging down through Apple’s docs I see simd_float3 and simd_int2 as the underlying structures, but I haven’t found anything useful down there.
Can anyone point me in the right direction?