We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

GDL
About building parametric objects with GDL.
SOLVED!

Random texture origin for FOR – TO – NEXT

jc4d
Expert

Hello,

 

I have a simple block using FOR – TO – NEXT to duplicate it, is there a way to add a random texture origin to each duplicated so there is no visible texture repetitions?

jc4d_0-1677498832649.png

 

Juan.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Solution
  1. RND(x) where x must be grater than 0, because RND will supply a random number between 0 and x.
  2. COOR{3} wants a direction vector. The default vector matrix would be:
    1, 0, 0,
    0, 1, 0,
    0, 0, 1
    Dont't know what you're doing? Just leave it as is.
Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text | My List of AC shortcomings & bugs | I Will Piledrive You If You Mention AI Again |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»

View solution in original post

Solution

Try this ...

Just use your surface material.

I have only offset in the 'y' direction.

And maybe turn the 'random origin' off in your surface material (mine is off).

 

 

 

board_width = 0.100
board_gap = 0.010

N1= CEIL(A /(board_width+board_gap))

FOR H=1 TO N1
GOSUB 20
ADDx board_width + board_gap
NEXT H


DEL TOP
END

20:

MATERIAL "Timber_Pine - vertical"
block board_width, B, ZZYZX
texture_origin_y = RND(10)
GOSUB 100

RETURN


100: !!texture mapping

VERT 0,0+texture_origin_y,0 !Origin
VERT 1,0+texture_origin_y,0 !X direction
VERT 0,1+texture_origin_y,0 !Y direction
VERT 0,0+texture_origin_y,1 !Z direction
COOR 2+256,1,2,3,4
body -1

RETURN

 

 

 

 

BarryKelly_0-1678168757745.png

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

View solution in original post

22 REPLIES 22
runxel
Legend

Have you tried using COOR{3} with the origos supplied by the RND() function?

Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text | My List of AC shortcomings & bugs | I Will Piledrive You If You Mention AI Again |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»
jc4d
Expert

Somehow I have tried but I cannot wrap my head around it.

20:
block RimaA, RimaB, B
COOR{3} 2,4,
RND(0),RND(0),RND(0),
2000,2000,2000,
2000,2000,2000,
2000,2000,2000
RETURN

 

Juan

Solution
  1. RND(x) where x must be grater than 0, because RND will supply a random number between 0 and x.
  2. COOR{3} wants a direction vector. The default vector matrix would be:
    1, 0, 0,
    0, 1, 0,
    0, 0, 1
    Dont't know what you're doing? Just leave it as is.
Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text | My List of AC shortcomings & bugs | I Will Piledrive You If You Mention AI Again |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»

You can also use translation with the coor{3}

So you can have it add a random distance each next.  That's how I have my wood siding accessory.

The format for COOR is like this.

This is what I use to adjust my tile surface in the x and y directions - not random but via a hotspot.

 

 

	prism_ 5, hob_height,
		0,0,15,
		0,b,15,
		a,b,15,
		a,0,15,
		0,0,-1!,

VERT 0+tile_fill_origin_x,0+tile_fill_origin_y,0 !Origin
VERT 1+tile_fill_origin_x,0+tile_fill_origin_y,0 !X direction
VERT 0+tile_fill_origin_x,1+tile_fill_origin_y,0 !Y direction
VERT 0+tile_fill_origin_x,0+tile_fill_origin_y,1 !Z direction
COOR 2+256,1,2,3,4
body -1

 

 

You will need to swap out the 'tile_fill_origin_x' & 'tile_fill_origin_y' for your randomly generated co-ordinate values, and add in something for z axis if tat is important.

 

RND(0) will not work.

You must specify an upper random number i.e. RND(10)

That will give you a random number between 0 and 10.

 

Sorry I never got around to actually sending this reply and I see others have beaten me to it.

 

I think there is an issue with the RND generator in that it will always give you the same sequence of 'random' numbers if used in a for next loop.

It does produce a 'random' number, but I think it is always the same 'random' number if you use the same seed (the number in brackets).

 

Barry.

 

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

I think there is an issue with the RND generator in that it will always give you the same sequence of 'random' numbers if used in a for next loop.

It does produce a 'random' number, but I think it is always the same 'random' number if you use the same seed (the number in brackets).

This is intentional, so that successive frames in a fly-through are stable relative to eachother.

The random sequence is different for each instance of the same library part.

You can use something like this to get a random number 1..._rangemax, initialized with a seed that is set from a global variable which changes when you need changes in the sequence:(SYMB_POS_X, GLOB_FRAME_NR, GLOB_ID):

int(rnd(_seed % _rangemax)) + 1

 

Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest

Screenshot 2023-02-28 072346.png

Screenshot 2023-02-28 072454.png

 not saying you guys are wrong but this confuses me as this is the outcome I get using rnd in my loop.

Maybe I can't see it but even when close the planks do not seem to be the same random number

Interesting, but two comments:

GLOB_ID is treated as string, so you can't do mathematical operations (modulo here) on it. So you can't set _seed to GLOB_ID.

Also using rnd() inside a loop will yield different results. However changing the object will indeed not change the individual loop results.

See this example code for the 2D script: "last" is a parameter. If you change it, you will see that the discrete results stay the same, only the overall number of course changes. E.g. if the first result is "9.3781" it will always be the same. But the second row is different random.

 

for i=1 to last
	_r = rnd(10)
	text2 0, -i*0.6, _r
next i

 

Using SYMB_POS_X as a seed is brilliant tho. That works like a charm.

Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text | My List of AC shortcomings & bugs | I Will Piledrive You If You Mention AI Again |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»
jc4d
Expert

I know there is an answer marked as solution, but now that I dig deeper, the less clear this whole thing is.

 

Why the texture becomes randomly rotated if what I set is the origin of it. Maybe my question wasn't clear enough and I apologize for it.

 

Let's say I have some planks of a terrace deck created using BLOCK on a  FOR-TO-NEXT, now if I assign a texture to that object, there will be an obvious texture tiling, what I'm going after is that each of those planks have the texture origin displaced so the texture tiling is not visible.


This is how the object looks like if I just apply a texture on it (not pretty at all):

jc4d_0-1678096954880.png

 

Now, what I'm going after is that each plank has its texture moved randomly in X,Y,Z coordinates but keeping the direction so they are not rotated.

Juan.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!