sketchucation logo sketchucation
    • Login
    1. Home
    2. chanz
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    C
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 9
    • Posts 38
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Issues with a simple material copy raycast script

      Thanks again for the reply TIG. Unfortunately, I see the same issues. To verify it wasn't the small differences in faces from DropVertices, I made a copy of the bottom textured model and moved it directly above. I removed the top materials and then ran the script. UV issue is still there. Have you actually downloaded the file and run this script with the top mesh faces selected? Have you seen the UV issues or did it look okay for you? Honestly, I guess I will just give up at this point.

      I have figured out another sort of workaround where I make a sandbox mesh above the original, run this script we wrote (which does perfectly with the texture and UVs when the raycast is from a flat surface), then use UVToolkit to save the UVs, then drop the vertices and then restore the UVs. It works. A few extra steps but this script has been enough of a headache.

      Regardless, thanks for your help.

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      I can see some issues, BUT you need to clarify what face's texture you are copying with UVs and onto which face you apply them...

      Maybe I'm just explaining it wrong, but I don't know how to be more clear about what I'm after. I have uploaded a few pictures about what I'm after as well as a model which allows me to test.

      In the model I have the original on the bottom and the recreated mesh on the top. I want the textures and UVs of the faces on the bottom to be copied to the untextured model above.

      Sorry. Maybe I'm just misunderstanding what you're asking.

      Thanks for being patient.

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      In my earlier version, if I make the to textured and project it onto a lower surface the top one's UV mapping is repeated on the lower surface.
      So I know it works.
      You just need to swap top/bottom properly to apply to you own chosen set up...

      If you use a blank face's UV mapping you won't get what's on the UV-mapped face...

      Try it with just a few facets first...

      Maybe I'm having trouble understanding. I'll use the script you posted and the test model I posted. What was your exact process to get the UVs on the top model looking like the original on the bottom? Maybe our process is just different. I assumed you used the test model I uploaded?

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      So your convention is upper surface has 'no-material', lower surface has 'textures'.
      Unless you known the two meshes have identical faces you can't safely tale a point on an upper facet and project down and be sure of hitting a lower facet...
      But for now let's assume all goes well and we have 'hits', how are you going to get the lower facet's texture ?
      Isn't it better to process each lower textured facet, and project upwards to get a matching upper facet.
      You then need to get the UV mapping for the lower facet, and apply it to the lower facet's material which is applied onto the equivalent upper facet.

      Just think about which is which...

      It really doesn't matter to me which direction is taken. I'm absolutely fine using the method you suggest where we raycast up applying the material and UVs from the raycast source face to the hit face. Works for me.

      I think your edits to my script were doing just that. But I got the same results as mine where the UVs were messed up

      Thinking about it, because I'm using drop vertices and the meshes are nearly identical but not perfectly the same, could that be causing issues with the UVs? Perhaps that's the issue where it copies it just fine but because the faces differ, we get issues.

      So if that's the case, the next questions is how difficult it would be to modify drop vertices to preserve the UVs when it drops. Vertex Tools has a similar feature where you can lock the UVs.

      Would that be an easier approach?

      Thanks as always, TIG.

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      In your image face_below is the 'source' face [the inverse of my assumptions].
      And therefore face_above is the 'target', so your code needs to swap them to suit.
      AND the ' raytest' then needs to follow Z_AXIS.reverse, so it look up NOT down...

      BOTH will work, BUT just be consistent...

      Exactly. So we are raytesting from face_above downwards to face_below (the source) to get the materials and UV. Apologies for the confusion.

      This still has no effect on the UVs though, which are still not working. I have attached the script with the above agreed upon naming convention and additional clarifying comments. Try it in the test scene if you get a chance. Thanks TIG. πŸ˜„


      Fixed naming conventions

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      If you want to recast [all but flip ?] it, so the face_below.material BELOW gets 'projected' onto the face_above... then you firstly need to swap my naming conventions etc, AND also change the Z_AXIS code to project your raytest upward, rather than down...

      I'm sure that if we can agree a common 'framework' this can be resolved...

      Isn't face_above raytesting down to face_below and then sampling the UVs the same as face_below raytesting up to face_above and setting the UVs?

      The original script I had written did the raytest downwards from the face_above and got the material and UV from face_below.

      Here is a terrible illustration to show what I mean:

      https://i.imgur.com/COl2dsP.png

      Either way, it doesn't bother me which way is preferred. All I want is for the Texture mapping uvs to look on the above mesh, just like the below mesh.

      The easiest way to see what I am talking about would be to download the sample project and script I attached. Select the faces in the model that's on top and then run the script.

      Thanks TIG πŸ˜„

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      Hey TIG! Thanks a bunch for the reply πŸ˜„

      I think there was maybe some confusion about what I was trying to accomplish here and perhaps the function name is misleading.

      I have textured terrain from an old game with way too many subdivisions and I want to simplify it. So I make a terrain with the correct size, and then use Drop Vertices to make the terrains the same height. I then move the new terrain up directly over the old terrain and then run my script which would do the raycast and copies from the model below. I think you assumed I would do it the other way around and my function name "Copy Materials -> To Nearest Below" was totally misleading. My apologies.

      I switched the the face arguments in the process_face function and it works again.

      When I run the script, I still get some strange looking results. In the image below, the left is the original and the right is the one that the script made.

      https://i.imgur.com/efmfMP1.png

      Notice that the UV mapping looks quite off, still. If I run the script on a flat sandbox mesh above the original mesh, it copies the UVs fine but I need it to be fine when the mesh is not flat. Or find a way to drop the vertices without messing up the UVs.

      I have reduced the size of the model I am using to test so hopefully you're able to try it with this test case.

      Again, your time is greatly appreciated. Thank you!


      A test scene for this plugin. Select the faces in the top (untextured) model and go to Extensions->Copy Materials->From Nearest Below


      The script with TIG's revisions and the argument order in the process_faces reversed

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      Played around with it a bit more last night. Couldn't find anything that jumped out as incorrect. Does anyone have any more suggestions? Happy to try anything πŸ˜„

      I appreciate it!

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      Read up on this:
      http://ruby.sketchup.com/Sketchup/UVHelper.html
      and this:
      http://ruby.sketchup.com/Sketchup/Face.html#position_material-instance_method

      PS: Please format your code examples using

      [code]...[/code]
      

      rather that

      [ruby]...[/ruby]
      

      It's much easier to read...

      Always wondered why my posts looked so strange right after being posted but then fixed themselves.

      Thanks for the links.

      So what I understand from this block:

      		samples = []
      		samples << face_two.vertices[0].position			   ### 0,0 | Origin
      		samples << samples[0].offset(face_two.normal.axes.x) ### 1,0 | Offset Origin in X
      		samples << samples[0].offset(face_two.normal.axes.y) ### 0,1 | Offset Origin in Y
      		samples << samples[1].offset(face_two.normal.axes.y) ### 1,1 | Offset X in Y
      		xyz = [];uv = []### Arrays containing 3D and UV points.
      		uvh = face_two.get_UVHelper(true, true, texture_writer)
      		samples.each { |position|
      		xyz << position ### XYZ 3D coordinates
      		
      		# I switched this to front_UVQ
      		uvq = uvh.get_front_UVQ(position) ### UV 2D coordinates
      		uv << self.flattenUVQ(uvq)
      		}
      	  
      		pts = [] ### Position texture.
      		(0..3).each { |i|
      		pts << xyz[i]
      		pts << uv[i]
      		}
      	  
      		# set the position and material of face_one
      		mat = face_two.material
      		face_one.position_material(mat, pts, true)
      
      

      From this function that I have adapted from your script, it seems like it should be correct.

      1. Gets the position of the four points from the face which we want to sample (0, 0), (1, 0), (0, 1), and (1, 1)
      2. Put the vertex position and UV coordinates (flattened - not sure why although not flattening had no effect) into two arrays (UVs returned in a point form, but only the x and y are used as u and v).
      3. Interlace these arrays as the position_material function calls for.
      4. Call position_material. Supply the correct material (which I do), the points (which I obviously don't) and true as it is a front face.

      I understand what's going on here. I am a bit confused about why we are flattening the UVs but the math behind the function to do so makes sense.

      Still stumped on what exactly I am getting wrong about the point array...

      Edit: Interestingly, if I just leave the model flat and raycast down, it gets the texture and orientation correct. Now I am wondering if it's the raycast, but I really doubt it...

      Also, it didn't seem to matter if I included just three points (0,0), (0,1) and (1,1) for both the points and uvs.

      Edit: I have attached what I have so far (code wise)


      The latest episode in my endless struggle for simplification πŸ™‚

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      I have found what look like a relevant function in FixReversedFaceMaterials.rb and have adapted it but it doesn't seem to do what I want. I changed the function to accept two faces, the one that needs the correct UVs (face_one) and the other that was hit during the raycast (face_two).

      def self.process_face(face_one, face_two)
        
      	# yes, I can create this outside and pass it in
          texture_writer=Sketchup.create_texture_writer
      	
      	if face_two.material.texture==nil 
      		# no texture on the raycast hit! skip it.
      	else
      	
      		# it looks like we are sampling the uvs from face two - which was hit in the raycast
      		samples = []
      		samples << face_two.vertices[0].position			   ### 0,0 | Origin
      		samples << samples[0].offset(face_two.normal.axes.x) ### 1,0 | Offset Origin in X
      		samples << samples[0].offset(face_two.normal.axes.y) ### 0,1 | Offset Origin in Y
      		samples << samples[1].offset(face_two.normal.axes.y) ### 1,1 | Offset X in Y
      		xyz = [];uv = []### Arrays containing 3D and UV points.
      		uvh = face_two.get_UVHelper(true, true, texture_writer)
      		samples.each { |position|
      		xyz << position ### XYZ 3D coordinates
      		
      		# I switched this to front_UVQ
      		uvq = uvh.get_front_UVQ(position) ### UV 2D coordinates
      		uv << self.flattenUVQ(uvq)
      		}
      	  
      		pts = [] ### Position texture.
      		(0..3).each { |i|
      		pts << xyz[i]
      		pts << uv[i]
      		}
      	  
      		# set the position and material of face_one
      		mat = face_two.material
      		face_one.position_material(mat, pts, true)
      
      
      	end
      end
      

      It does copy the material but the UVs are still incorrect.

      I have left some comments explaining my thought process. I am curious if it's different because yours works on a front face/back face and this is different.

      Thanks for taking a look.

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      Look at this:
      https://sketchucation.com/pluginstore?pln=FixReversedFaceMaterials

      Its code can extract UVs from one side of a face and apply them to the other etc - there are various tools - so you could glean some tips from it...
      Note the flattenUVQ() method it uses to get UVs...

      Thanks for the direction. Will try this tonight. I know there are a ton of really great scripts already written but it's hard to find which actually applies to my current situation.

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      Search my Plugins for Texture and Material...
      There are several regarding repeating UVs on faces etc...

      The best reference I found was TextureTools and I copied over the TextureScale function to fix the difference (value (scale * x = 1) * tile size)) - for example if in the material inspector, the scale is 0.25 and my terrain tile size is 100, then I scale it by 400. It scales up just as I need but of course the UVs are messed up.

      https://i.imgur.com/9am1FW1.jpg

      It really blows my mind that there isn't an easier way to simply slap a texture on a surface. I even tried UV Toolkit with saving the UVs before dropping the vertices and then restoring them and it doesn't do the trick perfectly either.

      Does anyone have any other suggestions? I essentially need it to match the UV mapping of the face that it raycasts to below. I know SketchUp hasn't always been great for UV mapping but I really didn't think this would be so difficult. And plus, it isn't like this is complex mapping...

      Any and all suggestions welcome! As much as I love messing around in a new language, I vastly prefer developing games. If someone wants to take a stab at it perhaps, I would gladly toss 20 euro or dollars their way! πŸ˜„

      posted in Developers' Forum
      C
      chanz
    • RE: Issues with a simple material copy raycast script

      @tig said:

      The faces that keep the default [white] material are triangles.
      If they are right-angled their bounds.center falls on an edge, not a face when projected downwards.
      So you get no face to have a material to 'clone'...
      Perhaps moving a vertex point inwards along the bisector of the vertex's two edges [belonging to that face] by say 1mm and testing that raytest would work ?

      To keep the exact UV mapping of the found texture and applying it to the reused one is convoluted...
      But not impossible.
      Look at some of my Texture Tools...

      Wow! It's TIG himself. Thanks for the help. That fixed the first issue. Great idea.

      For the second one, could you narrow down my search as to what part of TextureTools deals with this?

      In this particular model, each square face is 100m x 100m. If I change the x and y scaling of the material to 100, it looks fine on the recreated terrain but of course messed up on the one below. Clearly I don't want this as when I do it by hand, it works fine. Is there a way to edit the UVs or scaling of the new mesh via script?

      Again, thanks πŸ˜„! Made my day! πŸ˜„

      posted in Developers' Forum
      C
      chanz
    • Issues with a simple material copy raycast script

      Hey guys. I am a full time Unity/C#/C++ developer and I need a plugin and it didn't exist so I tried to take a stab at it. Forgive me if my Ruby isn't up to par πŸ˜„

      I am working with an old game format and to make rendering quicker, they would subdivide the levels based on plane BSP division (similar to how Quake did it). While that was faster back then, it's a lot of overhead now in triangle count and filesize. Here is an example:

      https://i.imgur.com/Z1vgeuz.jpg

      There are a ton of extra divisions. Plugins like CleanUp help a bit but in this case, it would be better to recreate the terrain. I have come up with a workflow where I fix the divisions by creating an equal size terrain via the sandbox tool and then use dropvertices by TIG to get the height correct. Awesome plugin - and it works great.

      The only issue is that I am left to repaint the mesh and it's very time consuming so I wrote a plugin to do it for me.

      The idea is that for every face (really, I want this to be a quad but it looks like it's operating on triangles), we raycast down until we hit another face. Then apply the material.

      This is the starting point:

      https://i.imgur.com/HSomZEq.png

      Here is the code (I edited DropVertices in case it looks familiar):

      MAKE SURE YOU SELECT THE EDGES OF THE MODEL FIRST

      ### CopyBelowMaterials.rb
      ### by Chanz - Based on DropVertices by TIG
      require 'sketchup.rb'
      ###
      module DAN
      ###
      def self.copymaterials()
      
        model=Sketchup.active_model
        ents=model.active_entities
        
        faces = ents.grep(Sketchup;;Face)
      
        faces.each {|x| 
        
          rayt=model.raytest(x.bounds.center, Z_AXIS.reverse)
      	if(rayt)
      
      		rayt[1].each{|entity|
      		
      		if entity.class == Sketchup;;Face
      				x.material = entity.material
      		end
      		}	
      	end
        }
        begin
          model.start_operation("DAN.copymaterials", true)
        rescue
          model.start_operation("DAN.copymaterials")
        end
        model.commit_operation
      end
      ###
      ### menu
      unless file_loaded?(File.basename(__FILE__)) 
        menu=UI.menu("Plugins").add_submenu("Copy Materials...")
        menu.add_item("To Nearest Below"){DAN.copymaterials()}
      end
      file_loaded(File.basename(__FILE__)) 
      
      end
      

      Here are the results:

      https://i.imgur.com/iazCdpx.png

      I am however having some issues.

      1. A bunch of faces have no material. It seems like all raycasts are hitting below so I am not sure what the deal is. A lot of the triangle faces are white.

      2. The texture scaling seems to be wrong (so it looks like a solid color). If I sample the below material by hand and then apply it directly to my model, it looks fine. Not sure how to resolve this issue.

      Any ideas? I have attached the test scene and plugin. Thanks πŸ˜„


      The plugin


      The file to test. Make sure you select all edges first

      posted in Developers' Forum
      C
      chanz
    • RE: [Plugin] OBJexporter v3.0 20130131

      Looks like vertex merging was added in the latest version. Anyone know if we can find older versions?

      2.9 20130130 Merging of shared vertices is now optional, as it slows processing
      for larger models.

      posted in Plugins
      C
      chanz
    • RE: [Plugin] OBJexporter v3.0 20130131

      @andybot said:

      The first versions definitely didn't weld vertices. I recall vividly because it added extra steps for me when exporting. It doesn't look like any of those older versions are here though. You might find it floating around on the web in some older plugin repositories.

      Thanks for the reply. While I have you here, is vertex welding something that SketchUp does internally? I am having issues where I need to load an OBJ and then export the OBJ without any modification to the vertices at all. No optimizations for any reason as I render using texture arrays and need the unique vertices to set the texture index. I wrote a post in the main forum but nobody has replied yet. Figured I would ask.

      Thanks πŸ˜„

      posted in Plugins
      C
      chanz
    • RE: [Plugin] OBJexporter v3.0 20130131

      Hi TIG,
      Does this plugin do any sort of vertex welding? I am noticing that vertices are welded/combined somewhere in the import/edit/export process with the native SketchUp exporter. Of course for most people, it's a welcomed optimization but for me, I need to keep the vertices unique.

      Thanks πŸ˜„

      posted in Plugins
      C
      chanz
    • Sketch-Up welds vertices during export/edit process

      I am working on models for old game formats. Because I am rendering these using texture arrays in external programs, I need every vertex to be unique even if it shares the same XYZ and UV coordinates. Whenever I try to load an .obj exported form Sketchup, there are issues as some of the vertices have been welded together and this causes issues with the texture array interpolation over this triangle.

      I tried three different OBJ import methods and they all seem to have the same result - and I don't think there is any work being done behind the scenes during import. I assume then it's during the export process that it thinks "hey, these two vertices are in the same place, why not combine them..."

      How can I force Skecthup to not combine or weld the vertices and how can I make it export them? Essentially I want to be able to load an .obj and export it and have virtually the same result.

      Thanks!

      posted in SketchUp Discussions sketchup
      C
      chanz
    • RE: Adopt texture from face directly below

      Thank you guys for the suggestions and replies. Unfortunately, I need the model to not have just 1 texture but to retain it's original tile texturing. Do I have any other options? Does Thrupaint have anything here that can help me? Is there any way I can paint through surfaces to all faces that are under the drop bucket tool?

      posted in SketchUp Discussions
      C
      chanz
    • RE: Adopt texture from face directly below

      Looks like this might be a bit more complicated than I thought. πŸ˜„ Does anyone have any idea? Or, can anyone confirm that the idea I have for the script would work?

      posted in SketchUp Discussions
      C
      chanz
    • 1
    • 2
    • 1 / 2