MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteTextureBufferAndView

Function WriteTextureBufferAndView

IO/Geometry/vtkGLTFWriter.cxx:228–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228std::string WriteTextureBufferAndView(const std::string& gltfFullDir,
229 const std::string& textureFullPath, bool inlineData, bool copyTextures, nlohmann::json& buffers,
230 nlohmann::json& bufferViews)
231{
232 std::string gltfRelativeTexturePath =
233 vtksys::SystemTools::RelativePath(gltfFullDir, textureFullPath);
234 // if inline then base64 encode the data. In this case we need to read the texture
235 std::string result;
236 std::string mimeType;
237 unsigned int byteLength = 0;
238 if (inlineData)
239 {
240 vtkSmartPointer<vtkTexture> t;
241 vtkSmartPointer<vtkImageData> id;
242
243 auto textureReader = SetupTextureReader(textureFullPath);
244 vtkNew<vtkTexture> texture;
245 texture->SetInputConnection(textureReader->GetOutputPort());
246 texture->Update();
247 t = texture;
248 id = t->GetInput();
249
250 vtkUnsignedCharArray* da = nullptr;
251 if (id && id->GetPointData()->GetScalars())
252 {
253 da = vtkUnsignedCharArray::SafeDownCast(id->GetPointData()->GetScalars());
254 }
255 if (!da)
256 {
257 return mimeType; /*empty mimeType signals error*/
258 }
259
260 vtkNew<vtkTrivialProducer> triv;
261 triv->SetOutput(id);
262 // no need to flip Y the texture as we flip the texture coordinates
263
264 // convert to png
265 vtkNew<vtkPNGWriter> png;
266 png->SetCompressionLevel(5);
267 png->SetInputConnection(triv->GetOutputPort());
268 png->WriteToMemoryOn();
269 png->Write();
270 da = png->GetResult();
271
272 mimeType = "image/png";
273
274 result = "data:application/octet-stream;base64,";
275 std::ostringstream toString;
276 vtkNew<vtkBase64OutputStream> ostr;
277 ostr->SetStream(&toString);
278 ostr->StartWriting();
279 vtkGLTFWriterUtils::WriteValues(da, ostr);
280 ostr->EndWriting();
281 result += toString.str();
282 unsigned int count = da->GetNumberOfTuples() * da->GetNumberOfComponents();
283 byteLength = da->GetElementComponentSize() * count;
284 }
285 else

Callers 1

WriteTextureFunction · 0.85

Calls 15

SplitStringFunction · 0.85
GetMimeTypeFunction · 0.85
CopyStreamFunction · 0.85
SetupTextureReaderFunction · 0.70
SetInputConnectionMethod · 0.45
GetOutputPortMethod · 0.45
UpdateMethod · 0.45
GetInputMethod · 0.45
GetScalarsMethod · 0.45
GetPointDataMethod · 0.45
SetOutputMethod · 0.45

Tested by

no test coverage detected