Absolute vs. Relative Meshes/Groups
-
Me again, though with a completely different issue this time.
I'm trying to write a script that computes a triangulation of the active model (using Face.Mesh), then outputs the vertices of the triangulation to a file. The script works perfectly fine for "simple" models -- that is to say, "models without any 'groups'." However, I discovered that if the model contains groups, the output is bizarre: all the geometries do get output to the file, but in a very distorted form. What seems to be happening is that the mesh that SketchUp outputs is relative to the group's coordinates, not the absolute coordinates of the world frame.
I'm going to try doing it the "correct" way, i.e. store the transformation information of each group and apply this transformation to all vertices before writing to the file. However, I'm worried that this might be a little painful, especially because groups can be nested arbitrarily deep and my recursive programming skills are a little rusty. So, in the meantime, I was wondering if anyone knew of a way to force SketchUp to output absolute vertex information (or "relative to the global coordinate system") instead of relative to the group.
Thanks a bunch again!
Kevin
-
Huh. Well. As it happens, it was much less painful adding in the transformation information than I thought: it works perfectly now.
For anyone interested, just as an fyi, if you want to recapture the correct geometry, you have to transform the mesh according to the value returned by Group.transform, not the inverse of Group.transform. In other words, you want something like:
t_matrix = Geom;;Tranformation.new def output_entity(entity, t_matrix) if entity.typename == "Group" t_matrix = t_matrix * entity.transformation # <== *NOT* t_matrix * entity.transformation.inverse entity.entities.each{|sub_entity| output_entity(sub_entity, t_matrix) } elsif entity.typename == "Face" mesh = entity.mesh 0 mesh = mesh.tranform! t_matrix # [Add output code here] end end
Anyway, I'd still be curious if there's a more "internal" solution, but it seems like everything's working perfectly, and much less painfully than I'd expected.
Kevin
Advertisement