How to get and set texture using C API

Hi gurus.
I have an application (developed using Skechup SDK in C++) that can display SKP file without texture.
But that file has texture, i can get texture detail with these functions

SUMaterialGetTexture(material, &texture);

if (SUIsValid(texture))//if there is texture
	SUStringRef     file_name = SU_INVALID;
	SUTextureGetFileName(texture, &file_name);

but i do not know how to get image data and associate image data with each vertex.

What do you exactly need?

For texture pixels, you should look at:

SUTextureGetDimensions(textureRef, &width, &height, &scaleU, &scaleV);

SUImageRepRef imageRep = SU_INVALID;
SUTextureGetImageRep(textureRef, &imageRep);
SUImageRepGetDataSize(imageRep, &pixelSize, &bpp);
SUImageRepGetRowPadding(imageRep, &rowPadding);
SUImageRepGetData(imageRep, pixelSize, (SUByte*)bitmap);

For STQ data for vertices:

SUMeshHelperRef polyMesh = SU_INVALID;
SUMeshHelperCreate(&polyMesh, faceRef);
SUMeshHelperGetNumVertices(polyMesh, &numberOfVertices);

std::vector<SUPoint3D> uvs(numberOfVertices);
std::vector<SUPoint3D> backUvs(numberOfVertices);

SUMeshHelperGetFrontSTQCoords(polyMesh, numberOfVertices, &uvs[0], &result);
SUMeshHelperGetBackSTQCoords(polyMesh, numberOfVertices, &backUvs[0], &result);

1 Like

FYI, if the .skp model file comes from someone else, then the path pointed to by the texture filepath may not exist on the computer running your application.