Include the following details (edit as applicable):
- Issue category: ARDK Documentation
- Device type & OS version: Any
- Host machine & OS version: Any
- Issue Environment : On Device
- Xcode version:
- ARDK version: 2.4.1
- Unity version: 2021.3
Description of the issue:
The IARReferenceImage documentation gives reference to:
- Loading an image from a file
- Loading an image from a Text asset containing the “bytes” for an image
But I cannot find an example of how to take a Texture File associated in the editor as a Texture2D and successfully load it. All attempts simply result in the extremely unhelpful “InvalidReferenceImage”
This is the code I have attempted to use, based on the documentation samples:
private bool GetImageDataFromTexture(Texture2D trackedImage)
{
byte[] textureBytes = trackedImage.GetRawTextureData();
try
{
IARReferenceImage trackedImageARReference =
ARReferenceImageFactory.Create
(
trackedImage.Name,
textureBytes ,
textureBytes .Length,
physicalImageWidth
);
}
catch (Exception)
{
return false;
}
return true;
}
I even (for fun) tried to convert the bytes in to a TextAsset to more closely mirror the documentation example: (granted, ridiculous)
private bool GetImageDataFromTexture(Texture2D trackedImage)
{
byte[] bytes = trackedImage.GetRawTextureData();
string texAsString = Convert.ToBase64String(bytes);
TextAsset imageText = new TextAsset(texAsString);
try
{
IARReferenceImage trackedImageARReference =
ARReferenceImageFactory.Create
(
trackedImage.Name,
imageText.bytes,
imageText.bytes.Length,
physicalImageWidth
);
AddTrackedImageToLibrary(trackedImage, trackedImageARReference);
}
catch (Exception)
{
return false;
}
return true;
}
But no joy, even using the sample images used in the ARDK examples, the same result.
It would also be MORE helpful if there was more explanation as to WHY the image was rejected, such as:
- Length does not match array (but why LENGTH has to be supplied when you already pass the array :S )
- Image format was not recognised
- Insufficient tracking points to detect
- The odds are not in your favour.
Any ideas on how this might be achieved?