------------------------------------------------------------------------------------------------
| 212 | |
| 213 | // ------------------------------------------------------------------------------------------------ |
| 214 | void ComputeUVMappingProcess::ComputeCylinderMapping(aiMesh *mesh, const aiVector3D &axis, aiVector3D *out) { |
| 215 | aiVector3D center, min, max; |
| 216 | |
| 217 | // If the axis is one of x,y,z run a faster code path. It's worth the extra effort ... |
| 218 | // currently the mapping axis will always be one of x,y,z, except if the |
| 219 | // PretransformVertices step is used (it transforms the meshes into worldspace, |
| 220 | // thus changing the mapping axis) |
| 221 | if (axis * base_axis_x >= angle_epsilon) { |
| 222 | FindMeshCenter(mesh, center, min, max); |
| 223 | const ai_real diff = max.x - min.x; |
| 224 | |
| 225 | // If the main axis is 'z', the z coordinate of a point 'p' is mapped |
| 226 | // directly to the texture V axis. The other axis is derived from |
| 227 | // the angle between ( p.x - c.x, p.y - c.y ) and (1,0), where |
| 228 | // 'c' is the center point of the mesh. |
| 229 | for (unsigned int pnt = 0; pnt < mesh->mNumVertices; ++pnt) { |
| 230 | const aiVector3D &pos = mesh->mVertices[pnt]; |
| 231 | aiVector3D &uv = out[pnt]; |
| 232 | |
| 233 | uv.y = (pos.x - min.x) / diff; |
| 234 | uv.x = (std::atan2(pos.z - center.z, pos.y - center.y) + (ai_real)AI_MATH_PI) / (ai_real)AI_MATH_TWO_PI; |
| 235 | } |
| 236 | } else if (axis * base_axis_y >= angle_epsilon) { |
| 237 | FindMeshCenter(mesh, center, min, max); |
| 238 | const ai_real diff = max.y - min.y; |
| 239 | |
| 240 | // just the same ... |
| 241 | for (unsigned int pnt = 0; pnt < mesh->mNumVertices; ++pnt) { |
| 242 | const aiVector3D &pos = mesh->mVertices[pnt]; |
| 243 | aiVector3D &uv = out[pnt]; |
| 244 | |
| 245 | uv.y = (pos.y - min.y) / diff; |
| 246 | uv.x = (std::atan2(pos.x - center.x, pos.z - center.z) + (ai_real)AI_MATH_PI) / (ai_real)AI_MATH_TWO_PI; |
| 247 | } |
| 248 | } else if (axis * base_axis_z >= angle_epsilon) { |
| 249 | FindMeshCenter(mesh, center, min, max); |
| 250 | const ai_real diff = max.z - min.z; |
| 251 | |
| 252 | // just the same ... |
| 253 | for (unsigned int pnt = 0; pnt < mesh->mNumVertices; ++pnt) { |
| 254 | const aiVector3D &pos = mesh->mVertices[pnt]; |
| 255 | aiVector3D &uv = out[pnt]; |
| 256 | |
| 257 | uv.y = (pos.z - min.z) / diff; |
| 258 | uv.x = (std::atan2(pos.y - center.y, pos.x - center.x) + (ai_real)AI_MATH_PI) / (ai_real)AI_MATH_TWO_PI; |
| 259 | } |
| 260 | } |
| 261 | // slower code path in case the mapping axis is not one of the coordinate system axes |
| 262 | else { |
| 263 | aiMatrix4x4 mTrafo; |
| 264 | aiMatrix4x4::FromToMatrix(axis, base_axis_y, mTrafo); |
| 265 | FindMeshCenterTransformed(mesh, center, min, max, mTrafo); |
| 266 | const ai_real diff = max.y - min.y; |
| 267 | |
| 268 | // again the same, except we're applying a transformation now |
| 269 | for (unsigned int pnt = 0; pnt < mesh->mNumVertices; ++pnt) { |
| 270 | const aiVector3D pos = mTrafo * mesh->mVertices[pnt]; |
| 271 | aiVector3D &uv = out[pnt]; |
nothing calls this directly
no test coverage detected