All faces with their backs facing the camera.
-
how to get a list of all faces with their backs facing the camera. PLEASE HELP
or even a list with all faces facing the camera -
@morci429 said:
how to get a list of all faces with their backs facing the camera. PLEASE HELP
or even a list with all faces facing the camera<span class="syntaxdefault">model</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />camera</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">camera<br />eye</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">camera</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">eye<br />target</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">camera</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">target<br />sline</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">eye</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vector_to</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">target</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">ffaces</span><span class="syntaxkeyword">=[];</span><span class="syntaxdefault">bfaces</span><span class="syntaxkeyword">=[];</span><span class="syntaxdefault">sfaces</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> next if e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">class </span><span class="syntaxkeyword">!=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face<br /> if sline</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">angle_between</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">></span><span class="syntaxdefault"> 90</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">degrees<br /> ffaces </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> e<br /> elsif sline</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">angle_between</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> 90</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">degrees<br /> bfcaes </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> e<br /> else </span><span class="syntaxcomment">### square-on<br /></span><span class="syntaxdefault"> sfaces </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> e<br /> end</span><span class="syntaxcomment">#if<br /></span><span class="syntaxkeyword">}</span><span class="syntaxdefault"> </span>
The 'ffaces' faces have their fronts to camera, the 'bfaces' faces have their backs facing the camera, and 'sfaces' faces are exactly perpendicular to the camera's sight-line. Do what you need with these array lists of faces........
-
Great, i'm testing it now.
i think i found a good solution to the faces front and back problem.
if we can get all faces facing the camera we can then use Tomasz http://www.google.com/support/forum/p/sketchup/thread?tid=22305a97ab418668&hl=en code to make sure they are facing the camera and then we can use TIG's http://forums.sketchucation.com/viewtopic.php?p=15273#p15273code to orient all the faces Contagious by each face.What do you think TIG?
-
TIG,
In general you can't do this test in an orthogonal world space - as in your code.
Imagine looking into a cube with a perspective view. Clearly, the sides are perpendicular to the camera view yet because of perspective foreshortening, you can also see them.
Perhaps the OP can explain more about what they're trying to do.
Adam
-
Didn't work.
I think i asked for the wrong thing.
If we can have a list of all the faces that the camera can see. not the ones that their normals towards the camera. -
@adamb said:
TIG,
In general you can't do this test in an orthogonal world space - as in your code.
Imagine looking into a cube with a perspective view. Clearly, the sides are perpendicular to the camera view yet because of perspective foreshortening, you can also see them.
Perhaps the OP can explain more about what they're trying to do.
Adam
IF he wants to list those faces he can actually 'see' the front/back of, then he needs to test the vector from the eye location to say face.bounds.center and compare face.normal with that. It will return faces that could not really be seen if there's an intervening face... To trap for that you need to do model.raytest([eye, vector]) where vector is to bb.center and perhaps all of the bb corners too. This then opens up a complete new can of worms as what do we do if the intervening face has a hole in it and we could see part of the face behind... testing a fine grid of points over the face until we get a positive raytest could take forever... I'm sure there are some clever ways... but we DO need to know exactly why he's asking for these lists as what he now has might be sufficient ???
-
Okay here's what i'm trying to do.
I’m trying to solve the front back faces problem with one plugin
Some of the buildings faces are fliped facing the inside of the building.
i'm trying to make a plugin to flip all the faces that are facing the inside of the building.
Looking at what others did "Tomaz" he made this tool that basically Hoover over faces and make sure their front side is facing the camera. Applying the same thing on all the faces in the model while the camera is in the right side for example would get all the faces to look at the camera.
but if we can get a list of only what the faces the camera can see then we can make sure their front face facing the camera and then use the TIG code of “orient_faces” to flip all the rest of the faces connected to each one in the list.
Does it make any sense? -
This would only ever work if the object is guaranteed as 'manifold', with no internal partitions etc - just try manually 'orienting' a face that has more that one other face sharing one of its edges to see the disastrous effects that non-manifold forms have on any 'orient' tool...
IF the object is manifold then simply making one face the right way round using 'reverse' [if needed], and then using 'orient' with that would ensure the whole thing is corrected. I use two short cut keys to do this all the time...
You are searching for the holy grail that doesn't exist...
The built-in tools work just fine IF the thing is manifold and it not then it will always break somehow - you can't code your way out of it ?? -
i now my idea sounds insane but it could be a good way for those who model building as boxes with no details inside them.
But really thank you for all the great help
Advertisement