1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "SphereUnwrappingTool.h"
5 #include "Util/ElementSet.h"
6 #include "Core/UVIslandManager.h"
7 #include "../UVMappingEditor.h"
9 #include "Util/UVUnwrapUtil.h"
14 void SphereUnwrappingTool::Enter()
16 ElementSet
* pSelected
= GetUVEditor()->GetSelectedElements();
17 if (pSelected
== NULL
)
20 _smart_ptr
<Designer::Model
> pModel
= pSelected
->CreateModel();
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");