I’m trying to write a SKP file using C++ SDK, but I cannot create multiple SUMaterialRef using the same SUTextureRef. My model uses one texture image multiple times with different attributes. If I create only one SUTextureRef with SUTextureCreateFromImageData, and assign it to multiple material, I get an exception in SUModelRelease. Testcase follows. The model is saved with two materials with the same image.
Any idea?
// Create an empty model
SUModelRef model;
SUSetInvalid(model);
SU_CALL (SUModelCreate(&model));
// Single texture
SUTextureRef textureSKP;
SUSetInvalid(textureSKP);
char *imageData = new char[500];
char *point = imageData;
for (int x = 0; x < 10; x++)
for (int y = 0; y < 10; y++)
{
*(point++) = 10*x;
*(point++) = 10*x;
*(point++) = 10*x;
}
SU_CALL(SUTextureCreateFromImageData( &textureSKP, 10, 10, 24, ( const SUByte *) imageData));
delete [] imageData; imageData = NULL;
SUMaterialRef matLocal1, matLocal2;
SUSetInvalid (matLocal1);
SUSetInvalid (matLocal2);
SU_CALL(SUMaterialCreate(&matLocal1));
SU_CALL(SUMaterialSetName(matLocal1,"Material 1"));
SU_CALL(SUMaterialSetType(matLocal1, SUMaterialType_Textured));
SU_CALL(SUMaterialSetTexture(matLocal1, textureSKP));
SU_CALL(SUMaterialCreate(&matLocal2));
SU_CALL(SUMaterialSetName(matLocal2,"Material 2"));
SU_CALL(SUMaterialSetType(matLocal2, SUMaterialType_Textured));
SU_CALL(SUMaterialSetTexture(matLocal2, textureSKP)); // If I remove this works
SU_CALL(SUModelAddMaterials(model, 1, &matLocal1));
SU_CALL(SUModelAddMaterials(model, 1, &matLocal2));
SU_CALL(SUModelSaveToFile(model, "c:\\tmp\\testcase.skp"));
SU_CALL(SUModelRelease(&model)); // unhandled Exception