Hi all,
I don't know how many times I announced this, but it has finally happened: As of rev #16681 the new, completely reworked(TM) 3D box tool code is now in SVN, hopefully still in time for 0.46.
Those of you who played around with the tool before may have noticed that although it was certainly usable, there were a couple of issues; most notably, undo/redo didn't work reliably, some box configurations in degenerate perspectives were not really stable, etc. But most of all, development was getting more and more of a pain, making both debugging and adding new features tremendously difficult. All this was due to the internal architectural design of the tool at the time. Since I didn't see a way to easily sort this out by continuing the chosen path (and even if I had, it would only have led the tool even further into a dead end as far as extensibility and applicability to other 3D related tasks are concerned), I decided that it would be better to rewrite a lot of it more or less from scratch. I apologize that this has taken me so long, but I'm studying for my finals right now (or rather should be :-/ ), which has been a major distraction for completion.
Anyway, the bulk is done now, and I'd like to give you a very quick overview of the changes.
As far as the "ordinary" user is concerned, the overall behaviour of the tool is roughly the same as before, except that it is more stable and reliable. :) (In particular, there haven't been any great new features added yet). The most notable visible changes are the following:
- Boxes now come equipped with a default depth, i.e. simply dragging on the canvas creates a full-featured box. This hides the allegedly hard-to-discover Shift+drag feature from the user and makes it easy for newcomers to find out what the tool actually does.
- Boxes sharing the same perspective move together when a vanishing point is dragged, as if they form part of the same 3D scene that is simply viewed from a different angle (before, they all moved independently of each other). This makes it easy to create entire scenes and adjust them as a whole during drawing.
If you want boxes to move independently of each other, you can split perspectives up by shift-dragging a vanishing point. For a full list of this and other features of the tool, please wait until I have updated the Release Notes (a copy will be posted to this list).
So much for the visible part of the tool. For those who are interested here comes a more in-depth description of the internal changes:
1) *All* 3D box related structures (namely, the box itself, its sides, and also perspectives) are now handled as SPObjects, which fixes the annoying issues with undo/redo. A notable consequence is that the SVG representation of boxes is now slightly different than it was before, which probably renders old files invalid or even unusable. This shouldn't be a great issue, though, since the tool has not officially been enabled yet (which turns out to be a good decision). I'm going to give the current representation a final revise in the next one or two days, but I don't expect it to change any more.
2) Perspectives are now added to the document's defs so that they can in principle be reused by other objects. This doesn't have an immediate effect on the tool itself but should make applications to other 3D related situations easier.
3) Before the refactoring, all constructions were made geometrically by computing connecting lines, points of intersection, etc. The way it works now is that we use the information given by the three vanishing points to compute a mapping from 3D space to the canvas which results in the specified perspective. By computing inverse images of canvas points, this allows us to determine "real" 3D coordinates of boxes, to model the concept of lengths (at least to a certain extent), to compare coordinates of boxes, etc. Also, degenerate perspectives can be handled in a numerically stable way because not the boxes themselves are degenerate but only their _images_ on the canvas.
In fact, this description is a bit of an oversimplification. In order to compute the mentioned perspective mapping, it is necessary to (at least implicitly) specify a _fourth_ point on the canvas, which can be thought of as the origin of the coordinate system (whose three axes point towards the vanishing points). This fourth point is not currently represented on screen. A while ago in one of our discussions Bulia suggested that it should be hidden from the user because its meaning might be unintuitive. Personally, I'm not entirely convinced and I'm tempted to leave it as an option to the user whether it should be drawn on the screen or not (it can also be quite useful for adjusting 3D scenes). Any opinions from other people? At present you can visualize this point by pressing 'O' in the 3D box tool (you may need to draw a box first). This draws a small pink point on the canvas. Note that I added this shortcut for debugging purposes and it will be removed later on. Think of this point as the "anchor" of the coordinate system - it is the only point that always remains fixed when vanishing points are dragged.
Well, that is pretty much all I can think of at the moment. Please ask if you are missing anything or if something remained unclear. In principle, everything should more or less work now. There are a few known issues I'm going to sort out in the next days, including (but probably not limited to) the following:
- I had to temporarily disable the spin buttons in the toolbar after introducing an undo-related crash yesterday (Inkscape chokes with the message "assertion failed: (doc->priv->sensitive)"). I will debug this and make them work again very soon. In the meantime, the states of vanishing points can be toggled using the shortcuts "X", "Y", and "Z". In addition, the angles of infinite perspective lines can be rotated using the various types of brackets - namely [], (), {} (where Alt+dragging results in a very small rotation angle).
- Although z-orders should be set reliably now, there may be a few degenerate cases where they are still wrong (I think I know which these are). If you discover such a case, you can send me a corresponding *.svg file if you wish.
- Transformations of boxes work, but if a single box is transformed this also transforms all other boxes sharing the same perspective. Bulia said that instead this box needs to be unlinked. Will fix this soon.
- Stroke, patterns, and gradients are not yet adapted during transformations. I'll have to see how to do this because transformations are implemented differently in 3D boxes than in the other tools. Any general pitfalls I need to know or keep in mind regarding this?
- Constrained dragging of handles (by using Ctrl) somehow sets the box off a certain amount from the intended position. Don't know precisely what causes this but I hope it won't be hard to fix.
- flipping boxes doesn't update its z-orders
- ... whatever you may discover ...
As always, if there are any questions, comments, suggestions, you name it - please don't hesitate to tell me. And now: Happy testing and enjoy. :=)
Cheers, Max
P.S.:There is still a number of debugging messages present in the code (most of them commented out, but maybe I forgot some). I will of course get rid of them soon, but currently they are helping me in resolving the remaining issues, so I left them in.