Setting Materials' Texture scale


#1

I am working on a script that needs to copy materials from one SU model to another empty one. I am currently having trouble getting textures that are copied to have the same scale as the original. The copied texture’s dimensions are tiny compared to the original.

I have found the function SUTextureGetDimensions (SUTextureRef texture, size_t *width, size_t *height, double *s_scale, double *t_scale) which allows me to get the scale (I think) of material, but I have no way of setting it for a material (No SUTextureGetDimensions() );

Note that I am not trying to apply this texture to a face - I just want to make sure the default scale of the material is like the original.

Any ideas?


#2

This doesn’t make sense. I think you meant (with corrections in emboldened italics) ?

I have found the function SUTextureGetDimensions (SUTextureRef texture, size_t *width, size_t *height, double *s_scale, double *t_scale) which allows me to get the scale (I think) of a texture, but I have no way of setting it for a texture (No SUTextureSetDimensions() );

I myself, also see that there is no SUTextureSetDimensions() function.

Seems like a C API request needs to be filed.
Did this …


It looks like your only current workaround will be the temporary file route.

  1. Get the “old” texture’s metrics for later use (as you’ve been doing.)
  2. Write the “old” texture to a temporary file: SUTextureWriteToFile().
  3. Create the “new” texture via load from: SUTextureCreateFromFile(),
    using the scale factors saved from the “old” texture object.
  4. Immediately associate the “new” texture with a “new” Material.
  5. Repeat … When done, cleanup the temporary image files.


#3

Thanks, Dan. Glad to hear I wasn’t missing something.

That workaround sounds eminently workable! Will get on it.

EDIT:
For the benefit others having to use this workaround, this is the code I used in Sketchup-Cpp-Wrapper project:

Texture Texture::copy() const {
  // First create the file.
  std::string file_path = "/tmp/tmptexture";
  SUResult res = this->save(file_path);
  assert(res == SU_ERROR_NONE);
  Texture new_texture(file_path, s_scale(), t_scale());
  // Delete the temporary file
  const char *file_path_c = file_path.c_str();
  int ret = std::remove(file_path_c);
  assert(ret == 0);
  // Reset the file name
  new_texture.file_name(this->file_name());
  return new_texture;
}

#4

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.