本文整理汇总了C++中AnimatedModel类的典型用法代码示例。如果您正苦于以下问题:C++ AnimatedModel类的具体用法?C++ AnimatedModel怎么用?C++ AnimatedModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AnimatedModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_object
Node* GameApplication::add_object(Node* pParentNode, const String& nodeName,enObjectType type,float x,float y,float z,const char* modelUrl,const char* material)
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
Node* pNode = pParentNode->CreateChild(nodeName);
pNode->SetPosition(Vector3(x, y, z));
if(type == enObjectType_StaticModel)
{
StaticModel* pModel = pNode->CreateComponent<StaticModel>();
pModel->SetModel(cache->GetResource<Model>(modelUrl));
if(material != NULL)
pModel->SetMaterial(0,cache->GetResource<Material>(material));
pModel->SetCastShadows(true);
}
else
{
AnimatedModel* pAniModel = pNode->CreateComponent<AnimatedModel>();
pAniModel->SetModel(cache->GetResource<Model>(modelUrl));
if(material != NULL)
pAniModel->SetMaterial(0,cache->GetResource<Material>(material));
pAniModel->SetCastShadows(true);
}
return pNode;
}
示例2: FindAnimation
bool AnimationController::FadeOthers(const String& name, float targetWeight, float fadeTime)
{
unsigned index;
AnimationState* state;
FindAnimation(name, index, state);
if (index == M_MAX_UNSIGNED || !state)
return false;
AnimatedModel* model = GetComponent<AnimatedModel>();
unsigned char layer = state->GetLayer();
bool needUpdate = false;
for (unsigned i = 0; i < animations_.Size(); ++i)
{
if (i != index)
{
AnimationControl& control = animations_[i];
AnimationState* otherState = model->GetAnimationState(control.hash_);
if (otherState && otherState->GetLayer() == layer)
{
control.targetWeight_ = Clamp(targetWeight, 0.0f, 1.0f);
control.fadeTime_ = fadeTime;
needUpdate = true;
}
}
}
if (needUpdate)
MarkNetworkUpdate();
return true;
}
示例3: Activate
void RagDoll::Activate()
{
//turn the whole thing on
//pawn_->GetNode()->RemoveComponent<RigidBody>();
//pawn_->GetNode()->RemoveComponent<CollisionShape>();
//pawn_->GetNode()->RemoveComponent(pawn_->GetBody());//remove the main components
//pawn_->GetNode()->RemoveComponent(pawn_->GetShape());//remove the main components
//if(node_->HasComponent<RigidBody>())
//{
//GetSubsystem<DebugHud>()->SetAppStats("state:", name_ );
node_->RemoveComponent<RigidBody>();
node_->RemoveComponent<CollisionShape>();
//}
AnimatedModel* model = node_->GetComponent<AnimatedModel>();
Skeleton& skeleton = model->GetSkeleton();
for (unsigned i = 0; i < skeleton.GetNumBones(); ++i)
skeleton.GetBone(i)->animated_ = false;
for (unsigned i = 0; i < boneNode_.Size(); ++i)
{
//URHO3D_LOGINFO(String(i));
RigidBody* rb = boneNode_[i]->GetComponent<RigidBody>();
rb->SetTrigger(false);
rb->SetMass(1.0f);
}
}
示例4: GetAnimationState
const PODVector<unsigned char>& AnimationController::GetNetAnimationsAttr() const
{
attrBuffer_.Clear();
AnimatedModel* model = GetComponent<AnimatedModel>();
unsigned validAnimations = 0;
for (Vector<AnimationControl>::ConstIterator i = animations_.Begin(); i != animations_.End(); ++i)
{
if (GetAnimationState(i->hash_))
++validAnimations;
}
attrBuffer_.WriteVLE(validAnimations);
for (Vector<AnimationControl>::ConstIterator i = animations_.Begin(); i != animations_.End(); ++i)
{
AnimationState* state = GetAnimationState(i->hash_);
if (!state)
continue;
unsigned char ctrl = 0;
Bone* startBone = state->GetStartBone();
if (state->IsLooped())
ctrl |= CTRL_LOOPED;
if (startBone && model && startBone != model->GetSkeleton().GetRootBone())
ctrl |= CTRL_STARTBONE;
if (i->autoFadeTime_ > 0.0f)
ctrl |= CTRL_AUTOFADE;
if (i->removeOnCompletion_)
ctrl |= CTRL_REMOVEONCOMPLETION;
if (i->setTimeTtl_ > 0.0f)
ctrl |= CTRL_SETTIME;
if (i->setWeightTtl_ > 0.0f)
ctrl |= CTRL_SETWEIGHT;
attrBuffer_.WriteString(i->name_);
attrBuffer_.WriteUByte(ctrl);
attrBuffer_.WriteUByte(state->GetLayer());
attrBuffer_.WriteShort((short)Clamp(i->speed_ * 2048.0f, -32767.0f, 32767.0f));
attrBuffer_.WriteUByte((unsigned char)(i->targetWeight_ * 255.0f));
attrBuffer_.WriteUByte((unsigned char)Clamp(i->fadeTime_ * 64.0f, 0.0f, 255.0f));
if (ctrl & CTRL_STARTBONE)
attrBuffer_.WriteStringHash(startBone->nameHash_);
if (ctrl & CTRL_AUTOFADE)
attrBuffer_.WriteUByte((unsigned char)Clamp(i->autoFadeTime_ * 64.0f, 0.0f, 255.0f));
if (ctrl & CTRL_SETTIME)
{
attrBuffer_.WriteUByte(i->setTimeRev_);
attrBuffer_.WriteUShort(i->setTime_);
}
if (ctrl & CTRL_SETWEIGHT)
{
attrBuffer_.WriteUByte(i->setWeightRev_);
attrBuffer_.WriteUByte(i->setWeight_);
}
}
return attrBuffer_.GetBuffer();
}
示例5: FindAnimationState
bool AnimationController::SetStartBone(const String& name, const String& startBoneName)
{
AnimationState* state = FindAnimationState(name);
if (!state)
return false;
AnimatedModel* model = GetComponent<AnimatedModel>();
Bone* bone = model->GetSkeleton().GetBone(startBoneName);
state->SetStartBone(bone);
MarkNetworkUpdate();
return true;
}
示例6: ATOMIC_LOGWARNING
void StaticModel::SetModel(Model* model)
{
if (model == model_)
return;
// If script erroneously calls StaticModel::SetModel on an AnimatedModel, warn and redirect
if (GetType() == AnimatedModel::GetTypeStatic())
{
ATOMIC_LOGWARNING("StaticModel::SetModel() called on AnimatedModel. Redirecting to AnimatedModel::SetModel()");
AnimatedModel* animatedModel = static_cast<AnimatedModel*>(this);
animatedModel->SetModel(model);
return;
}
// Unsubscribe from the reload event of previous model (if any), then subscribe to the new
if (model_)
UnsubscribeFromEvent(model_, E_RELOADFINISHED);
model_ = model;
if (model)
{
SubscribeToEvent(model, E_RELOADFINISHED, ATOMIC_HANDLER(StaticModel, HandleModelReloadFinished));
// Copy the subgeometry & LOD level structure
SetNumGeometries(model->GetNumGeometries());
const Vector<Vector<SharedPtr<Geometry> > >& geometries = model->GetGeometries();
const PODVector<Vector3>& geometryCenters = model->GetGeometryCenters();
const Matrix3x4* worldTransform = node_ ? &node_->GetWorldTransform() : (const Matrix3x4*)0;
for (unsigned i = 0; i < geometries.Size(); ++i)
{
batches_[i].worldTransform_ = worldTransform;
geometries_[i] = geometries[i];
geometryData_[i].center_ = geometryCenters[i];
// ATOMIC BEGIN
geometryData_[i].enabled_ = true;
geometryData_[i].batchGeometry_ = 0;
// ATOMIC END
}
SetBoundingBox(model->GetBoundingBox());
ResetLodLevels();
}
else
{
SetNumGeometries(0);
SetBoundingBox(BoundingBox());
}
MarkNetworkUpdate();
}
示例7: importer
bool ModelImporter::ImportAnimation(const String& filename, const String& name, float startTime, float endTime)
{
SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
//importer->SetVerboseLog(true);
importer->SetScale(scale_);
importer->SetExportAnimations(true);
importer->SetStartTime(startTime);
importer->SetEndTime(endTime);
if (importer->Load(filename))
{
importer->ExportModel(asset_->GetCachePath(), name, true);
const Vector<OpenAssetImporter::AnimationInfo>& infos = importer->GetAnimationInfos();
for (unsigned i = 0; i < infos.Size(); i++)
{
const OpenAssetImporter::AnimationInfo& info = infos.At(i);
String pathName, fileName, extension;
SplitPath(info.cacheFilename_, pathName, fileName, extension);
ResourceCache* cache = GetSubsystem<ResourceCache>();
AnimatedModel* animatedModel = importNode_->GetComponent<AnimatedModel>();
if (animatedModel)
{
Model* model = animatedModel->GetModel();
if (model)
{
SharedPtr<Animation> animation = cache->GetTempResource<Animation>(fileName + extension);
if (animation)
model->AddAnimationResource(animation);
}
}
LOGINFOF("Import Info: %s : %s", info.name_.CString(), fileName.CString());
}
return true;
}
return false;
}
示例8: AddAnimationState
AnimationState* AnimationController::AddAnimationState(Animation* animation)
{
if (!animation)
return 0;
// Model mode
AnimatedModel* model = GetComponent<AnimatedModel>();
if (model)
return model->AddAnimationState(animation);
// Node hierarchy mode
SharedPtr<AnimationState> newState(new AnimationState(node_, animation));
nodeAnimationStates_.Push(newState);
return newState;
}
示例9: Update
void Mover::Update(float timeStep)
{
node_->Translate(Vector3::FORWARD * moveSpeed_ * timeStep);
// If in risk of going outside the plane, rotate the model right
Vector3 pos = node_->GetPosition();
if (pos.x_ < bounds_.min_.x_ || pos.x_ > bounds_.max_.x_ || pos.z_ < bounds_.min_.z_ || pos.z_ > bounds_.max_.z_)
node_->Yaw(rotationSpeed_ * timeStep);
// Get the model's first (only) animation state and advance its time. Note the convenience accessor to other components
// in the same scene node
AnimatedModel* model = GetComponent<AnimatedModel>();
if (model->GetNumAnimationStates())
{
AnimationState* state = model->GetAnimationStates()[0];
state->AddTime(timeStep);
}
}
示例10: Quaternion
void CharacterDemo::CreateCharacter()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
Node* objectNode = scene_->CreateChild("Jack");
objectNode->SetPosition(Vector3(0.0f, 1.0f, 0.0f));
// spin node
Node* adjustNode = objectNode->CreateChild("AdjNode");
adjustNode->SetRotation( Quaternion(180, Vector3(0,1,0) ) );
// Create the rendering component + animation controller
AnimatedModel* object = adjustNode->CreateComponent<AnimatedModel>();
object->SetModel(cache->GetResource<Model>("Models/Mutant/Mutant.mdl"));
object->SetMaterial(cache->GetResource<Material>("Models/Mutant/Materials/mutant_M.xml"));
object->SetCastShadows(true);
adjustNode->CreateComponent<AnimationController>();
// Set the head bone for manual control
object->GetSkeleton().GetBone("Mutant:Head")->animated_ = false;
// Create rigidbody, and set non-zero mass so that the body becomes dynamic
RigidBody* body = objectNode->CreateComponent<RigidBody>();
body->SetCollisionLayer(1);
body->SetMass(1.0f);
// Set zero angular factor so that physics doesn't turn the character on its own.
// Instead we will control the character yaw manually
body->SetAngularFactor(Vector3::ZERO);
// Set the rigidbody to signal collision also when in rest, so that we get ground collisions properly
body->SetCollisionEventMode(COLLISION_ALWAYS);
// Set a capsule shape for collision
CollisionShape* shape = objectNode->CreateComponent<CollisionShape>();
shape->SetCapsule(0.7f, 1.8f, Vector3(0.0f, 0.9f, 0.0f));
// Create the character logic component, which takes care of steering the rigidbody
// Remember it so that we can set the controls. Use a WeakPtr because the scene hierarchy already owns it
// and keeps it alive as long as it's not removed from the hierarchy
character_ = objectNode->CreateComponent<Character>();
}
示例11: StopLayer
void AnimationController::StopLayer(unsigned char layer, float fadeOutTime)
{
AnimatedModel* model = GetComponent<AnimatedModel>();
if (!model)
return;
bool needUpdate = false;
for (Vector<AnimationControl>::Iterator i = animations_.Begin(); i != animations_.End(); ++i)
{
AnimationState* state = model->GetAnimationState(i->hash_);
if (state && state->GetLayer() == layer)
{
i->targetWeight_ = 0.0f;
i->fadeTime_ = fadeOutTime;
needUpdate = true;
}
}
if (needUpdate)
MarkNetworkUpdate();
}
示例12: HandleSceneUpdate
void Mover::HandleSceneUpdate(StringHash eventType, VariantMap& eventData)
{
// Get the timestep from the update event
using namespace SceneUpdate;
float timeStep = eventData[P_TIMESTEP].GetFloat();
node_->TranslateRelative(Vector3::FORWARD * moveSpeed_ * timeStep);
// If in risk of going outside the plane, rotate the model right
Vector3 pos = node_->GetPosition();
if (pos.x_ < bounds_.min_.x_ || pos.x_ > bounds_.max_.x_ || pos.z_ < bounds_.min_.z_ || pos.z_ > bounds_.max_.z_)
node_->Yaw(rotationSpeed_ * timeStep);
// Get the model's first (only) animation state and advance its time. Note the convenience accessor to other components
// in the same scene node
AnimatedModel* model = GetComponent<AnimatedModel>();
if (model->GetNumAnimationStates())
{
AnimationState* state = model->GetAnimationStates()[0];
state->AddTime(timeStep);
}
}
示例13: RemoveAnimationState
void AnimationController::RemoveAnimationState(AnimationState* state)
{
if (!state)
return;
// Model mode
AnimatedModel* model = GetComponent<AnimatedModel>();
if (model)
{
model->RemoveAnimationState(state);
return;
}
// Node hierarchy mode
for (Vector<SharedPtr<AnimationState> >::Iterator i = nodeAnimationStates_.Begin(); i != nodeAnimationStates_.End(); ++i)
{
if ((*i) == state)
{
nodeAnimationStates_.Erase(i);
return;
}
}
}
示例14: Play
bool AnimationController::Play(const String& name, unsigned char layer, bool looped, float fadeInTime)
{
AnimatedModel* model = GetComponent<AnimatedModel>();
if (!model)
return false;
// Check if already exists
unsigned index;
AnimationState* state;
FindAnimation(name, index, state);
if (!state)
{
Animation* newAnimation = GetSubsystem<ResourceCache>()->GetResource<Animation>(name);
state = model->AddAnimationState(newAnimation);
if (!state)
return false;
}
if (index == M_MAX_UNSIGNED)
{
AnimationControl newControl;
Animation* animation = state->GetAnimation();
newControl.hash_ = animation->GetNameHash();
animations_.Push(newControl);
index = animations_.Size() - 1;
}
state->SetLayer(layer);
state->SetLooped(looped);
animations_[index].targetWeight_ = 1.0f;
animations_[index].fadeTime_ = fadeInTime;
MarkNetworkUpdate();
return true;
}
示例15: Node
bool ModelImporter::Import()
{
String ext = asset_->GetExtension();
String modelAssetFilename = asset_->GetPath();
importNode_ = new Node(context_);
if (ext == ".mdl")
{
FileSystem* fs = GetSubsystem<FileSystem>();
ResourceCache* cache = GetSubsystem<ResourceCache>();
// mdl files are native file format that doesn't need to be converted
// doesn't allow scale, animations legacy primarily for ToonTown
if (!fs->Copy(asset_->GetPath(), asset_->GetCachePath() + ".mdl"))
{
importNode_= 0;
return false;
}
Model* mdl = cache->GetResource<Model>( asset_->GetCachePath() + ".mdl");
if (!mdl)
{
importNode_= 0;
return false;
}
// Force a reload, though file watchers will catch this delayed and load again
cache->ReloadResource(mdl);
importNode_->CreateComponent<StaticModel>()->SetModel(mdl);
}
else
{
// skip external animations, they will be brought in when importing their
// corresponding model
if (!modelAssetFilename.Contains("@"))
{
ImportModel();
if (importAnimations_)
{
ImportAnimations();
}
AnimatedModel* animatedModel = importNode_->GetComponent<AnimatedModel>();
if (animatedModel)
{
Model* model = animatedModel->GetModel();
if (model && model->GetAnimationCount())
{
// resave with animation info
File mdlFile(context_);
if (!mdlFile.Open(asset_->GetCachePath() + ".mdl", FILE_WRITE))
{
ErrorExit("Could not open output file " + asset_->GetCachePath() + ".mdl");
return false;
}
model->Save(mdlFile);
}
}
}
}
File outFile(context_);
if (!outFile.Open(asset_->GetCachePath(), FILE_WRITE))
ErrorExit("Could not open output file " + asset_->GetCachePath());
importNode_->SaveXML(outFile);
importNode_ = 0;
return true;
}