Flatten Plane / Match plane
-
I think my issue is i'm not actually capturing the first triangle being clicked anywhere I'm just enumerating the selected model and incidently just reversing the code. I think I need to some how determine which triangle was clicked first I.E. f0 or f1 and then adjust accordingly.
-
Technicallly the first face clicked should be f0=m.selection[0] If I were to select two faces...correct?
-
**selection=Sketchup.active_model.selection** f0=selection[0] f1=selection[1] n0=f0.normal n1=f1.normal
etc etcWith selections, arrays etc the first element is index 0, second index 1 etc...
So when you select two faces.
The selection has two elements - [0] and [1]
These are the faces referred to as f0 and f1 above...
From these we get their 'normals' [vectors - drawn perpendicular from their 'planes'] - n0 and n1...That's also why you can't Select any other things and hope this'll work, as there's no code in there [at the moment] to 'extract' the just the two faces from everything else that you might have selected... but then that's the subject for a separate thread...
-
Right. However in the array will the first position = the first item clicked? For example if I select one face the first array position[0] should contain that face. And in another instance if i click on the first face then the second face will the position[0] still be the first face I clicked on or will the second face be in that position as it changes how the model is enumerated? For some reason when I use the code no matter which face I click on it always flattens the same face regardless of the first face clicked. Currently as it stands if I click the first face and then the second face it will always flatten the first face to the second face....Basically to test the code I will select 1 face then select the next face and it will flatten. However If I perform an undo to reset the faces to the original position and select a different face as the first one it will still flatten the same face regardless of which order I clicked on.
` f0=m.selection[0]; #first face selected
f1=m.selection[1]; #second face selectedn0=f0.normal; #first plane normal
n1=f1.normal; #second plane normalc=n0.cross(n1);
set a equal to the angle between the first and second faces.
a=n0.angle_between(n1);
t=Geom::Transformation.rotation(f0.vertices[0].position,c,-a);
m.active_entities.transform_entities(t,f1);
m.commit_operation;` -
As an edit I just realized I think my comments should be #first face normal and #second face normal not #first plane normal etc...
-
I have been doing some debugging of sorts and if you do a puts f0.normal and a puts f1.normal then select face1 then face2 (look at the two values and the order they are outputted) then perform an undo and select face2 then face1 it produces the same values in the same order. Shouldn't the order be reversed if I clicked on a different plane first in each instance?
-
Sorry I meant to say clicked on a different face first...For some reason I keep wanting to say plane..
-
edge.erase!
-
To get the faces in a specific order you really need to make a Tool class - then pick the faces after the tool is activated, that way the first picked face is set.
We are only using the 'selection' based process to simplify things, as you try to get your head around how to find normals, crosses and transform vertices etc...
The order objects appear in a selection is not necessarily determined by the initial selection order, it may well relate to their 'creation' order - it's arbitrary.
If you recall my initial example even excluded a 'second' face as the selected face was laid 'flat'...If you need a Tool class to select the faces there are many examples available - find an 'unfold' tool's script...
That will have many details of selecting faces and getting suitable data from them and neighbors etc, used to 'unfold' them - much like you want to do... -
Thanks for the response I suspected something like that was going on. I do have code to make sure that only 2 faces have been selected and no other parts of the model. I will look into using the tool class so I can get the correct order of faces. Again Thanks to both of you for all of your help.
-
If you're new to SketchUp plugin development you might want to have a look at this article: http://www.thomthom.net/thoughts/2012/01/golden-rules-of-sketchup-plugin-development/
Advertisement