mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-22 12:07:45 +00:00
Simplify body part loading in gear view
This commit is contained in:
parent
2c780311c7
commit
1be5fc27d0
1 changed files with 15 additions and 67 deletions
|
@ -272,13 +272,10 @@ MDLPart &GearView::part() const
|
||||||
|
|
||||||
void GearView::updatePart()
|
void GearView::updatePart()
|
||||||
{
|
{
|
||||||
qInfo() << raceDirty << gearDirty << updating;
|
|
||||||
if (raceDirty) {
|
if (raceDirty) {
|
||||||
// if race changes, all of the models need to be reloaded.
|
// if race changes, all of the models need to be reloaded.
|
||||||
// TODO: in the future, we can be a bit smarter about this, lots of races use the same model (hyur)
|
// TODO: in the future, we can be a bit smarter about this, lots of races use the same model (hyur)
|
||||||
for (auto &part : loadedGears) {
|
mdlPart->clear();
|
||||||
mdlPart->removeModel(part.mdl);
|
|
||||||
}
|
|
||||||
queuedGearAdditions = loadedGears;
|
queuedGearAdditions = loadedGears;
|
||||||
loadedGears.clear();
|
loadedGears.clear();
|
||||||
gearDirty = true;
|
gearDirty = true;
|
||||||
|
@ -376,8 +373,8 @@ void GearView::updatePart()
|
||||||
queuedGearRemovals.clear();
|
queuedGearRemovals.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (face) {
|
const auto loadBodyPart = [this, &sanitizeMdlPath](int index, CharacterCategory category, auto build_material_path_func) {
|
||||||
const auto mdlPath = QLatin1String(physis_build_character_path(CharacterCategory::Face, *face, currentRace, currentSubrace, currentGender));
|
const auto mdlPath = QLatin1String(physis_build_character_path(category, index, currentRace, currentSubrace, currentGender));
|
||||||
auto mdl_data = cache.lookupFile(mdlPath);
|
auto mdl_data = cache.lookupFile(mdlPath);
|
||||||
|
|
||||||
if (mdl_data.size > 0) {
|
if (mdl_data.size > 0) {
|
||||||
|
@ -387,7 +384,7 @@ void GearView::updatePart()
|
||||||
for (uint32_t i = 0; i < mdl.num_material_names; i++) {
|
for (uint32_t i = 0; i < mdl.num_material_names; i++) {
|
||||||
const char *material_name = mdl.material_names[i];
|
const char *material_name = mdl.material_names[i];
|
||||||
const std::string skinmtrl_path =
|
const std::string skinmtrl_path =
|
||||||
physis_build_face_material_path(physis_get_race_code(currentRace, currentSubrace, currentGender), *face, material_name);
|
build_material_path_func(physis_get_race_code(currentRace, currentSubrace, currentGender), index, material_name);
|
||||||
|
|
||||||
if (cache.fileExists(QLatin1String(skinmtrl_path.c_str()))) {
|
if (cache.fileExists(QLatin1String(skinmtrl_path.c_str()))) {
|
||||||
auto mat = physis_material_parse(cache.lookupFile(QLatin1String(skinmtrl_path.c_str())));
|
auto mat = physis_material_parse(cache.lookupFile(QLatin1String(skinmtrl_path.c_str())));
|
||||||
|
@ -398,73 +395,22 @@ void GearView::updatePart()
|
||||||
mdlPart->addModel(mdl, true, glm::vec3(), sanitizeMdlPath(mdlPath), materials, currentLod);
|
mdlPart->addModel(mdl, true, glm::vec3(), sanitizeMdlPath(mdlPath), materials, currentLod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (face) {
|
||||||
|
loadBodyPart(*face, CharacterCategory::Face, physis_build_face_material_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hair) {
|
if (hair) {
|
||||||
const auto mdlPath = QLatin1String(physis_build_character_path(CharacterCategory::Hair, *hair, currentRace, currentSubrace, currentGender));
|
loadBodyPart(*hair, CharacterCategory::Hair, physis_build_hair_material_path);
|
||||||
auto mdl_data = cache.lookupFile(mdlPath);
|
|
||||||
|
|
||||||
if (mdl_data.size > 0) {
|
|
||||||
auto mdl = physis_mdl_parse(mdl_data);
|
|
||||||
if (mdl.p_ptr != nullptr) {
|
|
||||||
std::vector<physis_Material> materials;
|
|
||||||
for (uint32_t i = 0; i < mdl.num_material_names; i++) {
|
|
||||||
const char *material_name = mdl.material_names[i];
|
|
||||||
const std::string skinmtrl_path =
|
|
||||||
physis_build_hair_material_path(physis_get_race_code(currentRace, currentSubrace, currentGender), *hair, material_name);
|
|
||||||
|
|
||||||
if (cache.fileExists(QLatin1String(skinmtrl_path.c_str()))) {
|
|
||||||
auto mat = physis_material_parse(cache.lookupFile(QLatin1String(skinmtrl_path.c_str())));
|
|
||||||
materials.push_back(mat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mdlPart->addModel(mdl, true, glm::vec3(), sanitizeMdlPath(mdlPath), materials, currentLod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ear) {
|
if (ear) {
|
||||||
const auto mdlPath = QLatin1String(physis_build_character_path(CharacterCategory::Ear, *ear, currentRace, currentSubrace, currentGender));
|
loadBodyPart(*ear, CharacterCategory::Ear, physis_build_ear_material_path);
|
||||||
auto mdl_data = cache.lookupFile(mdlPath);
|
|
||||||
|
|
||||||
if (mdl_data.size > 0) {
|
|
||||||
auto mdl = physis_mdl_parse(mdl_data);
|
|
||||||
if (mdl.p_ptr != nullptr) {
|
|
||||||
std::vector<physis_Material> materials;
|
|
||||||
for (uint32_t i = 0; i < mdl.num_material_names; i++) {
|
|
||||||
const char *material_name = mdl.material_names[i];
|
|
||||||
const std::string skinmtrl_path =
|
|
||||||
physis_build_ear_material_path(physis_get_race_code(currentRace, currentSubrace, currentGender), *ear, material_name);
|
|
||||||
|
|
||||||
if (cache.fileExists(QLatin1String(skinmtrl_path.c_str()))) {
|
|
||||||
auto mat = physis_material_parse(cache.lookupFile(QLatin1String(skinmtrl_path.c_str())));
|
|
||||||
materials.push_back(mat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mdlPart->addModel(mdl, true, glm::vec3(), sanitizeMdlPath(mdlPath), materials, currentLod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tail) {
|
if (tail) {
|
||||||
const auto mdlPath = QLatin1String(physis_build_character_path(CharacterCategory::Tail, *tail, currentRace, currentSubrace, currentGender));
|
loadBodyPart(*tail, CharacterCategory::Tail, physis_build_tail_material_path);
|
||||||
auto mdl_data = cache.lookupFile(mdlPath);
|
|
||||||
|
|
||||||
if (mdl_data.size > 0) {
|
|
||||||
auto mdl = physis_mdl_parse(mdl_data);
|
|
||||||
if (mdl.p_ptr != nullptr) {
|
|
||||||
const char *material_name = mdl.material_names[0];
|
|
||||||
const std::string skinmtrl_path =
|
|
||||||
physis_build_tail_material_path(physis_get_race_code(currentRace, currentSubrace, currentGender), *tail, material_name);
|
|
||||||
|
|
||||||
if (cache.fileExists(QLatin1String(skinmtrl_path.c_str()))) {
|
|
||||||
auto mat = physis_material_parse(cache.lookupFile(QLatin1String(skinmtrl_path.c_str())));
|
|
||||||
mdlPart->addModel(mdl, true, glm::vec3(), sanitizeMdlPath(mdlPath), {mat}, currentLod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
raceDirty = false;
|
raceDirty = false;
|
||||||
|
@ -492,9 +438,11 @@ QString GearView::getLoadedGearPath() const
|
||||||
void GearView::changeEvent(QEvent *event)
|
void GearView::changeEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::EnabledChange: {
|
case QEvent::EnabledChange:
|
||||||
mdlPart->setEnabled(isEnabled());
|
mdlPart->setEnabled(isEnabled());
|
||||||
} break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
QFrame::changeEvent(event);
|
QFrame::changeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue