508 if (
nullptr == scene_)
510 gzerr <<
"Cloning a visual failed because the visual to be cloned is "
511 <<
"not attached to a scene.\n";
516 result = scene_->CreateVisual();
518 result = scene_->CreateVisual(_name);
520 if (
nullptr != _newParent)
522 auto parentScene = _newParent->Scene();
523 if (
nullptr != parentScene && parentScene->Id() != scene_->Id())
525 gzerr <<
"Cloning a visual failed because the desired parent of the "
526 <<
"cloned visual belongs to a different scene.\n";
527 scene_->DestroyVisual(result);
530 _newParent->AddChild(result);
533 result->SetOrigin(this->Origin());
534 result->SetInheritScale(this->InheritScale());
535 result->SetLocalScale(this->LocalScale());
536 result->SetLocalPose(this->LocalPose());
537 result->SetVisibilityFlags(this->VisibilityFlags());
538 result->SetWireframe(this->Wireframe());
546 gzerr <<
"Cast failed in BaseVisual::Clone\n";
547 scene_->DestroyVisual(result);
550 for (
auto it = children_->Begin(); it != children_->End(); ++it)
555 if (!visual || !visual->Clone(
"", result))
557 gzerr <<
"Cloning a child visual failed.\n";
558 scene_->DestroyVisual(result,
true);
563 for (
unsigned int i = 0; i < this->GeometryCount(); ++i)
564 result->AddGeometry(this->GeometryByIndex(i)->Clone());
567 result->SetMaterial(this->Material());
569 for (
const auto &[key, val] : this->userData)
570 result->SetUserData(key, val);
573 result->SetStatic(this->Static());