Changeset View
Changeset View
Standalone View
Standalone View
source/blender/render/intern/source/bake_api.c
| Show First 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | static bool cast_ray_highpoly( | ||||
| for (i = 0; i < tot_highpoly; i++) { | for (i = 0; i < tot_highpoly; i++) { | ||||
| float co_high[3], dir_high[3]; | float co_high[3], dir_high[3]; | ||||
| hits[i].index = -1; | hits[i].index = -1; | ||||
| /* TODO: we should use FLT_MAX here, but sweepsphere code isn't prepared for that */ | /* TODO: we should use FLT_MAX here, but sweepsphere code isn't prepared for that */ | ||||
| hits[i].dist = 10000.0f; | hits[i].dist = 10000.0f; | ||||
| /* transform the ray from the world space to the highpoly space */ | /* transform the ray from the world space to the highpoly space */ | ||||
| mul_v3_m4v3(co_high, highpoly[i].imat_high, co); | mul_v3_m4v3(co_high, highpoly[i].imat, co); | ||||
| copy_v3_v3(dir_high, dir); | /* rotates */ | ||||
| mul_transposed_mat3_m4_v3(highpoly[i].mat_high, dir_high); | mul_v3_m4v3(dir_high, highpoly[i].rotmat, dir); | ||||
| normalize_v3(dir_high); | normalize_v3(dir_high); | ||||
| /* cast ray */ | /* cast ray */ | ||||
| BLI_bvhtree_ray_cast(treeData[i].tree, co_high, dir_high, 0.0f, &hits[i], treeData[i].raycast_callback, &treeData[i]); | BLI_bvhtree_ray_cast(treeData[i].tree, co_high, dir_high, 0.0f, &hits[i], treeData[i].raycast_callback, &treeData[i]); | ||||
| if (hits[i].index != -1) { | if (hits[i].index != -1) { | ||||
| /* cull backface */ | /* cull backface */ | ||||
| const float dot = dot_v3v3(dir_high, hits[i].no); | const float dot = dot_v3v3(dir_high, hits[i].no); | ||||
| if (dot < 0.0f) { | if (dot < 0.0f) { | ||||
| float distance = hits[i].dist * highpoly[i].scale; | float distance; | ||||
| float hit_world[3]; | |||||
| /* distance comparison in world space */ | |||||
| mul_v3_m4v3(hit_world, highpoly[i].obmat, hits[i].co); | |||||
| distance = len_squared_v3v3(hit_world, co); | |||||
campbellbarton: No need for fabsf(), length is always positive | |||||
| if (distance < hit_distance) { | if (distance < hit_distance) { | ||||
| hit_mesh = i; | hit_mesh = i; | ||||
| hit_distance = distance; | hit_distance = distance; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 624 Lines • Show Last 20 Lines | |||||
No need for fabsf(), length is always positive