|
@@ -790,161 +790,3 @@ void CObjectManager::GatherUsedResources(CUsedResources& resources)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//////////////////////////////////////////////////////////////////////////
|
|
|
-namespace
|
|
|
-{
|
|
|
- AZStd::vector<AZStd::string> PyGetAllObjects()
|
|
|
- {
|
|
|
- IObjectManager* pObjMgr = GetIEditor()->GetObjectManager();
|
|
|
- CBaseObjectsArray objects;
|
|
|
- pObjMgr->GetObjects(objects);
|
|
|
- int count = pObjMgr->GetObjectCount();
|
|
|
- AZStd::vector<AZStd::string> result;
|
|
|
- for (int i = 0; i < count; ++i)
|
|
|
- {
|
|
|
- result.push_back(objects[i]->GetName().toUtf8().data());
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- void PyDeleteObject(const char* objName)
|
|
|
- {
|
|
|
- CUndo undo("Delete Object");
|
|
|
-
|
|
|
- CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(objName);
|
|
|
- if (pObject)
|
|
|
- {
|
|
|
- GetIEditor()->GetObjectManager()->DeleteObject(pObject);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- int PyClearSelection()
|
|
|
- {
|
|
|
- int numSel = 0;
|
|
|
- AzToolsFramework::ToolsApplicationRequestBus::BroadcastResult(
|
|
|
- numSel, &AzToolsFramework::ToolsApplicationRequests::GetSelectedEntitiesCount);
|
|
|
-
|
|
|
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
|
|
|
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, AzToolsFramework::EntityIdList());
|
|
|
-
|
|
|
- return numSel;
|
|
|
- }
|
|
|
-
|
|
|
- AZ::Vector3 PyGetObjectPosition(const char* pName)
|
|
|
- {
|
|
|
- CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(pName);
|
|
|
- if (!pObject)
|
|
|
- {
|
|
|
- throw std::logic_error((QString("\"") + pName + "\" is an invalid object.").toUtf8().data());
|
|
|
- }
|
|
|
- Vec3 position = pObject->GetPos();
|
|
|
- return AZ::Vector3(position.x, position.y, position.z);
|
|
|
- }
|
|
|
-
|
|
|
- void PySetObjectPosition(const char* pName, float fValueX, float fValueY, float fValueZ)
|
|
|
- {
|
|
|
- CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(pName);
|
|
|
- if (!pObject)
|
|
|
- {
|
|
|
- throw std::logic_error((QString("\"") + pName + "\" is an invalid object.").toUtf8().data());
|
|
|
- }
|
|
|
- CUndo undo("Set Object Base Position");
|
|
|
- pObject->SetPos(Vec3(fValueX, fValueY, fValueZ));
|
|
|
- }
|
|
|
-
|
|
|
- AZ::Vector3 PyGetObjectRotation(const char* pName)
|
|
|
- {
|
|
|
- CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(pName);
|
|
|
- if (!pObject)
|
|
|
- {
|
|
|
- throw std::logic_error((QString("\"") + pName + "\" is an invalid object.").toUtf8().data());
|
|
|
- }
|
|
|
- Ang3 ang = RAD2DEG(Ang3(pObject->GetRotation()));
|
|
|
- return AZ::Vector3(ang.x, ang.y, ang.z);
|
|
|
- }
|
|
|
-
|
|
|
- void PySetObjectRotation(const char* pName, float fValueX, float fValueY, float fValueZ)
|
|
|
- {
|
|
|
- CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(pName);
|
|
|
- if (!pObject)
|
|
|
- {
|
|
|
- throw std::logic_error((QString("\"") + pName + "\" is an invalid object.").toUtf8().data());
|
|
|
- }
|
|
|
- CUndo undo("Set Object Rotation");
|
|
|
- pObject->SetRotation(Quat(DEG2RAD(Ang3(fValueX, fValueY, fValueZ))));
|
|
|
- }
|
|
|
-
|
|
|
- AZ::Vector3 PyGetObjectScale(const char* pName)
|
|
|
- {
|
|
|
- CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(pName);
|
|
|
- if (!pObject)
|
|
|
- {
|
|
|
- throw std::logic_error((QString("\"") + pName + "\" is an invalid object.").toUtf8().data());
|
|
|
- }
|
|
|
- Vec3 scaleVec3 = pObject->GetScale();
|
|
|
- return AZ::Vector3(scaleVec3.x, scaleVec3.y, scaleVec3.z);
|
|
|
- }
|
|
|
-
|
|
|
- void PySetObjectScale(const char* pName, float fValueX, float fValueY, float fValueZ)
|
|
|
- {
|
|
|
- CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(pName);
|
|
|
- if (!pObject)
|
|
|
- {
|
|
|
- throw std::logic_error((QString("\"") + pName + "\" is an invalid object.").toUtf8().data());
|
|
|
- }
|
|
|
- CUndo undo("Set Object Scale");
|
|
|
- pObject->SetScale(Vec3(fValueX, fValueY, fValueZ));
|
|
|
- }
|
|
|
-
|
|
|
- void PyRenameObject(const char* pOldName, const char* pNewName)
|
|
|
- {
|
|
|
- CBaseObject* pObject = GetIEditor()->GetObjectManager()->FindObject(pOldName);
|
|
|
- if (!pObject)
|
|
|
- {
|
|
|
- throw std::runtime_error("Could not find object");
|
|
|
- }
|
|
|
-
|
|
|
- if (strcmp(pNewName, "") == 0 || GetIEditor()->GetObjectManager()->FindObject(pNewName))
|
|
|
- {
|
|
|
- throw std::runtime_error("Invalid object name.");
|
|
|
- }
|
|
|
-
|
|
|
- CUndo undo("Rename object");
|
|
|
- pObject->SetName(pNewName);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-namespace AzToolsFramework
|
|
|
-{
|
|
|
- void ObjectManagerFuncsHandler::Reflect(AZ::ReflectContext* context)
|
|
|
- {
|
|
|
- if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
|
|
- {
|
|
|
- // this will put these methods into the 'azlmbr.legacy.general' module
|
|
|
- auto addLegacyGeneral = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder)
|
|
|
- {
|
|
|
- methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
|
|
|
- ->Attribute(AZ::Script::Attributes::Category, "Legacy/Editor")
|
|
|
- ->Attribute(AZ::Script::Attributes::Module, "legacy.general");
|
|
|
- };
|
|
|
- addLegacyGeneral(behaviorContext->Method("get_all_objects", PyGetAllObjects, nullptr, "Gets the list of names of all objects in the whole level."));
|
|
|
-
|
|
|
- addLegacyGeneral(behaviorContext->Method("clear_selection", PyClearSelection, nullptr, "Clears selection."));
|
|
|
- addLegacyGeneral(behaviorContext->Method("delete_object", PyDeleteObject, nullptr, "Deletes a specified object."));
|
|
|
-
|
|
|
- addLegacyGeneral(behaviorContext->Method("get_position", PyGetObjectPosition, nullptr, "Gets the position of an object."));
|
|
|
- addLegacyGeneral(behaviorContext->Method("set_position", PySetObjectPosition, nullptr, "Sets the position of an object."));
|
|
|
-
|
|
|
- addLegacyGeneral(behaviorContext->Method("get_rotation", PyGetObjectRotation, nullptr, "Gets the rotation of an object."));
|
|
|
- addLegacyGeneral(behaviorContext->Method("set_rotation", PySetObjectRotation, nullptr, "Sets the rotation of an object."));
|
|
|
-
|
|
|
- addLegacyGeneral(behaviorContext->Method("get_scale", PyGetObjectScale, nullptr, "Gets the scale of an object."));
|
|
|
- addLegacyGeneral(behaviorContext->Method("set_scale", PySetObjectScale, nullptr, "Sets the scale of an object."));
|
|
|
-
|
|
|
- addLegacyGeneral(behaviorContext->Method("rename_object", PyRenameObject, nullptr, "Renames object with oldObjectName to newObjectName."));
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-} // namespace AzToolsFramework
|