Created
January 22, 2015 00:59
-
-
Save jimfoltz/1ce66dd5ab6171319c60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get vertices | |
def start | |
#get vertices | |
verts=[] #initialize vertices array | |
trans_h=[] #initialize transformation array use to store hierarchy of transformations | |
verts=createVerticesArray(sel,trans_h,verts) | |
end | |
def createVerticesArray(sel,trans_h,verts) | |
sel.each{|ent| | |
if (ent.is_a? Sketchup::Group) || (ent.is_a? Sketchup::ComponentInstance) | |
trans_h.push(ent.transformation) #push the Group/Component tranformation onto the array | |
ents=ent.definition.entities #get the entities in this Group/Component instance | |
verts=createVerticesArray(ents, trans_h, verts) #recurse | |
elsif (ent.is_a? Sketchup::Edge) | |
ent.vertices.each{|vert| #begin analysis of vertices in this edge | |
puts vert if @debugFFD | |
#get global position of the vertex by applying the hierarchy of transformations | |
v_gpos=vert.position #returns local Point3d position of vertex | |
puts v_gpos if @debugFFD | |
flat_t=flatten(trans_h) #get the flattened transformation for the hierarchy | |
puts flat_t if @debugFFD | |
v_gpos.transform! flat_t #transform the vertex to get the global position | |
vert.set_attribute("vert","gpos",v_gpos) | |
verts.push(vert) | |
} | |
end | |
} | |
#verts now contains redundant verts. remove duplicates. | |
verts.uniq! | |
return verts | |
end | |
#thanks to Adam for the idea! | |
def flatten(trans_h) #returns a flattened transformation from an array of transformations for the instance hierarchy | |
flat_t=Geom::Transformation.new #create an entity transformation object | |
#apply the hierarchy of transformations to the entity transformation | |
trans_h.each{|t| | |
flat_t=flat_t* t | |
} | |
return flat_t | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment