Hi TIG, I've got a few more patches for you, on your importer this time. I've been running into " - Material already exists..." errors a lot, which cause the associated group to be imported untextured.
I changed the following code to reuse the existing material, but it might be nice to have an option to automatically mangle the material name if it really is a different texture.
when "newmtl"
mat_name=values[0]
matnames=[];materials.each{|mat|matnames << mat.display_name}
if matnames.include?(mat_name)
puts mat_name+" - Material already exists..."
### traps for usemtl called x2 in obj or pre-existing materials
current_mat=nil
## NEW; make sure pre-existing materials are re-used
if nil==new_mats.find{|mat|mat.name==mat_name}
new_mats << materials[mat_name]
end
I also noticed that the vast majority of import time is spent updating the progress bar. A quick fix that shortens a minute-long import to a few seconds:
change
Sketchup.set_status_text("Processing line #{line_cnt} of #{lines.length}")
to
if line_cnt % 73 == 0 # could be any number, 73 just makes the digits spin nicely
Sketchup.set_status_text("Processing line #{line_cnt} of #{lines.length}")
end
Finally, one of my test models suffered from the "some faces get reversed" bug mentioned above - but I noticed that when I then imported the same object again, without my material reuse code so it ended up untextured, the problem disappeared. When I tested by commenting out the "position_material" line in the following code the problem also went away, but obviously so did the texture.
if new_face and @current_mat!= nil
if @current_mat.texture != nil
pt_array=[]
pt_array=[verts[0],face_uvs[0],verts[1],face_uvs[1],verts[2],face_uvs[2]]if verts_length==3 and face_uvs
pt_array=[verts[0],face_uvs[0],verts[1],face_uvs[1],verts[2],face_uvs[2],verts[3],face_uvs[3]]if verts_length>3 and face_uvs
# new_face.position_material(@current_mat,pt_array,true)
else
...
I'll keep poking at it, but I'm having to figure out both Ruby and Sketchup's API as I go, so you might have more luck.
Here's the globe model I noticed the problem on for referencetextured globe that suffers from some face-inversions when imported