How can I export a GLB / GLTF file format with PyDPF?
You will need to install any Python lib. to convert GLTF to GLB format because PyVista only exports GLTF. An example would be pip installing pygltflib
pygltflib
import os from ansys.dpf import core as dpf from ansys.dpf.core.plotter import DpfPlotter from pygltflib.utils import gltf2glb out_path = r"\FOLDER\PATH\TO\RESULT\FILE" rst_path = os.path.join(out_path, "file.rst") model = dpf.Model(rst_path) mesh = model.metadata.meshed_region print(mesh) displacement = model.results.displacement() disp_f = displacement.outputs.fields_container()[0] plotter = DpfPlotter() plotter.add_field(disp_f) gltf_path = os.path.join(out_path, r"test_export.gltf") gltf = plotter._internal_plotter._plotter.export_gltf(gltf_path) glb_path = os.path.join(out_path, r"test_export.glb") """Convert GLTF to GLB File""" gltf2glb(gltf_path, glb_path) """ Export just legend as an image with white Background Can be used as a background in a 3D viewer where the GLB is imported. """ plotter = DpfPlotter() plotter.add_field(disp_f, opacity=0.0) path_to_legend = os.path.join(out_path, "legend.png") plotter.show_figure(screenshot=path_to_legend)
There is a custom operator created as an example for this
https://dpf.docs.pyansys.com/version/stable/examples/08-python-operators/02-python_operators_with_dependencies.html
once loaded the usage is straightforward
new_operator = dpf.Operator("gltf_export") import os model = dpf.Model(dpf.upload_file_in_tmp_folder(examples.find_static_rst())) mesh = model.metadata.meshed_region skin_mesh = dpf.operators.mesh.tri_mesh_skin(mesh=mesh) displacement = model.results.displacement() displacement.inputs.mesh_scoping(skin_mesh) displacement.inputs.mesh(skin_mesh) new_operator.inputs.path(os.path.join(tmp, "out")) new_operator.inputs.mesh(skin_mesh) new_operator.inputs.field(displacement.outputs.fields_container()[0]) new_operator.run() print("operator ran successfully") dpf.download_file(os.path.join(tmp, "out.glb"), os.path.join(os.getcwd(), "out.glb"))
Just wanted to point out that the DPF's gltf_export also uses pygltflib behind the scenes.
gltf_export
Note: If the results field contains COMBIN14 and PRETS179, the exported GLB doesn't show any contour.