View Full Version : mel operators

 moegerbyte11 November 2010, 06:47 PMhey guys! since this is my first post on the forum, I hope it reaches you at some point. I have tried to search the forums, but since I don't know how to name my problem, I decided to open up a new thread. I'd appreciate any links/help/tips! Problem: I'm trying to visualize a simple bin packing problem. There is a container which is to be filled with as many boxes as possible. The boxes are randomly sized and their size is stored in an array. float \$ValueArray[10]; for (\$i=0; \$i<10; \$i++) { float \$Boxdepth = rand(1, 3); //float internal variable, each saved in \$ValueArray[] polyCube -w 1 -h 1 -d \$Boxdepth -n Box0; move -r ((\$i-4.5)*2) .5 (10-\$Boxdepth/2); \$ValueArray[\$i] = \$Boxdepth; } int \$s = size(\$ValueArray); Now, I want to check for each box, if it fits into the container, or not. float \$ContainerFill = 0; // 1st box if ((\$ContainerFill + \$ValueArray[0]) < 10) select Box0; move 0 .5 (-(\$ValueArray[0]/2)); \$ContainerFill = 0 + \$ValueArray[0]; if (\$ContainerFill < 10) print("\n There is still room in this Container\n"); // 2nd box if ((\$ContainerFill + \$ValueArray[1]) < 10) select Box1; move 0 .5 (-(\$ValueArray[1]/2)-\$ValueArray[0]); \$ContainerFill = 0 + \$ValueArray[0] + \$ValueArray[1]; if (\$ContainerFill < 10) print("\n There is still room in this Container\n"); //3rd box if ((\$ContainerFill + \$ValueArray[2]) < 10) select Box2; move 0 .5 (-(\$ValueArray[2]/2)-\$ValueArray[1]-\$ValueArray[0]); \$ContainerFill = 0 + \$ValueArray[0] + \$ValueArray[1] + \$ValueArray[2]; if (\$ContainerFill < 10) print("\n There is still room in this Container\n"); and so on... Since I want to check all 10 boxes, I assume it would be much smarter to write a for loop instead of all the if loops. Only I don't know how to (and haven't found any advice anywhere on how to) get the number that represents each position in the array into a variable. The problem is, I don't know, what this is called in programming language, so I can't google it. :( I want to have something like \$ValueArray[0+1+2+3+4]; to add them up, but logiacally that doesn't work that way. (I remember that there was something with the ´ and ` signs, but I don't know when to use them and can't look it up, because I don't have a name/term.) Please give me a hint on how to compress my formula into a for loop. Greets, m
CGTalk Moderation
11 November 2010, 06:47 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1