| 3187 | } |
| 3188 | |
| 3189 | void RiggedObject::MPCutPlane(const vec3& normal, const vec3& pos, const vec3& dir, int type, int depth, std::vector<int> mp_hit_list, vec3 mp_points[3]) { |
| 3190 | if (Graphics::Instance()->config_.blood() == BloodLevel::kNone) { |
| 3191 | return; |
| 3192 | } |
| 3193 | |
| 3194 | Model* model = &Models::Instance()->GetModel(model_id[0]); |
| 3195 | vec3 points[3]; |
| 3196 | |
| 3197 | for (int i = 0; i < 3; i++) |
| 3198 | points[i] = mp_points[i]; |
| 3199 | |
| 3200 | int num_pos_side = 0; |
| 3201 | int num_neg_side = 0; |
| 3202 | int num_hit = 0; |
| 3203 | std::vector<int> hit_list; |
| 3204 | |
| 3205 | hit_list = mp_hit_list; |
| 3206 | num_hit = mp_hit_list.size(); |
| 3207 | |
| 3208 | if (num_hit < 10 && depth < 4) { |
| 3209 | if (num_neg_side > num_pos_side) { |
| 3210 | MPCutPlane(normal, pos - normal * 0.1f, dir, type, depth + 1, mp_hit_list, mp_points); |
| 3211 | } else { |
| 3212 | MPCutPlane(normal, pos + normal * 0.1f, dir, type, depth + 1, mp_hit_list, mp_points); |
| 3213 | } |
| 3214 | } else { |
| 3215 | // blood_surface.AddBloodToTriangles(hit_list); |
| 3216 | for (int i : hit_list) { |
| 3217 | GetTransformedTri(i, mp_points); |
| 3218 | if (dot(cross(mp_points[1] - mp_points[0], mp_points[2] - mp_points[0]), dir) > 0.0f) { |
| 3219 | continue; |
| 3220 | } |
| 3221 | float time[3]; |
| 3222 | for (unsigned j = 0; j < 3; ++j) { |
| 3223 | const vec3 d = mp_points[(j + 1) % 3] - mp_points[j]; |
| 3224 | const vec3 o = mp_points[j] - pos; |
| 3225 | const vec3& n = normal; |
| 3226 | time[j] = (-o[0] * n[0] - o[1] * n[1] - o[2] * n[2]) / |
| 3227 | (d[0] * n[0] + d[1] * n[1] + d[2] * n[2]); |
| 3228 | } |
| 3229 | vec2 tex_points[3]; |
| 3230 | for (unsigned j = 0; j < 3; ++j) { |
| 3231 | tex_points[j][0] = model->tex_coords[model->faces[i * 3 + j] * 2 + 0]; |
| 3232 | tex_points[j][1] = model->tex_coords[model->faces[i * 3 + j] * 2 + 1]; |
| 3233 | } |
| 3234 | vec2 tex_intersect_points[2]; |
| 3235 | vec3 intersect_points[2]; |
| 3236 | int which_point = 0; |
| 3237 | for (unsigned j = 0; j < 3; ++j) { |
| 3238 | if (time[j] >= 0.0f && time[j] <= 1.0f) { |
| 3239 | tex_intersect_points[which_point] = |
| 3240 | mix(tex_points[j], tex_points[(j + 1) % 3], time[j]); |
| 3241 | intersect_points[which_point] = |
| 3242 | mix(points[j], mp_points[(j + 1) % 3], time[j]); |
| 3243 | ++which_point; |
| 3244 | if (which_point > 1) { |
| 3245 | break; |
| 3246 | } |
no test coverage detected