Skip to content

Commit

Permalink
hardwareinterface API for attaching existing nodes to groundplane. ob…
Browse files Browse the repository at this point in the history
…ject.js API for creating nodes and attaching to ground plane, and to reset (delete) all nodes on the object
  • Loading branch information
benptc committed May 1, 2019
1 parent 3e8d7d3 commit 9a74793
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
17 changes: 17 additions & 0 deletions libraries/hardwareInterfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,23 @@ exports.removeNode = function (objectName, frameName, nodeName) {
}
};

exports.attachNodeToGroundPlane = function (objectName, frameName, nodeName, shouldAttachToGroundPlane) {
var objectID = utilities.getObjectIdFromTarget(objectName, objectsPath);
var frameID = objectID + frameName;
var nodeID = objectID + frameName + nodeName;

if (!_.isUndefined(objectID) && !_.isNull(objectID)) {
if (objects.hasOwnProperty(objectID)) {
if (objects[objectID].frames.hasOwnProperty(frameID)) {
if (objects[objectID].frames[frameID].nodes.hasOwnProperty(nodeID)) {

objects[objectID].frames[frameID].nodes[nodeID].attachToGroundPlane = shouldAttachToGroundPlane;
console.log("attached node " + nodeName + " to ground plane");
}
}
}
}
};

exports.pushUpdatesToDevices = function(object){
var objectID = utilities.getObjectIdFromTarget(object, objectsPath);
Expand Down
21 changes: 19 additions & 2 deletions libraries/objectDefaultFiles/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
this.injectPostMessage();
} else {
this.sendGlobalMessage = makeSendStub('sendGlobalMessage');
this.sendResetNodes = makeSendStub('sendResetNodes');
this.sendCreateNode = makeSendStub('sendCreateNode');
this.subscribeToMatrix = makeSendStub('subscribeToMatrix');
this.subscribeToAcceleration = makeSendStub('subscribeToAcceleration');
Expand Down Expand Up @@ -824,13 +825,29 @@
}), '*');
};

this.sendCreateNode = function (name) {
this.sendResetNodes = function () {
//removes all nodes from the frame
parent.postMessage(JSON.stringify({
version: realityObject.version,
node: realityObject.node,
frame: realityObject.frame,
object: realityObject.object,
createNode: {name: name}
resetNodes: true
}), '*');
};

this.sendCreateNode = function (name, x, y, attachToGroundPlane) {
parent.postMessage(JSON.stringify({
version: realityObject.version,
node: realityObject.node,
frame: realityObject.frame,
object: realityObject.object,
createNode: {
name: name,
x: x,
y: y,
attachToGroundPlane: attachToGroundPlane
}
}), '*');
};

Expand Down

0 comments on commit 9a74793

Please sign in to comment.