Skip to content

Commit

Permalink
NWN: Fix body part texture overrides
Browse files Browse the repository at this point in the history
Creatures, like Pavel and Bim in the OC Prelude, now wear
the correct clothes.

Something is still wrong with body part switching though,
since shorter NPCs, like dwarves and gnomes, got their body
parts at the wrong heights. They're "pulled apart" like
ragdolls.
  • Loading branch information
DrMcCoy committed Apr 22, 2012
1 parent 402e202 commit 46c3ce5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
50 changes: 35 additions & 15 deletions src/engines/nwn/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,24 +282,44 @@ void Creature::setCommandable(bool commandable) {
_isCommandable = commandable;
}

void Creature::constructModelName(const Common::UString &type, uint32 id,
const Common::UString &gender,
const Common::UString &race,
const Common::UString &phenoType,
const Common::UString &phenoTypeAlt,
Common::UString &model) {
void Creature::constructPartName(const Common::UString &type, uint32 id,
const Common::UString &gender, const Common::UString &race,
const Common::UString &phenoType, Common::UString &part) {

part = Common::UString::sprintf("p%s%s%s_%s%03d",
gender.c_str(), race.c_str(), phenoType.c_str(), type.c_str(), id);
}

model = Common::UString::sprintf("p%s%s%s_%s%03d",
gender.c_str(), race.c_str(), phenoType.c_str(), type.c_str(), id);
void Creature::constructPartName(const Common::UString &type, uint32 id,
const Common::UString &gender, const Common::UString &race,
const Common::UString &phenoType, const Common::UString &phenoTypeAlt,
Aurora::FileType fileType, Common::UString &part) {

if (ResMan.hasResource(model, Aurora::kFileTypeMDL))
constructPartName(type, id, gender, race, phenoType, part);
if ((fileType == Aurora::kFileTypeNone) || ResMan.hasResource(part, fileType))
return;

model = Common::UString::sprintf("p%s%s%s_%s%03d",
gender.c_str(), race.c_str(), phenoTypeAlt.c_str(), type.c_str(), id);
constructPartName(type, id, gender, race, phenoTypeAlt, part);
if (!ResMan.hasResource(part, fileType))
part.clear();
}

void Creature::constructModelName(const Common::UString &type, uint32 id,
const Common::UString &gender, const Common::UString &race,
const Common::UString &phenoType, const Common::UString &phenoTypeAlt,
Common::UString &model, Common::UString &texture) {

constructPartName(type, id, gender, race, phenoType, phenoTypeAlt, Aurora::kFileTypeMDL, model);

constructPartName(type, id, gender, race, phenoType, phenoTypeAlt, Aurora::kFileTypePLT, texture);

// PLT texture doesn't exist, try a generic human PLT
if (texture.empty())
constructPartName(type, id, gender, "H", phenoType, phenoTypeAlt, Aurora::kFileTypePLT, texture);

if (!ResMan.hasResource(model, Aurora::kFileTypeMDL))
model.clear();
// Human PLT texture doesn't exist either, assume it's a non-PLT texture
if (texture.empty())
constructPartName(type, id, gender, race, phenoType, phenoTypeAlt, Aurora::kFileTypeNone, texture);
}

// Based on filenames in model2.bif
Expand Down Expand Up @@ -360,7 +380,7 @@ void Creature::getPartModels() {
for (uint i = 0; i < kBodyPartMAX; i++)
constructModelName(kBodyPartModels[i], _bodyParts[i].armor_id > 0 ? _bodyParts[i].armor_id : _bodyParts[i].id,
genderChar, raceChar, phenoChar, phenoAltChar,
_bodyParts[i].modelName);
_bodyParts[i].modelName, _bodyParts[i].texture);
}

void Creature::getArmorModels() {
Expand Down Expand Up @@ -434,7 +454,7 @@ void Creature::loadModel() {
TextureMan.clearNewPLTs();

// Try to load in the corresponding part model
Graphics::Aurora::Model *part_model = loadModelObject(_bodyParts[i].modelName, _bodyParts[i].modelName);
Graphics::Aurora::Model *part_model = loadModelObject(_bodyParts[i].modelName, _bodyParts[i].texture);
if (!part_model)
continue;

Expand Down
23 changes: 21 additions & 2 deletions src/engines/nwn/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class Creature : public Object {
uint32 id; ///< Index of the part variant.
uint32 armor_id; ///< Index of the part variant when armour equipped.
Common::UString modelName; ///< Name of the model.
Common::UString texture; ///< Name of the texture.
std::list<Graphics::Aurora::PLTHandle> plts; ///< Paletted textures.

BodyPart();
Expand Down Expand Up @@ -318,13 +319,31 @@ class Creature : public Object {

void loadEquippedItems(const Aurora::GFFStruct &gff);

/** Construct the resource name of a body part model. */
/** Construct the resource name of a body part files. */
void constructPartName(const Common::UString &type, uint32 id,
const Common::UString &gender,
const Common::UString &race,
const Common::UString &phenoType,
Common::UString &part);

/** Construct the resource name of a body part files. */
void constructPartName(const Common::UString &type, uint32 id,
const Common::UString &gender,
const Common::UString &race,
const Common::UString &phenoType,
const Common::UString &phenoTypeAlt,
Aurora::FileType fileType,
Common::UString &part);

/** Construct the resource name of a body part files. */
void constructModelName(const Common::UString &type, uint32 id,
const Common::UString &gender,
const Common::UString &race,
const Common::UString &phenoType,
const Common::UString &phenoTypeAlt,
Common::UString &model);
Common::UString &model,
Common::UString &texture);

void getPartModels(); ///< Construct all body part models' resource names.
void getArmorModels(); ///< Populate the armor info for body parts.

Expand Down
3 changes: 3 additions & 0 deletions src/graphics/aurora/model_nwn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@ void ModelNode_NWN_Binary::readMesh(Model_NWN::ParserContext &ctx) {
textureCount = 4;
}

if ((textureCount > 0) && !ctx.texture.empty())
textures[0] = ctx.texture;

textures.resize(textureCount);
loadTextures(textures);

Expand Down

0 comments on commit 46c3ce5

Please sign in to comment.