Skip to content

Commit

Permalink
Re-enable extrusion commands and fix a couple of issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Feb 21, 2025
1 parent 7ae512e commit edfd3d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
36 changes: 18 additions & 18 deletions Assets/Scripts/API/ApiMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,15 @@ public static void AddText(string text)
}

// TODO
// [ApiEndpoint(
// "text.extrude",
// "Sets a text object to be extruded by a given depth and color. Set depth to 0 to remove extrusion.",
// "-1,0.75,0.5,0.25,0")]
// public static void ExtrudeText(int index, float depth, Vector3 rgb)
// {
// var textWidget = _GetActiveTextWidget(index);
// textWidget.SetExtrusion(depth, new Color(rgb.x, rgb.y, rgb.z));
// }
[ApiEndpoint(
"text.extrude",
"Sets a text object to be extruded by a given depth and color. Set depth to 0 to remove extrusion.",
"-1,0.75,0.5,0.25,0")]
public static void ExtrudeText(int index, float depth, Vector3 rgb)
{
var textWidget = _GetActiveTextWidget(index);
textWidget.SetExtrusion(depth, new Color(rgb.x, rgb.y, rgb.z));
}

[ApiEndpoint(
"video.import",
Expand Down Expand Up @@ -610,15 +610,15 @@ public static ImageWidget ImportImage(string location)
}

// TODO - currently the polygon collider isn't using the imported SVG sprite
// [ApiEndpoint(
// "image.extrude",
// "Sets an SVG image to be extruded by a given depth and color. Set depth to 0 to remove extrusion.",
// "-1,0.75,0.5,0.25,0")]
// public static void ExtrudeImage(int index, float depth, Vector3 rgb)
// {
// var imageWidget = _GetActiveImage(index);
// imageWidget.SetExtrusion(depth, new Color(rgb.x, rgb.y, rgb.z));
// }
[ApiEndpoint(
"image.extrude",
"Sets an SVG image to be extruded by a given depth and color. Set depth to 0 to remove extrusion.",
"-1,0.75,0.5,0.25,0")]
public static void ExtrudeImage(int index, float depth, Vector3 rgb)
{
var imageWidget = _GetActiveImage(index);
imageWidget.SetExtrusion(depth, new Color(rgb.x, rgb.y, rgb.z));
}

[ApiEndpoint(
"environment.type",
Expand Down
10 changes: 8 additions & 2 deletions Assets/Scripts/Widgets/ImageWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,21 @@ public void SetExtrusion(float depth, Color color)
var imageMeshRenderer = m_Mesh.GetComponent<MeshRenderer>();
if (m_ReferenceImage.FilePath.EndsWith(".svg"))
{
// We handle SVG images differently for two reasons:
// 1. The Unity Vector Sprite doesn't seem to create
// a correct Polygon2DCollider mesh
// 2. Our fork of Unity Vector Graphics has native support for extruding SVG files
var extruderMeshFilter = extruder.GetComponent<MeshFilter>();
if (depth > 0)
{
imageMeshRenderer.enabled = false;
var scaleFix = new Vector3(0.002f, -0.002f, 0.5f);
var scaleFix = new Vector3(0.002f, -0.002f, 0.002f);
var positionFix = new Vector3(-0.5f, 0.5f, 0);
var tr = Matrix4x4.TRS(positionFix, Quaternion.identity, scaleFix);
var sceneInfo = importer.ImportAsSceneInfo(m_ReferenceImage.FilePath);
extruderMeshFilter.mesh = importer.SceneInfoToMesh(sceneInfo, tr, depth);
// The depth is multiplied by the inverse of the scaleFix.
// Modifying the y of the scale fix instead created precision issues
extruderMeshFilter.mesh = importer.SceneInfoToMesh(sceneInfo, tr, depth * 500);
}
else
{
Expand Down

0 comments on commit edfd3d0

Please # to comment.