So that’s how the model should look. But obviously the materials are on the back face of the wrong normals (red).
My main goal:
To have two models. The first model with materials for the red faces and then the second model with materials for just the white faces.
Issues:
It’s not possible to flip all the normals without a lot of manual work. Not with orient faces, fredo tools, you name it. But at the moment that isn’t my first priority.
A lot of the flipped faces have two materials see image below. Which means selecting by material is impossible while some faces share materials they shouldn’t.
If you are sure that the incorrectly orientated faces are only painted on their backs then try this…
If a face has materials on both sides it’s skipped !
There’s no UV mapping of a flipped texture…
Of course you could also flip the face AND delete all of its materials - using nil NOT back in the two blocks below…
f.material = nil
model=Sketchup.active_model
model.start_operation("ReOrientFacesWithMat", true)
# In Model’s faces
model.entities.grep(Sketchup::Face).each{|f|
if back=f.back_material && ! f.material
f.reverse!
f.material = back
f.back_material = nil
end
}
# In compo/group’s faces
model.definitions.each{|d|
next if d.image?
d.entities.grep(Sketchup::Face).each{|f|
if back=f.back_material && ! f.material
f.reverse!
f.material = back
f.back_material = nil
end
}
}
model.commit_operation
puts "Done."
No.
It only works if the faces only have a back material.
It’s difficult to know what face is wrongly oriented - as you’ve found.
So first you need to select only faces that appear reversed to the camera [i.e. you are looking at the back], and then delete their back [and front ?] material…
Of course if you look at a box with all of its faces correctly oriented, then the ones of its far side do have their backs looking towards the camera and you do NOT want to reverse them !
Try this to change the selection to include only those faces you can see the back of.
It doesn’t cope with faces inside ‘containers’ - it’s possible but much more complex !
model=Sketchup.active_model
model.start_operation("SelectBackFaces", true)
# In Model’s faces
direction = model.active_view.camera.direction
eye = model.active_view.camera.eye
faces = []
model.entities.grep(Sketchup::Face).each{|f|
normal = f.normal
# check if something is in the way !
if direction.angle_between(normal) < 90.degrees
center = f.bounds.center
if model.raytest([center,eye], false)
next
else
faces << f
end
end
}
ss = model.selection
ss.clear
ss.add(faces)
model.commit_operation
puts "Done."
You’ll probably need to locate the camera around the model 4 or more times to catch all faces.
If is badly modeled you might get some backs visible when you wouldn’t expect - e.g. one face walls !
You now have a selection of faces you can see the back of…
You can now use this to force a reversal and remove the material…
model = Sketchup.active_model
ss = model.selection
model.start_operation("Reverse+NoMats", true)
ss.grep(Sketchup::Face).each{|f|
f.material = nil
f.back_material = nil
f.reverse!
}
model.commit_operation
puts "Done.."
If you want to remove ALL faces’ materials use the methods outlined earlier…
The double material could be that some components have had materials applied while closed and on their faces when open for editing. Using a plugin that removes C/G materials may help clear things up a bit.