I got different UVTile
with ruby and C.
There is only one face in the model.
ruby code
Sketchup.active_model.active_entities.grep(Sketchup::Face).each do |face|
puts "===========reference #{ORIGIN}============="
reference = ORIGIN
mapping = face.uv_tile_at(reference, true)
mapping.each_slice(2) { |position, uv|
puts "World: #{position.inspect} - UV: #{uv.inspect}"
}
end
ruby output
===========reference (0 mm, 0 mm, 0 mm)=============
World: Point3d(0, 0, 0) - UV: Point3d(0, 0, 0)
World: Point3d(196.85, 0, 0) - UV: Point3d(1, 0, 0)
World: Point3d(196.85, 196.85, 0) - UV: Point3d(1, 1, 0)
World: Point3d(0, 196.85, 0) - UV: Point3d(0, 1, 0)
C code
#include<SketchUpAPI\sketchup.h>
#include<stdio.h>
#include<vector>
#include<assert.h>
#include<algorithm>
#define SU(api_function_call) {\
SUResult su_api_result = api_function_call;\
assert(SU_ERROR_NONE == su_api_result);\
}\
void debug(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args, fmt);
}
int main() {
SUInitialize();
SUModelRef src_model = SU_INVALID;
SUModelLoadStatus loadStatus;
// get the model from test_src.skp => src_model
SU(SUModelCreateFromFileWithStatus(&src_model, "F:\\Desktop\\test.skp", &loadStatus));
SUEntitiesRef src_entities = SU_INVALID;
// get the entities of the src_model
SU(SUModelGetEntities(src_model, &src_entities));
// get number of faces
size_t face_num = 0;
SU(SUEntitiesGetNumFaces(src_entities, &face_num));
// get faces
std::vector<SUFaceRef> faces(face_num);
SU(SUEntitiesGetFaces(src_entities, face_num,&(faces[0]), &face_num));
// There is only one face in the model
SUMaterialPositionInput mat_pos_input_front;
mat_pos_input_front.num_uv_coords = 4;
SUPoint3D pt;
pt.x = pt.y = pt.z = 0;
SU(SUFaceGetUVTileAt(faces[0], &pt, true, &(mat_pos_input_front.points[0]), &(mat_pos_input_front.uv_coords[0])));
debug("===========reference (0 mm, 0 mm, 0 mm)=============\n");
for (int i = 0; i < mat_pos_input_front.num_uv_coords; i++) {
debug("World: Point3d(%lf, %lf, %lf)", mat_pos_input_front.points[i].x, mat_pos_input_front.points[i].y, mat_pos_input_front.points[i].z);
debug(" - UV: Point3d(%lf, %lf, 0)\n", mat_pos_input_front.uv_coords[i].x, mat_pos_input_front.uv_coords[i].y);
}
SU(SUModelRelease(&src_model));
SUTerminate();
return 0;
}
C output
===========reference(0 mm, 0 mm, 0 mm)=============
World: Point3d(0.000000, 0.000000, 0.000000) - UV : Point3d(0.000000, 0.000000, 0)
World : Point3d(0.000000, 0.000000, 0.000000) - UV : Point3d(0.000000, 0.000000, 0)
World : Point3d(0.000000, 0.000000, 0.000000) - UV : Point3d(0.000000, 0.000000, 0)
World : Point3d(0.000000, 0.000000, 0.000000) - UV : Point3d(0.000000, 0.000000, 0)
test.skp (522.9 KB)