By kami
#318173
Hello

When using realscale, it often happens that similiar additive objects are all texutred exactly the same (e.g. if you model every single board of a wood wall). The one solution I use atm, is to apply a box mapping which will put the whole texture over all objects (not every single object itself) which is looking better, since not every board looks exactly the same, but still some repetitive pattern may be noticeable.
Now, If I'm in a very fancy mood, I randomly select some boards and apply a different offset for the texture which leads to the best solution.

My question would be: Is there any way to automate these steps?
Eg. I select all boards at the beginning and rhino applies a box mapping with a random u/v/w-offset for every object. This should be possible with eigther rhinoscript or grasshopper, not? Since I'm still not familiar with neighter of them, I'd like to ask, which one would be more helpful and easier to learn for just this script. Or is there even an existing script taking care of this issue?

Thank you very much for any information. I hope everything is understandable. If not I'll gladly supply some sample images.

cheers, kami
By JDHill
#318186
When using realscale ... apply a box mapping
This is a recipe for unexpected results - if you use Real Scale, you should let the plugin manage the mapping and not apply any explicit projectors.
Is there any way to automate these steps?
Try this:
Code: Select all
Option Explicit

Call Main()
Sub Main()

	On Error Resume Next
	
	Dim tileU, tileV, varU, varV
	
	tileU = Rhino.GetString("Enter U tile base value", 1.0)
	
	If IsNull(tileU) Then Exit Sub
	
	tileV = Rhino.GetString("Enter V tile base value", 1.0)
	
	If IsNull(tileV) Then Exit Sub
	
	varU  = Rhino.GetString("Enter U variation", 0.1)
	
	If IsNull(varU) Then Exit Sub
	
	varV  = Rhino.GetString("Enter V variation", 0.1)
	
	If IsNull(varV) Then Exit Sub
	
	Dim arrObjects, strObject, idx, incr, tmpU, tmpV

	arrObjects = Rhino.GetObjects("Select objects", 8 + 16 + 32)

	If IsArray(arrObjects) Then	
		
		varU = varU * 0.1
		varV = varV * 0.1
		
		idx = 0
		incr = 1
		
		Rhino.EnableRedraw(False)

		For Each strObject In arrObjects

			Rhino.UnselectAllObjects
			Rhino.SelectObject(strObject)
			
			tmpU = tileU + (idx * varU)
			tmpV = tileV + (idx * varV)
			
			If tmpU = 0.0 Then tmpU = 0.0001
			If tmpV = 0.0 Then tmpV = 0.0001
			
			Rhino.Command "-ApplyBoxMapping 1 _Enter _Enter " & CStr(tmpU) & " " & CStr(tmpV) & " " & "_Enter", False			
		
			If idx > 10 Or idx < -10 Then incr = -incr
			
			idx = idx + incr
			
		Next	

	End If
	
	Rhino.UnselectAllObjects
	Rhino.EnableRedraw(True)
	
End Sub
Just go to Tools > RhinoScript > Edit and copy/paste this into the window. Then, go to Tools > Run (in the RhinoScript window, or click the 'arrow' button in the toolbar). You should be prompted for Tile U/V values and variation U/V values - these will be used to create box mappings for the objects you select. So, if you run the script and give it Tile U/V = 1.0 and variation U/V = 0.1, the script will create box mappings for the objects you select, with the Tile U/V values for each mapping varying between -0.9 and 1.1. You will get a more random result if you do not window-select the objects; Rhino gives the list in the order it was selected.

If it works okay, you can create a new toolbar button (hold down CTRL and drag/drop an existing button) and then edit its macro (hold down SHIFT and right-click the new button) and paste the script into its macro ('Left mouse button command' or 'Right mouse button command'), wrapping it in a '-RunScript()' block, like this:
Code: Select all
! -RunScript ( _

Option Explicit

Call Main()
Sub Main()

	On Error Resume Next
	
	Dim tileU, tileV, varU, varV
	
	tileU = Rhino.GetString("Enter U tile base value", 1.0)
	
	If IsNull(tileU) Then Exit Sub
	
	tileV = Rhino.GetString("Enter V tile base value", 1.0)
	
	If IsNull(tileV) Then Exit Sub
	
	varU  = Rhino.GetString("Enter U variation", 0.1)
	
	If IsNull(varU) Then Exit Sub
	
	varV  = Rhino.GetString("Enter V variation", 0.1)
	
	If IsNull(varV) Then Exit Sub
	
	Dim arrObjects, strObject, idx, incr, tmpU, tmpV

	arrObjects = Rhino.GetObjects("Select objects", 8 + 16 + 32)

	If IsArray(arrObjects) Then	
		
		varU = varU * 0.1
		varV = varV * 0.1
		
		idx = 0
		incr = 1
		
		Rhino.EnableRedraw(False)

		For Each strObject In arrObjects

			Rhino.UnselectAllObjects
			Rhino.SelectObject(strObject)
			
			tmpU = tileU + (idx * varU)
			tmpV = tileV + (idx * varV)
			
			If tmpU = 0.0 Then tmpU = 0.0001
			If tmpV = 0.0 Then tmpV = 0.0001
			
			Rhino.Command "-ApplyBoxMapping 1 _Enter _Enter " & CStr(tmpU) & " " & CStr(tmpV) & " " & "_Enter", False			
		
			If idx > 10 Or idx < -10 Then incr = -incr
			
			idx = idx + incr
			
		Next	

	End If
	
	Rhino.UnselectAllObjects
	Rhino.EnableRedraw(True)
	
End Sub

)
By kami
#318200
thank you very much.
sadly I did not get the script to run. I did exactly like you described (rhino4 and 5). And it didn't work if I selected all objects before or afterwards.
I've searched a little bit on the web, but did just found this one script:
Code: Select all
Option Explicit

Call Main()
Sub Main()
    Dim dblLow, dblHigh
    dblLow = 10.0
    dblHigh = 50.0
    Randomize
    Rhino.Print Rnd * (dblHigh - dblLow) + dblLow

End Sub
which'll give you a random number.
I tried to change your script but did not understand completely how the "applyboxmapping" command worked :(
By JDHill
#318205
What did it do? Was there an error message? It should work fine if you just copy/paste into the RhinoScript editor. Don't bother pre-selecting objects; the script will tell you when it wants you to select them.
By JDHill
#318260
It should work like this:

Image

So, I chose to use 1.0 for the base Tile U/V values, and then to vary both U/V by 0.2. The script goes through the objects, adds a box mapping if one does not exist, and then sets the Tile U/V values for the mapping to between 0.8 and 1.2.

Does that make more sense?
By kami
#318367
this is the screen I get, when those textures magically move at your screenshot.
http://www.pictureupload.de/originals/p ... screen.jpg

the texturing didn't change and there's this "Tiling V <1>" at the control bar.
then I have to enter a number for every selected object and at the end it changes nothing but the "V Repeat" value of every selected objects to the value I entered.

don't know why it's behaving so strange. I run Rhino 4 SR7 as well!
By JDHill
#318654
No, I really don't know; maybe it could have to do with Windows regional settings vs. copy/paste from the web page to the script editor. Either way, it doesn't matter - try this plugin instead. Basically, it has one command, RandomizeTextures, which has a few different options:
  • tile U/V variation
  • offset U/V variation
  • method
The tile & offset U/V options are pretty self explanatory: you enter a percentage, and the plugin then randomly alters the associated value using that percentage as a range. The last one determines where the changes are made; there are two methods: Mapping and Material. If Mapping is used, then the objects should already have a box mapping applied to them; the plugin will alter the U/V values in those mappings (i.e. in Object Properties > Texture Mapping > [box mapping] > UVW Offset/Repeat). If Material is used, then it gets the Rhino materials for the selected objects and alters the U/V values for any active textures in them (i.e. in Object Properties > Material > Texture > Tiling > Modify).

There are a few other considerations:
  1. don't try to use the Mapping method with objects being managed by the Maxwell plugin's Real Scale feature; that's a one-way road, and this is going the wrong way for it to work; it should work fine for non-Real Scale textures.
  2. don't use the Material method at all for any objects which use Maxwell materials; Maxwell materials manage tile/offset on a one-to-many basis that goes one material > many Rhino objects. As such, setting differing tile/offset values directly via Rhino's Object Properties > Material page will have no effect.
  3. for objects with no Maxwell material assigned, either method will work fine; if you use Mapping, you will have one plugin-generated Maxwell material show up in your MXS, since each object will have different UVs directly on it. If you use the Material method, you will end up with one auto-generated Maxwell material in the MXS for each object which has a unique set of tile & offset values.
  4. if you use the Mapping method, it looks here like it won't work until you've shown the Texture Mapping page in Object Properties at least once in the session; don't ask me why.
  5. Also, it looks like mappings are shared between objects more than they should be; for example, I was testing with a box-mapped cube that I had arrayed; in fact, all 25 of my arrayed cubes were sharing the same mapping as the original one, and as such, the randomness introduced by this plugin was rendered completely ineffectual. The solution in this case is to use the TestSeparateMapping command first, so that each object actually gets its own mapping.
By kami
#318792
Hello Jeremy

I can report back: It works like a charm! That's really the plugin I've needed for some time now, thank you very much.
But as you say, it's kind of useless without the separate mappings. "TestSeparateMapping" did not work on Rhino4 and I couldn't find any info on what I need to install to get that command, but luckily there's the "SeparateMapping" in Rhino5.
I even succeeded in combining a box mapping on a certain channel with a real scale texture on another one.

Cheers,
Christoph
Sketchup 2025 Released

Thank you Fernando!!!!!!!!!!!!!!!!!!!!!!!!!!! hwol[…]

I've noticed that "export all" creates l[…]

hmmm can you elaborate a bit about the the use of […]

render engines and Maxwell

Funny, I think, that when I check CG sites they ar[…]