Fractal Structure

Script:

// Sample code for making a sierpinski fractal
// Author: Kim Czerniewski
// Purpose: Base script for P1. Extrapolate here to create a Sierpinski form.
//Coding Language: Maya Embedded Language

// Notes: Further down, I made two different light sets, one with multiple directional lights directed around the fractal, and one set with just one.
// If the basic one is the one that isn’t commented out, you’ll have to create an aiSkyDome Light.
// There is no working code to call it in that I’ve been able to make any Arnold exclusive tools work.

// Date: 10/1/17

//— Delete—//

/*
select – all;
delete;
*/

// —- CREATE VARIABLES FOR USE LATER ON

//////////___Control Variables/On_Off Switches___//////////

//___Multiplies with the randomized variable that makes points of the cubes raise and lower__//
//___0 for smooth cubes, 1 for randomized spikes___//
int $spike= 0;

//___Controls how wide the over all diamond is___//
float $wdth= 1.000;

//___Controls how tall the over all diamond is___//

float $hgt= 1.000;

//___basic directional light value intensity___//
float $l_brt=.8;

//___basic directional light color___//
float $lgt_r = 1;
float $lgt_g = 1;
float $lgt_b = .8;

//___Vein width__//
float $mtl_vein_wdt= 0.01935;

//__Vein diffusion__//

float $mtl_vein_dif= 0.02516;

//__How Many Cubes are Generated__//
int $cube_num=10000;

/////////___Vectors___////////

vector $vect_1 = <<0.000, (-1*$hgt), 0.000>>; //Bottom Point
vector $vect_2 = <<(-1*$wdth), 0.000, 0.000>>; //mid Point 1 -x
vector $vect_3 = <<(1*$wdth), 0.000, 0.000>>; //mid Point 2 +x
vector $vect_4 = <<0.000, (1*$hgt), 0.000>>; //Top Point
vector $vect_5 = <<0.000, 0.000, (-1*$wdth)>>; //mid Point 3 -z
vector $vect_6 = <<0.000, 0.000, (1*$wdth)>>; //mid Point 4 +z

vector $seed = << 0, 0.3, 0 >>;
vector $vertices_tet[] = {$vect_1, $vect_2, $vect_3, $vect_4, $vect_5, $vect_6};
vector $vertices_2D[] = {$vect_1, $vect_2, $vect_3};

int $num= 1;

//_____________________________________________________________________________________________________________________________________________________

//———— Create Lights

/*
/////__________Revolving_Directional_Light_Set___________/////

//the defaultDirectionalLight command makes a directional light
//____arguments are (intensity, color R,color G,color B, “use depthmap shadows”, shad ColorR, shad ColorG shad ColorB, active panel)
//____cant take name flags
float $l_int=1; //light color intensity //___Note: To make them all white lights set $l_int=2 and $l_vib=1- the default set makes 1 revolution each of cyan, magenta, and yellow light
float $l_vib=0; //light color purity- keep below 1- lower for purer colors, higher for more mixed
int $l_dcty=3;

for ($l=1; $l< ($l_dcty+1); $l++){
defaultDirectionalLight ($l_brt, $l_vib,($l_int-$l_vib),($l_int-$l_vib), “0”, 0,0,0, 0);
rename “directionalLight1” (“d_lgt_c_”+$l);
rotate -r ((360/$l_dcty)*$l) 0 0;
}

for ($g=1; $g< ($l_dcty+1); $g++){
defaultDirectionalLight ($l_brt, ($l_int-$l_vib),$l_vib,($l_int-$l_vib), “0”, 0,0,0, 0);
rename “directionalLight1” (“d_lgt_m_”+$g);
rotate -r (((360/$l_dcty)*$g)+30) 120 0;
}

for ($t=1; $t< ($l_dcty+1); $t++){
defaultDirectionalLight ($l_brt, ($l_int-$l_vib),($l_int-$l_vib),$l_vib, “0”, 0,0,0, 0);
rename “directionalLight1” (“d_lgt_y_”+$t);
rotate -r (((360/$l_dcty)*$t)+60) 240 0;
}

*/
/////__________Basic_Light_Set___________/////

//______!!!!!!!!!!!!Create an aiSkyDome Light- there is no working code to call it in!!!!!!!!!!!!!_____//

defaultDirectionalLight ($l_brt, $lgt_r,$lgt_g,$lgt_b, “0”, 0,0,0, 0);
rename “directionalLight1” “key_lgt”;
rotate -r 30 -60 0;

//_____________________________________________________________________________________________________________________________________________________

//———— Create Material

/////__Base Shader__/////
shadingNode -asShader aiStandard -name “fractal_shader”;
sets -renderable true -noSurfaceShader true -empty -name “fractal_shaderSG”;
connectAttr -f fractal_shader.outColor fractal_shaderSG.surfaceShader;

/////__Color__/////

//_______Veins_______//
shadingNode -asTexture marble -name “material_veins”;
shadingNode -asUtility place3dTexture -name “vein_placement”;
connectAttr vein_placement.wim[0] material_veins.pm;
setAttr “material_veins.veinWidth” $mtl_vein_wdt;
setAttr “material_veins.diffusion” $mtl_vein_dif;
setAttr “material_veins.contrast” 0.251613;
setAttr “material_veins.veinColor” -type double3 1 0.669467 0;

//_______Base_______//
shadingNode -asTexture ramp -name “material_body”;
shadingNode -asTexture projection -name “material_body_projection”;
shadingNode -asUtility place3dTexture -name “material_body_projection_placement”;
connectAttr material_body_projection_placement.wim[0] material_body_projection.pm;
connectAttr material_body.outColor material_body_projection.image;
shadingNode -asUtility place2dTexture -name “material_body_projection_map”;
connectAttr material_body_projection_map.outUV material_body.uv;
connectAttr material_body_projection_map.outUvFilterSize material_body.uvFilterSize;
setAttr “material_body.type” 0;
setAttr “material_body.colorEntryList[0].color” -type double3 0.1448 0.121 0.2375 ;
setAttr “material_body.colorEntryList[1].color” -type double3 0.0245 0.0183 0.0267 ;
setAttr “material_body.colorEntryList[0].position” 1;
setAttr “material_body_projection_placement.rotateX” -90;
setAttr “material_body_projection_map.mirrorV” 1;
setAttr “material_body_projection_map.mirrorU” 1;
setAttr “material_body.interpolation” 2;

shadingNode -asTexture mandelbrot3D -name “material_body_2”;
shadingNode -asUtility place3dTexture -name “material_body_2_placement”;
connectAttr material_body_2_placement.wim[0] material_body_2.pm;
setAttr “material_body_2.zoomFactor” 1.538462;
setAttr “material_body_2.depth” 50;
setAttr “material_body_2.lobes” 3;
setAttr “material_body_2.color[1].color_Color” -type double3 0.5106 0.5106 0.5451 ;
setAttr “material_body_2.color[2].color_Color” -type double3 0.5073 0.5192 0.5267 ;
setAttr “material_body_2.color[3].color_Color” -type double3 0.5502 0.5956 0.5069 ;
setAttr “material_body_2.color[4].color_Color” -type double3 0.6602 0.7681 0.7723 ;

connectAttr -force material_veins.outColor material_body_2.colorGain;

/////__Specular Color__/////

shadingNode -asTexture marble -name “material_veins_spec”;
shadingNode -asUtility place3dTexture -name “vein_spec_placement”;
connectAttr vein_spec_placement.wim[0] material_veins_spec.pm;
setAttr “material_veins_spec.veinWidth” $mtl_vein_wdt;
setAttr “material_veins_spec.diffusion” $mtl_vein_dif;
setAttr “material_veins_spec.contrast” 0.251613;
setAttr “material_veins_spec.veinColor” -type double3 .7 .7 0;

shadingNode -asTexture ramp -name “base_specularity”;
shadingNode -asUtility surfaceLuminance -name “specularity_surfaceLuminance”;
connectAttr -f specularity_surfaceLuminance.outValue base_specularity.vCoord;
setAttr “base_specularity.colorEntryList[0].color” -type double3 0.0745 0.7145 0.7604 ;
setAttr “base_specularity.colorEntryList[1].color” -type double3 0.4473 0.7604 0.5208 ;
setAttr “base_specularity.colorEntryList[1].position” 1;

/////__Specular weight__/////

shadingNode -asTexture marble -name “material_veins_spec_weight”;
shadingNode -asUtility place3dTexture -name “vein_spec_weight_placement”;
connectAttr vein_spec_weight_placement.wim[0] material_veins_spec_weight.pm;
setAttr “material_veins_spec_weight.veinWidth” $mtl_vein_wdt;
setAttr “material_veins_spec_weight.diffusion” $mtl_vein_dif;
setAttr “material_veins_spec_weight.contrast” 0.251613;
setAttr “material_veins_spec_weight.veinColor” -type double3 .8 .8 .8;
setAttr “material_veins_spec_weight.fillerColor” -type double3 0.0451613 0.0451613 0.0451613 ;
shadingNode -asUtility reverse -name “material_veins_spec_weight_inverse”;

//_____Combine Everything_____//

connectAttr -force material_body_projection.outColor material_veins.fillerColor;
connectAttr -force base_specularity.outColor material_veins_spec.fillerColor;

connectAttr -f material_veins.outColor fractal_shader.color;
connectAttr -f material_veins_spec.outColor fractal_shader.KsColor;
connectAttr -f material_veins_spec_weight.outColorR fractal_shader.Ks;

connectAttr -f material_veins_spec_weight.outColor material_veins_spec_weight_inverse.input;
connectAttr -f material_veins_spec_weight_inverse.outputX fractal_shader.Kd;

//_____________________________________________________________________________________________________________________________________________________

//————- CREATE SIERPINSKI FRACTAL
//_________________Made into a Diamond_________________//
vector $seed = << 0, 0.1, 0 >>;
string $cube_set[]={};

for($x = 0; $x < $cube_num; $x++){
// randomly pick points in vert list
int $somenum = `rand 0 6`;
// print $vertices_2D[$somenum];

vector $some_vert = $vertices_tet[$somenum];
print $some_vert;
print “\n”; //create line break
// select halfway point between seed and vert picked.
float $midpt_x = ($seed.x + $some_vert.x)/2;
float $midpt_y = ($seed.y + $some_vert.y)/2;
float $midpt_z = ($seed.z + $some_vert.z)/2;
vector $midpt = << $midpt_x, $midpt_y, $midpt_z >>;
print $midpt;
// place cube there with random points raised along the y axis
int $rand_vtx= `rand 0 6`;
float $rand_height= `rand 0 .1`*$spike;
$current_cube =`polyCube -d .075 -h .1 -w .075 -n (“cube”+$x)`;
sets -e -forceElement fractal_shaderSG;
move ($midpt.x) ($midpt.y) ($midpt.z);
select -r ($current_cube[0] +”.vtx[“+ $rand_vtx +”]”);
move -r 0 $rand_height 0;
int $rand_vtx= `rand 0 6`;
float $rand_height= `rand 0 -.05`*$spike;
select -r ($current_cube[0] +”.vtx[“+ $rand_vtx +”]”);
move -r 0 $rand_height 0;
$cube_set[$x] = $current_cube[0];
// update value of seed to be halfway point
$seed = $midpt;
}

select $cube_set;
group -n “fractal”;