Wrangle TreeTypes distribution help

   1291   2   1
User Avatar
Member
174 posts
Joined: April 2009
Offline
Hi all,
I could use a little help with a little attributewrangle i'm making.
What i'm trying to achieve is a node to control the distribution of types of trees for a forest.
I've got 10 versions of treetype 1, 15 versions of treetype2 etc, 4 TreeTypes at the moment.
What i've got so far (and is working perfectly fine) is this:

i@Tree1_vars = chi("Tree1_variations");
i@Tree2_vars = chi("Tree2_variations");
i@Tree3_vars = chi("Tree3_variations");
i@Tree4_vars = chi("Tree4_variations");

f@total = ch("TreeType1") + ch("TreeType2")+ch("TreeType3")+ ch("TreeType4") ;

f@TreeType1_cutOff = ch("TreeType1")/@total;
f@TreeType2_cutOff = (ch("TreeType1")+ch("TreeType2"))/@total;
f@TreeType3_cutOff = (ch("TreeType1")+ch("TreeType2")+ch("TreeType3"))/@total;

if ( rand(@ptnum) < @TreeType1_cutOff ) {
f@selection = ceil(rand(@ptnum+45563)*@Tree1_vars);
s@instance = "/obj/Berk_v" + itoa(int(@selection));
}else if ( rand(@ptnum) < @TreeType2_cutOff ) {
f@selection = ceil(rand(@ptnum/23)*@Tree2_vars);
s@instance = "/obj/BroadleafBark_v" + itoa(int(@selection));i@Tree1_vars = chi("Tree1_variations");
i@Tree2_vars = chi("Tree2_variations");
i@Tree3_vars = chi("Tree3_variations");
i@Tree4_vars = chi("Tree4_variations");

f@total = ch("TreeType1") + ch("TreeType2")+ch("TreeType3")+ ch("TreeType4") ;

f@TreeType1_cutOff = ch("TreeType1")/@total;
f@TreeType2_cutOff = (ch("TreeType1")+ch("TreeType2"))/@total;
f@TreeType3_cutOff = (ch("TreeType1")+ch("TreeType2")+ch("TreeType3"))/@total;

if ( rand(@ptnum) < @TreeType1_cutOff ) {
f@selection = ceil(rand(@ptnum+45563)*@Tree1_vars);
s@instance = "/obj/Berk_v" + itoa(int(@selection));
}else if ( rand(@ptnum) < @TreeType2_cutOff ) {
f@selection = ceil(rand(@ptnum/23)*@Tree2_vars);
s@instance = "/obj/BroadleafBark_v" + itoa(int(@selection));
}else if ( rand(@ptnum) < @TreeType3_cutOff ) {
f@selection = ceil(rand(@ptnum*+1223)*@Tree3_vars);
s@instance = "/obj/EuropeanLinden_v" + itoa(int(@selection));
}else {
f@selection = ceil(rand(@ptnum-12387)*@Tree4_vars);
s@instance = "/obj/CypressOak_v" + itoa(int(@selection));
}
}else if ( rand(@ptnum) < @TreeType3_cutOff ) {
f@selection = ceil(rand(@ptnum*+1223)*@Tree3_vars);
s@instance = "/obj/EuropeanLinden_v" + itoa(int(@selection));
}else {
f@selection = ceil(rand(@ptnum-12387)*@Tree4_vars);
s@instance = "/obj/CypressOak_v" + itoa(int(@selection));
}

Just hit the create spare parms btn after this and Bob's your uncle.

What i would like however is to have the number of treetypes a bit more dynamic as well. I was thinking somewhere in the line of arrays but that's a bit difficult still for me, when it comes to syntax and the creation of the space parms.

Could someone point me in the right direction for this?
Tnx in advance.
User Avatar
Member
174 posts
Joined: April 2009
Offline
Thanks Mestela,
I've used a ramp to distribute in the past but i found it a bit more quirky to adjust then just a bunch of sliders, although i do understand this is a question of personal preference.
I also like the idea of keeping it all in one wrangle node, nice, compact and fast. I need to set a couple of attributes anyway so it makes sense to keep it just in some lines of code. It's just the array syntaxing I lack.
  • Quick Links