sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    PolygonMesh behavior

    Scheduled Pinned Locked Moved Developers' Forum
    34 Posts 7 Posters 1.7k Views 7 Watching
    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.
    • 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
                      • thomthomT Offline
                        thomthom
                        last edited by

                        @unknownuser said:

                        @thomthom said:

                        Think so - SU doesn't provide vertex normals.

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

                        ?

                        From the docs I see nothing that indicate vertex index. http://code.google.com/apis/sketchup/docs/ourdoc/polygonmesh.html#normal_at
                        Saying that - it doesn't even say if it's polygon index.

                        Tomaz: you got a working example?

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

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

                          @thomthom said:

                          Toma**s**z: you got a working example?

                          Yep. SU2TH 😄

                          You have to extract a triangle indexes using
                          tri_indexes=polygonmesh.polygon_at(mesh_index)
                          and then
                          normal0=tri.normal_at(tri_indexes[0]) normal1=tri.normal_at(tri_indexes[1]) normal2=tri.normal_at(tri_indexes[2])

                          The docs are .... terribly bad, you know that you can't rely on them 😄

                          Now you know how to use it and speed-up your plugins.

                          EDITED. I was terribly wrong 😄 It is correct now.

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

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

                            I can't get it working...
                            PolygonMeshNormals.png

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

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

                              Do not count_points, count_polygons instead.
                              1 .. mesh.count_polygons
                              then

                              {
                              tri_indexes=mesh.polygon_at(i)
                              (0..2).each{|q| p mesh.normal_at(tri_indexes[q])}
                              }
                              

                              EDIT.
                              use mesh 7 to ensure you get also normals. Doc doesn't say what is a default flag.

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

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

                                But when you do 1 .. mesh.count_polygons you iterate over the polygons. And mesh.polygon_at(i) returns an array of point (vertex) indexes - which are the same indexes you get when you iterate mesh.count_points...

                                ??

                                PMIndex.png

                                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

                                  @unknownuser said:

                                  EDIT.
                                  use mesh 7 to ensure you get also normals. Doc doesn't say what is a default flag.

                                  Ah! Yes - of course. Now I get normals.

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

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

                                    Correct. They are same indexes, but now they define a triangle. In exporter you usually export triangles not a cloud of points...

                                    Have you used mesh(7)? Maybe this is why it returns Vector3d(0,0,0) instead of Vector3d(0,-1,0)?

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

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

                                      @unknownuser said:

                                      Have you used mesh(7)? Maybe this is why it returns Vector3d(0,0,0) instead of Vector3d(0,-1,0)?

                                      Ja - it worked then. I'm guessing that was the same reason Soldatino got 0,0,0 normals as well.

                                      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

                                        Thanks Tomasz and others!
                                        Wow, I was away some time!
                                        It seems it is possible, even if my english is terrible I think to understand something...
                                        thomthom, exactly I had the same your results...

                                        About the
                                        x = mesh.point_at((vertices[eachvrtx]).abs).xRatioPov
                                        Y = mesh.point_at((vertices[eachvrtx]).abs).y
                                        RatioPov
                                        z = mesh.point_at((vertices[eachvrtx]).abs).z*RatioPov
                                        instead of

                                        pt = mesh.point_at((vertices[eachvrtx]).abs)

                                        x = pt.x*RatioPov

                                        y = pt.y*RatioPov

                                        z = pt.z*RatioPov

                                        I cannot confirm the better time of the second way... I understand that it seems impossible but my tests are different...
                                        If I dont resolve I will send you my entire code of the plugin...

                                        r3nDer tools

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

                                          @soldatino said:

                                          I cannot confirm the better time of the second way.

                                          It was just a general suggestion. When I was doing Vertex Tools I spend quite some time looking at performance - and when you do lots of iterations you can some times save some time by avoiding doing multiple lookups.
                                          But overall gain will depend on what else your code is - there could be parts that offsets the performance gain too much.
                                          If you want you can PM me the code and I can have a look at it.

                                          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:

                                            I cannot confirm the better time of the second way.

                                            It was just a general suggestion. When I was doing Vertex Tools I spend quite some time looking at performance - and when you do lots of iterations you can some times save some time by avoiding doing multiple lookups.
                                            But overall gain will depend on what else your code is - there could be parts that offsets the performance gain too much.
                                            If you want you can PM me the code and I can have a look at it.

                                            Yes I do!
                                            HI, the normals are workin ! With flag 7 I got them !
                                            The code is the output for POV-Ray (the normals are as // NOTE at this moment...)
                                            triangle{<1.0,0.0,1.0><0.0,0.0,0.0><0.0,0.0,1.0>
                                            // normal (0.0, 0.0, -1.0)
                                            pigment{color rgb 1} finish{SkUpLight}}
                                            triangle{<0.0,0.0,0.0><1.0,0.0,1.0><1.0,0.0,0.0>
                                            // normal (0.0, 0.0, -1.0)
                                            pigment{color rgb 1} finish{SkUpLight}}
                                            triangle{<1.0,1.0,0.0><0.0,1.0,1.0><0.0,1.0,0.0>
                                            // normal (0.0, 0.0, 1.0)
                                            pigment{color rgb 1} finish{SkUpLight}}
                                            triangle{<0.0,1.0,1.0><1.0,1.0,0.0><1.0,1.0,1.0>
                                            // normal (0.0, 0.0, 1.0)
                                            pigment{color rgb 1} finish{SkUpLight}}
                                            triangle{<0.0,1.0,1.0><0.0,0.0,0.0><0.0,1.0,0.0>
                                            // normal (-1.0, 0.0, 0.0)
                                            pigment{color rgb 1} finish{SkUpLight}}
                                            triangle{<0.0,0.0,0.0><0.0,1.0,1.0><0.0,0.0,1.0>
                                            // normal (-1.0, 0.0, 0.0)
                                            pigment{color rgb 1} finish{SkUpLight}}

                                            r3nDer tools

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

                                            Advertisement