------------------------------------------------------------------------------
| 1155 | |
| 1156 | //------------------------------------------------------------------------------ |
| 1157 | bool vtkGLTFDocumentLoader::BuildPolyDataFromPrimitive(Primitive& primitive) |
| 1158 | { |
| 1159 | // Positions |
| 1160 | primitive.Geometry = vtkSmartPointer<vtkPolyData>::New(); |
| 1161 | if (primitive.AttributeValues.count("POSITION")) |
| 1162 | { |
| 1163 | primitive.Geometry->SetPoints(vtkSmartPointer<vtkPoints>::New()); |
| 1164 | primitive.Geometry->GetPoints()->SetData(primitive.AttributeValues["POSITION"]); |
| 1165 | primitive.AttributeValues.erase("POSITION"); |
| 1166 | } |
| 1167 | |
| 1168 | // Connectivity |
| 1169 | if (primitive.Indices == nullptr) |
| 1170 | { |
| 1171 | if (primitive.Geometry->GetPoints() == nullptr) |
| 1172 | { |
| 1173 | vtkErrorMacro("Primitive points are not initialized"); |
| 1174 | return false; |
| 1175 | } |
| 1176 | GenerateIndicesForPrimitive(primitive); |
| 1177 | } |
| 1178 | switch (primitive.Mode) |
| 1179 | { |
| 1180 | case vtkGLTFDocumentLoaderInternals::GL_TRIANGLES: |
| 1181 | case vtkGLTFDocumentLoaderInternals::GL_TRIANGLE_FAN: |
| 1182 | primitive.Geometry->SetPolys(primitive.Indices); |
| 1183 | break; |
| 1184 | case vtkGLTFDocumentLoaderInternals::GL_LINES: |
| 1185 | case vtkGLTFDocumentLoaderInternals::GL_LINE_STRIP: |
| 1186 | case vtkGLTFDocumentLoaderInternals::GL_LINE_LOOP: |
| 1187 | primitive.Geometry->SetLines(primitive.Indices); |
| 1188 | break; |
| 1189 | case vtkGLTFDocumentLoaderInternals::GL_POINTS: |
| 1190 | primitive.Geometry->SetVerts(primitive.Indices); |
| 1191 | break; |
| 1192 | case vtkGLTFDocumentLoaderInternals::GL_TRIANGLE_STRIP: |
| 1193 | primitive.Geometry->SetStrips(primitive.Indices); |
| 1194 | break; |
| 1195 | default: |
| 1196 | vtkWarningMacro("Invalid primitive draw mode. Ignoring connectivity."); |
| 1197 | } |
| 1198 | |
| 1199 | // Other attributes |
| 1200 | |
| 1201 | // Set array names |
| 1202 | for (const auto& it : primitive.AttributeValues) |
| 1203 | { |
| 1204 | it.second->SetName(it.first.c_str()); |
| 1205 | } |
| 1206 | |
| 1207 | auto pointData = primitive.Geometry->GetPointData(); |
| 1208 | if (primitive.AttributeValues.count("NORMAL")) |
| 1209 | { |
| 1210 | pointData->SetNormals(primitive.AttributeValues["NORMAL"]); |
| 1211 | primitive.AttributeValues.erase("NORMAL"); |
| 1212 | } |
| 1213 | if (primitive.AttributeValues.count("TANGENT")) |
| 1214 | { |
no test coverage detected