Duplicate Faces?
-
I'm seeing a serious defect in a sizable fraction of SketchUp models, namely the existence of duplicate faces.
By "duplicate", I mean, forFace a and Face b:
- The .to_s method returns the same string for a and b* .entityID is identical for a and b* Setting an custom attribute or changing Face properties affects both Face a and Face b
Note: The two faces are distinct visually and not connected or overlapping.
This makes a number of model manipulations impossible.
It's well known that the entityIDs of Faces are not persistent (and maybe not unique?), but this is far worse: saving references to Faces (for example, in a hash map with the key a custom ID attribute) is useless because one reference is referring to two faces.In case this still isn't clear, here is the output of printing the string representation of all the Faces in a simple model (and also the entityID):
@unknownuser said:
face=#Sketchup::Face:0xf464498, id=52
face=#Sketchup::Face:0xf464498, id=52
face=#Sketchup::Face:0xf464240, id=98
face=#Sketchup::Face:0xf464128, id=1827
face=#Sketchup::Face:0xf464010, id=1841
face=#Sketchup::Face:0xf463f34, id=1848
face=#Sketchup::Face:0xf463e58, id=1855
face=#Sketchup::Face:0xf463d68, id=1863The duplicate faces above (two windows) are both part of separate Groups; I haven't seen this bug in models without groups. If you continually select all entities in the model and "explode", the Faces are then all unique. So basically, this bug is likely due to Groups of Faces.
Any thoughts?
-
o_O
You got a sample model?
-
It could have to do with groups when they are first copied, the entity info window shows there being 4 of a single group in a model, which is absurd since groups in theory don't have copies. But until you double click on it, it counts itself as an instance of the group. So maybe that group instancing has something to do with it?
Chris
-
Ahh, yes. I can duplicate it. Make a face, turn it into a group. Then copy that group. Then list the id's of the faces inside the two groups and they faces share the same id. They do not share the same group parent. So I suppose you could test for that.
It looks like once the group no longer things its an instance then the faces become unique.
Chris
-
And here's how you fix it, with
make_unique
.https://developers.google.com/sketchup/docs/ourdoc/group#make_unique
Depending on what you're doing in your script, you might go through and make all groups unique before finding all the faces. Group definitions are listed in the model definitions collection. So if you iterate through the definitions, find the ones that are groups, then determine if they have more than one instance in the model, you can then make all their instances unique. Here's a working snippet.
defs = Sketchup.active_model.definitions defs.each do |e| if e.group? instances = e.count_instances if instances > 1 e.instances.each do |ee| ee.make_unique end end end end
-
Oh! I thought it was two faces in the same context!
Yes - Groups are just like ComponentInstances - you'll see the same behaviour there.
Have a look at this article I wrote a while back about definitions and instances in SketchUp: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/
It details the relationship and describes the special instances, Group and Image. -
When you duplicate a group manually [or in code] then you have two instances of it.
You can see this if you select the original group [or the copy] and use 'Entity Info', it says there are two in the model.
The faces etc inside this copy will all have the same id-references as the ones in the original group - because they are the very same definition !
Logically SketchUp should automatically make the group.copy into a unique instance of a new definition: but it doesn't.
If you manually edit that copy and close [without making any changes at all] it will become a unique instance of another definition - Entity Info will now say that there's only one instance of the original group, and/or that copy.
The faces etc inside this new definition will all have different id-references compared to the original group's definition, because they are no longer connected through that definition.
In code you can't 'edit/close' the copy, BUT you can do what Chris suggests.
This ensures you only ever have one instance of a copied group, so there's only ever one face reported with a particular id-reference etc.
Be prepared for some spurious warnings in the Ruby Console when you use the group.make_unique method - along the lines of "warning: make_unique is a deprecated method of group" - however, it works successfully. The API thinks you shouldn't ever need to use it, but since SketchUp doesn't run an auto-make_unique on group copies then you do need to use it to fix the anomaly ! -
Awesome gents, make_unique solved it.
Much thanks!
-
@jasef said:
Awesome gents, make_unique solved it.
What about ComponentInstances?
I hope you're not making them uniqe - as I doubt the user will be expecting that - or be happy to see that happening...
-
Advertisement