1
\$\begingroup\$

I'm in the progress of making a simple 3D editor, just for developing skills on 3d graphics.

After implementing some basic tools, I realize that scaling isn't working as I expected.

For example, when you scale down a model to a flat plane along some axis, how is it possible to restore that model when you scale up again on that axis?

Every vertex has been crunched to the same position, so they will all be scaling in the same way, so the model's vertex layout will be lost.

I assume that I need some metadata or "shadow copy" of the model, but I'm not sure.

How can I solve this problem in my editor?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Separate your notion of the model's source data, and the current display data of an instance of that model.

The source model is like a platonic ideal. Perfect, archetypal, and unchanging.

You do not sully this perfect ideal with every wiggle of a transform handle. You do not write to it at all, unless the user specifically asks you to "apply" or "bake" the transformation down into the source data.

You store the transformation components of an instance of the model separately, along with the positions of its transformed vertices. The instance stores a reference back to its source data, and many differently-transformed instances can refer back to the same source data.

When the transformation data changes (position, rotation, scale, or other more exotic transformations if you use them), you read the source data, run it through the transformation matrix, and write it into the transformed data. No data is lost this way because you do not overwrite the source data.

This also prevents rounding errors from accumulating and distorting your model.

If you want to apply changes the user makes to the transformed vertices back to the source model data, you can run the new vertex positions through the inverse transformation matrix to put them back in the source data's coordinate space. You'll just need a little special handling for the case where the user makes the matrix non-invertable, by flattening the model into a plane for instance - there they can still move the vertex in the two axes parallel to the plane, just not perpendicular to the plane, and you can still map those back to a corresponding position in the source model.

\$\endgroup\$
5
  • \$\begingroup\$ Thank, great answer. For clarifying that i understand correctly, interacting (mouse picking of edge, for example) i must do on transformed instance and source model only for producing trasformation data and add addition vertices information, splitting or copy faces of cube that will produce new vertices, for example? \$\endgroup\$
    – Akros
    Commented Dec 11, 2020 at 14:23
  • \$\begingroup\$ Changing a transformation - like scaling and rotating the model - should modify the transformation data (scale vector, rotation quaternion) and the display copies of the vertices. Any non-affine modifications (like moving just one vertex) can be applied to the source data immediately, so they're preserved after the next transformation. \$\endgroup\$
    – DMGregory
    Commented Dec 11, 2020 at 14:43
  • \$\begingroup\$ Sorry if i don't get it from you answer, but for mouse picking of edges, faces or vertices as i understand i just use transformation data on ray and it's up to me holding copy of whole trasformed model or applying it in proceess of hit test? \$\endgroup\$
    – Akros
    Commented Dec 11, 2020 at 14:58
  • \$\begingroup\$ Picking would use the display copy, because you're picking based on what's displayed on the user's monitor. (Though you could also inverse transform your ray and pick in the source data that way, but that makes it harder to get consistent selection tolerances) \$\endgroup\$
    – DMGregory
    Commented Dec 11, 2020 at 15:00
  • \$\begingroup\$ Sorry I didn't make it clear in the comment above, what you describe is what I meant for the first and second case, thanks for the help \$\endgroup\$
    – Akros
    Commented Dec 11, 2020 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .