• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

How to get face uvs if texture is applied to component inst

Scheduled Pinned Locked Moved Developers' Forum
18 Posts 5 Posters 607 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.
  • J Offline
    jbacigalupa
    last edited by 23 Nov 2009, 17:48

    I'm writing some ruby scripts related to faces and uvs. I am unsure how to get uv information from my faces when the material is not directly applied to the face. Here is my test scenario.

    1. Make a circle and extrude it to be a cylinder
    2. Select the cylinder and make it a component
    3. Apply a texture material to that component instance
    4. Adjust the texture's uv repeat information as needed

    The only way I can get the uv information is if I manually apply the component instance's material to the faces prior to loading them into a TextureWriter and grabbing a UVHelper, etc. The problem with this is when I call face.material= or face.back_material= it apparently makes the edge smooth tool think that this face is no longer part of a curve and I get faceted edges.

    So I'm kinda stuck between a rock and a hard-place. I can either have correct uv information but any curved surfaces get screwed up, or I can have smooth surfaces with no uv information. I guess the third option is I can force people to apply textures to the faces only - but I don't like forcing odd things like this on the users...especially if it appears correctly in the Sketchup viewport.

    I must be missing something simple - so hopefully someone can clear this up for me. How can I get uv information for the "actual" material that is being used on the face?

    If you need any clarification feel free to ask - I'd really like to solve this issue. I could probably write a quick script to fully demonstrate the problem, but I figured I would see if anyone had run into this issue before I did that.

    Thanks!

    Joe Bacigalupa

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 23 Nov 2009, 18:00

      I thought this issue sounded familiar. Then I read your name. πŸ˜‰
      Hi there Joe.

      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
        thomthom
        last edited by 23 Nov 2009, 18:06

        @jbacigalupa said:

        The problem with this is when I call face.material= or face.back_material= it apparently makes the edge smooth tool think that this face is no longer part of a curve and I get faceted edges.

        The adjacent becomes faceted? How do you mean? If I set a face' material on a cylinder's smooth surface, the edges still report back .soft? and .smooth?
        Are you seeing something differently? Or are you measuring faceted differently?

        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
          thomthom
          last edited by 23 Nov 2009, 18:32

          I'm looking at the UV data returned for faces with Default material. The values seems to be related to inches from the containing group/component or model.

          UVdata.png
          This cylinder is 100" above ground, and 100" tall. Notice the V value for that face. What is you took the UV values for faces with default material and divided by the width and height of the Material.texture?

          Will that give matching UV data? If so, then that should be a lot faster than applying the material to the faces, sample UV data, then remove it again.

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

          1 Reply Last reply Reply Quote 0
          • J Offline
            jbacigalupa
            last edited by 23 Nov 2009, 18:33

            @thomthom said:

            I thought this issue sounded familiar. Then I read your name. πŸ˜‰
            Hi there Joe.

            Hey Thom πŸ˜„ I was going to post this on the Sketchup api site but it looks like they don't really have a Ruby section any more. Devin suggested I check this site out instead.

            @thomthom said:

            The adjacent becomes faceted? How do you mean? If I set a face' material on a cylinder's smooth surface, the edges still report back .soft? and .smooth?
            Are you seeing something differently? Or are you measuring faceted differently?

            Let me show you a picture of what I get on my end...

            This is when I apply a material to the component instance:

            http://img267.imageshack.us/img267/139/facets.jpg

            This is when I apply the material directly to the faces:

            http://img692.imageshack.us/img692/2356/nofacets.jpg

            You can see the outline of the faces completely in render 1 - and in render 2 you can't. So that is where my assumption about the smooth tool came from. I am not sure if thats what it is but it seems like I'm breaking a "connection" or something when I modify the material. Maybe if I could do a batch material apply operation it would work out better...but since this is just a workaround to get uv info I don't want to muck around too much with the person's scene.

            Joe Bacigalupa

            1 Reply Last reply Reply Quote 0
            • J Offline
              jbacigalupa
              last edited by 23 Nov 2009, 18:35

              @thomthom said:

              Will that give matching UV data? If so, then that should be a lot faster than applying the material to the faces, sample UV data, then remove it again.

              Yeah I'd imagine I could just homebrew my own uv information but I'd rather just use theirs if possible. I am not sure if your solution would take into account the various translations, etc, that can be done with textures on faces.

              Joe Bacigalupa

              1 Reply Last reply Reply Quote 0
              • W Offline
                Whaat
                last edited by 23 Nov 2009, 18:37

                You can get the UVs by extracting the PolygonMesh object from the face. (Face.mesh)

                The UVs that you will get will need to be divided by the texture size that is set using the SketchUp materials editor. If the texture is applied directly the face, you can get the UVs directly (i.e. not dividing by the texture height and width).

                SketchUp Plugins for Professionals

                1 Reply Last reply Reply Quote 0
                • J Offline
                  jbacigalupa
                  last edited by 23 Nov 2009, 18:40

                  @whaat said:

                  The UVs that you will get will need to be divided by the texture size that is set using the SketchUp materials editor. If the texture is applied directly the face, you can get the UVs directly (i.e. not dividing by the texture height and width).

                  Ok I will give that a shot, I thought I was just getting garbage uvs...I hadn't thought that they were the actual uvs just not set to the proper repeat value. Wow...

                  I'll let you know how this goes.

                  Joe Bacigalupa

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 23 Nov 2009, 19:01

                    I did a quick test. I took the UV data from the faces with default material, and divided them with the Height and Width of the components material's texture, and then used position_material. The mapping seemed to be identical.


                    UVmappingDefault.png


                    default_uv.rb

                    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
                      thomthom
                      last edited by 23 Nov 2009, 19:04

                      @jbacigalupa said:

                      You can see the outline of the faces completely in render 1 - and in render 2 you can't. So that is where my assumption about the smooth tool came from. I am not sure if thats what it is but it seems like I'm breaking a "connection" or something when I modify the material. Maybe if I could do a batch material apply operation it would work out better...but since this is just a workaround to get uv info I don't want to muck around too much with the person's scene.

                      I've seen that happen. But I don't understand why. What do you do to determine if two faces should be smoothed?
                      As mentioned, the edge.smooth? and edge.soft? seem to remain true after you apply a material to the faces connected to it.

                      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
                        thomthom
                        last edited by 23 Nov 2009, 19:08

                        @whaat said:

                        You can get the UVs by extracting the PolygonMesh object from the face. (Face.mesh)

                        The UVs that you will get will need to be divided by the texture size that is set using the SketchUp materials editor. If the texture is applied directly the face, you can get the UVs directly (i.e. not dividing by the texture height and width).

                        Ah! Didn't see that post. Seems to confirm my theory and testing.

                        I guess this means, the parsing of groups/components with materials applied to them won't produce such an overhead any more. πŸ˜„

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

                        1 Reply Last reply Reply Quote 0
                        • dkendigD Offline
                          dkendig
                          last edited by 23 Nov 2009, 19:30

                          Shhh, don't jinx it... Joe got sucked off to a meeting, but we have managed to render a sphere with no faceting so far! I don't know what kind of impact this will have on scene parsing... fingers are crossed.

                          Devin Kendig
                          Developer

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            jbacigalupa
                            last edited by 23 Nov 2009, 20:25

                            @thomthom said:

                            I guess this means, the parsing of groups/components with materials applied to them won't produce such an overhead any more. πŸ˜„

                            πŸ˜„ Yeah - so far it looks like the width/height divide was all we needed. Thanks to Whaat and ThomThom for your help - that issue has annoyed me for so long.

                            I wish I came to this forum sooner!

                            Joe Bacigalupa

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              thomthom
                              last edited by 23 Nov 2009, 22:44

                              @whaat said:

                              You can get the UVs by extracting the PolygonMesh object from the face. (Face.mesh)

                              The UVs that you will get will need to be divided by the texture size that is set using the SketchUp materials editor. If the texture is applied directly the face, you can get the UVs directly (i.e. not dividing by the texture height and width).

                              Doesn't a PolygonMesh return only triangles? Can you get UV data for distorted textures from just 3 points?
                              Face.position_material requires four samples to set a distorted texture.

                              Here, sample file:
                              uv_sample.skp

                              It contains two identical faces, both triangles. One face has a distorted texture, the other not.

                              uv_sample.rb
                              This script has two different methods to copy the UV mapping from the one face to the other.
                              Select the two faces, ensure one of them does not have a material applied, and try out the following two methods.

                              sample_vertex - samples UV data from the three vertices of the triangle. Notice that the transferred texture does not match.

                              sample_plane - Picks four points from the face's plane. Notice that the transferred texture is identical.

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

                              1 Reply Last reply Reply Quote 0
                              • W Offline
                                Whaat
                                last edited by 24 Nov 2009, 01:46

                                thomthom:

                                have you released that UV inspector plugin that you show in one of your posts above? I was looking for it the other day and I couldn't find it. It would be really useful to me.

                                SketchUp Plugins for Professionals

                                1 Reply Last reply Reply Quote 0
                                • N Offline
                                  nomeradona
                                  last edited by 24 Nov 2009, 05:50

                                  seems were having a good news for vraysu here.... β˜€

                                  visit my blog: http://www.nomeradona.blogspot.com

                                  1 Reply Last reply Reply Quote 0
                                  • T Offline
                                    thomthom
                                    last edited by 24 Nov 2009, 07:29

                                    @whaat said:

                                    thomthom:

                                    have you released that UV inspector plugin that you show in one of your posts above? I was looking for it the other day and I couldn't find it. It would be really useful to me.

                                    http://forums.sketchucation.com/viewtopic.php?f=180&t=21472

                                    Though, I just noticed some weirdness when probing through groups/components. When I was testing the cylinder I'd draw the info correctly for every other face. πŸ˜• Need to track down a bug there.

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

                                    1 Reply Last reply Reply Quote 0
                                    • W Offline
                                      Whaat
                                      last edited by 24 Nov 2009, 14:13

                                      Thanks Thomas!

                                      SketchUp Plugins for Professionals

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

                                      Advertisement