DEV Community

orca forge
orca forge

Posted on Originally published at forge.workstyle.tech

How to Edit the Same Face in Blender Without Vertex IDs

📝 Originally published (in Japanese) at forge.workstyle.tech.

TL;DR Blender and browser edits can differ even when the edit center and displacement match. The face differed by 0.83 mm near the center. glTF splits vertices on export, so vertex indices do not match between the browser and Blender.

Conclusion First

The reason the edited face looks different in the browser and Blender is that exporting to glTF splits vertices, so their indices no longer match. Edit based on vertex positions instead of indices, and calculate symmetric weights from the same positions before editing. This produces the same shape in both.

How Blender and glTF Coordinates Correspond

To point to the same place on the same face, align the coordinate directions on the browser and Blender sides. A glTF coordinate (x,y,z) maps to (−x,z,y) in Blender. Conversely, a Blender coordinate (x,y,z) maps to (−x,z,y) in glTF.

When exporting VRM0 (VRM format 0), rotate 180° around the Y axis. To mirror left and right, flip only x: x → −x.

By specification, the face points in the −z direction. The nose tip is approximately at (0, 1.546, −0.066). When reading the position of the target to edit, assume this orientation and coordinate conversion.

In the first version, the coordinate conversion was once written as (x,−z,y). The specification at 16:52 on October 4 used that notation, but it was corrected to (−x,z,y) at 16:58. If the conversion formula is wrong, the entire assumption that edits are based on position breaks down. It is important to write the conversion formula clearly in one place from the start.

How to determine the edit amount from vertex positions

We determine the edit amount from each vertex’s position, not its index. An edit is defined by {c, d, r, sym}: c is the center of the edit, d is the displacement, r is the radius of influence, and sym indicates whether to apply the edit to the mirrored side as well.

Given a vertex position p, calculate a weight based on its distance from the center. This weight adjusts the amount of displacement:

t = clamp(1-|p-c|/r, 0, 1)
w = t*t*(3-2t)
p += w*d
Enter fullscreen mode Exit fullscreen mode

At the center c, t is large; outside the radius r, it becomes 0. The weight w determines how much to move the vertex based on its position. The key is to edit according to the relationship between position p and center c, without specifying vertex indices.

Why Did Symmetric Editing Drift by 0.83 mm?

When editing symmetrically, we also apply a mirrored edit if the center’s x-coordinate, c.x, satisfies |c.x| > 0.002. We calculate the mirrored center and movement by flipping the sign of x.

The drift happened because we calculated the mirrored edit’s weight using the vertex position after applying the original edit. With the old approach of applying the edits sequentially, the two sides drifted by 0.83 mm near the center.

In v6, we changed the approach: we calculate the weights for both the original and mirrored edits at the same position, then add them together. We use the position before either edit as the reference for both weights. For symmetric editing, the result of editing one side should not feed into the calculation for the other side.

How Does Expression Editing Error Differ From Whole-VRM Differences?

A match in expression editing alone and a comparison between VRMs produced through the full pipeline are separate results. In an early Blender version, the error in the facial expression editing was 1e-9 to 6e-8. The tolerance was 1e-5. The new method in v6 had an error of 5.8e-8. Later, the October 5 v8 curve had a maximum error of 5.9e-8 across 606 vertices; v9 had 6e-8, and v12 Bézier had 5.9e-8. The October 7 baked match had an error of 6.0e-8 across 1,350 vertices.

The 6e-8 m value here refers to the match in facial expression editing. Do not conflate it with the whole-VRM comparison value.

In the October 13 end-to-end check, we compared a VRM produced through the Blender pipeline with one exported as VRM0 from the browser-based studio. The difference in facial position and Fcl_EYE_Close was 1.2e-7. Joy had identical binds at 30/70, and the validator reported zero errors.

This is a separate comparison from expression-editing error alone. We record expression validation results and full-pipeline VRM comparison results as distinct categories.

Why I Made Browser-Side Export Official

In the end, I made browser-side export the official option. The user’s decision was: “Blender baking isn’t necessary.”

To create the same shape in both places, we didn’t need to match vertex indices. We needed to define the coordinate transform, calculate the edit amount from each position, and compute the mirrored weights at the same positions. Once complete, we verify that the formulas match and compare the VRM files as a whole separately.

Key takeaways

  • Confirm the glTF and Blender coordinate transform, and document the formula in one place.
  • Compute edits from vertex position p and edit center c, not vertex indices.
  • For symmetric edits, calculate both weights from the same pre-edit position.
  • Check edit formula error separately from comparisons between VRMs produced by the full workflow.

Top comments (0)