| 302 | } |
| 303 | |
| 304 | std::shared_ptr<Visual> MeshFactory::CreateBox(float xExtent, float yExtent, float zExtent) |
| 305 | { |
| 306 | // Quantities derived from inputs. |
| 307 | int32_t numVertices = 8; |
| 308 | int32_t numTriangles = 12; |
| 309 | |
| 310 | // Generate geometry. |
| 311 | auto vbuffer = CreateVBuffer(numVertices); |
| 312 | if (!vbuffer) |
| 313 | { |
| 314 | return nullptr; |
| 315 | } |
| 316 | |
| 317 | Vector3<float> pos{}, nor{}; |
| 318 | std::array<Vector3<float>, 3> basis{}; |
| 319 | Vector2<float> tcd{}; |
| 320 | |
| 321 | // Choose vertex normals in the diagonal directions. |
| 322 | Vector3<float> diag{ xExtent, yExtent, zExtent }; |
| 323 | Normalize(diag); |
| 324 | if (!mOutside) |
| 325 | { |
| 326 | diag = -diag; |
| 327 | } |
| 328 | |
| 329 | for (uint32_t z = 0, v = 0; z < 2; ++z) |
| 330 | { |
| 331 | float fz = static_cast<float>(z), omfz = 1.0f - fz; |
| 332 | float zSign = 2.0f * fz - 1.0f; |
| 333 | pos[2] = zSign * zExtent; |
| 334 | nor[2] = zSign * diag[2]; |
| 335 | for (uint32_t y = 0; y < 2; ++y) |
| 336 | { |
| 337 | float fy = static_cast<float>(y); |
| 338 | float ySign = 2.0f * fy - 1.0f; |
| 339 | pos[1] = ySign * yExtent; |
| 340 | nor[1] = ySign * diag[1]; |
| 341 | tcd[1] = (1.0f - fy) * omfz + (0.75f - 0.5f * fy) * fz; |
| 342 | for (uint32_t x = 0; x < 2; ++x, ++v) |
| 343 | { |
| 344 | float fx = static_cast<float>(x); |
| 345 | float xSign = 2.0f * fx - 1.0f; |
| 346 | pos[0] = xSign * xExtent; |
| 347 | nor[0] = xSign * diag[0]; |
| 348 | tcd[0] = fx * omfz + (0.25f + 0.5f * fx) * fz; |
| 349 | |
| 350 | basis[0] = nor; |
| 351 | ComputeOrthogonalComplement(1, basis.data()); |
| 352 | |
| 353 | SetPosition(v, pos); |
| 354 | SetNormal(v, nor); |
| 355 | SetTangent(v, basis[1]); |
| 356 | SetBitangent(v, basis[2]); |
| 357 | SetTCoord(v, tcd); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 |
nothing calls this directly
no test coverage detected