fixed camo generation when maps are not in order
This commit is contained in:
@ -241,7 +241,7 @@ namespace ZoneTool
|
||||
if (world->dpvs.surfaces)
|
||||
{
|
||||
map.dpvs.surfaces = mem->Alloc<IW4::GfxSurface>(world->surfaceCount);
|
||||
map.dpvs.surfacesBounds = mem->Alloc<IW4::GfxCullGroup>(world->surfaceCount);
|
||||
map.dpvs.surfacesBounds = mem->Alloc<IW4::GfxSurfaceBounds>(world->surfaceCount);
|
||||
|
||||
assert(sizeof(IW3::srfTriangles_t) == sizeof(IW4::srfTriangles_t));
|
||||
|
||||
|
@ -114,10 +114,14 @@ namespace ZoneTool
|
||||
memset(iw5_comworld->primaryLights, 0, sizeof(IW5::ComPrimaryLight) * iw5_comworld->primaryLightCount);
|
||||
|
||||
// copy data
|
||||
for (unsigned int i = 0; i < iw5_comworld->primaryLightCount; i++)
|
||||
for (auto i = 0u; i < iw5_comworld->primaryLightCount; i++)
|
||||
{
|
||||
memcpy(iw5_comworld->primaryLights[i]._portpad0, asset->primaryLights[i]._portpad0, 28);
|
||||
memcpy(iw5_comworld->primaryLights[i]._portpad1, asset->primaryLights[i]._portpad1, 40);
|
||||
|
||||
iw5_comworld->primaryLights[i].up[0] = 0.0f;
|
||||
iw5_comworld->primaryLights[i].up[1] = 0.0f;
|
||||
iw5_comworld->primaryLights[i].up[2] = 0.0f;
|
||||
}
|
||||
|
||||
// dump comworld
|
||||
@ -125,7 +129,7 @@ namespace ZoneTool
|
||||
|
||||
// free memory_
|
||||
delete[] iw5_comworld->primaryLights;
|
||||
delete[] iw5_comworld;
|
||||
delete iw5_comworld;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -839,10 +839,29 @@ namespace ZoneTool
|
||||
memcpy(&iw5_asset->lightGrid, &asset->lightGrid,
|
||||
Difference(&iw5_asset->fogTypesAllowed + 1, &iw5_asset->lightGrid));
|
||||
|
||||
// fix GfxDrawSurfs
|
||||
iw5_asset->dpvs.surfaceMaterials = new IW5::GfxDrawSurf[iw5_asset->indexCount];
|
||||
memset(iw5_asset->dpvs.surfaceMaterials, 0, sizeof IW5::GfxDrawSurf * iw5_asset->indexCount);
|
||||
for (auto i = 0u; i < iw5_asset->indexCount; i++)
|
||||
{
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.reflectionProbeIndex = asset->dpvs.surfaceMaterials[i].fields.reflectionProbeIndex;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.hasGfxEntIndex = asset->dpvs.surfaceMaterials[i].fields.hasGfxEntIndex;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.customIndex = asset->dpvs.surfaceMaterials[i].fields.customIndex;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.materialSortedIndex = asset->dpvs.surfaceMaterials[i].fields.materialSortedIndex;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.prepass = asset->dpvs.surfaceMaterials[i].fields.prepass;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.useHeroLighting = asset->dpvs.surfaceMaterials[i].fields.useHeroLighting;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.sceneLightIndex = asset->dpvs.surfaceMaterials[i].fields.sceneLightIndex;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.viewModelRender = 0;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.surfType = asset->dpvs.surfaceMaterials[i].fields.surfType;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.primarySortKey = asset->dpvs.surfaceMaterials[i].fields.primarySortKey;
|
||||
iw5_asset->dpvs.surfaceMaterials[i].fields.unused = asset->dpvs.surfaceMaterials[i].fields.unused;
|
||||
}
|
||||
|
||||
// dump asset
|
||||
IW5::IGfxWorld::dump(iw5_asset);
|
||||
|
||||
// free memory_
|
||||
delete[] iw5_asset->dpvs.surfaceMaterials;
|
||||
delete[] iw5_asset->cells;
|
||||
delete iw5_asset;
|
||||
}
|
||||
|
@ -321,14 +321,30 @@ namespace ZoneTool
|
||||
const auto material_name = std::string(patched_material->name).substr(0, strlen(patched_material->name) - 10).append(camo);
|
||||
patched_material->name = _strdup(material_name.data());
|
||||
|
||||
assert(patched_material->maps[patched_material->numMaps - 1].firstCharacter == 'd');
|
||||
|
||||
if (camo == "gold"s)
|
||||
{
|
||||
std::vector<MaterialImage> stored_maps;
|
||||
stored_maps.resize(patched_material->numMaps - 1);
|
||||
|
||||
// filter out detailmap
|
||||
auto target_index = 0;
|
||||
for (auto map = 0; map < patched_material->numMaps; map++)
|
||||
{
|
||||
if (patched_material->maps[map].firstCharacter == 'd')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(&stored_maps[target_index], &patched_material->maps[map], sizeof MaterialImage);
|
||||
target_index++;
|
||||
}
|
||||
|
||||
patched_material->numMaps -= 1;
|
||||
patched_material->techniqueSet = new MaterialTechniqueSet;
|
||||
memcpy(patched_material->techniqueSet, model->materials[i]->techniqueSet, sizeof MaterialTechniqueSet);
|
||||
|
||||
memcpy(patched_material->maps, stored_maps.data(), sizeof MaterialImage * patched_material->numMaps);
|
||||
|
||||
auto technique_name = std::string(patched_material->techniqueSet->name);
|
||||
const auto detail_pos = technique_name.find_first_of("d0");
|
||||
technique_name.replace(detail_pos + 2, 2, "");
|
||||
|
@ -2784,7 +2784,7 @@ namespace ZoneTool
|
||||
char flags;
|
||||
};
|
||||
|
||||
struct GfxCullGroup
|
||||
struct GfxSurfaceBounds
|
||||
{
|
||||
union
|
||||
{
|
||||
@ -2872,7 +2872,7 @@ namespace ZoneTool
|
||||
unsigned __int16* sortedSurfIndex;
|
||||
GfxStaticModelInst* smodelInsts;
|
||||
GfxSurface* surfaces;
|
||||
GfxCullGroup* surfacesBounds;
|
||||
GfxSurfaceBounds* surfacesBounds;
|
||||
GfxStaticModelDrawInst* smodelDrawInsts;
|
||||
GfxDrawSurf* surfaceMaterials;
|
||||
unsigned int* surfaceCastsSunShadow;
|
||||
@ -3010,7 +3010,7 @@ namespace ZoneTool
|
||||
unsigned __int16* sortedSurfIndex;
|
||||
GfxStaticModelInst* smodelInsts;
|
||||
GfxSurface* surfaces;
|
||||
GfxCullGroup* surfacesBounds;
|
||||
GfxSurfaceBounds* surfacesBounds;
|
||||
GfxStaticModelDrawInst* smodelDrawInsts;
|
||||
GfxDrawSurf* surfaceMaterials;
|
||||
unsigned int* surfaceCastsSunShadow;
|
||||
|
@ -81,7 +81,7 @@ namespace ZoneTool
|
||||
{
|
||||
asset->dpvs.surfaces[i].material = read.read_asset<Material>();
|
||||
}
|
||||
asset->dpvs.cullGroups = read.read_array<GfxCullGroup>();
|
||||
asset->dpvs.surfacesBounds = read.read_array<GfxSurfaceBounds>();
|
||||
asset->dpvs.smodelDrawInsts = read.read_array<GfxStaticModelDrawInst>();
|
||||
for (unsigned int i = 0; i < asset->dpvs.smodelCount; i++)
|
||||
{
|
||||
@ -947,11 +947,11 @@ namespace ZoneTool
|
||||
assert(data->indexCount > 0);
|
||||
assert(data->dpvs.surfaces != nullptr);
|
||||
|
||||
if (data->dpvs.cullGroups)
|
||||
if (data->dpvs.surfacesBounds)
|
||||
{
|
||||
buf->align(3);
|
||||
buf->write(data->dpvs.cullGroups, data->indexCount);
|
||||
ZoneBuffer::clear_pointer(&dest->dpvs.cullGroups);
|
||||
buf->write(data->dpvs.surfacesBounds, data->indexCount);
|
||||
ZoneBuffer::clear_pointer(&dest->dpvs.surfacesBounds);
|
||||
}
|
||||
|
||||
if (data->dpvs.smodelDrawInsts)
|
||||
@ -1115,7 +1115,7 @@ namespace ZoneTool
|
||||
write.dump_asset(asset->dpvs.surfaces[i].material);
|
||||
}
|
||||
|
||||
write.dump_array(asset->dpvs.cullGroups, asset->indexCount);
|
||||
write.dump_array(asset->dpvs.surfacesBounds, asset->indexCount);
|
||||
write.dump_array(asset->dpvs.smodelDrawInsts, asset->dpvs.smodelCount);
|
||||
|
||||
for (unsigned int i = 0; i < asset->dpvs.smodelCount; i++)
|
||||
|
@ -376,7 +376,7 @@ namespace ZoneTool
|
||||
|
||||
if (max_state_index >= mat->stateBitsCount)
|
||||
{
|
||||
ZONETOOL_FATAL("Material %s is referencing more statebit entries than it has!", mat->name);
|
||||
// ZONETOOL_FATAL("Material %s is referencing more statebit entries than it has!", mat->name);
|
||||
}
|
||||
|
||||
if (max_state_index != mat->stateBitsCount - 1)
|
||||
|
@ -3033,17 +3033,25 @@ namespace ZoneTool
|
||||
bool castsSunShadow;
|
||||
};
|
||||
|
||||
struct GfxCullGroup
|
||||
struct GfxSurfaceBounds
|
||||
{
|
||||
float mins[3];
|
||||
float maxs[3];
|
||||
//int surfaceCount;
|
||||
//int startSurfIndex;
|
||||
Bounds bounds;
|
||||
};
|
||||
|
||||
struct GfxDrawSurfFields
|
||||
{
|
||||
__int64 _bf0;
|
||||
unsigned __int64 objectId : 15;
|
||||
unsigned __int64 reflectionProbeIndex : 8;
|
||||
unsigned __int64 hasGfxEntIndex : 1;
|
||||
unsigned __int64 customIndex : 5;
|
||||
unsigned __int64 materialSortedIndex : 12;
|
||||
unsigned __int64 prepass : 2;
|
||||
unsigned __int64 useHeroLighting : 1;
|
||||
unsigned __int64 sceneLightIndex : 8;
|
||||
unsigned __int64 viewModelRender : 1;
|
||||
unsigned __int64 surfType : 4;
|
||||
unsigned __int64 primarySortKey : 6;
|
||||
unsigned __int64 unused : 1;
|
||||
};
|
||||
|
||||
union GfxDrawSurf
|
||||
@ -3099,7 +3107,7 @@ namespace ZoneTool
|
||||
unsigned __int16* sortedSurfIndex;
|
||||
GfxStaticModelInst* smodelInsts;
|
||||
GfxSurface* surfaces;
|
||||
GfxCullGroup* cullGroups;
|
||||
GfxSurfaceBounds* surfacesBounds;
|
||||
GfxStaticModelDrawInst* smodelDrawInsts;
|
||||
GfxDrawSurf* surfaceMaterials;
|
||||
unsigned int* surfaceCastsSunShadow;
|
||||
|
Reference in New Issue
Block a user