void WaveFrontExporter::exportBrush(IBrush& brush) { _output << "\ng " << "Brush" << _exportedBrushes << "\n"; std::string vertexBuf; std::string texCoordBuf; std::string faceBuf; for (std::size_t faceIdx = 0; faceIdx < brush.getNumFaces(); ++faceIdx) { IFace& face = brush.getFace(faceIdx); // Remember the index of the first vertex std::size_t firstVertex = _vertexCount; const IWinding& winding = face.getWinding(); for (std::size_t i = 0; i < winding.size(); ++i) { // Write coordinates into the export buffers vertexBuf += "v " + std::string(winding[i].vertex) + "\n"; texCoordBuf += "vt " + std::string(winding[i].texcoord) + "\n"; // Count the exported vertices ++_vertexCount; } // Construct the face section faceBuf += "\nf"; for (std::size_t i = firstVertex; i < _vertexCount; ++i) { faceBuf += " " + sizetToStr(i+1) + "/" + sizetToStr(i+1); } } _output << vertexBuf << "\n"; _output << texCoordBuf; _output << faceBuf << "\n"; ++_exportedBrushes; }
void ModelExporter::processBrush(const scene::INodePtr& node) { IBrush* brush = Node_getIBrush(node); if (brush == nullptr) return; Matrix4 exportTransform = node->localToWorld().getPremultipliedBy(_centerTransform); for (std::size_t b = 0; b < brush->getNumFaces(); ++b) { const IFace& face = brush->getFace(b); const std::string& materialName = face.getShader(); if (!isExportableMaterial(materialName)) continue; const IWinding& winding = face.getWinding(); std::vector<model::ModelPolygon> polys; if (winding.size() < 3) { rWarning() << "Skipping face with less than 3 winding verts" << std::endl; continue; } // Create triangles for this winding for (std::size_t i = 1; i < winding.size() - 1; ++i) { model::ModelPolygon poly; poly.a = convertWindingVertex(winding[i + 1]); poly.b = convertWindingVertex(winding[i]); poly.c = convertWindingVertex(winding[0]); polys.push_back(poly); } _exporter->addPolygons(materialName, polys, exportTransform); } }