Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/collada/PSAConvert.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | if (converter.GetInstance().GetType() == FCDEntityInstance::CONTROLLER) | ||||
// To catch broken animations / skeletons.xml: | // To catch broken animations / skeletons.xml: | ||||
REQUIRE(timeEnd > timeStart, "animation end frame must come after start frame"); | REQUIRE(timeEnd > timeStart, "animation end frame must come after start frame"); | ||||
// Count frames; don't include the last keyframe | // Count frames; don't include the last keyframe | ||||
size_t frameCount = (size_t)((timeEnd - timeStart) / frameLength - 0.5f); | size_t frameCount = (size_t)((timeEnd - timeStart) / frameLength - 0.5f); | ||||
REQUIRE(frameCount > 0, "animation must have frames"); | REQUIRE(frameCount > 0, "animation must have frames"); | ||||
// (TODO: sort out the timing/looping problems) | // (TODO: sort out the timing/looping problems) | ||||
size_t boneCount = skeleton.GetBoneCount(); | const size_t boneCount = skeleton.GetBoneCount(); | ||||
if (boneCount > 64) | |||||
Log(LOG_ERROR, "Skeleton has too many bones %zu/64", boneCount); | |||||
std::vector<BoneTransform> boneTransforms; | std::vector<BoneTransform> boneTransforms; | ||||
for (size_t frame = 0; frame < frameCount; ++frame) | for (size_t frame = 0; frame < frameCount; ++frame) | ||||
{ | { | ||||
float time = timeStart + frameLength * frame; | float time = timeStart + frameLength * frame; | ||||
BoneTransform boneDefault = { { 0, 0, 0 }, { 0, 0, 0, 1 } }; | BoneTransform boneDefault = { { 0, 0, 0 }, { 0, 0, 0, 1 } }; | ||||
std::vector<BoneTransform> frameBoneTransforms (boneCount, boneDefault); | std::vector<BoneTransform> frameBoneTransforms(boneCount, boneDefault); | ||||
// Move the model into the new animated pose | // Move the model into the new animated pose | ||||
// (We can't tell exactly which nodes should be animated, so | // (We can't tell exactly which nodes should be animated, so | ||||
// just update the entire world recursively) | // just update the entire world recursively) | ||||
EvaluateAnimations(converter.GetRoot(), time); | EvaluateAnimations(converter.GetRoot(), time); | ||||
// Convert the pose into the form require by the game | // Convert the pose into the form require by the game | ||||
for (size_t i = 0; i < controllerInstance.GetJointCount(); ++i) | for (size_t i = 0; i < controllerInstance.GetJointCount(); ++i) | ||||
▲ Show 20 Lines • Show All 213 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator