503 if (
nullptr == scene_)
505 gzerr <<
"Cloning a visual failed because the visual to be cloned is "
506 <<
"not attached to a scene.\n";
511 result = scene_->CreateVisual();
513 result = scene_->CreateVisual(_name);
515 if (
nullptr != _newParent)
517 auto parentScene = _newParent->Scene();
518 if (
nullptr != parentScene && parentScene->Id() != scene_->Id())
520 gzerr <<
"Cloning a visual failed because the desired parent of the "
521 <<
"cloned visual belongs to a different scene.\n";
522 scene_->DestroyVisual(result);
525 _newParent->AddChild(result);
528 result->SetOrigin(this->Origin());
529 result->SetInheritScale(this->InheritScale());
530 result->SetLocalScale(this->LocalScale());
531 result->SetLocalPose(this->LocalPose());
532 result->SetVisibilityFlags(this->VisibilityFlags());
533 result->SetWireframe(this->Wireframe());
541 gzerr <<
"Cast failed in BaseVisual::Clone\n";
542 scene_->DestroyVisual(result);
545 for (
auto it = children_->Begin(); it != children_->End(); ++it)
550 if (!visual || !visual->Clone(
"", result))
552 gzerr <<
"Cloning a child visual failed.\n";
553 scene_->DestroyVisual(result,
true);
558 for (
unsigned int i = 0; i < this->GeometryCount(); ++i)
559 result->AddGeometry(this->GeometryByIndex(i)->Clone());
562 result->SetMaterial(this->Material());
564 for (
const auto &[key, val] : this->userData)
565 result->SetUserData(key, val);
568 result->SetStatic(this->Static());