Getting UVs of untextured faces

Continuing the discussion from UV Map default Material:

From textured faces, we can get UVQ coordinates with the UVHelper, but untextured faces can also (still) be UV(Q)-mapped, as it is used for painting a parent material onto component instances (see Help Center).

Problem:

On faces with default material (nil), UVHelper returns the 3d query points (except of the Q=1 coordinate):

face.material = nil
uv_helper = face.get_UVHelper(true)
uv_helper.get_front_UVQ(Geom::Point3d.new(0, 10, 0))}
=> (0", 10", 1")

even if the face still has UV coordinates, so exporters cannot access these UV, and the feature of unpainted faces in components inheriting the parent material becomes worthless when working with software outside of SketchUp.

Solution:

@DanRathbun hinted me at work-around to apply a temporary textured material during the export and undo it later:

model.start_operation("Read UVQ", true)
tmp_mat = model.materials.add("tmp")
tmp_mat.texture = "/path/to/any/image"
faces.each{ |face|
  face.material = tmp_mat unless face.material && face.material.materialType >= Sketchup::Material::MATERIAL_TEXTURED
  uv_helper = face.get_UVHelper(true)
  ps = face.vertices[0,3].map(&:position)
  uvs = ps.map{ |p|
    uvq = uv_helper.get_front_UVQ(p)
    uvq.x /= uvq.z
    uvq.x /= uvq.z
    uvq.z = 1
    uvq
  }
  # Store the uv somewhere
}
model.abort_operation # Restore the faces' nil or untextured material

Now we got the UV, but the face got no material.

However we cannot query SketchUp whether a face was UV-mapped at all (or whether SketchUp returns default texture positioning which we may want to ignore).

1 Like

Aerillius,

Thanks for pushing this further.

Tomasz has also asked for the same thing (I think)

It’s a long standing request I have…

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