Start a new topic

Creating cable systems from C++

Hi,


Do you have any pointers on how to create a cable system using the C++ API, or general guidance on how to call extension code from C++? It seems I have to create the extension using an extension factory and can then use VxIDs to set parameters in a variant-like fashion? However unfortunately I can't find any examples on how to do something like this.


My goal is to replace VxCable usage in older code.


Thank you, that will definitely be helpful!

Hi,


Here is some code we use to create our test. I hope it will help you create a cable system by code.


 

void AttachmentPulleyAttachment::SetUp()

{

    mApplication = new VxSim::VxApplication;

   // You will need to set the application in edit mode


    mApplication->setSyncMode(VxSim::kSyncNone);

 

    mDynamicsModule = VxSim::VxExtensionFactory::create(VxSim::VxDynamicsModuleICD::kFactoryKey);

    mApplication->insertModule(mDynamicsModule);

 

    mMechanism = VxSim::VxSmartInterface<VxDynamics::Mechanism>::create(VxDynamics::MechanismICD::kFactoryKey);

    mApplication->add(mMechanism);

 

    mUniverse = mDynamicsModule->getUniverse();

 

    mCSDynamicPlugin = VxSim::VxSmartInterface<CableSystemDynamicPlugin>::create(CableSystemsICD::kDynamicsGenericCableKey);

    mMechanism->addExtension(mCSDynamicPlugin);

 

 

    mAssembly = VxSim::VxSmartInterface<VxDynamics::Assembly>::create(VxDynamics::AssemblyICD::kFactoryKey);

    mMechanism->addAssembly(mAssembly);

 

    VxData::Container& container = mCSDynamicPlugin->getProxy()->getParameterContainer();

    VxData::FieldBase& defFieldBase = container[kDefinitionID];

    mDefinition = dynamic_cast<CableSystemDefinitionContainer*>(&defFieldBase);

  CSTestFrameWork::SetUp();

 

    VxData::FieldBase& fieldBasePoints = (*mDefinition)[CableSystemDefinitionContainerID::kPointDefinitionsID];


    const Vector3 size(1,1,1);

    const double mass = 1.0;

 

    const Vector3 leftPos(-1,0,0);

    const Vector3 leftOffsetDir(0, 0, 1);

    mAttachmentLeft = CreateAttachment(*mAssembly, 0, "Left Box", *mDefinition, leftPos, size, mass, leftOffsetDir);

 

 

    const Vector3 axis(0,1,0);

    const double thickness = 0.1;

    const Vector3 pulleyPos(0,0,5);

    const double pulleyRadius = 1.0;

    mPulley = CreatePulley(*mAssembly, 1, "Pulley", NULL, *mDefinition, pulleyPos, axis, pulleyRadius, thickness);

 

    const Vector3 rightPos(1,0,0);

    const Vector3 rightOffsetDir(0, 0, 1);

    mAttachmentRight = CreateAttachment(*mAssembly, 2, "Right Box", *mDefinition, rightPos, size, mass, rightOffsetDir);

}


 

// Attach to something infinitely massive and small

/// @param[IN] idx The index of the PointDefinition in the list

VxSmartInterface<Part> CableSystems::Framework::Test::CreateAttachment(Assembly& assembly, size_t idx, const char* name,

                                                                          CableSystemDefinitionContainer& csDef,

                                                                          const Vector3& position,

                                                                          const Vector3& size, double mass, const Vector3& offsetDir)

{

    VxData::Container& ptDef = GetPointDefinition(idx, csDef);

    ptDef[PointDefinitionContainerID::kPointTypeID].setValue(VxEnum(PointDefinitionType::kAttachmentPoint));

 

    //application.update();

 

    auto attach = VxSmartInterface<Part>::create(PartICD::kFactoryKey); //TODO : this is unrefed!

    assembly.addPart(attach);

 

    attach->inputControlType = Part::kControlStatic;

    attach->setLocalTransform( VxMath::Transformation::createTranslation( position ) );

    attach->setName(name);

    VxPart* attachPart = attach->getVxPart();

 

    if (size[0] != 0.0)

    {

        VxCollisionGeometry* cg = new VxCollisionGeometry(new VxBox(size[0], size[1], size[2]));

        attachPart->addCollisionGeometry(cg);

    }

 

    ptDef[PointDefinitionContainerID::kPartID].setValue(attach.getExtension());

 

 

    Vector3 offset;

    for (size_t i = 0; i<3; ++i)

    {

        offset[i] = size[i] * offsetDir[i];

    }

 

    ptDef[PointDefinitionContainerID::kOffsetID].setValue(offset);

 

    return attach;

}


 

// Attach to something infinitely massive and small

/// @param[IN] idx The index of the PointDefinition in the list

VxSmartInterface<Part> CableSystems::Framework::Test::CreateAttachment(Assembly& assembly, size_t idx, const char* name,

                                                                          CableSystemDefinitionContainer& csDef,

                                                                          const Vector3& position,

                                                                          const Vector3& size, double mass, const Vector3& offsetDir)

{

    VxData::Container& ptDef = GetPointDefinition(idx, csDef);

    ptDef[PointDefinitionContainerID::kPointTypeID].setValue(VxEnum(PointDefinitionType::kAttachmentPoint));

 

    //application.update();

 

    auto attach = VxSmartInterface<Part>::create(PartICD::kFactoryKey); //TODO : this is unrefed!

    assembly.addPart(attach);

 

    attach->inputControlType = Part::kControlStatic;

    attach->setLocalTransform( VxMath::Transformation::createTranslation( position ) );

    attach->setName(name);

    VxPart* attachPart = attach->getVxPart();

 

    if (size[0] != 0.0)

    {

        VxCollisionGeometry* cg = new VxCollisionGeometry(new VxBox(size[0], size[1], size[2]));

        attachPart->addCollisionGeometry(cg);

    }

 

    ptDef[PointDefinitionContainerID::kPartID].setValue(attach.getExtension());

 

 

    Vector3 offset;

    for (size_t i = 0; i<3; ++i)

    {

        offset[i] = size[i] * offsetDir[i];

    }

 

    ptDef[PointDefinitionContainerID::kOffsetID].setValue(offset);

 

    return attach;

}



Remi




2 people like this
Login to post a comment