Exemplo n.º 1
0
const domSamplerRef getSampler(const domChannelRef& channel)
{
    const domURIFragmentType& uri = channel->getSource();
    daeElementRef element = uri.getElement();
    if (element && element->typeID() == COLLADA_TYPE::SAMPLER)
    {
        const domSamplerRef sampler = daeSafeCast<domSampler>(element);
        return sampler;
    }
    // resolve the source manually by searching for the sampler in the animation that the channel is a child of.
    const std::string& id = uri.id();
    const daeElementRef& parent = channel->getParent();
    if (parent && parent->typeID() == COLLADA_TYPE::ANIMATION)
    {
        const domAnimationRef animation = daeSafeCast<domAnimation>(parent);
        
        const domSampler_Array& samplerArray = animation->getSampler_array();
        size_t count = samplerArray.getCount();
        for (size_t i = 0; i < count; ++i)
        {
            const domSamplerRef& sampler = samplerArray.get(i);
            if (id.compare(sampler->getId()) == 0)
            {
                return sampler;
            }
        }
    }
    return NULL;
}
Exemplo n.º 2
0
void moveChannelAndSouresToAnimation(domChannelRef& channel, domAnimationRef& animation)
{
    assert(channel);
    assert(animation);

    daeElement::removeFromParent(channel);
    animation->add(channel); // move channel

    daeElementRef element = channel->getSource().getElement();
    if (element)
    {
        domSamplerRef sampler = daeSafeCast<domSampler>(element);

        domInputLocal_Array& inputArray = sampler->getInput_array();
        size_t inputArrayCount = inputArray.getCount();
        for (size_t i = 0; i < inputArrayCount; ++i)
        {
            inputArray = sampler->getInput_array();
            const domInputLocalRef& input = inputArray.get(i);
            daeElementRef element = input->getSource().getElement();
            if (element && element->typeID() == COLLADA_TYPE::SOURCE)
            {
                domSourceRef source = daeSafeCast<domSource>(element);
                assert(source);
                daeElement::removeFromParent(source);
                animation->add(source); // move source
            }
        }
        daeElement::removeFromParent(sampler);
        animation->add(sampler); // move sampler
    }
}
Exemplo n.º 3
0
DAEChannelTarget::DAEChannelTarget(const domChannelRef channelRef) : _channel(channelRef), _targetElement(NULL)
{
    const std::string target = channelRef->getTarget();
    size_t index = target.find('/');
    if (index == std::string::npos)
    {
        // If the string doesn't contain a '/' then the whole string is the id
        // and there are no sid's being targeted.
        _targetId = target;
    }
    else
    {
        // The targetId is the part before the first '/'
        _targetId = target.substr(0, index);

        // each '/' denotes another sid
        size_t start;
        size_t end;
        do
        {
            start = index + 1;
            end = target.find('/', start);
        
            std::string sub;
            if (end == std::string::npos)
            {
                sub = target.substr(start);
                // break;
            }
            else
            {
                sub = target.substr(start, end - start);
                index = end + 1;
            }
            _attributeIds.push_back(sub);
        } while (end != std::string::npos);
    }

}
Exemplo n.º 4
0
IZ_BOOL CColladaAnimation::GetAnmTarget(
    domChannelRef pChannel,
    SAnmChannel& sAnmChannel)
{
    static IZ_CHAR tmp[128];

    daeString target = pChannel->getTarget();

    // Get target joint's name.
    IZ_PCSTR pszId = _FindStr(target, "/");
    {
        if (pszId == IZ_NULL) {
            pszId = _FindStr(target, "(");
        }
        if (pszId == IZ_NULL) {
            pszId = _FindStr(target, ".");
        }

        VRETURN(pszId != IZ_NULL);

        size_t nSize = static_cast<size_t>(izanagi::CStdUtil::GetPtrDistance(target, pszId));
        VRETURN((1 < nSize) && (nSize < COUNTOF(tmp)));

        FILL_ZERO(tmp, sizeof(tmp));
        memcpy(tmp, target, nSize);

        sAnmChannel.joint = tmp;
    }

    static IZ_CHAR strMember[izanagi::ANM_NAME_LEN + 1];

    // Get target transform's sid.
    IZ_PCSTR pszSId = _FindStr(target, ".");
    {
        if (pszSId == IZ_NULL) {
            pszSId = _FindStr(target, "(");
        }
        if (pszSId == IZ_NULL) {
            pszSId = target + strlen(target);
        }

        VRETURN(pszSId != IZ_NULL);
        VRETURN(pszSId > pszId);

        size_t nSize = static_cast<size_t>(izanagi::CStdUtil::GetPtrDistance(pszSId, pszId));
        VRETURN((1 < nSize) && (nSize < COUNTOF(tmp)));

        FILL_ZERO(tmp, sizeof(tmp));
        memcpy(tmp, pszId + 1, nSize - 1);

        sAnmChannel.transform = tmp;

        FILL_ZERO(strMember, sizeof(strMember));
        if ((pszSId != '\0') && (strlen(pszSId) > 1)) {
            memcpy(strMember, pszSId + 1, strlen(pszSId) - 1);
        }
    }

    domElement* pRootNode = pChannel->getDocument()->getDomRoot();

    // Get transform element of target node.
    daeSIDResolver sidResolver(pRootNode, target);
    domElement* pElement = sidResolver.getElement();
    VRETURN(pElement != IZ_NULL);

#if 0
    COLLADA_TYPE::TypeEnum type = pElement->getElementType();
    switch (type) {
    case COLLADA_TYPE::TRANSLATE:
        sAnmChannel.type = izanagi::E_ANM_TRANSFORM_TYPE_TRANSLATE;
        break;
    case COLLADA_TYPE::ROTATE:
        sAnmChannel.type = izanagi::E_ANM_TRANSFORM_TYPE_QUATERNION;
        break;
    case COLLADA_TYPE::SCALE:
        sAnmChannel.type = izanagi::E_ANM_TRANSFORM_TYPE_SCALE;
        break;
    default:
        VRETURN(IZ_FALSE);
        break;
    }
#else
    izanagi::tool::CString type(pElement->getElementName());
    if (type == ColladaDOM141::COLLADA_TYPE_TRANSLATE)
    {
        sAnmChannel.type = izanagi::E_ANM_TRANSFORM_TYPE_TRANSLATE;
    }
    else if (type == ColladaDOM141::COLLADA_TYPE_ROTATE)
    {
        sAnmChannel.type = izanagi::E_ANM_TRANSFORM_TYPE_QUATERNION;
    }
    else if (type == ColladaDOM141::COLLADA_TYPE_SCALE)
    {
        sAnmChannel.type = izanagi::E_ANM_TRANSFORM_TYPE_SCALE;
    }
    else
    {
        VRETURN(IZ_FALSE);
    }
#endif

    if (strlen(strMember) > 0) {
        if (sAnmChannel.type & izanagi::E_ANM_TRANSFORM_TYPE_QUATERNION) {
            if (izanagi::tool::CString::CmpStr(strMember, "AXIS")) {
                sAnmChannel.type = izanagi::E_ANM_TRANSFORM_TYPE_QUATERNION_XYZ;
            }
            else if (izanagi::tool::CString::CmpStr(strMember, "ANGLE")) {
                sAnmChannel.type = izanagi::E_ANM_TRANSFORM_TYPE_QUATERNION_W;
            }
        }
        else if (izanagi::tool::CString::CmpStr(strMember, "X")) {
            sAnmChannel.type |= izanagi::E_ANM_TRANSFORM_TYPE_X;
        }
        else if (izanagi::tool::CString::CmpStr(strMember, "Y")) {
            sAnmChannel.type |= izanagi::E_ANM_TRANSFORM_TYPE_Y;
        }
        else if (izanagi::tool::CString::CmpStr(strMember, "Z")) {
            sAnmChannel.type |= izanagi::E_ANM_TRANSFORM_TYPE_Z;
        }
    }
    else {
        if (sAnmChannel.type & izanagi::E_ANM_TRANSFORM_TYPE_QUATERNION) {
            sAnmChannel.type |= izanagi::E_ANM_TRANSFORM_TYPE_XYZW;
        }
        else {
            sAnmChannel.type |= izanagi::E_ANM_TRANSFORM_TYPE_XYZ;
        }
    }

    return IZ_TRUE;
}