I get the correct SUMaterialPositionInput, but the model is wrong.
I copy faces from src.skp
to dest.skp
.
src.skp (1.2 MB)
dest.skp (1.8 MB)
Critical code of c++
#define SU(api_function_call) {\
SUResult su_api_result = api_function_call;\
assert(SU_ERROR_NONE == su_api_result);\
}\
SUResult AddFaceMaterial(SUFaceRef face,bool front,SUMaterialRef material_front_set,
SUGeometryInputRef geom_input, size_t added_face_index, SUPoint3D pt) {
SUMaterialPositionInput mat_pos_input_front;
mat_pos_input_front.num_uv_coords = 4;
mat_pos_input_front.material = material_front_set;
// get points of mat_pos_input_front and uv_coords of mat_pos_input_front
res = SUFaceGetUVTileAt(face, &pt, true, &(mat_pos_input_front.points[0]), &(mat_pos_input_front.uv_coords[0]));
if (res == SU_ERROR_NONE) {
// debug output
printf("SUMaterialPositionInput Front %d\n", added_face_index);
for (int i = 0; i < mat_pos_input_front.num_uv_coords; i++) {
printf("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);
printf(" - UV: Point3d(%lf, %lf, 0)\n", mat_pos_input_front.uv_coords[i].x, mat_pos_input_front.uv_coords[i].y);
}
// set material
SU(SUGeometryInputFaceSetFrontMaterialByPosition(geom_input, added_face_index, &mat_pos_input_front));
}
}
Critical code of ruby
Sketchup.active_model.selection.grep(Sketchup::Face).each do |face|
puts "SUMaterialPositionInput Front"
reference = face.vertices.first.position
mapping = face.uv_tile_at(reference, true)
mapping.each_slice(2) { |position, uv|
puts "World: #{position.inspect} - UV: #{uv.inspect}"
}
end
get info from src.skp by ruby
SUMaterialPositionInput Front
World: Point3d(3.72908, 393.77, 0) - UV: Point3d(-8, 0, 0)
World: Point3d(2.22821, 344.581, 0) - UV: Point3d(-7, 0, 0)
World: Point3d(2.22821, 344.581, 0) - UV: Point3d(-7, 0, 0)
World: Point3d(3.72908, 393.77, 0) - UV: Point3d(-8, 0, 0)
debug output by c
SUMaterialPositionInput Front 0
World: Point3d(3.729075, 393.770225, 0.000000) - UV: Point3d(-8.000000, 0.000000, 0)
World: Point3d(2.228215, 344.580518, 0.000000) - UV: Point3d(-7.000000, 0.000000, 0)
World: Point3d(2.228215, 344.580518, 0.000000) - UV: Point3d(-7.000000, 0.000000, 0)
World: Point3d(3.729075, 393.770225, 0.000000) - UV: Point3d(-8.000000, 0.000000, 0)
get info from dest.skp by ruby
SUMaterialPositionInput Front
World: Point3d(2.5793, 356.087, 0) - UV: Point3d(-356, 0, 0)
World: Point3d(2.5488, 355.087, 0) - UV: Point3d(-355, 0, 0)
World: Point3d(2.5488, 355.087, 0) - UV: Point3d(-355, 0, 0)
World: Point3d(2.5793, 356.087, 0) - UV: Point3d(-356, 0, 0)