Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion indra/llprimitive/lldaeloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,7 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
{
materials[model->mMaterialList[i]] = LLImportMaterial();
}
// todo: likely a bug here, shouldn't be using suffixed label, see how it gets used in other places.
mScene[transformation].push_back(LLModelInstance(model, model->mLabel, transformation, materials));
stretch_extents(model, transformation);
}
Expand Down Expand Up @@ -2414,7 +2415,7 @@ std::string LLDAELoader::getElementLabel(daeElement *element)
}

// static
size_t LLDAELoader::getSuffixPosition(std::string label)
size_t LLDAELoader::getSuffixPosition(const std::string &label)
{
if ((label.find("_LOD") != -1) || (label.find("_PHYS") != -1))
{
Expand Down
2 changes: 1 addition & 1 deletion indra/llprimitive/lldaeloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class LLDAELoader : public LLModelLoader
bool loadModelsFromDomMesh(domMesh* mesh, std::vector<LLModel*>& models_out, U32 submodel_limit);

static std::string getElementLabel(daeElement *element);
static size_t getSuffixPosition(std::string label);
static size_t getSuffixPosition(const std::string& label);
static std::string getLodlessLabel(daeElement *element);

static std::string preprocessDAE(std::string filename);
Expand Down
66 changes: 42 additions & 24 deletions indra/newview/gltf/llgltfloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ bool LLGLTFLoader::OpenFile(const std::string &filename)

void LLGLTFLoader::addModelToScene(
LLModel* pModel,
const std::string& model_name,
U32 submodel_limit,
const LLMatrix4& transformation,
const LLVolumeParams& volume_params,
Expand Down Expand Up @@ -239,7 +240,7 @@ void LLGLTFLoader::addModelToScene(
LLModel* next = new LLModel(volume_params, 0.f);
next->ClearFacesAndMaterials();
next->mSubmodelID = ++submodelID;
next->mLabel = pModel->mLabel + (char)((int)'a' + next->mSubmodelID) + lod_suffix[mLod];
next->mLabel = model_name + (char)((int)'a' + next->mSubmodelID) + lod_suffix[mLod];
next->getVolumeFaces() = remainder;
next->mNormalizedScale = current_model->mNormalizedScale;
next->mNormalizedTranslation = current_model->mNormalizedTranslation;
Expand Down Expand Up @@ -289,7 +290,12 @@ void LLGLTFLoader::addModelToScene(
materials[model->mMaterialList[i]] = LLImportMaterial();
}
}
mScene[transformation].push_back(LLModelInstance(model, model->mLabel, transformation, materials));
std::string base_name = model_name;
if (model->mSubmodelID > 0)
{
base_name += (char)((int)'a' + model->mSubmodelID);
}
mScene[transformation].push_back(LLModelInstance(model, base_name, transformation, materials));
stretch_extents(model, transformation);
}
}
Expand Down Expand Up @@ -387,15 +393,21 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
const LL::GLTF::Mesh& mesh = mGLTFAsset.mMeshes[node.mMesh];

// Get base mesh name and track usage
std::string base_name = mesh.mName;
std::string base_name = getLodlessLabel(mesh);
if (base_name.empty())
{
base_name = "mesh_" + std::to_string(node.mMesh);
}

S32 instance_count = mesh_name_counts[base_name]++;

if (populateModelFromMesh(pModel, mesh, node, mats, instance_count) &&
// make name unique
if (instance_count > 0)
{
base_name = base_name + "_copy_" + std::to_string(instance_count);
}

if (populateModelFromMesh(pModel, base_name, mesh, node, mats) &&
(LLModel::NO_ERRORS == pModel->getStatus()) &&
validate_model(pModel))
{
Expand Down Expand Up @@ -443,7 +455,7 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
mWarningsArray.append(args);
}

addModelToScene(pModel, submodel_limit, transformation, volume_params, mats);
addModelToScene(pModel, base_name, submodel_limit, transformation, volume_params, mats);
mats.clear();
}
else
Expand Down Expand Up @@ -529,29 +541,16 @@ bool LLGLTFLoader::addJointToModelSkin(LLMeshSkinInfo& skin_info, S32 gltf_skin_
return true;
}

bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats, S32 instance_count)
bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const std::string& base_name, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats)
{
// Set the requested label for the floater display and uploading
pModel->mRequestedLabel = gDirUtilp->getBaseFileName(mFilename, true);
// Set name and suffix. Suffix is nessesary for model matching logic
// because sometimes higher lod can be used as a lower one, so they
// need unique names not just in scope of one lod, but across lods.
pModel->mLabel = base_name + lod_suffix[mLod];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I missed that before for some reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is still incomplete, need to add getLodlessLabel.


// Create unique model name
std::string base_name = mesh.mName;
if (base_name.empty())
{
S32 mesh_index = static_cast<S32>(&mesh - &mGLTFAsset.mMeshes[0]);
base_name = "mesh_" + std::to_string(mesh_index);
}

LL_DEBUGS("GLTF_DEBUG") << "Processing model " << base_name << LL_ENDL;

if (instance_count > 0)
{
pModel->mLabel = base_name + "_copy_" + std::to_string(instance_count);
}
else
{
pModel->mLabel = base_name;
}
LL_DEBUGS("GLTF_DEBUG") << "Processing model " << pModel->mLabel << LL_ENDL;

pModel->ClearFacesAndMaterials();

Expand Down Expand Up @@ -1723,3 +1722,22 @@ void LLGLTFLoader::notifyUnsupportedExtension(bool unsupported)
}
}

size_t LLGLTFLoader::getSuffixPosition(const std::string &label)
{
if ((label.find("_LOD") != -1) || (label.find("_PHYS") != -1))
{
return label.rfind('_');
}
return -1;
}

std::string LLGLTFLoader::getLodlessLabel(const LL::GLTF::Mesh& mesh)
{
size_t ext_pos = getSuffixPosition(mesh.mName);
if (ext_pos != -1)
{
return mesh.mName.substr(0, ext_pos);
}
return mesh.mName;
}

11 changes: 5 additions & 6 deletions indra/newview/gltf/llgltfloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class LLGLTFLoader : public LLModelLoader
void computeCombinedNodeTransform(const LL::GLTF::Asset& asset, S32 node_index, glm::mat4& combined_transform) const;
void processNodeHierarchy(S32 node_idx, std::map<std::string, S32>& mesh_name_counts, U32 submodel_limit, const LLVolumeParams& volume_params);
bool addJointToModelSkin(LLMeshSkinInfo& skin_info, S32 gltf_skin_idx, size_t gltf_joint_idx);
bool populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh &mesh, const LL::GLTF::Node &node, material_map& mats, S32 instance_count);
bool populateModelFromMesh(LLModel* pModel, const std::string& base_name, const LL::GLTF::Mesh &mesh, const LL::GLTF::Node &node, material_map& mats);
void populateJointsFromSkin(S32 skin_idx);
void populateJointGroups();
void addModelToScene(LLModel* pModel, U32 submodel_limit, const LLMatrix4& transformation, const LLVolumeParams& volume_params, const material_map& mats);
void addModelToScene(LLModel* pModel, const std::string& model_name, U32 submodel_limit, const LLMatrix4& transformation, const LLVolumeParams& volume_params, const material_map& mats);
void buildJointGroup(LLJointData& viewer_data, const std::string& parent_group);
void buildOverrideMatrix(LLJointData& data, joints_data_map_t &gltf_nodes, joints_name_to_node_map_t &names_to_nodes, glm::mat4& parent_rest, glm::mat4& support_rest) const;
glm::mat4 buildGltfRestMatrix(S32 joint_node_index, const LL::GLTF::Skin& gltf_skin) const;
Expand All @@ -153,6 +153,9 @@ class LLGLTFLoader : public LLModelLoader

void notifyUnsupportedExtension(bool unsupported);

static size_t getSuffixPosition(const std::string& label);
static std::string getLodlessLabel(const LL::GLTF::Mesh& mesh);

// bool mPreprocessGLTF;

/* Below inherited from dae loader - unknown if/how useful here
Expand Down Expand Up @@ -190,10 +193,6 @@ class LLGLTFLoader : public LLModelLoader
//
bool loadModelsFromGltfMesh(gltfMesh *mesh, std::vector<LLModel *> &models_out, U32 submodel_limit);

static std::string getElementLabel(gltfElement *element);
static size_t getSuffixPosition(std::string label);
static std::string getLodlessLabel(gltfElement *element);

static std::string preprocessGLTF(std::string filename);
*/

Expand Down
Loading