Prevent two connections from sharing the same anchor - jsplumb

I am using jsPlumb to allow users to build graphs. I allow users to drag these elements around, so I'm using a collection of anchors for each endpoint, letting jsPlumb pick the "best" anchor from that collection for me when connections are made. The problem I'm having is that I can potentially have up to a dozen connections coming from any given endpoint, so these connections will become visually distracting when many end up choosing the same "best" anchor - creating an appearance of congestion in the graph. To resolve this problem, I would like to tell jsPlumb to restrict any two connections from sharing the same anchor on an endpoint.
The easiest way to visualize what I hope to achieve is in this demo:
https://jsplumbtoolkit.com/community/demo/dynamicAnchors/index.html
Out of the box, none of the connections in this demo will overlap.
If you read the source code, you can see this is done by having a 'source' set of anchors and a 'target' set of anchors and connections are exclusively made from the first set of anchors to the second. However, as I stated above, I can have up to a dozen types of connections that can connect from or to my endpoints, so I do not want to have to specify a unique set of anchors for each of them. That would restrict the amount of spacing I can leave between each potential anchor along the endpoint's edge, since each set of anchors could not intersect with any other set of anchors.
Is there a way to tell jsPlumb that I don't want connections to share the same anchors?

jsPlumb.bind('connection',function(info){
var con=info.connection;
var arr=jsPlumb.select({source:con.sourceId,target:con.targetId});
if(arr.length>1){
jsPlumb.detach(con);
}
});
A concise one with the updated API of jsPlumb.
See if there is another connection with same source & target exists, if yes then detach the newly created one. (jsPlumb ver. 1.5.5 - 1.6.1)
Update:
Use jsPlumb.deleteConnection instead of jsPlumb.detach, in versions after than 2.4

Is there a way to tell jsPlumb that I don't want connections to share
the same anchors?
Demo with JS Fiddle
JQuery
jsPlumb.bind("jsPlumbConnection", function (CurrentConnection) {
var DuplicateCount = 0;
var allConn = jsPlumb.getAllConnections();
var length = allConn["green dot"].length;
for (var i = 0; i < length; i++) {
if (allConn["green dot"][i].targetId ==
CurrentConnection.connection.targetId) {
DuplicateCount = DuplicateCount + 1;
}
}
if (DuplicateCount > 1) {
jsPlumb.detach(CurrentConnection.connection);
return;
}
});
You can connect Pink with Green. Pink with Pink and Green with Pink and Green with Green not allowed.

Related

Projecting negative coordinates inside display area

I am testing the RandomWaypointMobility with a constrained area minX=-3000m, maxX=3000m, minY=-3000m and maxY=3000m. The #displaystrings sets bgp=6000,6000. The result is that nodes in the negative part of the coordinate system are rendered outside the display/canvas area.
Are there some parameters I can use to tell OMNeT++/INET that origo for the coordinate system is at the center of the display/canvas? I have tried
*.visualizer.sceneVisualizer.sceneMaxX = 3000m
*.visualizer.sceneVisualizer.sceneMinX = -3000m
*.visualizer.sceneVisualizer.sceneMaxY = 3000m
*.visualizer.sceneVisualizer.sceneMinY = -3000m
*.visualizer.sceneVisualizer.sceneMaxZ = 3000m
*.visualizer.sceneVisualizer.sceneMinZ = -3000m
but it doesn't work as I hoped for.
I realize that for RandomWaypointMobility I can just use a constrained area with positive coordinates only, which would keep objects within the canvas. However, my next task is to pull in mobility traces that include negative coordinates. Do I need to manually shift all coordinates so they become positive and stay within the canvas/display, or is there a smarter way of doing things?
Any hints appreciated!
Thanks,
Dragos
What you set is in fact bgb=6000,6000 which sets the size of the module. There were indeed plans to add a tag called bgp directly into OMNeT++ which would introduce an offset, but at the end it was not implemented. The reason is that once you go down into that rabbit hole, you want to implement also scaling and then rotation etc. So the default display string based visualization left as simple as possible and all these transformation stuff was left for the model code.
So indeed, SceneCanvasVisualizer in INET has a viewScale and viewTranslation parameter that can be used for these purposes.

How to project (or paste)panorama to model?

Before question,I seached many places, I find some similar idea but without my solution.And my question can be also described as how to recalculate the model's uv to fix the panorama designed for six faces skybox.
Recently,I came upon a unique way to get fluent 3D roaming experience on matterport's Official network https://matterport.com/gallery/
I just want to know how did they do that?Their product is very fluent when swich the panorama picture.
After I roaming many times,I found the secret. I realized that the panorama carrier they use is not box or sphere,but is the object they show first!The evidence is that when switch the point,the object such as chair and table would have their own shadow(one chair have two image one stand up and the other one lie on the floor
With the object in panorama paste on their own correspond object and with depth information the roaming switch become more fluent (As for why they do not use the object directly ,I think because of the limited hardware,Many irregularity faces which get from scanning equipment cannot be use directly
And I want to use this idea in my project ,I have a group of six panorama which can paste on a boxGeometry perfectly,and I just want to paste them on model.but I stuck in project 360 degree.Yes I just find how to project one direction but I cannot project the remaining five.
var _p=BufferGeometry.attributes;
for (var i = 0; i < _p.position.count; i++){
var uvtempbeforeconvert= ( new THREE.Vector3(_p.position.array[3*i],_p.position.array[3*i+1],_p.position.array[3*i+2]) ).clone().applyMatrix4(houseObject.matrixWorld).project(camera1)
//use the worldvertices to get its screen coordinate
if(uvtempbeforeconvert.x<1&&uvtempbeforeconvert.x>-1 && uvtempbeforeconvert.y<1 &&uvtempbeforeconvert.y>-1) {
VerticesArray1.push(_p.position.array[3*i],_p.position.array[3*i+1],_p.position.array[3*i+2]);uvArray1.push(uvtempbeforeconvert.x*0.5+0.5,uvtempbeforeconvert.y*0.5+0.5);
Yes,I success in calculating one direction.BUT I cant deal with the triangle faces which occupy two more view frustum,like a face at the edge of the box.
How should I deal with this problem?Or I run in the FALSE direction at first?Which direction should i run in ?
After asking many people,I just find that I need to usd shadermaterial in threejs ,and use a function named cubetexture,samplercube.With that I can get the pixel color what I need!

argon-aframe move with the users geolocation

I have this project:
my codepen
I want to be able to move forward when the user walks, so it feels like they are walking thru the floor plan in VR as they are in real life.
my goal is get the geolocation of the user and show them the room matching theirs location and have them walk around the room while viewing the AR on the phone they would see paintings on the walls.
my challenges are:
walk in real life and move in VR (right now I have it auto walking forward in the meantime)
var speed = 0.0;
var iMoving = false;
var velocityDelta;
AFRAME.registerComponent("automove-controls", {
init: function() {
this.speed = 0.1;
this.isMoving = true;
this.velocityDelta = new THREE.Vector3();
},
isVelocityActive: function() {
return this.isMoving;
},
getVelocityDelta: function() {
this.velocityDelta.z = this.isMoving ? -this.speed : 0;
return this.velocityDelta.clone();
}
});
capture the user geo location so the moment they open the site they are placed relative to their location on the floor plan
this is my first attempt so any feed back would be appreciated.
As far as i know argon.js is more about geoposition than spatial/marker based augmented reality.
moreover It's quite worrying, that their repo for aframe was not touched for a while.
Argon seems like a library for creating scenes in certain points around the user, even their examples base on positioning stuff around, reason being the GPS/phone accelerometers are way too bad to provide useful data for providing spatial positioning. Thats why VIVE needs two towers, and other devices at least a camera/IR device, to get information about the HMD device.
Positioning the person inside a point depending where are they in a room is quite a difficult task, You would need to get a point of reference and position the user accordingly. It seems impossible, since the user can be anywhere in the world.
I would try to do this using jerome-etienne's marker based AR.js. The markers would be the points of reference You need, and although image processing seems like a difficult task, AR.js is surprisingly stable with multiple markers, which help in creating complex scenes.
The markers seems like a good idea, for they can help You with the positioning, moreover simple scenes have no problem with achieving 60+fps, making the experience quite comfortable.
I would start there, since AR.js seems to be updated frequently.

Fabric.js doesn't maintain group when exporting/importing JSON

So I have another issue with Fabric.js that's once again probably down to my own ignorance.
Imagine using free draw to scribble some line paths on to a canvas. When finished, we disable free draw and at this point I want to take all the objects drawn and group them in to a single entity.
I've created a fiddle here that shows the grouping stage.
var grp=new fabric.Group();
canvas.getObjects().map(function(o){
if(o.type=="path"){
o.hasControls=o.hasBorders=false;
grp.addWithUpdate(o);
//canvas.clear(); // this seems to break grouping
}
});
canvas.add(grp);
canvas._activeObject = null;
canvas.setActiveGroup(grp.setCoords()).renderAll();
This appears to work well enough (even if the paths themselves appear to darken once the group has been created).
I now want to export this to JSON, save at a DB, and in the future reload and replicate the whole layout.
In the fiddle above I reproduce this sort of behaviour by first saving the canvas to JSON after the group has been created, and then attempt to reload it.
As you'll see, the reload itself works fine and the positioning is good but the item that was previously grouped has been loaded in to it's constituent parts, rather than being maintained as a group.
Am I doing something dumb here?
Thanks for any help!

JsPlumb - Basic setup advice

I've never used jsplumb before and I have read some of the documentation and looked at the demos, but I still don't understand..
I want to create a DIV like this :
One Input and upto 8 outputs (this value may change)
How do I do this ?
I will be looking at cloning this div and incrementing the divs ID, so I could end up with two or more divs that need to be able to join like this.
Can anyone help with this or point me to some simple examples..
Thanks
You need to add the bigger div as a target endpoint and the smaller div's as source end point.
var e1 = jsPlumb.addEndpoint(idSource, sourceEndpoint);
var e2 = jsPlumb.addEndpoint(idTarget, targetEndpoint);
where sourceEndpoint and targetEndpoints are objects with definitions for how the endpoint will look and behave .
Have a look at one of the examples to get the behaviour you desire.
jsPlumb should then allow you to drag and drop connections from source to targets.
The state machine demo does almost the same thing as what you need.
http://www.jsplumb.org/demo/flowchart/dom.html

Resources