void Model::onBeforeReady() { static const int transparent_layer = m_renderer.getLayer("transparent"); for (Mesh& mesh : m_meshes) { mesh.layer_mask = mesh.material->getRenderLayerMask(); if (mesh.material->getRenderLayer() == transparent_layer) { mesh.type = Mesh::RIGID; } else if (mesh.material->getLayersCount() > 0) { if (getBoneCount() > 0) { mesh.type = Mesh::MULTILAYER_SKINNED; } else { mesh.type = Mesh::MULTILAYER_RIGID; } } else if (getBoneCount() > 0) { mesh.type = mesh.skin.empty() ? Mesh::RIGID_INSTANCED : Mesh::SKINNED; } else mesh.type = Mesh::RIGID_INSTANCED; } }
void Model::getPose(Pose& pose) { ASSERT(pose.count == getBoneCount()); Vec3* pos = pose.positions; Quat* rot = pose.rotations; for (int i = 0, c = getBoneCount(); i < c; ++i) { pos[i] = m_bones[i].transform.pos; rot[i] = m_bones[i].transform.rot; } pose.is_absolute = true; }
void Model::getPose(Pose& pose) { ASSERT(pose.getCount() == getBoneCount()); Vec3* pos = pose.getPositions(); Quat* rot = pose.getRotations(); Matrix mtx; for (int i = 0, c = getBoneCount(); i < c; ++i) { mtx = m_bones[i].inv_bind_matrix; mtx.fastInverse(); mtx.getTranslation(pos[i]); mtx.getRotation(rot[i]); } }
//! called before the action start. It will also set the target. void Animate3D::startWithTarget(Node *target) { Sprite3D* sprite = dynamic_cast<Sprite3D*>(target); CCASSERT(sprite && sprite->getSkeleton() && _animation, "Animate3D apply to Sprite3D only"); ActionInterval::startWithTarget(target); _boneCurves.clear(); auto skin = sprite->getSkeleton(); bool hasCurve = false; for (int i = 0; i < skin->getBoneCount(); i++) { auto bone = skin->getBoneByIndex(static_cast<unsigned int>(i)); auto curve = _animation->getBoneCurveByName(bone->getName()); if (curve) { _boneCurves[bone] = curve; hasCurve = true; } } if (!hasCurve) { CCLOG("warning: no animation finde for the skeleton"); } auto runningAction = s_runningAnimates.find(sprite); if (runningAction != s_runningAnimates.end()) { //make the running action fade out auto action = (*runningAction).second; if (action != this) { if (_transTime < 0.001f) { s_runningAnimates[sprite] = this; _state = Animate3D::Animate3DState::Running; _weight = 1.0f; } else { s_fadeOutAnimates[sprite] = action; action->_state = Animate3D::Animate3DState::FadeOut; action->_accTransTime = 0.0f; action->_weight = 1.0f; action->_lastTime = 0.f; s_fadeInAnimates[sprite] = this; _accTransTime = 0.0f; _state = Animate3D::Animate3DState::FadeIn; _weight = 0.f; _lastTime = 0.f; } } } else { s_runningAnimates[sprite] = this; _state = Animate3D::Animate3DState::Running; _weight = 1.0f; } }