#4204 Remove more unused code

master
Andrey Lihatskiy 2025-06-19 22:31:38 +03:00
parent 2083e652fe
commit 1a6e328611
2 changed files with 2 additions and 293 deletions

View File

@ -111,9 +111,6 @@ LLGLTFLoader::LLGLTFLoader(std::string filename,
jointsFromNodes,
jointAliasMap,
maxJointsPerMesh )
//mPreprocessGLTF(preprocess),
, mMeshesLoaded(false)
, mMaterialsLoaded(false)
, mGeneratedModelLimit(modelLimit)
, mViewerJointData(viewer_skeleton)
{
@ -137,15 +134,11 @@ bool LLGLTFLoader::OpenFile(const std::string &filename)
notifyUnsupportedExtension(false);
mMeshesLoaded = parseMeshes();
if (mMeshesLoaded) uploadMeshes();
mMaterialsLoaded = parseMaterials();
if (mMaterialsLoaded) uploadMaterials();
bool meshesLoaded = parseMeshes();
setLoadState(DONE);
return (mMeshesLoaded);
return meshesLoaded;
}
void LLGLTFLoader::addModelToScene(
@ -1486,195 +1479,6 @@ void LLGLTFLoader::checkForXYrotation(const LL::GLTF::Skin& gltf_skin)
}
}
bool LLGLTFLoader::parseMaterials()
{
if (!mGltfLoaded) return false;
// fill local texture data structures
mSamplers.clear();
for (auto& in_sampler : mGLTFAsset.mSamplers)
{
gltf_sampler sampler;
sampler.magFilter = in_sampler.mMagFilter > 0 ? in_sampler.mMagFilter : GL_LINEAR;
sampler.minFilter = in_sampler.mMinFilter > 0 ? in_sampler.mMinFilter : GL_LINEAR;
sampler.wrapS = in_sampler.mWrapS;
sampler.wrapT = in_sampler.mWrapT;
sampler.name = in_sampler.mName;
mSamplers.push_back(sampler);
}
mImages.clear();
for (auto& in_image : mGLTFAsset.mImages)
{
gltf_image image;
image.numChannels = in_image.mComponent;
image.bytesPerChannel = in_image.mBits >> 3; // Convert bits to bytes
image.pixelType = in_image.mPixelType;
image.size = 0; // We'll calculate this below if we have valid dimensions
// Get dimensions from the texture if available
if (in_image.mTexture && in_image.mTexture->getDiscardLevel() >= 0)
{
image.height = in_image.mTexture->getHeight();
image.width = in_image.mTexture->getWidth();
// Since we don't have direct access to the raw data, we'll use the dimensions to calculate size
if (image.height > 0 && image.width > 0 && image.numChannels > 0 && image.bytesPerChannel > 0)
{
image.size = static_cast<U32>(image.height * image.width * image.numChannels * image.bytesPerChannel);
}
}
else
{
// Fallback to provided dimensions
image.height = in_image.mHeight;
image.width = in_image.mWidth;
if (image.height > 0 && image.width > 0 && image.numChannels > 0 && image.bytesPerChannel > 0)
{
image.size = static_cast<U32>(image.height * image.width * image.numChannels * image.bytesPerChannel);
}
}
// If we couldn't determine the size, skip this image
if (image.size == 0)
{
LL_WARNS("GLTF_IMPORT") << "Image size could not be determined" << LL_ENDL;
continue;
}
// We don't have direct access to the image data, so data pointer remains nullptr
image.data = nullptr;
mImages.push_back(image);
}
mTextures.clear();
for (auto& in_tex : mGLTFAsset.mTextures)
{
gltf_texture tex;
tex.imageIdx = in_tex.mSource;
tex.samplerIdx = in_tex.mSampler;
tex.imageUuid.setNull();
if (tex.imageIdx >= mImages.size() || tex.samplerIdx >= mSamplers.size())
{
LL_WARNS("GLTF_IMPORT") << "Texture sampler/image index error" << LL_ENDL;
return false;
}
mTextures.push_back(tex);
}
// parse each material
mMaterials.clear();
for (const auto& gltf_material : mGLTFAsset.mMaterials)
{
gltf_render_material mat;
mat.name = gltf_material.mName;
// PBR Metallic Roughness properties
mat.hasPBR = true;
// Base color factor
mat.baseColor = LLColor4(
gltf_material.mPbrMetallicRoughness.mBaseColorFactor[0],
gltf_material.mPbrMetallicRoughness.mBaseColorFactor[1],
gltf_material.mPbrMetallicRoughness.mBaseColorFactor[2],
gltf_material.mPbrMetallicRoughness.mBaseColorFactor[3]
);
// Base color texture
mat.hasBaseTex = gltf_material.mPbrMetallicRoughness.mBaseColorTexture.mIndex >= 0;
mat.baseColorTexIdx = gltf_material.mPbrMetallicRoughness.mBaseColorTexture.mIndex;
mat.baseColorTexCoords = gltf_material.mPbrMetallicRoughness.mBaseColorTexture.mTexCoord;
// Metalness and roughness
mat.metalness = gltf_material.mPbrMetallicRoughness.mMetallicFactor;
mat.roughness = gltf_material.mPbrMetallicRoughness.mRoughnessFactor;
// Metallic-roughness texture
mat.hasMRTex = gltf_material.mPbrMetallicRoughness.mMetallicRoughnessTexture.mIndex >= 0;
mat.metalRoughTexIdx = gltf_material.mPbrMetallicRoughness.mMetallicRoughnessTexture.mIndex;
mat.metalRoughTexCoords = gltf_material.mPbrMetallicRoughness.mMetallicRoughnessTexture.mTexCoord;
// Normal texture
mat.normalScale = gltf_material.mNormalTexture.mScale;
mat.hasNormalTex = gltf_material.mNormalTexture.mIndex >= 0;
mat.normalTexIdx = gltf_material.mNormalTexture.mIndex;
mat.normalTexCoords = gltf_material.mNormalTexture.mTexCoord;
// Occlusion texture
mat.occlusionScale = gltf_material.mOcclusionTexture.mStrength;
mat.hasOcclusionTex = gltf_material.mOcclusionTexture.mIndex >= 0;
mat.occlusionTexIdx = gltf_material.mOcclusionTexture.mIndex;
mat.occlusionTexCoords = gltf_material.mOcclusionTexture.mTexCoord;
// Emissive texture and color
mat.emissiveColor = LLColor4(
gltf_material.mEmissiveFactor[0],
gltf_material.mEmissiveFactor[1],
gltf_material.mEmissiveFactor[2],
1.0f
);
mat.hasEmissiveTex = gltf_material.mEmissiveTexture.mIndex >= 0;
mat.emissiveTexIdx = gltf_material.mEmissiveTexture.mIndex;
mat.emissiveTexCoords = gltf_material.mEmissiveTexture.mTexCoord;
// Convert AlphaMode enum to string
switch (gltf_material.mAlphaMode)
{
case LL::GLTF::Material::AlphaMode::OPAQUE:
mat.alphaMode = "OPAQUE";
break;
case LL::GLTF::Material::AlphaMode::MASK:
mat.alphaMode = "MASK";
break;
case LL::GLTF::Material::AlphaMode::BLEND:
mat.alphaMode = "BLEND";
break;
default:
mat.alphaMode = "OPAQUE";
break;
}
mat.alphaMask = gltf_material.mAlphaCutoff;
// Verify that all referenced textures are valid
if ((mat.hasNormalTex && (mat.normalTexIdx >= mTextures.size())) ||
(mat.hasOcclusionTex && (mat.occlusionTexIdx >= mTextures.size())) ||
(mat.hasEmissiveTex && (mat.emissiveTexIdx >= mTextures.size())) ||
(mat.hasBaseTex && (mat.baseColorTexIdx >= mTextures.size())) ||
(mat.hasMRTex && (mat.metalRoughTexIdx >= mTextures.size())))
{
LL_WARNS("GLTF_IMPORT") << "Texture resource index error" << LL_ENDL;
return false;
}
// Verify texture coordinate sets are valid (mesh can have up to 3 sets of UV)
if ((mat.hasNormalTex && (mat.normalTexCoords > 2)) ||
(mat.hasOcclusionTex && (mat.occlusionTexCoords > 2)) ||
(mat.hasEmissiveTex && (mat.emissiveTexCoords > 2)) ||
(mat.hasBaseTex && (mat.baseColorTexCoords > 2)) ||
(mat.hasMRTex && (mat.metalRoughTexCoords > 2)))
{
LL_WARNS("GLTF_IMPORT") << "Image texcoord index error" << LL_ENDL;
return false;
}
mMaterials.push_back(mat);
}
return true;
}
// TODO: convert raw vertex buffers to UUIDs
void LLGLTFLoader::uploadMeshes()
{
//llassert(0);
}
// convert raw image buffers to texture UUIDs & assemble into a render material
void LLGLTFLoader::uploadMaterials()
{
}
std::string LLGLTFLoader::extractTextureToTempFile(S32 textureIndex, const std::string& texture_type)
{
if (textureIndex < 0 || textureIndex >= mGLTFAsset.mTextures.size())

View File

@ -35,89 +35,6 @@
#include "lljointdata.h"
#include "llmodelloader.h"
// gltf_* structs are temporary, used to organize the subset of data that eventually goes into the material LLSD
class gltf_sampler
{
public:
// Uses GL enums
S32 minFilter; // GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR or GL_LINEAR_MIPMAP_LINEAR
S32 magFilter; // GL_NEAREST or GL_LINEAR
S32 wrapS; // GL_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT or GL_REPEAT
S32 wrapT; // GL_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT or GL_REPEAT
//S32 wrapR; // Found in some sample files, but not part of glTF 2.0 spec. Ignored.
std::string name; // optional, currently unused
// extensions and extras are sampler optional fields that we don't support - at least initially
};
class gltf_image
{
public:// Note that glTF images are defined with row 0 at the top (opposite of OpenGL)
U8* data; // ptr to decoded image data
U32 size; // in bytes, regardless of channel width
U32 width;
U32 height;
U32 numChannels; // range 1..4
U32 bytesPerChannel; // converted from gltf "bits", expects only 8, 16 or 32 as input
U32 pixelType; // one of (TINYGLTF_COMPONENT_TYPE)_UNSIGNED_BYTE, _UNSIGNED_SHORT, _UNSIGNED_INT, or _FLOAT
};
class gltf_texture
{
public:
U32 imageIdx;
U32 samplerIdx;
LLUUID imageUuid = LLUUID::null;
};
class gltf_render_material
{
public:
std::string name;
// scalar values
LLColor4 baseColor; // linear encoding. Multiplied with vertex color, if present.
double metalness;
double roughness;
double normalScale; // scale applies only to X,Y components of normal
double occlusionScale; // strength multiplier for occlusion
LLColor4 emissiveColor; // emissive mulitiplier, assumed linear encoding (spec 2.0 is silent)
std::string alphaMode; // "OPAQUE", "MASK" or "BLEND"
double alphaMask; // alpha cut-off
// textures
U32 baseColorTexIdx; // always sRGB encoded
U32 metalRoughTexIdx; // always linear, roughness in G channel, metalness in B channel
U32 normalTexIdx; // linear, valid range R[0-1], G[0-1], B[0.5-1]. Normal = texel * 2 - vec3(1.0)
U32 occlusionTexIdx; // linear, occlusion in R channel, 0 meaning fully occluded, 1 meaning not occluded
U32 emissiveTexIdx; // always stored as sRGB, in nits (candela / meter^2)
// texture coordinates
U32 baseColorTexCoords;
U32 metalRoughTexCoords;
U32 normalTexCoords;
U32 occlusionTexCoords;
U32 emissiveTexCoords;
// TODO: Add traditional (diffuse, normal, specular) UUIDs here, or add this struct to LL_TextureEntry??
bool hasPBR;
bool hasBaseTex, hasMRTex, hasNormalTex, hasOcclusionTex, hasEmissiveTex;
// This field is populated after upload
LLUUID material_uuid = LLUUID::null;
};
class gltf_mesh
{
public:
std::string name;
// TODO add mesh import DJH 2022-04
};
class LLGLTFLoader : public LLModelLoader
{
public:
@ -185,18 +102,9 @@ protected:
LL::GLTF::Asset mGLTFAsset;
tinygltf::Model mGltfModel;
bool mGltfLoaded;
bool mMeshesLoaded;
bool mMaterialsLoaded;
bool mApplyXYRotation = false;
U32 mGeneratedModelLimit;
std::vector<gltf_mesh> mMeshes;
std::vector<gltf_render_material> mMaterials;
std::vector<gltf_texture> mTextures;
std::vector<gltf_image> mImages;
std::vector<gltf_sampler> mSamplers;
// GLTF isn't aware of viewer's skeleton and uses it's own,
// so need to take viewer's joints and use them to
// recalculate iverse bind matrices
@ -212,9 +120,6 @@ protected:
private:
bool parseMeshes();
void uploadMeshes();
bool parseMaterials();
void uploadMaterials();
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 populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh &mesh, const LL::GLTF::Node &node, material_map& mats, S32 instance_count);