How do I remove UV coordinates from a face?

advice
bug

#1

I have a model which when imported with textures is 56MB, when imported without textures is 25MB.
The difference in file size is not due to the images, which total only 100KB, instead, the difference is due to each face now having an array of positions and UV coordinates per vertex.

I want to work with the textured model, over-paint with basic colours, and then later remove the textures. However, when I remove the textures, the file size is still 56MB less the 100KB or so for the images.

I have tried…

  1. Floodfill with a simple material
  2. Floodfill with the default (nil) material
  3. pt_array = []
    face.position_material face.material,pt_array,true
    face.position_material face.back_material,pt_array,false
  4. face.position_material face.material,nil,true
    face.position_material face.back_material,nil,false
  5. face.position_material nil,nil,true
    face.position_material nil,nil,false

The only solution that I’ve found so far is to export the model after painting with basic colours, and then re-import. But I’d prefer a ruby-script solution if possible.


#2

what happens if you remove the textures?

model = Sketchup.active_model
model.start_operation('texture = nil')
model.materials.each { |material|
  material.texture = nil
}
model.commit_operation

john


#3

Nothing happens if I remove the textures programmatically like you suggest, the model already contains no textures as I have deleted them from the materials.
The problem is the faces somehow maintains their UV coordinates, even if the face material is set to nil.


#4

I finally found a programmatic way to remove the texture coordinate positions from a face, it is not an elegant solution, but I’m posting here in case anyone else encounters the same problem (as we should).

The solution

For each face that does not have a texture, i.e.face.material.texture == nil
I need to delete the face, then recreate it.

points = []
face.outer_loop.vertices.each { |vert|
	points.push(vert.position)
}
mat = face.material
face.erase!
face = entities.add_face points
face.material = mat
face.back_material = mat

Thats all there is to it!

The file now saves without the bloated overhead of including the UV coordinates with each face.

[Edit: Sketchup should be removing the unused texture coordinates during a ‘Purge Unused’ operation]


#5

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.