USD: Add support for Text objects during export

Similar to the existing meta-ball export, and the other exporters,
convert Text objects to meshes for export.

Ref #138883

Pull Request: https://projects.blender.org/blender/blender/pulls/138903
This commit is contained in:
Jesse Yurkovich
2025-05-16 22:12:48 +02:00
committed by Jesse Yurkovich
parent de5d0cfdc5
commit 3b2bbad609
10 changed files with 134 additions and 9 deletions

View File

@@ -975,6 +975,66 @@ class USDExportTest(AbstractUSDTest):
weight_samples = anim.GetBlendShapeWeightsAttr().GetTimeSamples()
self.assertEqual(weight_samples, [1.0, 2.0, 3.0, 4.0, 5.0])
def test_export_text(self):
"""Test various forms of Text/Font export."""
bpy.ops.wm.open_mainfile(filepath=str(self.testdir / "usd_text_test.blend"))
export_path = str(self.tempdir / "usd_text_test.usda")
self.export_and_validate(filepath=export_path, export_animation=True, evaluation_mode="RENDER")
stats = UsdUtils.ComputeUsdStageStats(export_path)
stage = Usd.Stage.Open(export_path)
# There should be 4 meshes in the output
self.assertEqual(stats['primary']['primCountsByType']['Mesh'], 4)
bboxcache_frame1 = UsdGeom.BBoxCache(1.0, [UsdGeom.Tokens.default_])
bboxcache_frame5 = UsdGeom.BBoxCache(5.0, [UsdGeom.Tokens.default_])
# Static, flat, text
mesh = UsdGeom.Mesh(stage.GetPrimAtPath("/root/static/static"))
bounds1 = bboxcache_frame1.ComputeWorldBound(mesh.GetPrim())
bbox1 = bounds1.GetRange().GetMax() - bounds1.GetRange().GetMin()
self.assertEqual(mesh.GetPointsAttr().GetTimeSamples(), [])
self.assertEqual(mesh.GetExtentAttr().GetTimeSamples(), [])
self.assertTrue(bbox1[0] > 0.0)
self.assertTrue(bbox1[1] > 0.0)
self.assertAlmostEqual(bbox1[2], 0.0, 5)
# Dynamic, flat, text
mesh = UsdGeom.Mesh(stage.GetPrimAtPath("/root/dynamic/dynamic"))
bounds1 = bboxcache_frame1.ComputeWorldBound(mesh.GetPrim())
bounds5 = bboxcache_frame5.ComputeWorldBound(mesh.GetPrim())
bbox1 = bounds1.GetRange().GetMax() - bounds1.GetRange().GetMin()
bbox5 = bounds5.GetRange().GetMax() - bounds5.GetRange().GetMin()
self.assertEqual(mesh.GetPointsAttr().GetTimeSamples(), [1.0, 2.0, 3.0, 4.0, 5.0])
self.assertEqual(mesh.GetExtentAttr().GetTimeSamples(), [1.0, 2.0, 3.0, 4.0, 5.0])
self.assertEqual(bbox1[2], 0.0)
self.assertTrue(bbox1[0] < bbox5[0]) # Text grows on x-axis
self.assertAlmostEqual(bbox1[1], bbox5[1], 5)
self.assertAlmostEqual(bbox1[2], bbox5[2], 5)
# Static, extruded on Z, text
mesh = UsdGeom.Mesh(stage.GetPrimAtPath("/root/extruded/extruded"))
bounds1 = bboxcache_frame1.ComputeWorldBound(mesh.GetPrim())
bbox1 = bounds1.GetRange().GetMax() - bounds1.GetRange().GetMin()
self.assertEqual(mesh.GetPointsAttr().GetTimeSamples(), [])
self.assertEqual(mesh.GetExtentAttr().GetTimeSamples(), [])
self.assertTrue(bbox1[0] > 0.0)
self.assertTrue(bbox1[1] > 0.0)
self.assertAlmostEqual(bbox1[2], 0.1, 5)
# Static, uses depth, text
mesh = UsdGeom.Mesh(stage.GetPrimAtPath("/root/has_depth/has_depth"))
bounds1 = bboxcache_frame1.ComputeWorldBound(mesh.GetPrim())
bbox1 = bounds1.GetRange().GetMax() - bounds1.GetRange().GetMin()
self.assertEqual(mesh.GetPointsAttr().GetTimeSamples(), [])
self.assertEqual(mesh.GetExtentAttr().GetTimeSamples(), [])
self.assertTrue(bbox1[0] > 0.0)
self.assertTrue(bbox1[1] > 0.0)
self.assertAlmostEqual(bbox1[2], 0.1, 5)
def test_export_volumes(self):
"""Test various combinations of volume export including with all supported volume modifiers."""