!XT (BREAK-16) (Sandbox) Remove double-newlines at the end of files.
[CRYENGINE.git] / Code / Sandbox / Plugins / CryDesigner / UVMappingEditor / UnwrappingTools / SphereUnwrappingTool.cpp
bloba979dbd0d87b285241f35c91a907478ad5c91ffa
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #include "StdAfx.h"
4 #include "SphereUnwrappingTool.h"
5 #include "Util/ElementSet.h"
6 #include "Core/UVIslandManager.h"
7 #include "../UVMappingEditor.h"
8 #include "../UVUndo.h"
9 #include "Util/UVUnwrapUtil.h"
11 namespace Designer {
12 namespace UVMapping
14 void SphereUnwrappingTool::Enter()
16 ElementSet* pSelected = GetUVEditor()->GetSelectedElements();
17 if (pSelected == NULL)
18 return;
20 _smart_ptr<Designer::Model> pModel = pSelected->CreateModel();
21 if (pModel == NULL)
22 return;
24 BrushVec3 origin = ToBrushVec3(pModel->GetBoundBox().GetCenter());
26 CUndo undo("UV Mapping : Sphere Projection");
27 CUndo::Record(new UVIslandUndo);
28 CUndo::Record(new UVProjectionUndo);
30 AssignMatIDToSelectedPolygons(GetUVEditor()->GetSubMatID());
32 UVIslandManager* pUVIslandMgr = GetUVEditor()->GetUVIslandMgr();
33 UVIslandPtr pUVIsland = new UVIsland;
35 float radius = UnwrapUtil::CalculateSphericalRadius(pModel);
36 for (int i = 0, iCount(pModel->GetPolygonCount()); i < iCount; ++i)
38 PolygonPtr polygon = pModel->GetPolygon(i);
39 UnwrapUtil::ApplySphereProjection(origin, radius, polygon);
40 pUVIsland->AddPolygon(polygon);
43 pUVIslandMgr->AddUVIsland(pUVIsland);
44 std::vector<UVIslandPtr> UVIslands;
45 UVIslands.push_back(pUVIsland);
47 GetUVEditor()->SelectUVIslands(UVIslands);
48 GetUVEditor()->UpdateGizmoPos();
49 GetUVEditor()->GetUVIslandMgr()->ConvertIsolatedAreasToIslands();
50 GetUVEditor()->SetTool(eUVMappingTool_Island);
51 GetUVEditor()->ApplyPostProcess();
56 REGISTER_UVMAPPING_TOOL_AND_COMMAND(eUVMappingTool_Sphere, eUVMappingToolGroup_Unwrapping, "Sphere", SphereUnwrappingTool,
57 sphere_unwrapping, "runs sphere unwrapping tool", "uvmapping.sphere_unwrapping");