back out some changes to Model.cpp, change how rig pointer is delivered to model initilizer

This commit is contained in:
Seth Alves 2015-07-22 13:41:31 -07:00
parent fecdc08720
commit 7c8d52cbd1
12 changed files with 228 additions and 358 deletions

View file

@ -75,9 +75,9 @@ namespace render {
} }
} }
Avatar::Avatar() : Avatar::Avatar(RigPointer rig) :
AvatarData(), AvatarData(),
_skeletonModel(this), _skeletonModel(this, nullptr, rig),
_skeletonOffset(0.0f), _skeletonOffset(0.0f),
_bodyYawDelta(0.0f), _bodyYawDelta(0.0f),
_positionDeltaAccumulator(0.0f), _positionDeltaAccumulator(0.0f),

View file

@ -72,7 +72,7 @@ class Avatar : public AvatarData {
Q_PROPERTY(glm::vec3 skeletonOffset READ getSkeletonOffset WRITE setSkeletonOffset) Q_PROPERTY(glm::vec3 skeletonOffset READ getSkeletonOffset WRITE setSkeletonOffset)
public: public:
Avatar(); Avatar(RigPointer rig = nullptr);
~Avatar(); ~Avatar();
typedef render::Payload<AvatarData> Payload; typedef render::Payload<AvatarData> Payload;

View file

@ -65,7 +65,7 @@ AvatarManager::AvatarManager(QObject* parent) :
{ {
// register a meta type for the weak pointer we'll use for the owning avatar mixer for each avatar // register a meta type for the weak pointer we'll use for the owning avatar mixer for each avatar
qRegisterMetaType<QWeakPointer<Node> >("NodeWeakPointer"); qRegisterMetaType<QWeakPointer<Node> >("NodeWeakPointer");
_myAvatar = std::make_shared<MyAvatar>(); _myAvatar = std::make_shared<MyAvatar>(std::make_shared<Rig>());
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver(); auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
packetReceiver.registerListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket"); packetReceiver.registerListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket");
@ -160,7 +160,7 @@ void AvatarManager::simulateAvatarFades(float deltaTime) {
} }
AvatarSharedPointer AvatarManager::newSharedAvatar() { AvatarSharedPointer AvatarManager::newSharedAvatar() {
return AvatarSharedPointer(std::make_shared<Avatar>()); return AvatarSharedPointer(std::make_shared<Avatar>(std::make_shared<Rig>()));
} }
// virtual // virtual

View file

@ -78,8 +78,8 @@ const float MyAvatar::ZOOM_MIN = 0.5f;
const float MyAvatar::ZOOM_MAX = 25.0f; const float MyAvatar::ZOOM_MAX = 25.0f;
const float MyAvatar::ZOOM_DEFAULT = 1.5f; const float MyAvatar::ZOOM_DEFAULT = 1.5f;
MyAvatar::MyAvatar() : MyAvatar::MyAvatar(RigPointer rig) :
Avatar(), Avatar(rig),
_gravity(0.0f, 0.0f, 0.0f), _gravity(0.0f, 0.0f, 0.0f),
_wasPushing(false), _wasPushing(false),
_isPushing(false), _isPushing(false),
@ -102,8 +102,8 @@ MyAvatar::MyAvatar() :
_eyeContactTarget(LEFT_EYE), _eyeContactTarget(LEFT_EYE),
_realWorldFieldOfView("realWorldFieldOfView", _realWorldFieldOfView("realWorldFieldOfView",
DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES), DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES),
_rig(new Rig()), _rig(rig),
_firstPersonSkeletonModel(this, nullptr, _rig), _firstPersonSkeletonModel(this, nullptr, rig),
_prevShouldDrawHead(true) _prevShouldDrawHead(true)
{ {
_firstPersonSkeletonModel.setIsFirstPerson(true); _firstPersonSkeletonModel.setIsFirstPerson(true);

View file

@ -36,7 +36,7 @@ class MyAvatar : public Avatar {
//TODO: make gravity feature work Q_PROPERTY(glm::vec3 gravity READ getGravity WRITE setGravity) //TODO: make gravity feature work Q_PROPERTY(glm::vec3 gravity READ getGravity WRITE setGravity)
public: public:
MyAvatar(); MyAvatar(RigPointer rig);
~MyAvatar(); ~MyAvatar();
QByteArray toByteArray(); QByteArray toByteArray();

View file

@ -42,6 +42,7 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer r
_headClipDistance(DEFAULT_NEAR_CLIP), _headClipDistance(DEFAULT_NEAR_CLIP),
_isFirstPerson(false) _isFirstPerson(false)
{ {
assert(_rig);
assert(_owningAvatar); assert(_owningAvatar);
_enableShapes = true; _enableShapes = true;
} }
@ -269,7 +270,6 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) {
} }
} }
void SkeletonModel::updateJointState(int index) { void SkeletonModel::updateJointState(int index) {
if (index < 0 && index >= _jointStates.size()) { if (index < 0 && index >= _jointStates.size()) {
return; // bail return; // bail
@ -297,7 +297,6 @@ void SkeletonModel::updateJointState(int index) {
} }
} }
void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, JointState& state) { void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, JointState& state) {
if (!_owningAvatar->isMyAvatar()) { if (!_owningAvatar->isMyAvatar()) {
return; return;

View file

@ -184,17 +184,28 @@ void Rig::resetAllTransformsChanged() {
} }
} }
glm::quat Rig::setJointRotationInBindFrame(int jointIndex, const glm::quat& rotation, float priority) { glm::quat Rig::setJointRotationInBindFrame(int jointIndex, const glm::quat& rotation, float priority, bool constrain) {
glm::quat endRotation; glm::quat endRotation;
if (jointIndex == -1 || _jointStates.isEmpty()) { if (jointIndex == -1 || _jointStates.isEmpty()) {
return endRotation; return endRotation;
} }
JointState& state = _jointStates[jointIndex]; JointState& state = _jointStates[jointIndex];
state.setRotationInBindFrame(rotation, priority); state.setRotationInBindFrame(rotation, priority, constrain);
endRotation = state.getRotationInBindFrame(); endRotation = state.getRotationInBindFrame();
return endRotation; return endRotation;
} }
glm::quat Rig::setJointRotationInConstrainedFrame(int jointIndex, glm::quat targetRotation, float priority, bool constrain) {
glm::quat endRotation;
if (jointIndex == -1 || _jointStates.isEmpty()) {
return endRotation;
}
JointState& state = _jointStates[jointIndex];
state.setRotationInConstrainedFrame(targetRotation, priority, constrain);
endRotation = state.getRotationInConstrainedFrame();
return endRotation;
}
void Rig::applyJointRotationDelta(int jointIndex, const glm::quat& delta, bool constrain, float priority) { void Rig::applyJointRotationDelta(int jointIndex, const glm::quat& delta, bool constrain, float priority) {
if (jointIndex == -1 || _jointStates.isEmpty()) { if (jointIndex == -1 || _jointStates.isEmpty()) {
return; return;

View file

@ -54,7 +54,9 @@ public:
void clearJointStates(); void clearJointStates();
void setJointState(int index, bool valid, const glm::quat& rotation, float priority); void setJointState(int index, bool valid, const glm::quat& rotation, float priority);
void clearJointAnimationPriority(int index); void clearJointAnimationPriority(int index);
glm::quat setJointRotationInBindFrame(int jointIndex, const glm::quat& rotation, float priority); glm::quat setJointRotationInBindFrame(int jointIndex, const glm::quat& rotation, float priority, bool constrain = false);
glm::quat setJointRotationInConstrainedFrame(int jointIndex, glm::quat targetRotation,
float priority, bool constrain = false);
void applyJointRotationDelta(int jointIndex, const glm::quat& delta, bool constrain, float priority); void applyJointRotationDelta(int jointIndex, const glm::quat& delta, bool constrain, float priority);
QVector<JointState> getJointStates() { return _jointStates; } QVector<JointState> getJointStates() { return _jointStates; }

View file

@ -83,7 +83,6 @@ Model::Model(QObject* parent, RigPointer rig) :
_isWireframe(false), _isWireframe(false),
_renderCollisionHull(false), _renderCollisionHull(false),
_rig(rig) { _rig(rig) {
// we may have been created in the network thread, but we live in the main thread // we may have been created in the network thread, but we live in the main thread
if (_viewState) { if (_viewState) {
moveToThread(_viewState->getMainThread()); moveToThread(_viewState->getMainThread());
@ -114,9 +113,11 @@ void Model::RenderPipelineLib::addRenderPipeline(Model::RenderKey key,
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vertexShader, pixelShader)); gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vertexShader, pixelShader));
gpu::Shader::makeProgram(*program, slotBindings); gpu::Shader::makeProgram(*program, slotBindings);
auto locations = std::make_shared<Locations>(); auto locations = std::make_shared<Locations>();
initLocations(program, *locations); initLocations(program, *locations);
auto state = std::make_shared<gpu::State>(); auto state = std::make_shared<gpu::State>();
// Backface on shadow // Backface on shadow
@ -133,8 +134,7 @@ void Model::RenderPipelineLib::addRenderPipeline(Model::RenderKey key,
// Blend on transparent // Blend on transparent
state->setBlendFunction(key.isTranslucent(), state->setBlendFunction(key.isTranslucent(),
gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, // For transparent only, this keep the highlight intensity
gpu::State::INV_SRC_ALPHA, // For transparent only, this keep the highlight intensity
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
// Good to go add the brand new pipeline // Good to go add the brand new pipeline
@ -145,13 +145,8 @@ void Model::RenderPipelineLib::addRenderPipeline(Model::RenderKey key,
if (!key.isWireFrame()) { if (!key.isWireFrame()) {
RenderKey wireframeKey(key.getRaw() | RenderKey::IS_WIREFRAME); RenderKey wireframeKey(key.getRaw() | RenderKey::IS_WIREFRAME);
<<<<<<< HEAD
gpu::StatePointer wireframeState = gpu::StatePointer(new gpu::State(state->getValues()));
=======
auto wireframeState = std::make_shared<gpu::State>(state->getValues()); auto wireframeState = std::make_shared<gpu::State>(state->getValues());
>>>>>>> cf88bce0820df76a55473370db0fcb8c5fe6763d
wireframeState->setFillMode(gpu::State::FILL_LINE); wireframeState->setFillMode(gpu::State::FILL_LINE);
// create a new RenderPipeline with the same shader side and the mirrorState // create a new RenderPipeline with the same shader side and the mirrorState
@ -173,13 +168,8 @@ void Model::RenderPipelineLib::addRenderPipeline(Model::RenderKey key,
if (!key.isWireFrame()) { if (!key.isWireFrame()) {
RenderKey wireframeKey(key.getRaw() | RenderKey::IS_MIRROR | RenderKey::IS_WIREFRAME); RenderKey wireframeKey(key.getRaw() | RenderKey::IS_MIRROR | RenderKey::IS_WIREFRAME);
<<<<<<< HEAD
gpu::StatePointer wireframeState = gpu::StatePointer(new gpu::State(state->getValues()));;
=======
auto wireframeState = std::make_shared<gpu::State>(state->getValues()); auto wireframeState = std::make_shared<gpu::State>(state->getValues());
>>>>>>> cf88bce0820df76a55473370db0fcb8c5fe6763d
wireframeState->setFillMode(gpu::State::FILL_LINE); wireframeState->setFillMode(gpu::State::FILL_LINE);
// create a new RenderPipeline with the same shader side and the mirrorState // create a new RenderPipeline with the same shader side and the mirrorState
@ -262,9 +252,6 @@ QVector<JointState> Model::createJointStates(const FBXGeometry& geometry) {
}; };
void Model::initJointTransforms() { void Model::initJointTransforms() {
if (_rig) {
_rig->initJointTransforms(_scale, _offset);
} else {
// compute model transforms // compute model transforms
int numStates = _jointStates.size(); int numStates = _jointStates.size();
for (int i = 0; i < numStates; ++i) { for (int i = 0; i < numStates; ++i) {
@ -281,7 +268,6 @@ void Model::initJointTransforms() {
state.initTransform(parentState.getTransform()); state.initTransform(parentState.getTransform());
} }
} }
}
} }
void Model::init() { void Model::init() {
@ -410,9 +396,6 @@ void Model::init() {
} }
void Model::reset() { void Model::reset() {
if (_rig) {
_rig->resetJoints();
} else {
if (_jointStates.isEmpty()) { if (_jointStates.isEmpty()) {
return; return;
} }
@ -420,7 +403,6 @@ void Model::reset() {
for (int i = 0; i < _jointStates.size(); i++) { for (int i = 0; i < _jointStates.size(); i++) {
_jointStates[i].setRotationInConstrainedFrame(geometry.joints.at(i).rotation, 0.0f); _jointStates[i].setRotationInConstrainedFrame(geometry.joints.at(i).rotation, 0.0f);
} }
}
_meshGroupsKnown = false; _meshGroupsKnown = false;
_readyWhenAdded = false; // in case any of our users are using scenes _readyWhenAdded = false; // in case any of our users are using scenes
@ -446,8 +428,6 @@ bool Model::updateGeometry() {
return false; return false;
} }
bool jointStatesEmpty = _rig ? _rig->jointStatesEmpty() : _jointStates.isEmpty();
QSharedPointer<NetworkGeometry> geometry = _geometry->getLODOrFallback(_lodDistance, _lodHysteresis); QSharedPointer<NetworkGeometry> geometry = _geometry->getLODOrFallback(_lodDistance, _lodHysteresis);
if (_geometry != geometry) { if (_geometry != geometry) {
@ -456,7 +436,7 @@ bool Model::updateGeometry() {
const FBXGeometry& newGeometry = geometry->getFBXGeometry(); const FBXGeometry& newGeometry = geometry->getFBXGeometry();
QVector<JointState> newJointStates = createJointStates(newGeometry); QVector<JointState> newJointStates = createJointStates(newGeometry);
if (! jointStatesEmpty) { if (! _jointStates.isEmpty()) {
// copy the existing joint states // copy the existing joint states
const FBXGeometry& oldGeometry = _geometry->getFBXGeometry(); const FBXGeometry& oldGeometry = _geometry->getFBXGeometry();
for (QHash<QString, int>::const_iterator it = oldGeometry.jointIndices.constBegin(); for (QHash<QString, int>::const_iterator it = oldGeometry.jointIndices.constBegin();
@ -464,11 +444,7 @@ bool Model::updateGeometry() {
int oldIndex = it.value() - 1; int oldIndex = it.value() - 1;
int newIndex = newGeometry.getJointIndex(it.key()); int newIndex = newGeometry.getJointIndex(it.key());
if (newIndex != -1) { if (newIndex != -1) {
JointState jointState; newJointStates[newIndex].copyState(_jointStates[oldIndex]);
if (!getJointStateAtIndex(oldIndex, jointState)) {
return false;
}
newJointStates[newIndex].copyState(jointState);
} }
} }
} }
@ -481,7 +457,7 @@ bool Model::updateGeometry() {
invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid
initJointStates(newJointStates); initJointStates(newJointStates);
needToRebuild = true; needToRebuild = true;
} else if (jointStatesEmpty) { } else if (_jointStates.isEmpty()) {
const FBXGeometry& fbxGeometry = geometry->getFBXGeometry(); const FBXGeometry& fbxGeometry = geometry->getFBXGeometry();
if (fbxGeometry.joints.size() > 0) { if (fbxGeometry.joints.size() > 0) {
initJointStates(createJointStates(fbxGeometry)); initJointStates(createJointStates(fbxGeometry));
@ -499,15 +475,9 @@ bool Model::updateGeometry() {
foreach (const FBXMesh& mesh, fbxGeometry.meshes) { foreach (const FBXMesh& mesh, fbxGeometry.meshes) {
MeshState state; MeshState state;
state.clusterMatrices.resize(mesh.clusters.size()); state.clusterMatrices.resize(mesh.clusters.size());
<<<<<<< HEAD
_meshStates.append(state);
gpu::BufferPointer buffer(new gpu::Buffer());
=======
_meshStates.append(state); _meshStates.append(state);
auto buffer = std::make_shared<gpu::Buffer>(); auto buffer = std::make_shared<gpu::Buffer>();
>>>>>>> cf88bce0820df76a55473370db0fcb8c5fe6763d
if (!mesh.blendshapes.isEmpty()) { if (!mesh.blendshapes.isEmpty()) {
buffer->resize((mesh.vertices.size() + mesh.normals.size()) * sizeof(glm::vec3)); buffer->resize((mesh.vertices.size() + mesh.normals.size()) * sizeof(glm::vec3));
buffer->setSubData(0, mesh.vertices.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.vertices.constData()); buffer->setSubData(0, mesh.vertices.size() * sizeof(glm::vec3), (gpu::Byte*) mesh.vertices.constData());
@ -523,9 +493,6 @@ bool Model::updateGeometry() {
// virtual // virtual
void Model::initJointStates(QVector<JointState> states) { void Model::initJointStates(QVector<JointState> states) {
if (_rig) {
_boundingRadius = _rig->initJointStates(_scale, _offset, states);
} else {
_jointStates = states; _jointStates = states;
initJointTransforms(); initJointTransforms();
@ -542,7 +509,6 @@ void Model::initJointStates(QVector<JointState> states) {
_jointStates[i].slaveVisibleTransform(); _jointStates[i].slaveVisibleTransform();
} }
_boundingRadius = radius; _boundingRadius = radius;
}
} }
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance, bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance,
@ -1106,40 +1072,28 @@ glm::vec3 Model::calculateScaledOffsetPoint(const glm::vec3& point) const {
bool Model::getJointState(int index, glm::quat& rotation) const { bool Model::getJointState(int index, glm::quat& rotation) const {
if (_rig) {
return _rig->getJointState(index, rotation);
} else {
if (index == -1 || index >= _jointStates.size()) { if (index == -1 || index >= _jointStates.size()) {
return false; return false;
} }
const JointState& state = _jointStates.at(index); const JointState& state = _jointStates.at(index);
rotation = state.getRotationInConstrainedFrame(); rotation = state.getRotationInConstrainedFrame();
return !state.rotationIsDefault(rotation); return !state.rotationIsDefault(rotation);
}
} }
bool Model::getVisibleJointState(int index, glm::quat& rotation) const { bool Model::getVisibleJointState(int index, glm::quat& rotation) const {
if (_rig) {
return _rig->getVisibleJointState(index, rotation);
} else {
if (index == -1 || index >= _jointStates.size()) { if (index == -1 || index >= _jointStates.size()) {
return false; return false;
} }
const JointState& state = _jointStates.at(index); const JointState& state = _jointStates.at(index);
rotation = state.getVisibleRotationInConstrainedFrame(); rotation = state.getVisibleRotationInConstrainedFrame();
return !state.rotationIsDefault(rotation); return !state.rotationIsDefault(rotation);
}
} }
void Model::clearJointState(int index) { void Model::clearJointState(int index) {
if (_rig) {
_rig->clearJointState(index);
} else {
if (index != -1 && index < _jointStates.size()) { if (index != -1 && index < _jointStates.size()) {
JointState& state = _jointStates[index]; JointState& state = _jointStates[index];
state.setRotationInConstrainedFrame(glm::quat(), 0.0f); state.setRotationInConstrainedFrame(glm::quat(), 0.0f);
} }
}
} }
void Model::clearJointAnimationPriority(int index) { void Model::clearJointAnimationPriority(int index) {
@ -1153,9 +1107,6 @@ void Model::clearJointAnimationPriority(int index) {
} }
void Model::setJointState(int index, bool valid, const glm::quat& rotation, float priority) { void Model::setJointState(int index, bool valid, const glm::quat& rotation, float priority) {
if (_rig) {
_rig->setJointState(index, valid, rotation, priority);
} else {
if (index != -1 && index < _jointStates.size()) { if (index != -1 && index < _jointStates.size()) {
JointState& state = _jointStates[index]; JointState& state = _jointStates[index];
if (valid) { if (valid) {
@ -1164,7 +1115,6 @@ void Model::setJointState(int index, bool valid, const glm::quat& rotation, floa
state.restoreRotation(1.0f, priority); state.restoreRotation(1.0f, priority);
} }
} }
}
} }
int Model::getParentJointIndex(int jointIndex) const { int Model::getParentJointIndex(int jointIndex) const {
@ -1238,82 +1188,62 @@ void Model::setCollisionModelURL(const QUrl& url) {
_collisionGeometry = DependencyManager::get<GeometryCache>()->getGeometry(url, QUrl(), true); _collisionGeometry = DependencyManager::get<GeometryCache>()->getGeometry(url, QUrl(), true);
} }
bool Model::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position) const {
bool Model::getJointStateAtIndex(int jointIndex, JointState& jointState) const {
if (_rig) {
return _rig->getJointStateAtIndex(jointIndex, jointState);
} else {
if (jointIndex == -1 || jointIndex >= _jointStates.size()) { if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
return false; return false;
} }
jointState = _jointStates[jointIndex];
return true;
}
}
bool Model::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position) const {
JointState jointState;
if (!getJointStateAtIndex(jointIndex, jointState)) {
return false;
}
// position is in world-frame // position is in world-frame
position = _translation + _rotation * jointState.getPosition(); position = _translation + _rotation * _jointStates[jointIndex].getPosition();
return true; return true;
} }
bool Model::getJointPosition(int jointIndex, glm::vec3& position) const { bool Model::getJointPosition(int jointIndex, glm::vec3& position) const {
JointState jointState; if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
if (!getJointStateAtIndex(jointIndex, jointState)) {
return false; return false;
} }
// position is in model-frame // position is in model-frame
position = extractTranslation(jointState.getTransform()); position = extractTranslation(_jointStates[jointIndex].getTransform());
return true; return true;
} }
bool Model::getJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) const { bool Model::getJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) const {
JointState jointState; if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
if (!getJointStateAtIndex(jointIndex, jointState)) {
return false; return false;
} }
rotation = _rotation * jointState.getRotation(); rotation = _rotation * _jointStates[jointIndex].getRotation();
return true; return true;
} }
bool Model::getJointRotation(int jointIndex, glm::quat& rotation) const { bool Model::getJointRotation(int jointIndex, glm::quat& rotation) const {
JointState jointState; if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
if (!getJointStateAtIndex(jointIndex, jointState)) {
return false; return false;
} }
rotation = jointState.getRotation(); rotation = _jointStates[jointIndex].getRotation();
return true; return true;
} }
bool Model::getJointCombinedRotation(int jointIndex, glm::quat& rotation) const { bool Model::getJointCombinedRotation(int jointIndex, glm::quat& rotation) const {
JointState jointState; if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
if (!getJointStateAtIndex(jointIndex, jointState)) {
return false; return false;
} }
rotation = _rotation * jointState.getRotation(); rotation = _rotation * _jointStates[jointIndex].getRotation();
return true; return true;
} }
bool Model::getVisibleJointPositionInWorldFrame(int jointIndex, glm::vec3& position) const { bool Model::getVisibleJointPositionInWorldFrame(int jointIndex, glm::vec3& position) const {
JointState jointState; if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
if (!getJointStateAtIndex(jointIndex, jointState)) {
return false; return false;
} }
// position is in world-frame // position is in world-frame
position = _translation + _rotation * jointState.getVisiblePosition(); position = _translation + _rotation * _jointStates[jointIndex].getVisiblePosition();
return true; return true;
} }
bool Model::getVisibleJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) const { bool Model::getVisibleJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) const {
JointState jointState; if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
if (!getJointStateAtIndex(jointIndex, jointState)) {
return false; return false;
} }
rotation = _rotation * jointState.getVisibleRotation(); rotation = _rotation * _jointStates[jointIndex].getVisibleRotation();
return true; return true;
} }
@ -1508,20 +1438,12 @@ void Model::updateClusterMatrices() {
if (_showTrueJointTransforms) { if (_showTrueJointTransforms) {
for (int j = 0; j < mesh.clusters.size(); j++) { for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j); const FBXCluster& cluster = mesh.clusters.at(j);
JointState jointState; state.clusterMatrices[j] = modelToWorld * _jointStates[cluster.jointIndex].getTransform() * cluster.inverseBindMatrix;
if (!getJointStateAtIndex(cluster.jointIndex, jointState)) {
return;
}
state.clusterMatrices[j] = modelToWorld * jointState.getTransform() * cluster.inverseBindMatrix;
} }
} else { } else {
for (int j = 0; j < mesh.clusters.size(); j++) { for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j); const FBXCluster& cluster = mesh.clusters.at(j);
JointState jointState; state.clusterMatrices[j] = modelToWorld * _jointStates[cluster.jointIndex].getVisibleTransform() * cluster.inverseBindMatrix;
if (!getJointStateAtIndex(cluster.jointIndex, jointState)) {
return;
}
state.clusterMatrices[j] = modelToWorld * jointState.getVisibleTransform() * cluster.inverseBindMatrix;
} }
} }
} }
@ -1535,17 +1457,12 @@ void Model::simulateInternal(float deltaTime) {
handle->simulate(deltaTime); handle->simulate(deltaTime);
} }
if (_rig) { for (int i = 0; i < _jointStates.size(); i++) {
const FBXGeometry& geometry = _geometry->getFBXGeometry(); updateJointState(i);
glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset; }
_rig->updateJointStates(parentTransform);
_rig->resetAllTransformsChanged();
} else {
updateJointStates();
for (int i = 0; i < _jointStates.size(); i++) { for (int i = 0; i < _jointStates.size(); i++) {
_jointStates[i].resetTransformChanged(); _jointStates[i].resetTransformChanged();
} }
}
_shapesAreDirty = !_shapes.isEmpty(); _shapesAreDirty = !_shapes.isEmpty();
@ -1557,20 +1474,12 @@ void Model::simulateInternal(float deltaTime) {
if (_showTrueJointTransforms) { if (_showTrueJointTransforms) {
for (int j = 0; j < mesh.clusters.size(); j++) { for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j); const FBXCluster& cluster = mesh.clusters.at(j);
JointState jointState; state.clusterMatrices[j] = modelToWorld * _jointStates[cluster.jointIndex].getTransform() * cluster.inverseBindMatrix;
if (!getJointStateAtIndex(cluster.jointIndex, jointState)) {
return;
}
state.clusterMatrices[j] = modelToWorld * jointState.getTransform() * cluster.inverseBindMatrix;
} }
} else { } else {
for (int j = 0; j < mesh.clusters.size(); j++) { for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j); const FBXCluster& cluster = mesh.clusters.at(j);
JointState jointState; state.clusterMatrices[j] = modelToWorld * _jointStates[cluster.jointIndex].getVisibleTransform() * cluster.inverseBindMatrix;
if (!getJointStateAtIndex(cluster.jointIndex, jointState)) {
return;
}
state.clusterMatrices[j] = modelToWorld * jointState.getVisibleTransform() * cluster.inverseBindMatrix;
} }
} }
} }
@ -1582,15 +1491,7 @@ void Model::simulateInternal(float deltaTime) {
} }
} }
void Model::updateJointStates() {
assert(!_rig);
for (int i = 0; i < _jointStates.size(); i++) {
updateJointState(i);
}
}
void Model::updateJointState(int index) { void Model::updateJointState(int index) {
assert(!_rig);
JointState& state = _jointStates[index]; JointState& state = _jointStates[index];
const FBXJoint& joint = state.getFBXJoint(); const FBXJoint& joint = state.getFBXJoint();
@ -1614,38 +1515,13 @@ void Model::updateVisibleJointStates() {
// no need to update visible transforms // no need to update visible transforms
return; return;
} }
if (_rig) {
_rig->updateVisibleJointStates();
} else {
for (int i = 0; i < _jointStates.size(); i++) { for (int i = 0; i < _jointStates.size(); i++) {
_jointStates[i].slaveVisibleTransform(); _jointStates[i].slaveVisibleTransform();
} }
}
} }
glm::quat Model::setJointRotationInBindFrame(int jointIndex, const glm::quat& rotation, float priority) {
glm::quat endRotation;
if (jointIndex == -1 || _jointStates.isEmpty()) {
return endRotation;
}
JointState& state = _jointStates[jointIndex];
state.setRotationInBindFrame(rotation, priority);
endRotation = state.getRotationInBindFrame();
return endRotation;
}
bool Model::setJointPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation, bool useRotation, bool Model::setJointPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation, bool useRotation,
int lastFreeIndex, bool allIntermediatesFree, const glm::vec3& alignment, float priority) { int lastFreeIndex, bool allIntermediatesFree, const glm::vec3& alignment, float priority) {
if (_rig) {
const FBXGeometry& geometry = _geometry->getFBXGeometry();
glm::mat4 parentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
bool result = _rig->setJointPosition(jointIndex, position, rotation, useRotation, lastFreeIndex, allIntermediatesFree,
alignment, priority, parentTransform);
_shapesAreDirty = !_shapes.isEmpty();
return result;
}
if (jointIndex == -1 || _jointStates.isEmpty()) { if (jointIndex == -1 || _jointStates.isEmpty()) {
return false; return false;
} }
@ -1730,16 +1606,8 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position, const gl
return true; return true;
} }
void Model::inverseKinematics(int endIndex, glm::vec3 targetPosition, void Model::inverseKinematics(int endIndex, glm::vec3 targetPosition, const glm::quat& targetRotation, float priority) {
const glm::quat& targetRotation, float priority) {
// NOTE: targetRotation is from bind- to model-frame // NOTE: targetRotation is from bind- to model-frame
if (_rig) {
const FBXGeometry& geometry = _geometry->getFBXGeometry();
glm::mat4 topParentTransform = glm::scale(_scale) * glm::translate(_offset) * geometry.offset;
_rig->inverseKinematics( endIndex, targetPosition, targetRotation, priority, topParentTransform);
_shapesAreDirty = !_shapes.isEmpty();
return;
}
if (endIndex == -1 || _jointStates.isEmpty()) { if (endIndex == -1 || _jointStates.isEmpty()) {
return; return;
@ -1854,9 +1722,6 @@ void Model::inverseKinematics(int endIndex, glm::vec3 targetPosition,
} }
bool Model::restoreJointPosition(int jointIndex, float fraction, float priority) { bool Model::restoreJointPosition(int jointIndex, float fraction, float priority) {
if (_rig) {
return _rig->restoreJointPosition(jointIndex, fraction, priority);
}
if (jointIndex == -1 || _jointStates.isEmpty()) { if (jointIndex == -1 || _jointStates.isEmpty()) {
return false; return false;
} }
@ -1871,9 +1736,6 @@ bool Model::restoreJointPosition(int jointIndex, float fraction, float priority)
} }
float Model::getLimbLength(int jointIndex) const { float Model::getLimbLength(int jointIndex) const {
if (_rig) {
return _rig->getLimbLength(jointIndex, _scale);
}
if (jointIndex == -1 || _jointStates.isEmpty()) { if (jointIndex == -1 || _jointStates.isEmpty()) {
return 0.0f; return 0.0f;
} }
@ -1955,9 +1817,6 @@ void Model::applyNextGeometry() {
void Model::deleteGeometry() { void Model::deleteGeometry() {
_blendedVertexBuffers.clear(); _blendedVertexBuffers.clear();
_jointStates.clear(); _jointStates.clear();
if (_rig) {
_rig->clearJointStates();
}
_meshStates.clear(); _meshStates.clear();
clearShapes(); clearShapes();

View file

@ -64,7 +64,7 @@ public:
static void setAbstractViewStateInterface(AbstractViewStateInterface* viewState) { _viewState = viewState; } static void setAbstractViewStateInterface(AbstractViewStateInterface* viewState) { _viewState = viewState; }
Model(QObject* parent = NULL, RigPointer rig = nullptr); Model(QObject* parent = nullptr, RigPointer rig = nullptr);
virtual ~Model(); virtual ~Model();
/// enables/disables scale to fit behavior, the model will be automatically scaled to the specified largest dimension /// enables/disables scale to fit behavior, the model will be automatically scaled to the specified largest dimension
@ -206,6 +206,7 @@ public:
QStringList getJointNames() const; QStringList getJointNames() const;
AnimationHandlePointer createAnimationHandle();
const QList<AnimationHandlePointer>& getRunningAnimations() const { return _runningAnimations; } const QList<AnimationHandlePointer>& getRunningAnimations() const { return _runningAnimations; }
@ -259,7 +260,6 @@ protected:
bool _showTrueJointTransforms; bool _showTrueJointTransforms;
bool getJointStateAtIndex(int jointIndex, JointState& jointState) const;
QVector<JointState> _jointStates; QVector<JointState> _jointStates;
class MeshState { class MeshState {
@ -281,13 +281,10 @@ protected:
void simulateInternal(float deltaTime); void simulateInternal(float deltaTime);
/// Updates the state of the joint at the specified index. /// Updates the state of the joint at the specified index.
void updateJointStates();
virtual void updateJointState(int index); virtual void updateJointState(int index);
virtual void updateVisibleJointStates(); virtual void updateVisibleJointStates();
glm::quat setJointRotationInBindFrame(int jointIndex, const glm::quat& rotation, float priority);
/// \param jointIndex index of joint in model structure /// \param jointIndex index of joint in model structure
/// \param position position of joint in model-frame /// \param position position of joint in model-frame
/// \param rotation rotation of joint in model-frame /// \param rotation rotation of joint in model-frame

View file

@ -113,6 +113,8 @@ void vhacd::VHACDUtil::fattenMeshes(const FBXMesh& mesh, FBXMesh& result,
int index1 = triangles[i * 3 + 1] + indexStartOffset; int index1 = triangles[i * 3 + 1] + indexStartOffset;
int index2 = triangles[i * 3 + 2] + indexStartOffset; int index2 = triangles[i * 3 + 2] + indexStartOffset;
// TODO: skip triangles with a normal that points more negative-y than positive-y
glm::vec3 p0 = result.vertices[index0]; glm::vec3 p0 = result.vertices[index0];
glm::vec3 p1 = result.vertices[index1]; glm::vec3 p1 = result.vertices[index1];
glm::vec3 p2 = result.vertices[index2]; glm::vec3 p2 = result.vertices[index2];