Created Objects are formed "inside out"

Hi fellow sketchupers,

I am currently working on a modelling skript for forest plots to depict them on posters. Everything works fine apart from one thing: Sometimes trees are created “inside out”, which you can see in the following picture:

I discovered that this occures randomly when I load the codefile into sketchup, so I think there is not a problem with the code. Either way I just want to detect wether the outside of the object faces inside (or the other way arround) to then turn that arround.
Does on of you know a way of doing this?

I am looking forward to your answers.
Best Regards

The face reversal in FollowMe comes from the interaction of the direction of the path [circle] - cw/ccw - and the orientation of the profile face, when compared to the direction.
Either ensure consistency, or check in your code for both of these factors - reverse the face before the FollowMe, as might be needed…

Thanks a lot for your reply.
As the trees are all created with a while loop, the code is consistend and the faces and paths all share the same orientation. Apart from that, this mistakes occures at random, so I do not really know where to look, as the code does not change.
Either way, I think i can work arround it with changing the insides colour. Do you know, whether that is possible?

Follow Me might introduce some randomness. When creating individual faces with Entities#add_face the orientation is governed by a set of (somewhat odd) rules and always predictable when you know these rules.

A set of vertices/points/edges that form an outer-loop for a face, when set up ccw makes a face with a normal perpendicular to the loop. However, if the loop is flat at z==0 then the created face’s normal is always Z_AXIS.reverse and the cw/ccw nature of the loop is ignored.
You see this in manual face creation in SketchUp itself.
Making cw/ccw face loops produces faces with different normals, except when flat at z==0, when the face is always down - allowing a PushPull up while keeping the bottom face logically oriented.
A face’s normal relative to a FollowMe path’s starting edge direction will affect how the extruded form’s surface is oriented. Your code needs to check the face.normal against this, and use face.reverse! if needed, also making allowance for the times when the face is made flat at z==0, with an unexpected flipped normal…

1 Like

I would just add some of my own thoughts, I maybe makes some sense…

Looking at the face and the vertices order are clockwise you will see the back face, but:

http://ruby.sketchup.com/Sketchup/Entities.html#add_face-instance_method
Note that a special case exists for any face created on the ground plane, in which case the vertex order is ignored and the face is always facing down.

Yup, the rules are a bit weird but once you know them you can work around that. When creating new faces this way you can check the normal and reverse the faces if needed.

Again, I am really gratefull to your reply.
I worked on checking the normal vectors of the created faces and let sketchup put them in the ruby window / console. What it showed me was the following:

"Baumnummer: 1; Normalenvector Bst Face: (0, -1, 0); Normalenvector Path Face: (-0, -0, 1)

  1. Normalenvector Kuk Face: (0, 0, -1)
  2. Normalenvector Kuk Face: (0, 0, -1)

Baumnummer: 2; Normalenvector Bst Face: (0, -1, 0); Normalenvector Path Face: (-0, -0, 1)

  1. Normalenvector Kuk Face: (-0, -0, 1)
  2. Normalenvector Kuk Face: (0, 0, -1)

[…]
***Baumnummer: 7; Normalenvector Bst Face: (0, -1, 0); Normalenvector Path Face: (-0, -0, 1)

  1. Normalenvector Kuk Face: (-0, -0, 1)
  2. Normalenvector Kuk Face: (0, 0, -1)

[…]
***Baumnummer: 10; Normalenvector Bst Face: (0, -1, 0); Normalenvector Path Face: (-0, -0, 1)

  1. Normalenvector Kuk Face: (-0, -0, 1)
  2. Normalenvector Kuk Face: (0, 0, -1)

[…]
true"

The only relevant thing to notice is, that “Normalenvector Bst Face” and “Normalenvector Path Face” do not Change. With the corresponding model it is different though:

As you can see, there are two trees that have red surfaces. Those are tree 7 and 10, (marked with *** in the text above), which means, that I can not use the .normal method to help me out here, as it does not show what the model ends up like.

My idea is now to check whether I can use another way, which I need your help with.
At the Bottom of every tree, that is generated with the followme method, there is a face that either Points up (red is shown) or downwards (brow is shown). Using the find method I could search for a face that has the normal Vector [0,0,1]. The Problem is, that in every tree, there are at least to faces that have the same orientation. To cope with that I could search for faces that do not have the same Variablename as These two. Is this possible?

An example:
With this Code, I can search for such a face, but it can only give out one. How can i include the Name (in my case “kuk_face” or “path_face”)?

ents = Sketchup.active_model.entities
xface = ents.find {|ent| ent.typename == “Face” &&
ent.normal == [0, 0, 1]} <-- The third condition would Need to be the Name
xface.material = [0, 0, 255]
puts "The face is: " + xface.to_s

Thanks a lot for your help!

Best regards
Hendrik

P.S.: Sorry for the wrong capitalization, my autorcorrect wants to make everything in german.

ents = Sketchup.active_model.active_entities # .active_entities NOT .entities
faces = ents.grep(Sketchup::Face).find_all{|e| e.normal == Z_AXIS }
# .find_all for ALL such faces, .find returns just the first one that matches
faces.each{|e|
  e.material='blue'
  puts e
}

This collects all faces with a normal matching the Z_AXIS ([0,0,1]) into the array ‘faces’
It then iterates them, to assign them a ‘blue’ material, and also prints their reference id[s]…

1 Like