How to judge whether a 3D point is visible or not
-
Hi everyone,
Suppose I have opened the Sketchup software, I want to know whether a 3D point is visible or not in current view.
For example, the 3D point may locate on the back of a person, thus we can't see it when the person facing to us.This should be done by Sketchup ruby code.Could anyone help me?
-
@lbsswu said:
Hi everyone,
Suppose I have opened the Sketchup software, I want to know whether a 3D point is visible or not in current view.
For example, the 3D point may locate on the back of a person, thus we can't see it when the person facing to us.This should be done by Sketchup ruby code.Could anyone help me?
I placed a construction point, the little black dot just below the horizon, and "Nancy" in the model. I then used the following code to test if the point was visible.
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection vue = mod.active_view eye = vue.camera.eye cp = ent.grep(Sketchup;;ConstructionPoint)[0] pt = cp.position vec = pt.vector_to(eye) hit = mod.raytest([pt,vec]) if hit puts "pt is not visible" else puts "pt is visible" end


-
@sdmitch, is the logic reversed in your test on hit? I think raytest returns nil if the point is not visible.
OK, I'm confused...unfortunately, the Ruby API site is not responding right now (server issues?) so I can't look at the documentation for raytest.
-
if the ray "hits" something then that means that that object must be between the point and the camera. If there are no obstructions then raytest will return nil.
-
@sdmitch said:
if the ray "hits" something then that means that that object must be between the point and the camera. If there are no obstructions then raytest will return nil.
Yeah, I figured that out by experimentation since I can't get to the docs. Thanks!
-
@sdmitch said:
@lbsswu said:
Hi everyone,
Suppose I have opened the Sketchup software, I want to know whether a 3D point is visible or not in current view.
For example, the 3D point may locate on the back of a person, thus we can't see it when the person facing to us.This should be done by Sketchup ruby code.Could anyone help me?
I placed a construction point, the little black dot just below the horizon, and "Nancy" in the model. I then used the following code to test if the point was visible.
mod = Sketchup.active_model > ent = mod.active_entities > sel = mod.selection > vue = mod.active_view > eye = vue.camera.eye > cp = ent.grep(Sketchup;;ConstructionPoint)[0] > pt = cp.position > vec = pt.vector_to(eye) > hit = mod.raytest([pt,vec]) > if hit > puts "pt is not visible" > else > puts "pt is visible" > end >Hi, sdmitch. Thank you very much. It works!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement