Hi,
We use the SketchUp 2016 SDK for exporting SKP files from our ARCHICAD software and we found that the
SUTextureCreateFromImageData () method behaves differently depending on the platform we use. On Mac OS X this method works as expected if we use an RGBA pixel array, while on Windows we need to use a BGRA pixel array for this.
Here is the scheme of the code we use for creating a texture (not compileable):
SUGeometryInputRef geometry = SU_INVALID;
size_t faceIdx = 0;
... // Here we init the geometry input and add a face to it (this part works)
// Create a new material input object
SUMaterialInput matInput;
SUSetInvalid (matInput.material);
SUMaterialCreate (&matInput.material);
SUMaterialSetName (matInput.material, "material");
// Fill texture image data using ARCHICAD (AC) pixel map representation
// You can test it replacing AC* constants with specific numbers
std::vector<SUByte> pixels (ACPixelMapSize * 4);
for (size_t pixelIdx = 0; pixelIdx < ACPixelMapSize; ++pixelIdx) {
#if defined(WINDOWS)
// BGRA array
pixels[4 * pixelIdx] = ACPixelMap[pixelIdx].blue;
pixels[4 * pixelIdx + 1] = ACPixelMap[pixelIdx].green;
pixels[4 * pixelIdx + 2] = ACPixelMap[pixelIdx].red;
pixels[4 * pixelIdx + 3] = ACPixelMap[pixelIdx].alpha ;
#else
// RGBA array
pixels[4 * pixelIdx] = ACPixelMap[pixelIdx].red;
pixels[4 * pixelIdx + 1] = ACPixelMap[pixelIdx].green;
pixels[4 * pixelIdx + 2] = ACPixelMap[pixelIdx].blue;
pixels[4 * pixelIdx + 3] = ACPixelMap[pixelIdx].alpha ;
#endif
}
SUTextureRef skpTexture = SU_INVALID;
SUTextureCreateFromImageData (&skpTexture, ACPixelMapXSize, ACPixelMapYSize, 32, pixels.data ());
// Add texture to material and set material to face
SUMaterialSetTexture (matInput.material, skpTexture);
SUMaterialSetType (matInput.material, SUMaterialType_Textured);
CalculateUVCoords (matInput); // Here the UV coords are set correctly
SUGeometryInputFaceSetFrontMaterial (geometry, faceIdx, &matInput);
... // Fill geometry to model and save the model to a file
The code were tested and works well, but this platform dependent behavior seems a bug.
Any idea?
Thanks,
Tamás Zolnai