mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 11:50:39 +02:00
Merge pull request #2117 from ey6es/master
Preserve joint states when switching between LODs. Closes #2077.
This commit is contained in:
commit
af550b8ae0
3 changed files with 28 additions and 7 deletions
|
@ -1249,7 +1249,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
joint.boneRadius = 0.0f;
|
joint.boneRadius = 0.0f;
|
||||||
joint.inverseBindRotation = joint.inverseDefaultRotation;
|
joint.inverseBindRotation = joint.inverseDefaultRotation;
|
||||||
geometry.joints.append(joint);
|
geometry.joints.append(joint);
|
||||||
geometry.jointIndices.insert(model.name, geometry.joints.size() - 1);
|
geometry.jointIndices.insert(model.name, geometry.joints.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// find our special joints
|
// find our special joints
|
||||||
|
|
|
@ -46,6 +46,17 @@ void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locati
|
||||||
program.release();
|
program.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<Model::JointState> Model::createJointStates(const FBXGeometry& geometry) {
|
||||||
|
QVector<JointState> jointStates;
|
||||||
|
foreach (const FBXJoint& joint, geometry.joints) {
|
||||||
|
JointState state;
|
||||||
|
state.translation = joint.translation;
|
||||||
|
state.rotation = joint.rotation;
|
||||||
|
jointStates.append(state);
|
||||||
|
}
|
||||||
|
return jointStates;
|
||||||
|
}
|
||||||
|
|
||||||
bool Model::isLoadedWithTextures() const {
|
bool Model::isLoadedWithTextures() const {
|
||||||
if (!isActive()) {
|
if (!isActive()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -106,9 +117,23 @@ void Model::reset() {
|
||||||
|
|
||||||
void Model::simulate(float deltaTime) {
|
void Model::simulate(float deltaTime) {
|
||||||
// update our LOD
|
// update our LOD
|
||||||
|
QVector<JointState> newJointStates;
|
||||||
if (_geometry) {
|
if (_geometry) {
|
||||||
QSharedPointer<NetworkGeometry> geometry = _geometry->getLODOrFallback(_lodDistance, _lodHysteresis);
|
QSharedPointer<NetworkGeometry> geometry = _geometry->getLODOrFallback(_lodDistance, _lodHysteresis);
|
||||||
if (_geometry != geometry) {
|
if (_geometry != geometry) {
|
||||||
|
if (!_jointStates.isEmpty()) {
|
||||||
|
// copy the existing joint states
|
||||||
|
const FBXGeometry& oldGeometry = _geometry->getFBXGeometry();
|
||||||
|
const FBXGeometry& newGeometry = geometry->getFBXGeometry();
|
||||||
|
newJointStates = createJointStates(newGeometry);
|
||||||
|
for (QHash<QString, int>::const_iterator it = oldGeometry.jointIndices.constBegin();
|
||||||
|
it != oldGeometry.jointIndices.constEnd(); it++) {
|
||||||
|
int newIndex = newGeometry.jointIndices.value(it.key());
|
||||||
|
if (newIndex != 0) {
|
||||||
|
newJointStates[newIndex - 1] = _jointStates.at(it.value() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
deleteGeometry();
|
deleteGeometry();
|
||||||
_dilatedTextures.clear();
|
_dilatedTextures.clear();
|
||||||
_geometry = geometry;
|
_geometry = geometry;
|
||||||
|
@ -121,12 +146,7 @@ void Model::simulate(float deltaTime) {
|
||||||
// set up world vertices on first simulate after load
|
// set up world vertices on first simulate after load
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||||
if (_jointStates.isEmpty()) {
|
if (_jointStates.isEmpty()) {
|
||||||
foreach (const FBXJoint& joint, geometry.joints) {
|
_jointStates = newJointStates.isEmpty() ? createJointStates(geometry) : newJointStates;
|
||||||
JointState state;
|
|
||||||
state.translation = joint.translation;
|
|
||||||
state.rotation = joint.rotation;
|
|
||||||
_jointStates.append(state);
|
|
||||||
}
|
|
||||||
foreach (const FBXMesh& mesh, geometry.meshes) {
|
foreach (const FBXMesh& mesh, geometry.meshes) {
|
||||||
MeshState state;
|
MeshState state;
|
||||||
state.clusterMatrices.resize(mesh.clusters.size());
|
state.clusterMatrices.resize(mesh.clusters.size());
|
||||||
|
|
|
@ -269,6 +269,7 @@ private:
|
||||||
static SkinLocations _skinNormalMapLocations;
|
static SkinLocations _skinNormalMapLocations;
|
||||||
|
|
||||||
static void initSkinProgram(ProgramObject& program, SkinLocations& locations);
|
static void initSkinProgram(ProgramObject& program, SkinLocations& locations);
|
||||||
|
static QVector<JointState> createJointStates(const FBXGeometry& geometry);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__Model__) */
|
#endif /* defined(__interface__Model__) */
|
||||||
|
|
Loading…
Reference in a new issue