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); } }
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; }