| 324 | } |
| 325 | |
| 326 | void makeGeometries(const PlanarSurface& planarSurface, std::vector<ThreeGeometry>& geometries, std::vector<ThreeUserData>& userDatas, |
| 327 | bool triangulateSurfaces, bool includeGeometryDiagnostics) { |
| 328 | std::string name = planarSurface.nameString(); |
| 329 | boost::optional<Surface> surface = planarSurface.optionalCast<Surface>(); |
| 330 | boost::optional<PlanarSurfaceGroup> planarSurfaceGroup = planarSurface.planarSurfaceGroup(); |
| 331 | |
| 332 | // get the transformation to site coordinates |
| 333 | Transformation buildingTransformation; |
| 334 | if (planarSurfaceGroup) { |
| 335 | buildingTransformation = planarSurfaceGroup->buildingTransformation(); |
| 336 | } |
| 337 | |
| 338 | // get the vertices |
| 339 | Point3dVector vertices = planarSurface.vertices(); |
| 340 | Transformation t = Transformation::alignFace(vertices); |
| 341 | //Transformation r = t.rotationMatrix(); |
| 342 | Transformation tInv = t.inverse(); |
| 343 | Point3dVector faceVertices = reverse(tInv * vertices); |
| 344 | |
| 345 | // get vertices of all sub surfaces |
| 346 | Point3dVectorVector faceSubVertices; |
| 347 | if (surface) { |
| 348 | for (const auto& subSurface : surface->subSurfaces()) { |
| 349 | faceSubVertices.push_back(reverse(tInv * subSurface.vertices())); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | Point3dVectorVector finalFaceVertices; |
| 354 | if (triangulateSurfaces) { |
| 355 | finalFaceVertices = computeTriangulation(faceVertices, faceSubVertices); |
| 356 | if (finalFaceVertices.empty()) { |
| 357 | LOG_FREE(Error, "modelToThreeJS", "Failed to triangulate surface " << name << " with " << faceSubVertices.size() << " sub surfaces"); |
| 358 | return; |
| 359 | } |
| 360 | } else { |
| 361 | finalFaceVertices.push_back(faceVertices); |
| 362 | } |
| 363 | |
| 364 | Point3dVector allVertices; |
| 365 | std::vector<size_t> faceIndices; |
| 366 | for (const auto& finalFaceVerts : finalFaceVertices) { |
| 367 | Point3dVector finalVerts = buildingTransformation * t * finalFaceVerts; |
| 368 | //normal = buildingTransformation.rotationMatrix*r*z |
| 369 | |
| 370 | // https://github.com/mrdoob/three.js/wiki/JSON-Model-format-3 |
| 371 | // 0 indicates triangle |
| 372 | // 1 indicates quad |
| 373 | // 2 indicates triangle with material |
| 374 | // 3 indicates quad with material |
| 375 | // .... |
| 376 | // 255 quad with everything |
| 377 | // 1024 - OpenStudio format, all vertices belong to single face |
| 378 | |
| 379 | if (triangulateSurfaces) { |
| 380 | faceIndices.push_back(0); |
| 381 | } else { |
| 382 | faceIndices.push_back(openstudioFaceFormatId()); |
| 383 | } |
no test coverage detected