Beispiel #1
0
Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,const MaterialDatas& matrialdatas)
{
    auto sprite = new (std::nothrow) Sprite3D();
    if (sprite)
    {
        sprite->setName(nodedata->id);
        auto mesh = Mesh::create(nodedata->id, getMeshIndexData(modeldata->subMeshId));
        if (modeldata->matrialId == "" && matrialdatas.materials.size())
        {
            const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
            if (!textureData->filename.empty())
                mesh->setTexture(textureData->filename);
        }
        else
        {
            const NMaterialData*  materialData=matrialdatas.getMaterialData(modeldata->matrialId);
            if(materialData)
            {
                const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
                if(textureData && !textureData->filename.empty())
                {
                    auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
                    if(tex)
                    {
                        Texture2D::TexParams    texParams;
                        texParams.minFilter = GL_LINEAR;
                        texParams.magFilter = GL_LINEAR;
                        texParams.wrapS = textureData->wrapS;
                        texParams.wrapT = textureData->wrapT;
                        tex->setTexParameters(texParams);
                        mesh->setTexture(tex);
                        mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr);
                    }

                }
            }
        }
        sprite->setAdditionalTransform(&nodedata->transform);
        sprite->addMesh(mesh);
        sprite->autorelease();
        sprite->genGLProgramState(); 
    }
    return   sprite;
}
Beispiel #2
0
void Node::setAdditionalTransform(const AffineTransform& additionalTransform)
{
    kmMat4 tmp;
    CGAffineToGL(additionalTransform, tmp.mat);
    setAdditionalTransform(&tmp);
}
Beispiel #3
0
void Animate3D::update(float t)
{
    if (_target)
    {
        if (_state == Animate3D::Animate3DState::FadeIn && _lastTime > 0.f)
        {
            _accTransTime += (t - _lastTime) * getDuration();
            
            _weight = _accTransTime / _transTime;
            if (_weight >= 1.0f)
            {
                _accTransTime = _transTime;
                _weight = 1.0f;
                _state = Animate3D::Animate3DState::Running;
                s_fadeInAnimates.erase(_target);
                s_runningAnimates[_target] = this;
            }
        }
        else if (_state == Animate3D::Animate3DState::FadeOut && _lastTime > 0.f)
        {
            _accTransTime += (t - _lastTime) * getDuration();
            
            _weight = 1 - _accTransTime / _transTime;
            if (_weight <= 0.0f)
            {
                _accTransTime = _transTime;
                _weight = 0.0f;
                
                s_fadeOutAnimates.erase(_target);
                _target->stopAction(this);
                return;
            }
        }
        float lastTime = _lastTime;
        _lastTime = t;
        
        if (_quality != Animate3DQuality::QUALITY_NONE)
        {
            if (_weight > 0.0f)
            {
                float transDst[3], rotDst[4], scaleDst[3];
                float* trans = nullptr, *rot = nullptr, *scale = nullptr;
                if (_playReverse){
                    t = 1 - t;
                    lastTime = 1.0f - lastTime;
                }
                
                t = _start + t * _last;
                lastTime = _start + lastTime * _last;
                
                for (const auto& it : _boneCurves) {
                    auto bone = it.first;
                    auto curve = it.second;
                    if (curve->translateCurve)
                    {
                        curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
                        trans = &transDst[0];
                    }
                    if (curve->rotCurve)
                    {
                        curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
                        rot = &rotDst[0];
                    }
                    if (curve->scaleCurve)
                    {
                        curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
                        scale = &scaleDst[0];
                    }
                    bone->setAnimationValue(trans, rot, scale, this, _weight);
                }
                
                for (const auto& it : _nodeCurves)
                {
                    auto node = it.first;
                    auto curve = it.second;
                    Mat4 transform;
                    if (curve->translateCurve)
                    {
                        curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
                        transform.translate(transDst[0], transDst[1], transDst[2]);
                    }
                    if (curve->rotCurve)
                    {
                        curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
                        Quaternion qua(rotDst[0], rotDst[1], rotDst[2], rotDst[3]);
                        transform.rotate(qua);
                    }
                    if (curve->scaleCurve)
                    {
                        curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
                        transform.scale(scaleDst[0], scaleDst[1], scaleDst[2]);
                    }
                    node->setAdditionalTransform(&transform);
                }
                if (!_keyFrameUserInfos.empty()){
                    float prekeyTime = lastTime * getDuration() * _frameRate;
                    float keyTime = t * getDuration() * _frameRate;
                    std::vector<Animate3DDisplayedEventInfo*> eventInfos;
                    for (auto keyFrame : _keyFrameUserInfos)
                    {
                        if ((!_playReverse && keyFrame.first >= prekeyTime && keyFrame.first < keyTime)
                            || (_playReverse && keyFrame.first >= keyTime && keyFrame.first < prekeyTime))
                            {
                                auto& frameEvent = _keyFrameEvent[keyFrame.first];
                                if (frameEvent == nullptr)
                                    frameEvent = new (std::nothrow) EventCustom(Animate3DDisplayedNotification);
                                auto eventInfo = &_displayedEventInfo[keyFrame.first];
                                eventInfo->target = _target;
                                eventInfo->frame = keyFrame.first;
                                eventInfo->userInfo = &_keyFrameUserInfos[keyFrame.first];
                                eventInfos.push_back(eventInfo);
                                frameEvent->setUserData((void*)eventInfo);
                            }
                    }
                    std::sort(eventInfos.begin(), eventInfos.end(), _playReverse ? cmpEventInfoDes : cmpEventInfoAsc);
                    for (auto eventInfo : eventInfos) {
                        Director::getInstance()->getEventDispatcher()->dispatchEvent(_keyFrameEvent[eventInfo->frame]);
                    }
                }
            }
        }
    }
}
Beispiel #4
0
void Node::setAdditionalTransform(const AffineTransform& additionalTransform)
{
    Matrix tmp;
    CGAffineToGL(additionalTransform, tmp.m);
    setAdditionalTransform(&tmp);
}
void Animate3D::update(float t)
{
    if (_target)
    {
        if (_state == Animate3D::Animate3DState::FadeIn && _lastTime > 0.f)
        {
            _accTransTime += (t - _lastTime) * getDuration();
            
            _weight = _accTransTime / _transTime;
            if (_weight >= 1.0f)
            {
                _accTransTime = _transTime;
                _weight = 1.0f;
                _state = Animate3D::Animate3DState::Running;
                s_fadeInAnimates.erase(_target);
                s_runningAnimates[_target] = this;
            }
        }
        else if (_state == Animate3D::Animate3DState::FadeOut && _lastTime > 0.f)
        {
            _accTransTime += (t - _lastTime) * getDuration();
            
            _weight = 1 - _accTransTime / _transTime;
            if (_weight <= 0.0f)
            {
                _accTransTime = _transTime;
                _weight = 0.0f;
                
                s_fadeOutAnimates.erase(_target);
            }
        }
        _lastTime = t;
        
        if (_weight > 0.0f)
        {
            float transDst[3], rotDst[4], scaleDst[3];
            float* trans = nullptr, *rot = nullptr, *scale = nullptr;
            if (_playReverse)
                t = 1 - t;
            
            t = _start + t * _last;
 
            for (const auto& it : _boneCurves) {
                auto bone = it.first;
                auto curve = it.second;
                if (curve->translateCurve)
                {
                    curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
                    trans = &transDst[0];
                }
                if (curve->rotCurve)
                {
                    curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
                    rot = &rotDst[0];
                }
                if (curve->scaleCurve)
                {
                    curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
                    scale = &scaleDst[0];
                }
                bone->setAnimationValue(trans, rot, scale, this, _weight);
            }
            
            for (const auto& it : _nodeCurves)
            {
                auto node = it.first;
                auto curve = it.second;
                Mat4 transform;
                if (curve->translateCurve)
                {
                    curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
                    transform.translate(transDst[0], transDst[1], transDst[2]);
                }
                if (curve->rotCurve)
                {
                    curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
                    Quaternion qua(rotDst[0], rotDst[1], rotDst[2], rotDst[3]);
                    transform.rotate(qua);
                }
                if (curve->scaleCurve)
                {
                    curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
                    transform.scale(scaleDst[0], scaleDst[1], scaleDst[2]);
                }
                node->setAdditionalTransform(&transform);
            }
        }
    }
}