Show messages: 1-10 … 271-290 291-310 311-330 331-350 351-370 371-390 391-410 … 911-912
Attachments:
03_order_of_selection.3dm
04_order_of_selection.nod
Image Attachments:
01_Capture.PNG
02_Capture.PNG
Attachments:
litegraph.js
wrappedFunctions.js
Image Attachments:
addOut.gif
Attachments:
curves2.js
// 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);
Image Attachments:
Outputs.gif
// PatternSelectArray function PatternSelArray() { this.size = [160,70]; this.minsize = [160,70]; this.addInput("In","pointarray"); this.addInput("Start_Idx","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_idx:0, qt_max:-1, step:1 }; } PatternSelArray.title = "PatternSelArray"; PatternSelArray.desc = "PatternSelArray"; PatternSelArray.prototype.onExecute = function() { /* source = the source array start_idx = index of the first element to pick numMaxElem = max number of elements that will be present in the resulting array step = step amount for the for..loop */ var getPointArraySection = function(source, start_idx, numMaxElem, step) { var result = new pointArray(); if (source) { var sourceLength = source.getLength(); for (i = start_idx, cont = 0; i < sourceLength && cont < numMaxElem; i += step, cont++) { var source_elem = source.getElement(i); result.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); } } return result; } /* source = the source array pattern = string that define the selection pattern 1 or + = pick element 0 or - = skip element */ var applyPatternToPointArray = function(source, pattern) { function ResultObj(pattern) { this.array = new pointArray(); this.pattern = pattern; } var usePattern = false; var isMixedPattern = false; var result = new ResultObj(pattern); if (pattern) { result.pattern = pattern.trim(); // check the pattern if (result.pattern != '') { // check if pattern contains valid characters usePattern = result.pattern.match('^[+\-0-1]+$'); if (usePattern) { // check if pattern contains only include characters (+ or 1) usePattern = !result.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 = !result.pattern.match('^[\-0]+$'); } } } } if (usePattern) { if (isMixedPattern) { var len = source.getLength(); var patLen = result.pattern.length; var cn = 0; for (i = 0; i < len ; i++) { if ( result.pattern[cn] === '1' || result.pattern[cn] === '+') { var source_elem = source.getElement(i); result.array.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 < (patLen - 1)) ? (cn + 1) : 0; } } } else { // elaborate the whole source pointarray result.pattern = ''; result.array = source; } return result; } // Business logic var source = this.getInputData(0, new pointArray()); this.properties.start_idx = this.getInputData(1, this.properties.start_idx); this.properties.qt_max = this.getInputData(2, this.properties.qt_max); this.properties.step = this.getInputData(3, this.properties.step); if (this.properties.step <= 0) this.properties.step = 1; var patternedArray; var outputIntermediate; var outIntermLength; if (this.properties.mode[0] == "Pattern + Subset") { patternedArray = applyPatternToPointArray(source, this.properties.pattern); outputIntermediate = patternedArray.array; outIntermLength = outputIntermediate.getLength(); } else { outputIntermediate = source; outIntermLength = source.getLength(); } if ((this.properties.start_idx < 0) || (this.properties.start_idx > (outIntermLength - 1))) this.properties.start_idx = 0; if (this.properties.qt_max < 0) this.properties.qt_max = outIntermLength; outputIntermediate = getPointArraySection(outputIntermediate, this.properties.start_idx, this.properties.qt_max, this.properties.step); if (this.properties.mode[0] == "Subset + Pattern") { patternedArray = applyPatternToPointArray(outputIntermediate, this.properties.pattern); outputIntermediate = patternedArray.array; outIntermLength = outputIntermediate.getLength(); } this.properties.pattern = patternedArray.pattern; patternedArray = null; this.outputs[0].label = "Out (" + outputIntermediate.getLength() + ")"; this.outputs[1].label = "Elems (" + outputIntermediate.getLength() + ")"; this.inputs[0].label = "In (" + source.getLength() + ")"; this.setOutputData(0, outputIntermediate); this.setOutputData(1, outputIntermediate.getLength()); this.setOutputData(2, source); } LiteGraph.registerNodeType("Arrays/PatternSelArray", PatternSelArray); // ArrayReplicator function ArrayReplicator() { this.labels = "abcdef"; this.size = [140,40]; this.minsize = [140,40]; this.internal = {a:1, b:1}; this.addInput("In","pointarray"); } ArrayReplicator.title = "Array Replicator"; ArrayReplicator.desc = "Array Replicator"; ArrayReplicator.prototype.onGetOutputs = function() { var list = []; for ( var i = 0; i<this.labels.length; i++ ) { var out = this.labels.charAt(i); if ( !(out in this.internal)) { list.push([this.labels.charAt(i),"pointarray", {locked:true}]); break; } } return list; } ArrayReplicator.prototype.onOutputAdded = function(out) { this.internal[out.name] = 1; for ( var i in this.outputs ) this.outputs[i].locked = true; if (i>1) this.outputs[i].locked = false; } ArrayReplicator.prototype.onOutputRemoved = function(slot, name) { if ( this.internal[name] ) delete this.internal[name]; for ( var i in this.outputs ) this.outputs[i].locked = true; if ( this.outputs.length > 2 )this.outputs[i].locked = false; } ArrayReplicator.prototype.onAdded = function() { for ( var i = 0; i<this.labels.length; i++ ) if ( this.internal[this.labels.charAt(i)] && this.outputs.length == i ) this.addOutput(this.labels.charAt(i), "pointarray"); this.setDirtyCanvas(true); } ArrayReplicator.prototype.onExecute = function() { var source = this.getInputData(0, new pointArray()); this.inputs[0].label = "In (" + source.getLength() + ")"; for ( var i = 0; i<this.outputs.length; i++) { this.setOutputData(i, source); } } LiteGraph.registerNodeType("Arrays/ArrayReplicator", ArrayReplicator);
Image Attachments:
01_Capture.PNG
02_Capture.PNG
Show messages: 1-10 … 271-290 291-310 311-330 331-350 351-370 371-390 391-410 … 911-912