Closed acruikshank closed 8 years ago
alex, it's is great to have you weigh in on this. you make it sound and look so simple ;)
I don't know enough about the OBJ export to determine how we might do this, if there are any provisions for matrix storage.
we have another issue to fix now however,, When lines are grouped together, the new lines are positioned off of the 'selected' line. When we inverse & multiply the position, we lose that relative information.. I remember that's why I stuck with the boundingBox.min.x value although it isn't a robust solution...
I saw some code related to grouped lines, but I don't understand how to use the interface to group lines together. All we need to do is either set a line's transform to the value of the group's original line when it is added to the group, or set the transform of all the lines in the group to the value of the new line. This should maintain all the relationships. If you can tell me how to group, I can add this pretty easily.
ah. ok.. every new line is added to either a) a pre-existing group that has at least one line in it already b) a new group. In the case of A, the user has selected a pre-existing line: "currentIntersected". We get the parent group - copiedObj, and add the new line to it
This change makes pasting work, but only for objects that have not been downloaded and then imported.
The problem with the existing code was that it was using the lower left corner of the object's bounding box as the origin. This meant that pasted objects would generally be offset up and to the right (depending on where they were drawn on the original plane). This strategy also lacked any compensation for rotations of the original drawing, so pasting and object that was drawn after the camera was rotated would result in a drawing at an angle to the destination plane.
Unfortunately, by the time we copy a drawing, information about the plane it was drawn on is lost. This PR addresses that by storing the transform of the drawing plane when the line is initialized. We can invert this matrix to transform the drawing to a plane unrotated at the origin and then apply the new plane's world matrix to move the lines to the correct place. This works well.
The downside is the stored plane matrix is lost when we save it to the obj file. The obj file format doesn't appear to be capable of storing arbitrary information like this. I noticed that the line widths also change after reloading, so it might be worth moving to a more flexible format. Another option would be to compute the matrix from the points. They all line in a plane, so it should be reasonably easy to solve for the transform, but it's a bit of a project, so I thought this would do for now.