Understandindg the way Moi and Nodeeditor follow to manage the order of selected objects
All  1-8  9-10

Previous
Next
 From:  mkdm
7957.9 In reply to 7957.7 
Hi Max,

Thank you very much for your help.

Point 1)

As suggested also by Karsten, i already successfully tested the use of sortBySelectionOrder() method
to manage the selected objects in a predictable and defined way.

Here's the modified version of the node SelectedObjects() that i used :

code:
// ######### Get selected objects  ##########
function SelectedObjects()
{
	this.addOutput("","objectlist");
	this.inputobjects = moi.geometryDatabase.createObjectList();
	this.clones = moi.geometryDatabase.getObjects();
	
        this.properties = { order:["By Selection", "By Selection", "By Creation"] };
	this.origSelobjects = moi.geometryDatabase.createObjectList();
	
}

SelectedObjects.title = "Selected";
SelectedObjects.desc = "Selected objects";

SelectedObjects.prototype.onAdded = function() 
{
	var allobjects = moi.geometryDatabase.getObjects();
	var createdObjs = this.graph.getCreatedObjects();
	
	this.origSelobjects = moi.geometryDatabase.createObjectList();
	
	for ( var o = 0; o < allobjects.length; o++ ) {
		var obj = allobjects.item(o);
		if ( obj.selected && obj.displayMode === 0 && !obj.hidden && createdObjs.indexOf(obj.id)<0 ) {
			this.inputobjects.addObject(obj);
			this.origSelobjects.addObject(obj);
		}
	}
	
	if (this.properties.order[0] == "By Selection") {
		this.inputobjects.sortBySelectionOrder();
	}
	
	this.inputobjects.setProperty( 'selected',0);
	this.inputobjects.setProperty( 'displayMode',1);
	if (this.graph.status > 1 && !this.selected ) this.inputobjects.setProperty( 'hidden', true);
	this.outputs[0].label = "("+this.inputobjects.length+")";
	this.clones = moi.geometryDatabase.createObjectList();
	for ( var o = 0; o < this.inputobjects.length; o++ ) { this.clones.addObject(this.inputobjects.item(o).clone()); this.clones.item(o).styleIndex = this.inputobjects.item(o).styleIndex; }
	this.computeSize();
}

SelectedObjects.prototype.onPropertyChange = function() 
{
	this.inputobjects = moi.geometryDatabase.createObjectList();
	for ( var o = 0; o < this.origSelobjects.length; o++ ) {
		this.inputobjects.addObject(this.origSelobjects.item(o));
	}
	
	if (this.properties.order[0] == "By Selection") {
		this.inputobjects.sortBySelectionOrder();
	}	
	this.clones = moi.geometryDatabase.createObjectList();
	for ( var o = 0; o < this.inputobjects.length; o++ ) { this.clones.addObject(this.inputobjects.item(o).clone()); this.clones.item(o).styleIndex = this.inputobjects.item(o).styleIndex; }
}

SelectedObjects.prototype.getExtraMenuOptions = function(graphcanvas) {var that = this, thatgraph = this.graph;  return [{content:lang.getTranslation("Update"), callback: function() { that.onClear(); that.onAdded(); thatgraph.setisChangedFlag(that.id);}}, { content:lang.getTranslation("Clear"), callback: function() { that.onClear(); thatgraph.setisChangedFlag(that.id);}}]; }
SelectedObjects.prototype.onClear = function() { this.onRemoved(); this.inputobjects = moi.geometryDatabase.createObjectList(); this.outputs[0].label = this.inputobjects.length; this.clones = moi.geometryDatabase.createObjectList();}
SelectedObjects.prototype.onRemoved = function() { this.inputobjects.setProperty( 'displayMode',0); this.inputobjects.setProperty( 'hidden', false);  this.inputobjects.setProperty( 'selected',1);}
SelectedObjects.prototype.onStart = function() { if (!this.selected) this.inputobjects.setProperty( 'hidden',true); }
SelectedObjects.prototype.onStop = function() { this.inputobjects.setProperty( 'hidden', false); }
SelectedObjects.prototype.onSelected = function() { this.inputobjects.setProperty( 'hidden', false); }
SelectedObjects.prototype.onDeselected = function() { if (this.graph.status > 1) this.inputobjects.setProperty( 'hidden',true); }
SelectedObjects.prototype.onExecute = function()
{
	this.setOutputData(0, this.clones);
}
SelectedObjects.prototype.onApply = function() {}
SelectedObjects.prototype.onDrawBackground = function(ctx) {}

LiteGraph.registerNodeType("Objects/Selected", SelectedObjects);


Point 2)

>>I don't understand how a selection order could affect on automatically generated pointArrays?

You're right, i didn't explain well.

I try to better illustrate what i would like to do.

I'm trying to understand if could be a way to control the generation order of the objects that are AUTOMATICALLY GENERATED
inside Nodeeditor by the "Array" family nodes.

Or, to be more precise, if and how the "Array" family nodes, could be extended with a business logic that allow
to pick or get a subset of all the points present in the arrays, in a SPECIFIC ORDER.

Just by way of example, consider this "SPECIFIC ORDER" like a sort of PATH formula.

In the same way, i'm thinking of an "Array" as a "stream" of points,
from which extract the elements not in a sequential order, or by following the creation order,
but with an order specified by a formula or any other logic way.

Just to try to be less unclear, the attached picture it is an attempt to explain what i'm saying.

In the picture, the green polyline represent a possible elaboration of the 3d grid of points,
obtained by "extracting" the points from the stream, represented by the "Array",
in a given order.

What do you think about this idea ?

Nice night,

Marco.
Image Attachments:
Size: 2 MB, Downloaded: 31 times, Dimensions: 1918x1035px
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  mkdm
7957.10 In reply to 7957.8 
Hi Michael,

Thank you very much for your help.

As suggested also by Karsten, i already successfully tested the use of sortBySelectionOrder() method
to manage the selected objects in a predictable and defined way.

Nice night,

Marco.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1-8  9-10