Texture inconsistent on the same component in different locations


#1

Happy Friday,

I have a question regarding textures on components using Ruby script. Please see the image below:

All three of these components are created using the same code, but the only difference is their positioning. The texture on the back-right component is how it is supposed to look, and the geometry for that component is based off the point [0,0,0]. But once the component is moved the texture gets distorted.

The texture that I’m using is an .skm file that I created from a jpeg.

Is there a known way to fix this issue?


Applying a material to a specific Face within a Group
#2

I can’t answer from a Ruby standpoint but it looks to me as if you are applying the texture to the component container instead of the surface. Is that correct? If you apply it to the surface, you wouldn’t have that issue.


#3

From your other thread …


#4

Dave, you are correct, and applying the material to the surface is the solution I am looking for. Now my issue is that I am not sure what the ruby code would be to apply the texture to the surface since that surface is not named. The above components are created from pushpulling the bottom face. Do you happen to know of any code I can use to select the front face of my component?

Thank you.


#5

Hi Dan, is it possible to specify one of the faces on a component after it has been pushpulled? If I could call out just the front face of my component I believe that I could just apply the material to that face. Is this correct?

Currently my components are created by creating the bottom face, applying a material, and then pushpulling the face a certain distance up.


#6

Sure you can. In fact it cannot be done before the pushpull, because those face(s) do not yet exist.

So you’ll need to be able to find the faces somehow, perhaps by the direction of the normal vector ?


#7

Well if you are creating the bottom face, you should be able to collect an array of vertices of the inner curve, subtract the curve’s end and start vertices from the array, and then after pushpull collect an array of faces that use any of the pre-pushpull vertices and have only 4 vertices themselves (this eliminates the bottom face.)

(Not using the bottom inner curve’s start and end vertices eliminates the end faces.)


#8

@JMZ, … Jeremy. Likely a bit easier using edges instead of vertices … try …

# within the component's entities collection
edges = inner_curve.edges
# do pushpull
faces = ents.grep(Sketchup::Face).collect do |f|
  f.edges.size == 4 && f.edges.any? {|e| edges.include?(e) }
end

#9

It appears the component axes aren’t consistently places in relation to the content.


#10

I hid all of the lines that make up the curved face (treating it as a single face instead of a ton of small ones) in hopes that I could apply the texture to that face and every other face in the group with entities1.grep(Sketchup::Face).each{|f| f.material = wallmat } just like it would when using the paint bucket like below but with script, but it did not work. Am I completely off track here?


#11

Also, this is what the bottom group looks like after I explode it. It looks like I didn’t actually did anything to change the edges of the curve? Except when I click on the curved face it highlights the whole curved face as one surface which I can then apply a texture to manually…


#12

Paint bucket tool doesn’t merely apply the material to the faces - it also sets the UV mapping according to some quite complex rules.


#13

I just tried it in SU2016 and it worked for me but I also did …

  • made sure Show Hidden Geometry was true
  • I had all of the curve’s faces and hidden edges manually selected (in the selection set)
    (This means I was within the component’s edit context.)

and did …

sel.grep(Sketchup::Face) {|f| f.material= mat }

I was using “Cinder Block” as the material.


#14

And I just tried it again by holding an array of the curve faces, exiting the edit context, setting view Hidden geometry false, and assigning the material to the array of faces, and it working again.


#15

Hi Dan,

What code do you use to hold the array of curve faces? And if done this way, everything will be able to be done through script with no manual input needed?


#16
fs = sel.grep(Sketchup::Face)

Well I manually selected the curve faces. So see the other thread on getting an array of the faces.

All I can say is it worked for me.


#17

Dan,

Would it matter that the part I am trying to texture is in a group? The following code is what I am using and it isn’t working for me. Still breaks up the texture on each face of the curve.

group = entities.add_group
entities1 = group.entities
edges1 = entities1.add_arc base_centerpoint, vector2, vector1, 33.107, 0.degrees, 90.degrees, numsegs = 23
edges2 = entities1.add_arc base_centerpoint, vector2, vector1, 40.107, 0.degrees, 90.degrees, numsegs = 29
edges3 = entities1.add_edges [@x-3.50,@y-36.607,@z+0.001], [@x+3.50,@y-36.607,@z+0.001]
edges4 = entities1.add_edges [@x-36.607,@y-3.50,@z+0.001], [@x-36.607,@y+3.50,@z+0.001]

base_face = entities1.add_face *edges1,*edges3,*edges2,*edges4
entities1.grep(Sketchup::Edge).each{|e| e.hidden=true }
base_solid = base_face.pushpull -height

selection = model.selection.add(entities1.to_a)
sel = Sketchup.active_model.selection.grep(Sketchup::Face).each{|e|e.material=wallmat}


#18

Face#material doesn’t set any texture mapping, it merely sets the material property of the face. Setting the UV mapping is not trivial but can be done. TT’s QuadFace tools does it


#19

Eneroth,

Thank you for the feedback. I guess I didn’t realize that the paint bucket tool was so complex, and it looks like what I’m trying to do is a lot harder than I initially thought…

I noticed that when I select all of the faces of my group through ruby script each face on the curve is selected separately, but when I use the select tool manually it highlights the whole curved surface like it is one face. Is it possible to do this with code? Or is the select tool much more complicated than I thought too?

The gif below shows what is selected when I run my code verses what gets selected when I use the select tool. Sorry for all of the visuals, but that is how I learn best, and it helps me realize what I am trying to say since I am pretty new to coding especially with SketchUp.

Face_Selection_Test


#20

I was testing inside a component instance context. So no I do not think it matters.

Re, your code,
(1) please quote it correctly for the forum
(2) I cannot test as it has variables I do not know the value of. (When you post code, please post code that others can test.)
(3) Do not use weird odd numbers of segments for curves and circles. (This causes problems where cardinal points do not fall on vertices. Should use an even number that divides into 360 well, ie, 6, 8, 12, 16, 18, 36, etc.)

EDIT: Oh, and post the material if it’s not one of the distro SketchUp materials.

The main difference is that in my test, I did not make the bottom curve’s edges hidden before pushpull.
Instead, I only made the vertical inner edges of the inner curve surface hidden, after pushpull.