Skip to content

Commit 543d194

Browse files
committed
- fix exporter duplicates objects multiple times
1 parent abb374f commit 543d194

1 file changed

Lines changed: 30 additions & 39 deletions

File tree

DriverLevelTool/exporter/export_regions.cpp

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -129,56 +129,47 @@ int ExportRegionDriver2(CDriver2LevelRegion* region, IVirtualStream* levelFileSt
129129
{
130130
CELL_ITERATOR_D2 ci;
131131

132-
for (int i = 0; i < 20; i++)
132+
PACKED_CELL_OBJECT* pco = region->StartIterator(&ci, i);
133+
134+
if (!pco)
135+
continue;
136+
137+
while (pco)
133138
{
134-
int cellLevel;
135-
if (i == 19)
136-
cellLevel = 100; // 100 is the special slot for event object placement
137-
else
138-
cellLevel = i;
139+
CELL_OBJECT co;
140+
CDriver2LevelMap::UnpackCellObject(co, pco, ci.nearCell);
139141

140-
PACKED_CELL_OBJECT* pco = region->StartIterator(&ci, i);
142+
Vector3D absCellPosition(co.pos.vx * -EXPORT_SCALING, co.pos.vy * EXPORT_SCALING, co.pos.vz * EXPORT_SCALING);
143+
float cellRotationRad = co.yang / 64.0f * PI_F * 2.0f;
141144

142-
if (!pco)
143-
continue;
145+
ModelRef_t* ref = g_levModels.GetModelByIndex(co.type);
144146

145-
while (pco)
147+
if (ref)
146148
{
147-
CELL_OBJECT co;
148-
CDriver2LevelMap::UnpackCellObject(co, pco, ci.nearCell);
149-
150-
Vector3D absCellPosition(co.pos.vx * -EXPORT_SCALING, co.pos.vy * EXPORT_SCALING, co.pos.vz * EXPORT_SCALING);
151-
float cellRotationRad = co.yang / 64.0f * PI_F * 2.0f;
149+
if (g_export_worldUnityScript)
150+
{
151+
String modelName = strlen(ref->name) > 0 ? String::fromCString(ref->name) : String::fromPrintf("MOD_%d", ref->index);
152152

153-
ModelRef_t* ref = g_levModels.GetModelByIndex(co.type);
153+
float cellRotationDeg = RAD2DEG(cellRotationRad) + 180;
154154

155-
if (ref)
155+
levelFileStream->Print("var reg%d_o%d = Instantiate(%s, new Vector3(%gf,%gf,%gf), Quaternion.Euler(0.0f,%gf,0.0f)) as GameObject;\n",
156+
region->GetNumber(), numRegionObjects, (char*)modelName, absCellPosition.x, absCellPosition.y, absCellPosition.z, -cellRotationDeg);
157+
}
158+
else
156159
{
157-
if (g_export_worldUnityScript)
158-
{
159-
String modelName = strlen(ref->name) > 0 ? String::fromCString(ref->name) : String::fromPrintf("MOD_%d", ref->index);
160-
161-
float cellRotationDeg = RAD2DEG(cellRotationRad) + 180;
162-
163-
levelFileStream->Print("var reg%d_o%d = Instantiate(%s, new Vector3(%gf,%gf,%gf), Quaternion.Euler(0.0f,%gf,0.0f)) as GameObject;\n",
164-
region->GetNumber(), numRegionObjects, (char*)modelName, absCellPosition.x, absCellPosition.y, absCellPosition.z, -cellRotationDeg);
165-
}
166-
else
167-
{
168-
// transform objects and save
169-
Matrix4x4 transform = translate(absCellPosition);
170-
transform = transform * rotateY4(cellRotationRad) * scale4(1.0f, 1.0f, 1.0f);
171-
172-
WriteMODELToObjStream(levelFileStream, ref->model, ref->size, co.type,
173-
String::fromPrintf("reg%d", region->GetNumber()),
174-
false, transform, &lobj_first_v, &lobj_first_t);
175-
}
160+
// transform objects and save
161+
Matrix4x4 transform = translate(absCellPosition);
162+
transform = transform * rotateY4(cellRotationRad) * scale4(1.0f, 1.0f, 1.0f);
163+
164+
WriteMODELToObjStream(levelFileStream, ref->model, ref->size, co.type,
165+
String::fromPrintf("reg%d", region->GetNumber()),
166+
false, transform, &lobj_first_v, &lobj_first_t);
176167
}
168+
}
177169

178-
numRegionObjects++;
170+
numRegionObjects++;
179171

180-
pco = levMapDriver2->GetNextPackedCop(&ci);
181-
}
172+
pco = levMapDriver2->GetNextPackedCop(&ci);
182173
}
183174
}
184175

0 commit comments

Comments
 (0)