sketchucation logo sketchucation
    • Login
    ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

    PolygonMesh behavior

    Scheduled Pinned Locked Moved Developers' Forum
    34 Posts 7 Posters 1.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      dvonhausen
      last edited by

      I am writing an obj exporter. I notice that the normals for each vertice from PolygonMesh is different depending on whether I first run Google's obj exporter using:
      "Sketchup::active_model.export(objFileName,false)"

      If I run my exporter without running Google's exporter, the normal for all the vertices of a face from PolygonMesh are the same which is just the normal for the face itself producing a faceted render.

      However, if I run my exporter after running Google's exporter on the same object, the normal for all the vertices of any face from PolygonMesh are different producing a smooth face. This tells me that Google's exporter takes into account smooth edges that are connected to a vertice when computing a normal for a vertice and stores it somewhere that PolygonMesh can assess but there is nothing in the doc to suggest this.

      Does anyone know why this is and where are the normals for vertices stored when exporting? Any doc or examples?

      Thanks

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        This is odd...

        Are you saying that the face normal doesn't depend on the order which the vertices of the PolygonMesh is added?

        When you say it produces a smooth face - in SU? Or in the app that imports the OBJ you export?

        AFIK, the only way to smooth a PolygonMesh was to specify Soft+Smooth when you add the mesh to the model. I've not seen any methods of smoothing individual polygons in a mesh - though I'd very much like to have that control.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • mitcorbM Offline
          mitcorb
          last edited by

          Pardon my eavesdropping, but exactly how would I visualize a vertex normal? I can visualize a face normal, even an edge normal under some conditions. Or is it sort of like a tesseract?

          I take the slow, deliberate approach in my aimless wandering.

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @mitcorb said:

            Pardon my eavesdropping, but exactly how would I visualize a vertex normal? I can visualize a face normal, even an edge normal under some conditions. Or is it sort of like a tesseract?

            I did that for Vertex Tools, I take the average normal of the faces connected to the vertex.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • AdamBA Offline
              AdamB
              last edited by

              @thomthom said:

              I did that for Vertex Tools, I take the average normal of the faces connected to the vertex.

              You're missing a step with your averaging there. You need to weight by the contribution each face connected to the vertex makes - ie weight by the interior angle otherwise a cube constructed of triangles will end up with vertex normals not all pointing out exactly at 45 degrees.

              Developer of LightUp Click for website

              1 Reply Last reply Reply Quote 0
              • S Offline
                soldatino
                last edited by

                I am sorry but I use this topic because it seems to be about my question.
                I make a solid using the help example for smooth surfaces (6 sides), then I push for the elevation, then I select all the object, then I apply Soften edges angle 79,0 degrees, and the edge appear soft.
                But if I get the normals at each point I read always (0, 0, 0), that is not a valid vector.
                Sorry, where I am wrong?

                 
                for np in 1..numpol do
                  vertices=mesh.polygon_at np
                  numvrtx=vertices.length - 1
                  for eachvrtx in 0..numvrtx do
                    x = mesh.point_at((vertices[eachvrtx]).abs).x*RatioPov
                    y = mesh.point_at((vertices[eachvrtx]).abs).y*RatioPov
                    z = mesh.point_at((vertices[eachvrtx]).abs).z*RatioPov
                
                
                    nx = mesh.normal_at (eachvrtx+1) #index is base 1
                    UI.messagebox(nx.to_s)
                

                r3nDer tools

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  @soldatino said:

                  I make a solid using the help example for smooth surfaces (6 sides

                  Which example?

                  @soldatino said:

                  But if I get the normals at each point

                  I think that .normal_at( index ) refer to the normal of a polygon - not point...

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    soldatino
                    last edited by

                    Error 404 (Not Found)!!1

                    favicon

                    (code.google.com)

                    but this is about points "particular index in the mesh."
                    Or it is for each face? In this case I have to calculate each angle between vertexes of adjacent faces?
                    Anyway the vector that I get is 0,0,0, but the faces have smooting in SU.
                    http://sketchup.google.com/support/bin/answer.py?hl=it&answer=114941
                    the procedure is explained in the yellow window..

                    r3nDer tools

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      I think "particular index in the mesh." refer to the index of polygons.

                      @soldatino said:

                      Anyway the vector that I get is 0,0,0, but the faces have smooting in SU.

                      Normals in SketchUp does not relate the smoothing. Normals are always perpendicular to the face/polygon.

                      To find out of the mesh has smooth edges use PolygonMesh.polygon_at http://code.google.com/intl/it/apis/sketchup/docs/ourdoc/polygonmesh.html#polygon_at or PolygonMesh.polygons http://code.google.com/intl/it/apis/sketchup/docs/ourdoc/polygonmesh.html#polygons

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        soldatino
                        last edited by

                        yes, thanks, pointing at the face I get the float values of the vector.
                        Now if it is a offset valid for all the points of each face, I have to find the common points of adjacent faces, and interpolate their offsets to get the vector for the points. A lot of work... do yo think it is right?

                        r3nDer tools

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          Think so - SU doesn't provide vertex normals.
                          When I wrote Vertex Tools I have to work them out manually from the connected faces.

                          Thomas Thomassen — SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 Reply Last reply Reply Quote 0
                          • TIGT Offline
                            TIG Moderator
                            last edited by

                            Look at a vertex.
                            Get its faces.
                            Get the normals of the faces [lets say there are 3 of them].
                            Combine the faces' normals [vectors] using v = v1 + v2 + v3
                            Now 'v' should be the combined-vector at that vertex [the vertex-normal?]...
                            Test it using entities.add_line(vertex.position,v.to_a)
                            which should draw a line at the vertex along the direction of the combined-vector 'v'...

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • S Offline
                              soldatino
                              last edited by

                              thomthom, TIG, thanks. I will attempt to write this in Ruby, even if I dont know much of this language, to do it with a post editor would be very easy, storing the array of all the normals of every face as comments within the ouput of the points ...

                              note: Vertex.used_by? in a loop of all connected faces ? waiting for the eternity...

                              r3nDer tools

                              1 Reply Last reply Reply Quote 0
                              • thomthomT Offline
                                thomthom
                                last edited by

                                @soldatino said:

                                note: Vertex.used_by? in a loop of all connected faces ? waiting for the eternity...

                                ❓

                                Thomas Thomassen — SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund

                                1 Reply Last reply Reply Quote 0
                                • S Offline
                                  soldatino
                                  last edited by

                                  @thomthom said:

                                  @soldatino said:

                                  note: Vertex.used_by? in a loop of all connected faces ? waiting for the eternity...

                                  ❓

                                  I am worried because I think that with large model the time required will be huge.
                                  Addictionally I would not repeat the calculation for the same point when the loop scans the already involved faces, but if I do not want to repeat I have to save an array for all the entities, containing normals already calculated, and to scan it also, which could be worse...

                                  r3nDer tools

                                  1 Reply Last reply Reply Quote 0
                                  • thomthomT Offline
                                    thomthom
                                    last edited by

                                    What are you doing? An exporter?

                                    Thomas Thomassen — SketchUp Monkey & Coding addict
                                    List of my plugins and link to the CookieWare fund

                                    1 Reply Last reply Reply Quote 0
                                    • thomthomT Offline
                                      thomthom
                                      last edited by

                                      <span class="syntaxdefault"><br />&nbsp;&nbsp;</span><span class="syntaxkeyword">for&nbsp;</span><span class="syntaxdefault">eachvrtx&nbsp;in&nbsp;0.</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">numvrtx&nbsp;</span><span class="syntaxkeyword">do<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">x&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">mesh</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">point_at</span><span class="syntaxkeyword">((</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">eachvrtx</span><span class="syntaxkeyword">]).</span><span class="syntaxdefault">abs</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br />&nbsp;&nbsp;&nbsp;&nbsp;y&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">mesh</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">point_at</span><span class="syntaxkeyword">((</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">eachvrtx</span><span class="syntaxkeyword">]).</span><span class="syntaxdefault">abs</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">y</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br />&nbsp;&nbsp;&nbsp;&nbsp;z&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">mesh</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">point_at</span><span class="syntaxkeyword">((</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">eachvrtx</span><span class="syntaxkeyword">]).</span><span class="syntaxdefault">abs</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">z</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br /></span>
                                      

                                      Change into this

                                      <span class="syntaxdefault"><br />&nbsp;&nbsp;</span><span class="syntaxkeyword">for&nbsp;</span><span class="syntaxdefault">eachvrtx&nbsp;in&nbsp;0.</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">numvrtx&nbsp;</span><span class="syntaxkeyword">do<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">pt&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">mesh</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">point_at</span><span class="syntaxkeyword">((</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">eachvrtx</span><span class="syntaxkeyword">]).</span><span class="syntaxdefault">abs</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">x&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br />&nbsp;&nbsp;&nbsp;&nbsp;y&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">y</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br />&nbsp;&nbsp;&nbsp;&nbsp;z&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">z</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br /></span>
                                      

                                      Should be a little bit faster.

                                      Thomas Thomassen — SketchUp Monkey & Coding addict
                                      List of my plugins and link to the CookieWare fund

                                      1 Reply Last reply Reply Quote 0
                                      • S Offline
                                        soldatino
                                        last edited by

                                        This is a part of my exporter to POV-Ray. Yes, now I apply your suggestion !

                                        r3nDer tools

                                        1 Reply Last reply Reply Quote 0
                                        • S Offline
                                          soldatino
                                          last edited by

                                          SenzaTitoloSTa.jpg

                                          17/11/2010 10:03:00
                                          //Ending at 17/11/2010 10:03:18

                                          17/11/2010 10:09:00
                                          //Ending at 17/11/2010 10:09:18

                                          28935 faces
                                          Later I will check on largest files...

                                          r3nDer tools

                                          1 Reply Last reply Reply Quote 0
                                          • T Offline
                                            tomasz
                                            last edited by

                                            @thomthom said:

                                            Think so - SU doesn't provide vertex normals.

                                            You are wrong Thomas!
                                            Check this :
                                            polygonmesh.normal_at(vertex_index)

                                            Soldatino, your exporter will work faster now 😄
                                            I think that is what you have been looking for, unless you want to do vertex welding.

                                            Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement