Friday
- last edited
Friday
by
Laszlo Nagy
Monday
void DuplicateTexture()
{
ModelerAPI::Model model;
auto err = ACAPI_Sight_GetSelectedSightModel(model);
if (err != NoError)
return;
GS::Int32 texture_count = model.GetTextureCount();
for (GS::Int32 i = 0; i < texture_count; i++)
{
if (!model.IsTextureUsed(ModelerAPI::AttributeIndex(ModelerAPI::AttributeIndex::TextureIndex, i)))
continue;
ModelerAPI::Texture texture;
model.GetTexture(ModelerAPI::AttributeIndex(ModelerAPI::AttributeIndex::TextureIndex, i), &texture);
//
if (texture.GetPixelType() != ModelerAPI::Texture::ARGBPixelType)
continue;
//
Int32 pixel_x_size = texture.GetPixelMapXSize();
Int32 pixel_y_size = texture.GetPixelMapYSize();
Int32 pixel_size = texture.GetPixelMapSize();
//
ModelerAPI::Texture::ARGBPixel* pixel = new ModelerAPI::Texture::ARGBPixel[pixel_size];
texture.GetPixelMap(pixel);
//save bitmap
{
IO::Location fileLocation;
IO::fileSystem.GetSpecialLocation(IO::FileSystem::TemporaryFolder, &fileLocation);
fileLocation.AppendToLocal(IO::Name(texture.GetName()+".jpg"));
//
std::string filePath;
GS::UniString filePath_uni;
fileLocation.ToPath(&filePath_uni);
filePath = filePath_uni.ToCStr();
//
int ow = pixel_x_size;
int oh = pixel_y_size;
int n = 4;
unsigned char* odata = (unsigned char*)malloc(ow * oh * n);
for (size_t w = 0; w < pixel_x_size; w++)
{
for (size_t h = 0; h < pixel_y_size; h++)
{
odata[(w * pixel_x_size + h) * n] = pixel[w * pixel_x_size + h].red;
odata[(w * pixel_x_size + h) * n+1] = pixel[w * pixel_x_size + h].green;
odata[(w * pixel_x_size + h) * n+2] = pixel[w * pixel_x_size + h].blue;
odata[(w * pixel_x_size + h) * n+3] = pixel[w * pixel_x_size + h].alpha;
}
}
// write jpg
stbi_write_jpg(filePath.c_str(), ow, oh, n, odata, 100);
stbi_image_free(odata);
}
delete[] pixel;
}
}
Friday
- last edited
Friday
by
Laszlo Nagy
API_Component3D mat = {};
mat.header.typeID = API_UmatID;
mat.header.index = iumat;
auto err = ACAPI_ModelAccess_GetComponent(&mat);
if(err != NoError)
return;
delete mat.umat.mater.texture.fileLoc;//this is texture location in embedded library
mat.umat.mater.texture.fileLoc = nullptr;
Hello,I already know the path of the texture in embedded library. Is there a way to directly copy it from the library?
I found your answer in another post, but that method is not suitable for me.
https://community.graphisoft.com/t5/Archicad-C-API/How-to-get-the-path-of-texture/m-p/261656#M2314
Monday
void DuplicateTexture()
{
ModelerAPI::Model model;
auto err = ACAPI_Sight_GetSelectedSightModel(model);
if (err != NoError)
return;
GS::Int32 texture_count = model.GetTextureCount();
for (GS::Int32 i = 0; i < texture_count; i++)
{
if (!model.IsTextureUsed(ModelerAPI::AttributeIndex(ModelerAPI::AttributeIndex::TextureIndex, i)))
continue;
ModelerAPI::Texture texture;
model.GetTexture(ModelerAPI::AttributeIndex(ModelerAPI::AttributeIndex::TextureIndex, i), &texture);
//
if (texture.GetPixelType() != ModelerAPI::Texture::ARGBPixelType)
continue;
//
Int32 pixel_x_size = texture.GetPixelMapXSize();
Int32 pixel_y_size = texture.GetPixelMapYSize();
Int32 pixel_size = texture.GetPixelMapSize();
//
ModelerAPI::Texture::ARGBPixel* pixel = new ModelerAPI::Texture::ARGBPixel[pixel_size];
texture.GetPixelMap(pixel);
//save bitmap
{
IO::Location fileLocation;
IO::fileSystem.GetSpecialLocation(IO::FileSystem::TemporaryFolder, &fileLocation);
fileLocation.AppendToLocal(IO::Name(texture.GetName()+".jpg"));
//
std::string filePath;
GS::UniString filePath_uni;
fileLocation.ToPath(&filePath_uni);
filePath = filePath_uni.ToCStr();
//
int ow = pixel_x_size;
int oh = pixel_y_size;
int n = 4;
unsigned char* odata = (unsigned char*)malloc(ow * oh * n);
for (size_t w = 0; w < pixel_x_size; w++)
{
for (size_t h = 0; h < pixel_y_size; h++)
{
odata[(w * pixel_x_size + h) * n] = pixel[w * pixel_x_size + h].red;
odata[(w * pixel_x_size + h) * n+1] = pixel[w * pixel_x_size + h].green;
odata[(w * pixel_x_size + h) * n+2] = pixel[w * pixel_x_size + h].blue;
odata[(w * pixel_x_size + h) * n+3] = pixel[w * pixel_x_size + h].alpha;
}
}
// write jpg
stbi_write_jpg(filePath.c_str(), ow, oh, n, odata, 100);
stbi_image_free(odata);
}
delete[] pixel;
}
}