Parametric design in MoI?

 From:  mkdm
7713.336 
Hi everyone!

While waiting for new versions of Max's NodeEditor,
i'm doing some experiments with PatternArray selection :

Here's my current unfinished version of the node PatternSelectArray :

code:
// PatternSelectArray
function PatternSelArray()
{
	this.addInput("In","pointarray");
	this.addInput("Start","number");
	this.addInput("Qt_Max","number");
	this.addInput("Step","number");		
	
	this.addOutput("Out","pointarray");
	this.addOutput("Elems","number");
	this.addOutput("Source","pointarray");
	
	this.properties = { mode:["Pattern + Subset", "Pattern + Subset", "Subset + Pattern"],
		pattern:"+",
		start:0,
		qt_max:-1,
		step:1};
	
}

PatternSelArray.title = "PatternSelArray";
PatternSelArray.desc = "PatternSelArray";

PatternSelArray.prototype.onExecute = function()
{
	//if (this.properties.order[0] == "By Selection") {
		
	var source = this.getInputData(0, new pointArray());
	this.properties.pattern = this.properties.pattern.trim();
	
	var usePattern = false;
	var isMixedPattern = false;
	
	// check the pattern
	if (this.properties.pattern != '') {
		// check if pattern contains valid characters
		usePattern = this.properties.pattern.match('^[+\-0-1]+$');
		
		if (usePattern) {
			// check if pattern contains only include characters (+ or 1)
			usePattern = !this.properties.pattern.match('^[+1]+$');
			
			if (usePattern) {
				// if pattern contains both include and exclude characters, then the pattrn will be used
				// otherwise it means that contains only exclude characters (- or 0), and therefore
				// the output pointarray list will be empty
				isMixedPattern = !this.properties.pattern.match('^[\-0]+$');
			}
		}
	}

	var output = new pointArray(); // init to empty list

	if (usePattern) {
		if (isMixedPattern) {
			var len = source.getLength();
			var cn = 0;
			
			for (i = 0; i < len ; i++) {
				if ( this.properties.pattern[cn] === '1' || this.properties.pattern[cn] === '+') {
							
					var source_elem = source.getElement(i);
					
					output.push(source_elem.pt.x,
						source_elem.pt.y,
						source_elem.pt.z,
						source_elem.AngleX,
						source_elem.AngleY,
						source_elem.AngleZ,
						source_elem.Size);
				}
				cn = (cn < this.properties.pattern.length-1) ? cn+1 : 0;
			}
		}
	} else {
		// elaborate the whole source pointarray
		this.properties.pattern = '';
		output = source;		
	}

	var outLength = output.getLength();
	
	this.properties.start = this.getInputData(1, this.properties.start);
	if (this.properties.start < 0) this.properties.start = 0;
	if (this.properties.start > (outLength - 1)) this.properties.start = (outLength - 1);

	this.properties.qt_max = this.getInputData(2, this.properties.qt_max);
	if ((this.properties.qt_max < 0) || (this.properties.qt_max > outLength)) this.properties.qt_max = outLength;
	
	this.properties.step = this.getInputData(3, this.properties.step);
	if (this.properties.step <= 0) this.properties.step = 1;
	if (this.properties.step > outLength) this.properties.step = outLength;
	
	// generate the final pointarray list
	var outputFinal = new pointArray();
		
	for (i = this.properties.start, cont = 0; i < outLength && cont < this.properties.qt_max; i += this.properties.step, cont++) {
		var source_elem = output.getElement(i);
		
		outputFinal.push(source_elem.pt.x,
			source_elem.pt.y,
			source_elem.pt.z,
			source_elem.AngleX,
			source_elem.AngleY,
			source_elem.AngleZ,
			source_elem.Size);
	}
	
	output = null;
	
	this.setOutputData(0, outputFinal);
	this.setOutputData(1, outputFinal.getLength());
	this.setOutputData(2, source);
	
	this.outputs[1].label = "Elems(" + outputFinal.getLength() + ")";
}

LiteGraph.registerNodeType("Arrays/PatternSelArray", PatternSelArray);


The inputs and outputs are :

1 - In : the source PointArray
2 - pattern : the filter pattern string : 1 or + pick the element, 0 or - skip the element
Example "1001" or "+--+"

3 - Start : the first element index of the resulting array after the pattern filtering
4 - Qt_Max : Max quantity of elements present in the final output array
5 - Step : The step used while iterate over the patterned array

6 - Out : the final array
7 - Elems : the number of elements present in the final array
8 - Source : The initial source PointArray


Actually the node works in this way :

1) The pattern is applied to the source array
2) Start , Qt_Max and Step are used to iterate over the patterned PointArray

Actually the property "mode" is not used, but when activated,
will determine the order of the used logic :
First do Pattern operation and then Iterates
or
First Iterates and then do Pattern operation


Nice evening to all,


Marco.