Recursion issue

935
2
09-21-2016 11:35 PM
KennethLindhardt
Occasional Contributor

Hi, I’m trying to create a little hobby project. The background for this is that I have a lot of textures, and no order in those. So my idea was to link a texture finder rule into all my other rules, and when necessary activate a plane with all the textures matching my filesearch criteria, and a annotation below that I could use in the main rule to texture my models.

I created  a primitivequad, that will have the sqrt size of the total number of textures in the filesearch. The I’ve splited it up in the x and z direction. That would bring me a grid, where I need to assign different materials to each one.

I redefined the Index of my splits so it will keep growing, so if the last split in the X direction in the first split of the Z direction will end up with Index 10 the first split in the X direction  in the second split of the Z direction will be 11, and so on….

Okay… I can do a listItem on a string from a fileSearch, so let’s say the I have a spit with a value of 10, I would like the the 10th texture in the listItem, comeing from the fileSearch to be assigned to that Index.

No problem there, if I create a case for each Index, but I need that to be a recursion, and now the chain is broken.

I think I’ve tried to put this together in every different ways I could think of, but maybe I’ve stared my self blind on it.

In my rule the Selector is the definition of which number of texture it should take from the list, the Number is the Index.

So in case the number equals the selector map the texture that has the same index/Selector value as the number.

Else go back to the same rule and raise the Selector value with one, until there is no more splits == Selecto > ListSize : NIL

Maybe this is cryptic writing , but hopefully it makes sense:  

PS: I know that the current recursion will not work 

attr ListSize = listSize(fileSearch("Textures/*"))
attr ListSearch = fileSearch("Textures/*")
Start -->
primitiveQuad(ceil(sqrt(ListSize)), ceil(sqrt(ListSize)))
SplitX

SplitX -->
split(x) {1 : SplitY(split.index)}*

SplitY(IndexOne) -->
split(z) {1 : Shape(IndexOne,split.index+1,split.total,1,1)}*

Shape(IndexOne,IndexTwo,Total,Iterations,Selector) -->
//print(ListSearch)
Next(IndexTwo+Total*IndexOne,Selector)

Next(Number,Selector) -->
case Number > 1000 : NIL
else : set(material.colormap,listItem(ListSearch,Number))projectUV(0) Next(Number,Selector+1)

0 Kudos
2 Replies
ThomasFuchs
Esri Regular Contributor

Hi Kenneth,

First, I need to say, that I'm not 100% sure how you want to use the selected texture number in your other rules.

But, I made a version of your rule, that makes a grid of textures and marks the selected one red.

I did not find a meaningful break condition in your recursive call of next, so I removed it.

attr searchString = "/ESRI.lib/assets/Facades/International/Groundfloors/*Educational*"
attr ListSize = listSize(fileSearch(searchString))
attr ListSearch = fileSearch(searchString)
attr Selector = 1

Start -->
     primitiveQuad(ceil(sqrt(ListSize)), ceil(sqrt(ListSize)))
     SplitX

SplitX -->
     split(x) {1 : SplitY(split.index)}*

SplitY(IndexOne) -->
     split(z) {1 : Shape(IndexOne,split.index+1,split.total,1,floor(Selector))}*

Shape(IndexOne,IndexTwo,Total,Iterations,Selector) -->
     Next(IndexTwo+Total*IndexOne,Selector)

Next(Number,Selector) -->
     case Number >= ListSize : NIL 
     case Selector == Number:
          setback(0.05) { all : Highlight | remainder : Texture(Number) }
     else : 
          Texture(Number)
          
Texture(Number) -->
          setupProjection(0, scope.xz, 1, 1)
          set(material.colormap,listItem(ListSearch,Number))
          projectUV(0)

Highlight -->
          color("#FF0000")
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
KennethLindhardt
Occasional Contributor

Hi Thomas, thank you for the answer. It really helped a lot. My late reply is not be course I did not appreciated your answer, I simply wanted to have some time to create something that could illustrate my plan. So the idea was to have a catalog of materials to choose from, and see them visually in CE, then quickly assign the desired material to a building.

I haven’t had that much time, so it still needs a lot of work, but my testing passed, and I just need to make it shine from now on.

First you create your building rule, and link to the textureSearch.cga. Her I’ve created a beautiful cube. When I enable the ShowMaterial attr, all my materials get shown next to the building.  

Let’s say I want material number 8. The I type in 8 in MaterialNumber, and because I use the same logic in the  Building rule and the material rule, it will match on the building.

Just another example on how everything seems possible with cga, You just need an idea some knowledge and some help.

How useable this will be at the end, time will tell. But I expect incorporating the workflow into all my rules. I have this huge library, with almost seamless textures, and I never use them because there was an overload of materials, and it took forever find the right one. In the passed I googled “Brick Texture” Now I think I can make use of my “pro“ materials, and even filter by material type. The cool thing is, that I got my bumpmaps, right next to the texture  

Cheers!