void
OSBTextureChunkElement::postRead(void)
{
    OSG_OSB_LOG(("OSBTextureChunkElement::postRead:\n"));
    OSBRootElement *pRoot = editRoot();

    // for the id remapping TexEnv needs an id that is not used in the file
    UInt32 texEnvIdFile = pRoot->getIdMap().rbegin()->first;
    while(pRoot->getIdMap().find(texEnvIdFile) != pRoot->getIdMap().end())
    {
        ++texEnvIdFile;
    }
    
    // add mapping entry for TexEnv
    pRoot->editIdMap()[texEnvIdFile] = _pTexEnv->getId();
    
    PtrFieldListIt ptrFieldIt  = pRoot->editPtrFieldList().begin();
    PtrFieldListIt ptrFieldEnd = pRoot->editPtrFieldList().end  ();

    for(; ptrFieldIt != ptrFieldEnd; ++ptrFieldIt)
    {
        ChunkMaterial *chkMat =
            dynamic_cast<ChunkMaterial *>(ptrFieldIt->getContainer());

        if(chkMat != NULL)
        {
            // OSBChunkMaterialElement takes care of handling the two chunks
            // replacing TextureChunk
            continue;
        }
        else
        {
            UInt32 numIds  = ptrFieldIt->getIdStore     ().size();
            UInt32 numBind = ptrFieldIt->getBindingStore().size();

            if(numBind > 0)
            {
                // TextureChunk is pointed to from an attachment map
                for(UInt32 i = 0; (i < numIds) && (i < numBind); ++i)
                {
                    if(ptrFieldIt->getIdStore()[i] == getFCIdFile())
                    {
                        // insert a pointer to TexEnv right after the TexObj
                        ptrFieldIt->editIdStore().insert(
                            ptrFieldIt->editIdStore().begin() + i + 1,
                            texEnvIdFile                              );

                        // duplicate the binding of the TexObj
                        ptrFieldIt->editBindingStore().insert(
                            ptrFieldIt->editBindingStore().begin() + i + 1,
                            ptrFieldIt->getBindingStore()[i]               );

                        ++numIds;
                        ++numBind;
                    }
                }
            }
            else
            {
                for(UInt32 i = 0; i < numIds; ++i)
                {
                    if(ptrFieldIt->getIdStore()[i] == getFCIdFile())
                    {
                        // insert a pointer to TexEnv right after the TexObj
                        ptrFieldIt->editIdStore().insert(
                            ptrFieldIt->editIdStore().begin() + i + 1,
                            texEnvIdFile                              );

                        ++numIds;
                    }
                }
            }
        }
    }
}
예제 #2
0
void
OSBGeometryElement::postReadV100(void)
{
    OSG_OSB_LOG(("OSBGeometryElement::postReadV100\n"));

    OSBRootElement  *root             = editRoot();
    Geometry        *geo              =
        dynamic_cast<Geometry*>(getContainer());
    UInt32           indexMappingSize = UInt32(_indexMapping.size());

    if(indexMappingSize <= 1)
    {
        OSG_OSB_LOG(("OSBGeometryElement::postReadV100: "
                "Converting single index.\n"          ));

        if(_indicesPacked)
        {
            OSG_OSB_LOG(("OSBGeometryElement::postReadV100: "
                    "Converting packed indices.\n"        ));
            geo->setIndices(_indices);
        }
        else
        {
            OSG_OSB_LOG(("OSBGeometryElement::postReadV100: "
                    "Converting non-packed indices.\n"    ));

            // indices stored in container with id _indicesId
            // create PtrFieldInfo structure to set all entries of field
            // "propIndices" to the container with id _indicesId

            FieldDescriptionBase *indFieldDesc =
                geo->getFieldDescription("propIndices");
            UInt32                indFieldId   = indFieldDesc->getFieldId();

            root->editPtrFieldList().push_back(PtrFieldInfo(geo, indFieldId));
            PtrFieldInfo &indFieldPFI = root->editPtrFieldList().back();

            for(UInt32 i = 0; i < Geometry::MaxAttribs; ++i)
            {
                indFieldPFI.editIdStore().push_back(_indicesId);
            }
        }
    }
    else
    {
        OSG_OSB_LOG(("OSBGeometryElement::postReadV100: "
                "Converting multi index.\n"          ));

        OSBGeometryHelper gh;

        if(_indicesPacked)
        {
            OSG_OSB_LOG(("OSBGeometryElement::postReadV100: "
                    "Converting packed indices.\n"        ));

            // create 16 bit or 32 bit indices
            if(_indices16Bit)
            {
                GeoUInt16Property *ui16Indices =
                    dynamic_pointer_cast<GeoUInt16Property>(_indices);

                gh.splitMultiIndex<GeoUInt16Property *>(
                    _indexMapping, ui16Indices, geo);
            }
            else
            {
                GeoUInt32Property *ui32Indices =
                    dynamic_pointer_cast<GeoUInt32Property>(_indices);

                gh.splitMultiIndex<GeoUInt32Property *>(
                    _indexMapping, ui32Indices, geo);
            }
        }
        else
        {
            OSG_OSB_LOG(("OSBGeometryElement::postReadV100: "
                         "Converting non-packed indices.\n"    ));

            FieldContainerIdMapConstIt mapIt =
                root->getIdMap().find(_indicesId);

            if(mapIt != root->getIdMap().end())
            {
                _indices = dynamic_cast<GeoIntegralProperty *>(
                    FieldContainerFactory::the()->getContainer(mapIt->second));
            }
            else
            {
                FWARNING(("OSBGeometryElement::postReadV100: "
                          "Could not find indices property.\n"));
                return;
            }

            if(_indices->getFormatSize() == sizeof(UInt16))
            {
                GeoUInt16Property *ui16Indices =
                    dynamic_pointer_cast<GeoUInt16Property>(_indices);

                gh.splitMultiIndex<GeoUInt16Property *>(
                    _indexMapping, ui16Indices, geo);
            }
            else if(_indices->getFormatSize() == sizeof(UInt32))
            {
                GeoUInt32Property *ui32Indices =
                    dynamic_pointer_cast<GeoUInt32Property>(_indices);

                gh.splitMultiIndex<GeoUInt32Property *>(
                    _indexMapping, ui32Indices, geo);
            }
        }
    }
}