@@ -166,6 +166,37 @@ namespace LevelEditor
166
166
s_center.y = boundsMin.y ;
167
167
}
168
168
}
169
+ else if (s_editMode == LEDIT_ENTITY)
170
+ {
171
+ const u32 objCount = selection_getCount ();
172
+ if (objCount)
173
+ {
174
+ s_transformToolActive = true ;
175
+
176
+ // Get bounds based on vertex set.
177
+ s32 objIndex = -1 ;
178
+ EditorSector* sector = nullptr ;
179
+ Vec3f boundsMin = { FLT_MAX, FLT_MAX, FLT_MAX };
180
+ Vec3f boundsMax = { -FLT_MAX,-FLT_MAX,-FLT_MAX };
181
+
182
+ for (u32 v = 0 ; v < objCount; v++)
183
+ {
184
+ selection_getEntity (v, sector, objIndex);
185
+ const EditorObject* obj = §or->obj [objIndex];
186
+ boundsMin.x = std::min (boundsMin.x , obj->pos .x );
187
+ boundsMin.z = std::min (boundsMin.z , obj->pos .z );
188
+ boundsMax.x = std::max (boundsMax.x , obj->pos .x );
189
+ boundsMax.z = std::max (boundsMax.z , obj->pos .z );
190
+
191
+ const Entity* entity = &s_level.entities [obj->entityId ];
192
+ const f32 base = (entity->type == ETYPE_3D) ? obj->pos .y + entity->obj3d ->bounds [0 ].y : obj->pos .y ;
193
+ boundsMin.y = std::min (boundsMin.y , obj->pos .y );
194
+ }
195
+ s_center.x = (boundsMin.x + boundsMax.x ) * 0 .5f ;
196
+ s_center.z = (boundsMin.z + boundsMax.z ) * 0 .5f ;
197
+ s_center.y = boundsMin.y ;
198
+ }
199
+ }
169
200
else if (s_editMode == LEDIT_GUIDELINES)
170
201
{
171
202
}
@@ -927,7 +958,7 @@ namespace LevelEditor
927
958
return totalObjCount;
928
959
}
929
960
930
- void captureObjectRotationData (u32 vertexCount )
961
+ void captureObjectRotationData ()
931
962
{
932
963
if (s_editMode != LEDIT_SECTOR) { return ; }
933
964
u32 totalObjectCount = captureGetTotalObjectCount ();
@@ -959,16 +990,31 @@ namespace LevelEditor
959
990
EditorSector* sector = nullptr ;
960
991
s32 index = -1 ;
961
992
962
- const u32 vertexCount = selection_getCount (SEL_VERTEX);
963
- const u32 totalObjCount = captureGetTotalObjectCount ();
964
- s_vertexData.resize (vertexCount);
965
- Vec2f* vtxData = s_vertexData.data ();
966
- for (u32 v = 0 ; v < vertexCount; v++)
993
+ if (s_editMode == LEDIT_ENTITY)
967
994
{
968
- selection_getVertex (v, sector, index);
969
- vtxData[v] = sector->vtx [index];
995
+ const u32 objCount = selection_getCount (SEL_ENTITY);
996
+ s_objData.resize (objCount);
997
+ Vec3f* objData = s_objData.data ();
998
+ for (u32 s = 0 ; s < objCount; s++)
999
+ {
1000
+ selection_getEntity (s, sector, index);
1001
+ EditorObject* obj = §or->obj [index];
1002
+ objData[s] = { obj->pos .x , obj->pos .z , obj->angle };
1003
+ }
1004
+ }
1005
+ else
1006
+ {
1007
+ const u32 vertexCount = selection_getCount (SEL_VERTEX);
1008
+ const u32 totalObjCount = captureGetTotalObjectCount ();
1009
+ s_vertexData.resize (vertexCount);
1010
+ Vec2f* vtxData = s_vertexData.data ();
1011
+ for (u32 v = 0 ; v < vertexCount; v++)
1012
+ {
1013
+ selection_getVertex (v, sector, index);
1014
+ vtxData[v] = sector->vtx [index];
1015
+ }
1016
+ captureObjectRotationData ();
970
1017
}
971
- captureObjectRotationData (vertexCount);
972
1018
}
973
1019
}
974
1020
@@ -1002,8 +1048,12 @@ namespace LevelEditor
1002
1048
1003
1049
void applyRotationToData (f32 angle)
1004
1050
{
1005
- const u32 vertexCount = selection_getCount (SEL_VERTEX);
1006
- if (!vertexCount) { return ; }
1051
+ if ((s_editMode == LEDIT_ENTITY && !selection_getCount ()) ||
1052
+ (s_editMode != LEDIT_ENTITY && !selection_getCount (SEL_VERTEX)))
1053
+ {
1054
+ return ;
1055
+ }
1056
+
1007
1057
if (!s_dataCaptured)
1008
1058
{
1009
1059
captureRotationData ();
@@ -1021,37 +1071,78 @@ namespace LevelEditor
1021
1071
1022
1072
EditorSector* sector;
1023
1073
s32 index;
1024
- const Vec2f* srcVtx = s_vertexData.data ();
1025
- if (fabsf (angle) < 0 .0001f )
1074
+ if (s_editMode == LEDIT_ENTITY)
1026
1075
{
1027
- // If the angle is very close to zero, then just copy the original data.
1028
- for (u32 v = 0 ; v < vertexCount; v++)
1076
+ const u32 objCount = selection_getCount ();
1077
+ const Vec3f* srcObjData = s_objData.data ();
1078
+ if (fabsf (angle) < 0 .0001f )
1029
1079
{
1030
- selection_getVertex (v, sector, index);
1031
- sector->vtx [index] = srcVtx[v];
1032
- if (sector->searchKey != s_searchKey)
1080
+ for (u32 o = 0 ; o < objCount; o++)
1033
1081
{
1034
- s_sectorChangeList.push_back (sector);
1035
- sector->searchKey = s_searchKey;
1082
+ selection_getEntity (o, sector, index);
1083
+ EditorObject* obj = §or->obj [index];
1084
+ obj->pos .x = srcObjData[o].x ;
1085
+ obj->pos .z = srcObjData[o].y ;
1086
+ obj->angle = srcObjData[o].z ;
1087
+ if (sector->searchKey != s_searchKey)
1088
+ {
1089
+ s_sectorChangeList.push_back (sector);
1090
+ sector->searchKey = s_searchKey;
1091
+ }
1092
+ }
1093
+ }
1094
+ else
1095
+ {
1096
+ for (u32 o = 0 ; o < objCount; o++)
1097
+ {
1098
+ selection_getEntity (o, sector, index);
1099
+ EditorObject* obj = §or->obj [index];
1100
+ obj->pos .x = (srcObjData[o].x - s_center.x ) * mtx[0 ].x + (srcObjData[o].y - s_center.z ) * mtx[0 ].y + mtx[0 ].z ;
1101
+ obj->pos .z = (srcObjData[o].x - s_center.x ) * mtx[1 ].x + (srcObjData[o].y - s_center.z ) * mtx[1 ].y + mtx[1 ].z ;
1102
+ obj->angle = srcObjData[o].z + angle;
1103
+ if (sector->searchKey != s_searchKey)
1104
+ {
1105
+ s_sectorChangeList.push_back (sector);
1106
+ sector->searchKey = s_searchKey;
1107
+ }
1036
1108
}
1037
1109
}
1038
1110
}
1039
1111
else
1040
1112
{
1041
- // Otherwise apply the rotation.
1042
- for (u32 v = 0 ; v < vertexCount; v++)
1113
+ const u32 vertexCount = selection_getCount (SEL_VERTEX);
1114
+ const Vec2f* srcVtx = s_vertexData.data ();
1115
+ if (fabsf (angle) < 0 .0001f )
1043
1116
{
1044
- selection_getVertex (v, sector, index);
1045
- sector->vtx [index].x = (srcVtx[v].x - s_center.x ) * mtx[0 ].x + (srcVtx[v].z - s_center.z ) * mtx[0 ].y + mtx[0 ].z ;
1046
- sector->vtx [index].z = (srcVtx[v].x - s_center.x ) * mtx[1 ].x + (srcVtx[v].z - s_center.z ) * mtx[1 ].y + mtx[1 ].z ;
1047
- if (sector->searchKey != s_searchKey)
1117
+ // If the angle is very close to zero, then just copy the original data.
1118
+ for (u32 v = 0 ; v < vertexCount; v++)
1048
1119
{
1049
- s_sectorChangeList.push_back (sector);
1050
- sector->searchKey = s_searchKey;
1120
+ selection_getVertex (v, sector, index);
1121
+ sector->vtx [index] = srcVtx[v];
1122
+ if (sector->searchKey != s_searchKey)
1123
+ {
1124
+ s_sectorChangeList.push_back (sector);
1125
+ sector->searchKey = s_searchKey;
1126
+ }
1127
+ }
1128
+ }
1129
+ else
1130
+ {
1131
+ // Otherwise apply the rotation.
1132
+ for (u32 v = 0 ; v < vertexCount; v++)
1133
+ {
1134
+ selection_getVertex (v, sector, index);
1135
+ sector->vtx [index].x = (srcVtx[v].x - s_center.x ) * mtx[0 ].x + (srcVtx[v].z - s_center.z ) * mtx[0 ].y + mtx[0 ].z ;
1136
+ sector->vtx [index].z = (srcVtx[v].x - s_center.x ) * mtx[1 ].x + (srcVtx[v].z - s_center.z ) * mtx[1 ].y + mtx[1 ].z ;
1137
+ if (sector->searchKey != s_searchKey)
1138
+ {
1139
+ s_sectorChangeList.push_back (sector);
1140
+ sector->searchKey = s_searchKey;
1141
+ }
1051
1142
}
1052
1143
}
1144
+ applyRotationToObjects (mtx, angle);
1053
1145
}
1054
- applyRotationToObjects (mtx, angle);
1055
1146
1056
1147
// Update sectors after changes.
1057
1148
const size_t changeCount = s_sectorChangeList.size ();
0 commit comments