Global vertex position fails, when I pull a face
-
Hi!
I have a problem with the global vertex positions....
Initial situation:
- a group with different faces inside
- to get the global positions of the single verticies: group.transformation + vertex.position
up till now: everything is fine...
now I pull a face - the group gets larger - group.transformation changes.... AND the moved verticies get a NEGATIV value.
Is there an easy possibility to "rearrange" the verticies? If not, I have to go over all verticies - get the smallest value and rearrange each value.
Thanks a lot for your help!
-
Hard to tell what is going on here without seeing any code.
But you are aware that then you open a group of component its coordinated are transformed into world coordinates automatically by SU?
-
@thomthom said:
Hard to tell what is going on here without seeing any code.
But you are aware that then you open a group of component its coordinated are transformed into world coordinates automatically by SU?
Okay, sorry, here more explanations with code:
model = Sketchup.active_model groups = model.entities result = groups[0] UI.messagebox result.transformation entities = result.entities face = Array.new # read all faces i=0 entities.each do |tmp| if tmp.typename == "Face" if tmp.normal[2] != 0 face[i]=Face.new(tmp) i+=1 end end end
And the class for faces:
class Face def initialize(face) vertices = face.vertices UI.messagebox vertices[0].position end end
Now I start the code... everything is okay....
then I pull a face manually in Sketchup and start the code again... every verticies has a different NOT GLOBAL position.I hope I could help you to understand my problem
Thanks a lot for your help!
-
hm... I'm not reading your code flow... I don't see anywhere where you apply any transformation to the vertex positions...
Mind you, how are you comparing that the positions changed? There is nothing that guaranties that the entities and vertices will be returned in the same order after the model has been modified.
btw, on a side note -
.typename
is a terrible performance killer. For more information: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/ -
@thomthom said:
There is nothing that guaranties that the entities and vertices will be returned in the same order after the model has been modified.
Yes, you're right and I know that - I just compared the minimum of (for example) y values.... at the beginning it should be 0 for some verticies. I pull a face and then the minimum of y is (for example) -10.
@thomthom said:
btw, on a side note -
.typename
is a terrible performance killer. For more information: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/Oh, thanks a lot! I didn't know that! That's a great info! I will adjust my code.
-
@niccah said:
@thomthom said:
btw, on a side note -
.typename
is a terrible performance killer. For more information: http://www.thomthom.net/thoughts/2011/12/never-ever-use-typename/Oh, thanks a lot! I didn't know that! That's a great info! I will adjust my code.
There's a whole lot more optimization tips in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=25305
And a nice list of other resources here: http://forums.sketchucation.com/viewtopic.php?f=180&t=10142Both are stickies in the Developer section.
As for your original topic, I'm still not sure what we are dealing with. I think there's something in what you do which is an important clue to what you experience.
-
Hang on....
I think I might see what causes what you describe... you're not obtaining global coordinates at all. You're just looking at the local coordinates. You need to apply the transformation of the parent entities to the Point3d object.
When you then change the geometry in your group, you then offset it bounding box, affecting the coordinates. (If I understand this all right)
global_position = vertex.position.transform( parent_transformations )
-
@thomthom said:
Hang on....
I think I might see what causes what you describe... you're not obtaining global coordinates at all. You're just looking at the local coordinates. You need to apply the transformation of the parent entities to the Point3d object.
When you then change the geometry in your group, you then offset it bounding box, affecting the coordinates. (If I understand this all right)
global_position = vertex.position.transform( parent_transformations )
Uhh jeah - I think that's the point I looked for! I didn't know that I can transform the position it self - but that's exactly that I want!
Thanks a lot!
And thanks for all your tips for optimizations!
-
Note that the method doesn't transform the point itself - but returns a copy.
Advertisement