Skip to content

Commit

Permalink
WMR controllers interaction profile
Browse files Browse the repository at this point in the history
  • Loading branch information
kwahoo2 committed Aug 4, 2021
1 parent bcf7444 commit 45dc981
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 59 deletions.
54 changes: 43 additions & 11 deletions src/Gui/CoinXRWidget.cpp
Expand Up @@ -587,6 +587,33 @@ void CoinXRWidget::prepareControls()
instance.suggestInteractionProfileBindings(suggestedBindings);
}

{
dispatch.xrStringToPath(instance, "/interaction_profiles/microsoft/motion_controller", interactionProfilePath.put());

const xr::ActionSuggestedBinding bindings[] {
{poseAction,
posePaths[0]},
{poseAction,
posePaths[1]},
{xLeverAction,
trackpadXPath[0]},
{xLeverAction,
trackpadXPath[1]},
{yLeverAction,
trackpadYPath[0]},
{yLeverAction,
trackpadYPath[1]},
{grabAction,
triggerValuePath[0]},
{grabAction,
triggerValuePath[1]}
};
suggestedBindings.suggestedBindings = bindings;
suggestedBindings.interactionProfile = interactionProfilePath;
suggestedBindings.countSuggestedBindings = sizeof(bindings) / sizeof(bindings[0]);
instance.suggestInteractionProfileBindings(suggestedBindings);
}

xr::ActionSpaceCreateInfo actionSpaceInfo {};
actionSpaceInfo.type = xr::StructureType::ActionSpaceCreateInfo;
actionSpaceInfo.next = nullptr;
Expand Down Expand Up @@ -933,8 +960,8 @@ void CoinXRWidget::updateXrControls()
mXRi->setControllerState(i, conTrans[i], conRotat[i], currTriggerVal[i]);
}

if (((currTriggerVal[0] > 0.2 && oldTriggerVal[0] <= 0.2) && (currTriggerVal[1] > 0.2))
|| ((currTriggerVal[1] > 0.2 && oldTriggerVal[1] <= 0.2) && (currTriggerVal[0] > 0.2))) //enable or disable Interaction
if (((currTriggerVal[0] > 0.2f && oldTriggerVal[0] <= 0.2f) && (currTriggerVal[1] > 0.2f))
|| ((currTriggerVal[1] > 0.2f && oldTriggerVal[1] <= 0.2f) && (currTriggerVal[0] > 0.2f))) //enable or disable Interaction
{
if (interaction)
{
Expand All @@ -955,6 +982,7 @@ void CoinXRWidget::updateXrGui()
{
if (interaction)
{
const SoPickedPoint *pp;
//picking ray
SbVec3f startVec = conTrans[secondaryConId]->translation.getValue();
SbVec3f endVec = conTrans[secondaryConId]->translation.getValue() - rayAxis;
Expand All @@ -965,23 +993,27 @@ void CoinXRWidget::updateXrGui()
menuRoot->addChild(camera[0]);
menuRoot->addChild(conMenuSep);

if (mXRi->findPickedObject(menuRoot, vpReg,
startVec, endVec, rayAxis,
nearPlane, farPlane))
{
//place for menu operations

pp = mXRi->findPickedObject(menuRoot, vpReg,
startVec, endVec, rayAxis,
nearPlane, farPlane);
if (pp)
{
//place for menu operations
mXRi->pickMenuItem(pp, secondaryConId);
}
else
{
//if menu not hit, check the scene
mXRi->findPickedObject(wSep, vpReg,
startVec, endVec, rayAxis,
nearPlane, farPlane);
pp = mXRi->findPickedObject(wSep, vpReg,
startVec, endVec, rayAxis,
nearPlane, farPlane);
mXRi->getPickedObjectInfo(pp, secondaryConId);
}

//prepare and execute commands
mXRi->applyInput();
mXRi->applyInput(primaryConId);

}

}
Expand Down
153 changes: 106 additions & 47 deletions src/Gui/XRInteraction.cpp
Expand Up @@ -33,12 +33,17 @@

#include "PreCompiled.h"
#include "XRInteraction.h"

#include <View3DInventor.h>
#include <View3DInventorViewer.h>
#include <ViewProvider.h>
#include "ViewProviderDocumentObject.h"
#include "ViewProviderExtern.h"

XRInteraction::XRInteraction()
{
doc = App::GetApplication().getActiveDocument();
cmd = QString::fromLatin1("import Part, math");

cmd = QString::fromLatin1("import Part, math, pivy");
Gui::Command::doCommand(Gui::Command::Doc, cmd.toUtf8());

//menu
Expand All @@ -47,21 +52,32 @@ XRInteraction::XRInteraction()
SoTranslation *menuTrans = new SoTranslation;
menuTrans->translation.setValue(SbVec3f(0.0f, 0.12f,-0.15f));
menuSep->addChild(menuTrans);
menuCube = new SoCube();
/*menuCube = new SoCube();
menuCube->width.setValue(0.2f);
menuCube->height.setValue(0.2f);
menuCube->depth.setValue(0.001f);
menuSep->addChild(menuCube);
menuSep->addChild(menuCube);*/
SoTranslation *textTrans = new SoTranslation;
textTrans->translation.setValue(SbVec3f(0.0f, 0.1f,0.01f));
menuSep->addChild(textTrans);
menuText = new SoText3;
menuText = new SoText3; //this is status bar
SoScale * textScale = new SoScale;
textScale->scaleFactor.setValue(SbVec3f(0.005f, 0.005f, 0.005f));
menuText->string = "Press triggers to enable ray";
menuSep->addChild(textScale);
menuSep->addChild(menuText);

SoTranslation *lineSpacing = new SoTranslation;
lineSpacing->translation.setValue(SbVec3f(0.0f, -10.0f, 0.0f));
menuSep->addChild(lineSpacing);
menuTextLine0 = new SoText3; //this menu item
menuTextLine0->string = "Menu Item 0";
menuSep->addChild(menuTextLine0);
menuSep->addChild(lineSpacing);
menuTextLine1 = new SoText3; //this menu item
menuTextLine1->string = "Menu Item 1";
menuSep->addChild(menuTextLine1);
menuSep->addChild(lineSpacing);

//ray for picking objects
rSep = new SoSeparator();
Expand All @@ -84,54 +100,97 @@ XRInteraction::XRInteraction()

}

void XRInteraction::applyInput()
void XRInteraction::applyInput(uint32_t conId)
{
for (uint32_t i = 0; i < hands; i++){
if (currTriggerVal[i] > 0.9 && oldTriggerVal[i] <= 0.9)
{

double l = 200.0;
double w = 100.0;
double h = 500.0;

cmd = QString::fromLatin1("box%1 = App.getDocument('%2').addObject('%3','%4')\n"
"box%1.Length = %5\n"
"box%1.Width = %6\n"
"box%1.Height = %7\n"
"q = (%11, %12, %13, %14)\n"
"r=FreeCAD.Rotation(*q)\n"
"box%1.Placement.rotate(App.Vector(0, 0, 0), r.Axis, r.Angle*180/math.pi)\n"
"box%1.Placement.move(App.Vector(%8, %9, %10))\n"
)
.arg(QString::number(objCount))
.arg(QString::fromLatin1(doc->getName()))
.arg(QString::fromLatin1("Part::Box"))
.arg(QString::fromLatin1("Cube") + QString::number(objCount))
.arg(l)
.arg(w)
.arg(h)
/*meters to milimeters conversion*/
.arg((conTransVec[i][0]) * 1000)
.arg((conTransVec[i][1]) * 1000)
.arg((conTransVec[i][2]) * 1000)
.arg(conRotatQuat[i][0])
.arg(conRotatQuat[i][1])
.arg(conRotatQuat[i][2])
.arg(conRotatQuat[i][3]);


Gui::Command::doCommand(Gui::Command::Doc, cmd.toUtf8());
//doc->recompute();
objCount++;

std::string s = "Cube " + std::to_string(objCount);
menuText->string = s.c_str();
if (currTriggerVal[conId] > 0.9f && oldTriggerVal[conId] <= 0.9f)
{

double l = 200.0;
double w = 100.0;
double h = 500.0;

cmd = QString::fromLatin1("box%1 = App.getDocument('%2').addObject('%3','%4')\n"
"box%1.Length = %5\n"
"box%1.Width = %6\n"
"box%1.Height = %7\n"
"q = (%11, %12, %13, %14)\n"
"r=FreeCAD.Rotation(*q)\n"
"box%1.Placement.rotate(App.Vector(0, 0, 0), r.Axis, r.Angle*180/math.pi)\n"
"box%1.Placement.move(App.Vector(%8, %9, %10))\n"
)
.arg(QString::number(objCount))
.arg(QString::fromLatin1(doc->getName()))
.arg(QString::fromLatin1("Part::Box"))
.arg(QString::fromLatin1("Cube") + QString::number(objCount))
.arg(l)
.arg(w)
.arg(h)
/*meters to milimeters conversion*/
.arg((conTransVec[conId][0]) * 1000)
.arg((conTransVec[conId][1]) * 1000)
.arg((conTransVec[conId][2]) * 1000)
.arg(conRotatQuat[conId][0])
.arg(conRotatQuat[conId][1])
.arg(conRotatQuat[conId][2])
.arg(conRotatQuat[conId][3]);


Gui::Command::doCommand(Gui::Command::Doc, cmd.toUtf8());
//doc->recompute();
objCount++;

std::string s = "Cube " + std::to_string(objCount);
menuText->string = s.c_str();
}
oldTriggerVal[conId] = currTriggerVal[conId];

}


void XRInteraction::getPickedObjectInfo(const SoPickedPoint *Point, uint32_t conId)
{

/* if (currTriggerVal[conId] > 0.9f)
{
std::string objStr = "";
Gui::Document* doc = Gui::Application::Instance->activeDocument();
Gui::View3DInventor* view = dynamic_cast<Gui::View3DInventor*>(doc->getActiveView());
if (view) {
Gui::ViewProvider *vp = doc ? doc->getViewProviderByPathFromHead(Point->getPath())
: view->getViewer()->getViewProviderByPath(Point->getPath());
Gui::ViewProviderDocumentObject* vpd = static_cast<Gui::ViewProviderDocumentObject*>(vp);
auto obj = vpd->getObject();
if (obj)
{
objStr = obj->getNameInDocument();
//Base::Console().Message("%s\n", objStr.c_str());
}
oldTriggerVal[i] = currTriggerVal[i];
}
//menuText->string = objStr.c_str();
}*/
}
void XRInteraction::pickMenuItem(const SoPickedPoint *Point, uint32_t conId)
{

SoNode *tail = Point->getPath()->getTail();
if (tail->getNodeId() == menuTextLine0->getNodeId())
{
// menuTextLine0->string = "[Menu Item 0]";
//menuTextLine1->string = "Menu Item 1";
Base::Console().Message("Menu Item 0\n");
}
else if (tail->getNodeId() == menuTextLine1->getNodeId())
{
//menuTextLine0->string = "Menu Item 0";
//menuTextLine1->string = "[Menu Item 1]";
Base::Console().Message("Menu Item 1\n");
}

}



void XRInteraction::setControllerState(uint32_t id, const SoTranslation *st, const SoRotation *sr, float tv)
{
conTransVec[id] = st->translation.getValue();
Expand Down
7 changes: 6 additions & 1 deletion src/Gui/XRInteraction.h
Expand Up @@ -64,13 +64,15 @@ class XRInteraction
explicit XRInteraction();
~XRInteraction();

void applyInput();
void applyInput(uint32_t conId);
void setControllerState(uint32_t id, const SoTranslation *st, const SoRotation *sr, float tv);
SoSeparator * getMenuSeparator();
SoSeparator * getRaySeparator();
const SoPickedPoint * findPickedObject(SoSeparator *sep, SbViewportRegion vpReg,
SbVec3f startVec, SbVec3f endVec, SbVec3f rayAxis,
float nearPlane, float farPlane);
void getPickedObjectInfo(const SoPickedPoint *Point, uint32_t conId);
void pickMenuItem(const SoPickedPoint *Point, uint32_t conId);

private:

Expand All @@ -93,7 +95,10 @@ class XRInteraction

SoSeparator *menuSep;
SoText3 *menuText;
SoText3 *menuTextLine0;
SoText3 *menuTextLine1;
SoCube *menuCube;

};

#endif // GUI_XRInteraction

0 comments on commit 45dc981

Please sign in to comment.