Skip to content

Add mirror groups. WIP.#1057

Closed
phkahler wants to merge 1 commit intosolvespace:masterfrom
phkahler:mirror
Closed

Add mirror groups. WIP.#1057
phkahler wants to merge 1 commit intosolvespace:masterfrom
phkahler:mirror

Conversation

@phkahler
Copy link
Member

This is my 4th try at mirror groups. Face entites are not working, normals may not either. Other entities work. The shell works, but faces can not be selected yet. Plans are to include options to mirror the group across selected points and to have it work in 2D as well.

Shift->M will create the new group.

@kk6mrp
Copy link

kk6mrp commented Jun 16, 2021

This is pretty cool! Even as it is seems to work pretty well!

@phkahler
Copy link
Member Author

@kk6mrp Thanks for trying it out. If you mirror arcs they will fail, at least in 3D.

@kk6mrp
Copy link

kk6mrp commented Jun 16, 2021

The 3D rotation seemed a little different than other objects rotate, not necessarily bad but just different. Is that because it isn't mirroring across anything?

I'll have to test it out more tonight, last night I just tried out mirroring a rectangle and cube...

@phkahler
Copy link
Member Author

The 3D rotation seemed a little different than other objects rotate, not necessarily bad but just different. Is that because it isn't mirroring across anything?

It's mirroring across an invisible mirror plane. If you drag a point, the mirror plane is adjusted to that point and it's reflection are on opposite sides of the mirror. This means there are 3 degrees of freedom in the reflected part, not a full 6. When you do it in a 2D sketch, it will constrain the mirror to be perpendicular to the sketch plane so the reflected sketch elements are also in that plane.

I plan to add an option so any 1,2, or 3 points selected (or ends of a selected line segment) will be constrained on the mirror, or rather the mirror will be constrained to pass through those points. Also hoping to constrain the mirror to a face if one is selected, which would just reflect a solid across that face and join the 2 together. Just have to get the basics working first!

@phkahler
Copy link
Member Author

This is turning out to be hard. In EntityBase::NormalGetNum() for the mirrored normals...
You can't use the Mirror() function of a normal/quaternion. That function builds a new "normal" by flipping the U and V basis vectors defined by the quaternion. the problem is negating those has no effect on the N basis vector which is needed for ARC entities. There is no way to represent a left handed coordinate system using the quaternions here. So I'm creating a rotation quaternion to rotate the "normal" through the mirror planes normal. the x,y,z for that rotation quaternion should be the original normal.RotationN() vector cross product with the mirror normal vector (params 0,1,2 of the mirror group). The 4th (W) parameter would just need to be sqrt(1.0 - (xx + yy + z*z)). This seems to work half the time. If you extrude something with an arc and then mirror the solid, the mirrored arcs will appear correctly about half the time. If you drag them around the originals it will spin around correctly, and then again incorrectly. I'm wondering if there are times when the square root needs to be negative or something.

I'm also wondering if Quaternion.Mirror() is ever used and if we can change the definition so the resulting quaternion will have its RotationN() vector flipped, as that would be useful here.

@kk6mrp
Copy link

kk6mrp commented Jul 2, 2021

Is this what you were referring to that faces cannot be selected yet? I get an assert when selecting any face of the mirrored object or when selecting two faces of the mirror I get an assert.

Missing (absent) translation for group-name'mirror'
File ./src/dsc.h, line 526, function FindById:
Assertion failed: t != nullptr.
Message: Cannot find handle.
Aborted (core dumped)

@phkahler
Copy link
Member Author

phkahler commented Jul 2, 2021

@kk6mrp Yes, that looks like an example. The latest version of this doesn't crash for me, but the faces don't highlight when hovering over them, and they don't do anything when clicked. I think it has to do with having consistent parameters passed to Remap and RemapFaces. I think something is missing like remapping the surfaces?

@phkahler
Copy link
Member Author

@jwesthues Could you look at this? I'm not sure why the surfaces of a mirrored extrusion can not be selected. I've had trouble with that before. I might not be defining the new face entities correctly, or might not be doing something right with remap.

Other entities are working now.

Adding options (constraints) when creating the group will get added after the groups mirror correctly ;-)

@jwesthues
Copy link
Member

Very cool. It looks like you're aiming to create two copies of the original geometry, one unchanged with REMAP_BOTTOM and the other mirrored with REMAP_TOP? I don't immediately see anything wrong with your remapping, though perhaps it would make sense to make just one mirrored copy. If I understand correctly, you couldn't use your current implementation e.g. to create an extrusion of just the mirrored version of a plane sketch, since you'd have both copies in the resulting group.

I do notice that you're setting timesApplied to 0 and 1 for the two copies (made with CopyEntity()) but never using it. That seems unnecessary but not harmful.

The problem you note with the quaternion's n is fundamental--if we had an entity that generated points/curves lying outside the uv plane, then there would be nothing we could do with that quaternion to mirror that entity. But I think all entities defined in terms of quaternions lie entirely in the uv plane, so that's not actually a problem? If it were then we should hit that when mirroring by importing scaled by a negative number too, and I don't recall any trouble there.

Have you tried graphically debugging the faces, like drawing the point and normal vector for each face in the group? I suspect that will be much easier than trying to get all the math right blind.

@phkahler
Copy link
Member Author

I think making 2 copies in the new group is consistent with step-rotating and step-translating. That way after mirroring half of something to create a whole, the entire thing can be step-copied or rotated again.

By setting timesApplied to 0 or 1 we have the option of making both copies copy-as mirror (the mirror math would only apply to one), but then I decided the first copy could just be a numeric copy, so that's redundant.

Arcs seem to be defined by 3 points in 3D and a normal. In order to mirror an arc, I think the normals N vector has to flip. Negating U and V just rotated 180 degrees in the plane. That might need some more investigation. Text entities don't scale by -1 properly but they do mirror correctly.

@jwesthues
Copy link
Member

I think making 2 copies in the new group is consistent with step-rotating and step-translating. That way after mirroring half of something to create a whole, the entire thing can be step-copied or rotated again.

That's a good point. Perhaps then use the same flag that distinguishes start "with original" vs. "with copy #1" for translate/rotate, and make it user-selectable?

Text entities don't scale by -1 properly but they do mirror correctly.

What fails in the text entities? I did a quick test, and they seem to work linking scaled by -1. The behavior of normals there is rather subtle and I can't immediately articulate why it works, but as far as I knew it did.

image

@phkahler
Copy link
Member Author

The problem with selecting faces was sovled by adding the MIRROR type to the condition in Group::Activate which sets ShowFaces = true; Now they highlight when hovered and the "new" object faces can be clicked/selected. The original crashes when clicked. I've seen this before but don't recall what causes it ;-) more investigating....

@ghost
Copy link

ghost commented Sep 11, 2021

I've seen this before but don't recall what causes it ;-) more investigating...

Any news? "Mirror" feature is really needed to design various parts geometry features.

@phkahler
Copy link
Member Author

Had to manually rebase changes on master. Did that in a new branch so closing this PR

@phkahler phkahler closed this Sep 12, 2021
@ruevs
Copy link
Member

ruevs commented Sep 22, 2021

#1109 is the new pull request - just for historical cross linking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants