diff --git a/VirtualRobot/Nodes/RobotNode.cpp b/VirtualRobot/Nodes/RobotNode.cpp index e02ea25f2bd1f231b94de2d89a60885d7ccb778b..3ec10dcdc0ed0f5afe756a1df8eea000704f19cd 100644 --- a/VirtualRobot/Nodes/RobotNode.cpp +++ b/VirtualRobot/Nodes/RobotNode.cpp @@ -525,7 +525,11 @@ namespace VirtualRobot } } - RobotNodePtr RobotNode::clone(RobotPtr newRobot, bool cloneChildren, RobotNodePtr initializeWithParent, CollisionCheckerPtr colChecker, float scaling) + RobotNodePtr RobotNode::clone(RobotPtr newRobot, bool cloneChildren, + RobotNodePtr initializeWithParent, + CollisionCheckerPtr colChecker, + float scaling, + bool preventCloningMeshesIfScalingIs1) { ReadLockPtr lock = getRobot()->getReadLock(); @@ -539,16 +543,17 @@ namespace VirtualRobot VisualizationNodePtr clonedVisualizationNode; + const bool deepMeshClone = !preventCloningMeshesIfScalingIs1 || std::abs(scaling - 1) <= 0; if (visualizationModel) { - clonedVisualizationNode = visualizationModel->clone(true, scaling); + clonedVisualizationNode = visualizationModel->clone(deepMeshClone, scaling); } CollisionModelPtr clonedCollisionModel; if (collisionModel) { - clonedCollisionModel = collisionModel->clone(colChecker, scaling); + clonedCollisionModel = collisionModel->clone(colChecker, scaling, deepMeshClone); } RobotNodePtr result = _clone(newRobot, clonedVisualizationNode, clonedCollisionModel, colChecker, scaling); @@ -569,7 +574,7 @@ namespace VirtualRobot if (n) { - RobotNodePtr c = n->clone(newRobot, true, RobotNodePtr(), colChecker, scaling); + RobotNodePtr c = n->clone(newRobot, true, RobotNodePtr(), colChecker, scaling, preventCloningMeshesIfScalingIs1); if (c) { diff --git a/VirtualRobot/Nodes/RobotNode.h b/VirtualRobot/Nodes/RobotNode.h index 0140cf6b14662479376abb258ef39544a1d1c37f..4437628d38b51fc915c0bedf85de7e485b16bb67 100644 --- a/VirtualRobot/Nodes/RobotNode.h +++ b/VirtualRobot/Nodes/RobotNode.h @@ -144,7 +144,7 @@ namespace VirtualRobot /* This call locks the robot's mutex. */ - virtual Eigen::Matrix4f getGlobalPose() const override; + Eigen::Matrix4f getGlobalPose() const override; /*! The pose of this node in the root coordinate system of the robot. @@ -235,7 +235,12 @@ namespace VirtualRobot \param colChecker Must only be set if the cloned RobotNode should be registered to a different collision checker instance. \param scaling Scale Can be set to create a scaled version of this robot. Scaling is applied on kinematic, visual, and collision data. */ - virtual RobotNodePtr clone(RobotPtr newRobot, bool cloneChildren = true, RobotNodePtr initializeWithParent = RobotNodePtr(), CollisionCheckerPtr colChecker = CollisionCheckerPtr(), float scaling = 1.0f); + virtual RobotNodePtr clone(RobotPtr newRobot, + bool cloneChildren = true, + RobotNodePtr initializeWithParent = RobotNodePtr(), + CollisionCheckerPtr colChecker = CollisionCheckerPtr(), + float scaling = 1.0f, + bool preventCloningMeshesIfScalingIs1 = false); inline float getJointValueOffset() const { diff --git a/VirtualRobot/Robot.cpp b/VirtualRobot/Robot.cpp index 00954690f807329312459725280c800e7e7a14b7..4ded518edf76764c8e43ea2d0146b1b89e6f71cb 100644 --- a/VirtualRobot/Robot.cpp +++ b/VirtualRobot/Robot.cpp @@ -754,7 +754,14 @@ namespace VirtualRobot return result; } - VirtualRobot::RobotPtr Robot::extractSubPart(RobotNodePtr startJoint, const std::string& newRobotType, const std::string& newRobotName, bool cloneRNS, bool cloneEEFs, CollisionCheckerPtr collisionChecker, float scaling) + VirtualRobot::RobotPtr Robot::extractSubPart(RobotNodePtr startJoint, + const std::string& newRobotType, + const std::string& newRobotName, + bool cloneRNS, + bool cloneEEFs, + CollisionCheckerPtr collisionChecker, + float scaling, + bool preventCloningMeshesIfScalingIs1) { THROW_VR_EXCEPTION_IF(!startJoint, " StartJoint is nullptr"); THROW_VR_EXCEPTION_IF(!hasRobotNode(startJoint), " StartJoint '" + startJoint->getName() + "' is not part of this robot '" + getName() + "'"); @@ -770,7 +777,7 @@ namespace VirtualRobot //stefan Warning!!!!! which robot-type to create RobotPtr result(new LocalRobot(newRobotName, newRobotType)); - RobotNodePtr rootNew = startJoint->clone(result, true, RobotNodePtr(), colChecker, scaling); + RobotNodePtr rootNew = startJoint->clone(result, true, RobotNodePtr(), colChecker, scaling, preventCloningMeshesIfScalingIs1); THROW_VR_EXCEPTION_IF(!rootNew, "Clone failed..."); result->setRootNode(rootNew); result->setScaling(scaling); @@ -884,9 +891,17 @@ namespace VirtualRobot } - VirtualRobot::RobotPtr Robot::clone(const std::string& name, CollisionCheckerPtr collisionChecker, float scaling) + VirtualRobot::RobotPtr Robot::clone(const std::string& name, + CollisionCheckerPtr collisionChecker, + float scaling, + bool preventCloningMeshesIfScalingIs1) { - VirtualRobot::RobotPtr result = extractSubPart(this->getRootNode(), this->getType(), name, true, true, collisionChecker, scaling); + VirtualRobot::RobotPtr result = extractSubPart(this->getRootNode(), + this->getType(), + name, true, true, + collisionChecker, + scaling, + preventCloningMeshesIfScalingIs1); result->setGlobalPose(getGlobalPose()); result->filename = filename; result->type = type; @@ -894,9 +909,11 @@ namespace VirtualRobot return result; } - RobotPtr Robot::clone() + RobotPtr Robot::clone(CollisionCheckerPtr collisionChecker, + float scaling, + bool preventCloningMeshesIfScalingIs1) { - return clone(getName()); + return clone(getName(), collisionChecker, scaling, preventCloningMeshesIfScalingIs1); } void Robot::createVisualizationFromCollisionModels() diff --git a/VirtualRobot/Robot.h b/VirtualRobot/Robot.h index 7410f4cb917edd6d8daa50630ad3d69f6150c71f..e832ffb80f83684dec213bfa419ad136257bf117 100644 --- a/VirtualRobot/Robot.h +++ b/VirtualRobot/Robot.h @@ -233,7 +233,14 @@ namespace VirtualRobot \param collisionChecker The new robot can be registered to a different collision checker. If not set, the collision checker of the original robot is used. \param scaling Can be set to create a scaled version of this robot. Scaling is applied on kinematic, visual, and collision data. */ - virtual RobotPtr extractSubPart(RobotNodePtr startJoint, const std::string& newRobotType, const std::string& newRobotName, bool cloneRNS = true, bool cloneEEFs = true, CollisionCheckerPtr collisionChecker = CollisionCheckerPtr(), float scaling = 1.0f); + virtual RobotPtr extractSubPart(RobotNodePtr startJoint, + const std::string& newRobotType, + const std::string& newRobotName, + bool cloneRNS = true, + bool cloneEEFs = true, + CollisionCheckerPtr collisionChecker = CollisionCheckerPtr(), + float scaling = 1.0f, + bool preventCloningMeshesIfScalingIs1 = false); /*! Clones this robot. @@ -242,8 +249,13 @@ namespace VirtualRobot \param scaling Scale Can be set to create a scaled version of this robot. Scaling is applied on kinematic, visual, and collision data. */ - virtual RobotPtr clone(const std::string& name, CollisionCheckerPtr collisionChecker = CollisionCheckerPtr(), float scaling = 1.0f); - virtual RobotPtr clone(); + virtual RobotPtr clone(const std::string& name, + CollisionCheckerPtr collisionChecker = CollisionCheckerPtr(), + float scaling = 1.0f, + bool preventCloningMeshesIfScalingIs1 = false); + virtual RobotPtr clone(CollisionCheckerPtr collisionChecker = CollisionCheckerPtr(), + float scaling = 1.0f, + bool preventCloningMeshesIfScalingIs1 = false); //! Just storing the filename. virtual void setFilename(const std::string& filename); @@ -443,7 +455,7 @@ namespace VirtualRobot std::shared_ptr<T> Robot::getVisualization(SceneObject::VisualizationType visuType, bool sensors) { static_assert(::std::is_base_of_v<Visualization, T>, - "TEMPLATE_PARAMETER_FOR_VirtualRobot_getVisualization_MUST_BT_A_SUBCLASS_OF_VirtualRobot__Visualization"); + "TEMPLATE_PARAMETER_FOR_VirtualRobot_getVisualization_MUST_BT_A_SUBCLASS_OF_VirtualRobot__Visualization"); std::vector<RobotNodePtr> collectedRobotNodes; getRobotNodes(collectedRobotNodes); std::vector<VisualizationNodePtr> collectedVisualizationNodes;