Face pointing towards the camera?
-
@thomthom said:
Does
PickHelper.transformation_at
return the total transformation for that entity, including it's parents?Yes.
Seems to be working fine now.
-
Sounds complicated. How about:
` center = face.bounds.center
edge1 = camera.eye to center
edge2 = camera.eye to (center + face.normal)edge1 longerThan edge2 ? outside : inside`
This fails in the special case when camera's line-of-sight is nearly parallel to face's plane.
-
Heh, I like that method Martin. I think the logic is sound. Should be simple to implement also, which is always welcome!
Chris
-
@martinrinehart said:
Sounds complicated. How about:
` center = face.bounds.center
edge1 = camera.eye to center
edge2 = camera.eye to (center + face.normal)edge1 longerThan edge2 ? outside : inside`
This fails in the special case when camera's line-of-sight is nearly parallel to face's plane.
That will tell if the face is pointing frontside or backside towards the camera?
This seems to work without any special cases.
t = ph.transformation_at(index) n = picked.normal.transform(t).normalize c = Sketchup.active_model.active_view.camera.direction m = (c % n > 0) ? e.back_material ; e.material
-
face = Sketchup.active_model.selection[0] cam = Sketchup.active_model.active_view.camera.eye e1 = cam.vector_to(face.bounds.center) e2 = e1 + (face.normal) (e1.length > e2.length) ? (puts "front") : (puts "back")
That is the method Martin outlined. I don't know about the transformation. I guess you would have to figure that in on your own. Is it because the InpointPoint returns the un-transformed normal for a face?
Chris
-
InputPoint only returns entities. So when I pick a face I only get the normal via face.normal, which is the local normal.
But
PickHelper.transformation_at(index)
returns the complete global transformation for the entity.only thing is - I need to test what happends when I'm inside an open group/component, but pick from something outside the current context. (if that's at all possible)
-
Yikes, good luck. This seems to go back to the complaint that SU does not like to traverse through the heirarchy backwards like this.
-
Turns out - there isn't a problem. The PickHelper doesn't pick anything but what's in the currently open context.
-
@martinrinehart said:
Sounds complicated. How about:
` center = face.bounds.center
edge1 = camera.eye to center
edge2 = camera.eye to (center + face.normal)edge1 longerThan edge2 ? outside : inside`
This fails in the special case when camera's line-of-sight is nearly parallel to face's plane.
But thats much more work than a dot product. Your turning an orientation problem into something its not.
-
Interesting Thom. So how do people make tools that select entities outside the current editing level? Can you use the inputpoint class to succesfully return entities outside the current editing level? This is something I really never work with, in case you couldn't tell!
Chris
-
I'm not sure if you can. I think that when the user digs into groups/components it narrows the available scope.
Though this is not something I've explored, as I've never needed to do this. -
@adamb said:
But thats much more work than a dot product. Your turning an orientation problem into something its not.
I'm not seeing how a dot product solves the problem. Could you articulate or maybe Sketch something Up?
-
The result of the dot product can be used to determine if its the front or back side pointing towards the camera.
t = ph.transformation_at(index) n = picked.normal.transform(t).normalize # global vector orientation c = Sketchup.active_model.active_view.camera.direction m = (c % n > 0) ? e.back_material : e.material
If the dot product is positive then the backface is facing the camera, otherwise it's the front side.
-
@thomthom said:
The result of the dot product can be used to determine if its the front or back side pointing towards the camera.
t = ph.transformation_at(index) n = picked.normal.transform(t).normalize # global vector orientation c = Sketchup.active_model.active_view.camera.direction m = (c % n > 0) ? e.back_material : e.material
If the dot product is positive then the backface is facing the camera, otherwise it's the front side.
Who is
ph
? Who ispicked
? -
ph
is thePickHelper
I used andpicked
is the face picked.It was taken from my test code.
this is a more condensed sample:
back_side = camera.direction % global_face_normal > 0
-
@thomthom said:
Any clues to how to determine that?
Check my FrontFace.
I just compare normals. The global transformation problem is solved by shooting a ray. That allows you to get an array of all parents of a face.
Advertisement