CModelWriterNode100_Model::CModelWriterNode100_Model(_In_ CModel * pModel, _In_ CXmlWriter * pXMLWriter)
    :CModelWriterNode(pModel, pXMLWriter)
{
    m_ResourceCounter = pModel->generateResourceID();

    m_pColorMapping = std::make_shared<CModelWriter_ColorMapping>(generateOutputResourceID ());

    m_pTexCoordMappingContainer = std::make_shared<CModelWriter_TexCoordMappingContainer>();

    nfInt32 nObjectCount = pModel->getObjectCount();
    nfInt32 nObjectIndex;

    for (nObjectIndex = 0; nObjectIndex < nObjectCount; nObjectIndex++) {
        PModelResource pResource = pModel->getObjectResource(nObjectIndex);

        CModelMeshObject * pMeshObject = dynamic_cast<CModelMeshObject*> (pResource.get());
        if (pMeshObject) {
            CMesh * pMesh = pMeshObject->getMesh();
            if (pMesh) {
                calculateColors(pMesh);
                calculateTexCoords(pMesh);
            }
        }

        // Register Default Property Resources
        CModelObject * pObject = dynamic_cast<CModelObject*> (pResource.get());
        if (pObject) {
            PModelDefaultProperty pProperty = pObject->getDefaultProperty();

            CModelDefaultProperty_Color * pColorProperty = dynamic_cast<CModelDefaultProperty_Color *> (pProperty.get());
            if (pColorProperty != nullptr) {
                nfColor cColor = pColorProperty->getColor();
                if (cColor != 0)
                    m_pColorMapping->registerColor(cColor);
            }

            CModelDefaultProperty_TexCoord2D * pTexCoord2DProperty = dynamic_cast<CModelDefaultProperty_TexCoord2D *> (pProperty.get());
            if (pTexCoord2DProperty != nullptr) {
                PModelWriter_TexCoordMapping pTexCoordMapping = m_pTexCoordMappingContainer->findTexture(pTexCoord2DProperty->getTextureID());
                if (pTexCoordMapping.get() == nullptr) {
                    pTexCoordMapping = m_pTexCoordMappingContainer->addTexture(pTexCoord2DProperty->getTextureID(), generateOutputResourceID());
                }

                pTexCoordMapping->registerTexCoords(pTexCoord2DProperty->getU(), pTexCoord2DProperty->getV());
            }

        }
    }
}
Exemplo n.º 2
0
RGBMap RGBAudio::rgbMap(const QSize& size, uint rgb, int step)
{
    Q_UNUSED(step)

    m_mutex.lock();
    RGBMap map(size.height());
    for (int y = 0; y < size.height(); y++)
    {
        map[y].resize(size.width());
        map[y].fill(0);
    }

    // on the first round, just set the proper number of
    // spectrum bands to receive
    if (m_bandsNumber == -1)
    {
        m_bandsNumber = size.width();
        m_audioInput->setBandsNumber(m_bandsNumber);
        if (m_audioInput->isInitialized() == false)
            m_audioInput->initialize(44100, 1, 2048);
        m_audioInput->start();
        m_mutex.unlock();
        return map;
    }
    if (m_barColors.count() == 0)
        calculateColors(size.height());

    double volHeight = (m_volumePower * size.height()) / 0x7FFF;
    for (int x = 0; x < m_spectrumValues.count(); x++)
    {
        int barHeight =  (volHeight * m_spectrumValues[x]) / m_maxMagnitude;
        for (int y = size.height() - barHeight; y < size.height(); y++)
        {
            if (m_barColors.count() == 0)
                map[y][x] = rgb;
            else
                map[y][x] = m_barColors.at(y);
        }
    }

    m_mutex.unlock();
    return map;
}