简体   繁体   English

OSG:为什么有纹理坐标数组而没有纹理本身?

[英]OSG: Why there is texture coordinate array but not texture itself?

I am trying to get texture file name from an osg::Geometry I get the texture coordinates like this:我正在尝试从osg::Geometry获取纹理文件名我得到这样的纹理坐标:

osg::Geometry* geom = dynamic_cast<osg::Geometry*> (drawable);
const osg::Geometry::ArrayList& texCoordArrayList = dynamic_cast<const osg::Geometry::ArrayList&>(geom->getTexCoordArrayList());
auto texCoordArrayListSize = texCoordArrayList.size();

auto sset = geom->getOrCreateStateSet();
processStateSet(sset);

for (size_t k = 0; k < texCoordArrayListSize; k++)
{
    const osg::Vec2Array* texCoordArray = dynamic_cast<const osg::Vec2Array*>(geom->getTexCoordArray(k));
    //doing sth with vertexarray, normalarray and texCoordArray
}

But I am not able to get texture file name in processStateSet() function.但我无法在processStateSet() function 中获取纹理文件名。 I take the processStateSet function code from OSG examples (specifically from osganalysis example).我从 OSG 示例(特别是来自 osganalysis 示例)中获取processStateSet function 代码。 Even though there is a texture file, Sometimes it works and gets the name but sometimes not.即使有一个纹理文件,有时它可以工作并获得名称,但有时不能。 Here is my processStateSet function这是我的processStateSet function

void processStateSet(osg::StateSet* stateset)
{
    if (!stateset) return;

    for (unsigned int ti = 0; ti < stateset->getNumTextureAttributeLists(); ++ti)
    {
        osg::StateAttribute* sa = stateset->getTextureAttribute(ti, osg::StateAttribute::TEXTURE);
        osg::Texture* texture = dynamic_cast<osg::Texture*>(sa);
        if (texture)
        {
            LOG("texture! ");

            //TODO: something with this.
            for (unsigned int i = 0; i < texture->getNumImages(); ++i)
            {
                auto img (texture->getImage(i));
                auto texturefname (img->getFileName());

                LOG("image ! image no: " + IntegerToStr(i) +  " file: " + texturefname);
            }
        }
    }
}

EDIT:编辑:

I just realized that: if the model that I load is ".3ds", texturefname is exist but if model is ".flt" there is not texture name.我刚刚意识到:如果我加载的texturefname是“.3ds”,则纹理名称存在,但如果 model 是“.flt”,则没有纹理名称。

Is it about loading different types?是关于加载不同的类型吗? But I know that they both have textures.但我知道它们都有纹理。 What is the difference?有什么区别? I confused.我很困惑。

Some 3D models don't have texture names.一些 3D 模型没有纹理名称。 Your choices are to deal with it, or use model files that do.您的选择是处理它,或者使用 model 文件。 It also depends on the format.这也取决于格式。 Some formats can't have texture names.某些格式不能有纹理名称。 Some Blender export scripts can't write texture names even though the format supports it.即使格式支持,某些 Blender 导出脚本也无法写入纹理名称。 And so on.等等。

3D model formats are not interchangeable - every one is different. 3D model 格式不可互换 - 每一种都不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM