mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 19:36:45 +02:00
splitting AnimNode implementation into two files
This commit is contained in:
parent
e6776ef5eb
commit
3869887610
2 changed files with 61 additions and 41 deletions
54
libraries/animation/src/AnimNode.cpp
Normal file
54
libraries/animation/src/AnimNode.cpp
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
//
|
||||||
|
// AnimNode.cpp
|
||||||
|
//
|
||||||
|
// Created by Anthony J. Thibault on 9/2/15.
|
||||||
|
// Copyright (c) 2015 High Fidelity, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "AnimNode.h"
|
||||||
|
|
||||||
|
void AnimNode::removeChild(AnimNode::Pointer child) {
|
||||||
|
auto iter = std::find(_children.begin(), _children.end(), child);
|
||||||
|
if (iter != _children.end()) {
|
||||||
|
_children.erase(iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimNode::Pointer AnimNode::getChild(int i) const {
|
||||||
|
assert(i >= 0 && i < (int)_children.size());
|
||||||
|
return _children[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimNode::setSkeleton(const AnimSkeleton::Pointer skeleton) {
|
||||||
|
setSkeletonInternal(skeleton);
|
||||||
|
for (auto&& child : _children) {
|
||||||
|
child->setSkeleton(skeleton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const AnimPose AnimNode::getRootPose(int jointIndex) const {
|
||||||
|
AnimPose pose = AnimPose::identity;
|
||||||
|
if (_skeleton && jointIndex != -1) {
|
||||||
|
const AnimPoseVec& poses = getPosesInternal();
|
||||||
|
int numJoints = (int)(poses.size());
|
||||||
|
if (jointIndex < numJoints) {
|
||||||
|
int parentIndex = _skeleton->getParentIndex(jointIndex);
|
||||||
|
while (parentIndex != -1 && parentIndex < numJoints) {
|
||||||
|
jointIndex = parentIndex;
|
||||||
|
parentIndex = _skeleton->getParentIndex(jointIndex);
|
||||||
|
}
|
||||||
|
pose = poses[jointIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pose;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimNode::setCurrentFrame(float frame) {
|
||||||
|
setCurrentFrameInternal(frame);
|
||||||
|
for (auto&& child : _children) {
|
||||||
|
child->setCurrentFrameInternal(frame);
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,25 +60,13 @@ public:
|
||||||
|
|
||||||
// hierarchy accessors
|
// hierarchy accessors
|
||||||
void addChild(Pointer child) { _children.push_back(child); }
|
void addChild(Pointer child) { _children.push_back(child); }
|
||||||
void removeChild(Pointer child) {
|
void removeChild(Pointer child);
|
||||||
auto iter = std::find(_children.begin(), _children.end(), child);
|
|
||||||
if (iter != _children.end()) {
|
Pointer getChild(int i) const;
|
||||||
_children.erase(iter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Pointer getChild(int i) const {
|
|
||||||
assert(i >= 0 && i < (int)_children.size());
|
|
||||||
return _children[i];
|
|
||||||
}
|
|
||||||
int getChildCount() const { return (int)_children.size(); }
|
int getChildCount() const { return (int)_children.size(); }
|
||||||
|
|
||||||
// pair this AnimNode graph with a skeleton.
|
// pair this AnimNode graph with a skeleton.
|
||||||
void setSkeleton(const AnimSkeleton::Pointer skeleton) {
|
void setSkeleton(const AnimSkeleton::Pointer skeleton);
|
||||||
setSkeletonInternal(skeleton);
|
|
||||||
for (auto&& child : _children) {
|
|
||||||
child->setSkeleton(skeleton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimSkeleton::ConstPointer getSkeleton() const { return _skeleton; }
|
AnimSkeleton::ConstPointer getSkeleton() const { return _skeleton; }
|
||||||
|
|
||||||
|
@ -87,36 +75,14 @@ public:
|
||||||
return evaluate(animVars, dt, triggersOut);
|
return evaluate(animVars, dt, triggersOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
const AnimPose getRootPose(int jointIndex) const {
|
const AnimPose getRootPose(int jointIndex) const;
|
||||||
AnimPose pose = AnimPose::identity;
|
|
||||||
if (_skeleton && jointIndex != -1) {
|
|
||||||
const AnimPoseVec& poses = getPosesInternal();
|
|
||||||
int numJoints = (int)(poses.size());
|
|
||||||
if (jointIndex < numJoints) {
|
|
||||||
int parentIndex = _skeleton->getParentIndex(jointIndex);
|
|
||||||
while (parentIndex != -1 && parentIndex < numJoints) {
|
|
||||||
jointIndex = parentIndex;
|
|
||||||
parentIndex = _skeleton->getParentIndex(jointIndex);
|
|
||||||
}
|
|
||||||
pose = poses[jointIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pose;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void setCurrentFrame(float frame) {
|
void setCurrentFrame(float frame);
|
||||||
setCurrentFrameInternal(frame);
|
|
||||||
for (auto&& child : _children) {
|
|
||||||
child->setCurrentFrameInternal(frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setCurrentFrameInternal(float frame) {}
|
virtual void setCurrentFrameInternal(float frame) {}
|
||||||
virtual void setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) {
|
virtual void setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) { _skeleton = skeleton; }
|
||||||
_skeleton = skeleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for AnimDebugDraw rendering
|
// for AnimDebugDraw rendering
|
||||||
virtual const AnimPoseVec& getPosesInternal() const = 0;
|
virtual const AnimPoseVec& getPosesInternal() const = 0;
|
||||||
|
|
Loading…
Reference in a new issue