I have a text file with coordinates and rgb values. I read the file and insert faces like this.
if File.exists?(filepath)
filename = File.basename(filepath,“.txt”)
strarr = File.readlines(filepath)
addLayer(filename,true)
strarr.each{|string|
pts = Array.new
begin
pts[0] = [string.split(',')[0].to_f,string.split(',')[1].to_f,string.split(',')[2].to_f]
pts[1] = [string.split(',')[3].to_f,string.split(',')[4].to_f,string.split(',')[5].to_f]
pts[2] = [string.split(',')[6].to_f,string.split(',')[7].to_f,string.split(',')[8].to_f]
face = entities.add_face(pts)
edges = face.edges
edges.each{|e|
e.layer = filename
e.hidden=true
}
face.material = [string.split(',')[9].to_i,string.split(',')[10].to_i,string.split(',')[11].to_i]
face.layer = filename
rescue
next
end
}
end
But it is taking long time for more number of faces. I usually insert more than 20000 faces. Now i am trying to use polygon mesh instead of faces(as it is quicker). I want to colour each polygon of the mesh and also hide the edges.
Is there any sample code for creating a polygon mesh and colouring each polygon with a colour?
PolygonMesh will be quicker to load from your file because it is only “helper geometry”, that is, a standalone data object that does not create any geometry in the SketchUp model. You have to invoke Entities#add_faces_from_mesh or Entities#fill_from_mesh to create Faces and Edges corresponding to the polygons in the PolygonMesh. Because they are bulk operations running in compiled C behind the Ruby API instead of a Ruby loop in your code, those methods should be significantly faster than your code. But this may not be suitable for what you describe because these methods only provide ways to apply one kind of smoothing/softening to all Edges and one front material and back material for all the Faces. You can not color them one by one based on your file data without an expensive step to find which Face corresponds to each polygon from your data.