Correct from full FOV to assimp half-fov in camera. Compute from filmWidth and focalLength if FOV not specified.
parent
9c54540a19
commit
aab3c8010c
|
@ -93,6 +93,8 @@ FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBo
|
||||||
mSceneOut(out),
|
mSceneOut(out),
|
||||||
doc(doc),
|
doc(doc),
|
||||||
mRemoveEmptyBones(removeEmptyBones) {
|
mRemoveEmptyBones(removeEmptyBones) {
|
||||||
|
|
||||||
|
|
||||||
// animations need to be converted first since this will
|
// animations need to be converted first since this will
|
||||||
// populate the node_anim_chain_bits map, which is needed
|
// populate the node_anim_chain_bits map, which is needed
|
||||||
// to determine which nodes need to be generated.
|
// to determine which nodes need to be generated.
|
||||||
|
@ -427,12 +429,26 @@ void FBXConverter::ConvertCamera(const Camera &cam, const std::string &orig_name
|
||||||
out_camera->mLookAt = aiVector3D(1.0f, 0.0f, 0.0f);
|
out_camera->mLookAt = aiVector3D(1.0f, 0.0f, 0.0f);
|
||||||
out_camera->mUp = aiVector3D(0.0f, 1.0f, 0.0f);
|
out_camera->mUp = aiVector3D(0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
out_camera->mHorizontalFOV = AI_DEG_TO_RAD(cam.FieldOfView());
|
// NOTE: Some software (maya) does not put FieldOfView in FBX, so we compute
|
||||||
|
// mHorizontalFOV from FocalLength and FilmWidth with unit conversion.
|
||||||
|
|
||||||
out_camera->mClipPlaneNear = cam.NearPlane();
|
// TODO: This is not a complete solution for how FBX cameras can be stored.
|
||||||
out_camera->mClipPlaneFar = cam.FarPlane();
|
// TODO: Incorporate non-square pixel aspect ratio.
|
||||||
|
// TODO: FBX aperture mode might be storing vertical FOV in need of conversion with aspect ratio.
|
||||||
|
|
||||||
|
float fov_deg = cam.FieldOfView();
|
||||||
|
// If FOV not specified in file, compute using FilmWidth and FocalLength.
|
||||||
|
if (fov_deg == FBX_FOV_UNKNOWN) {
|
||||||
|
float film_width_inches = cam.FilmWidth();
|
||||||
|
float focal_length_mm = cam.FocalLength();
|
||||||
|
ASSIMP_LOG_VERBOSE_DEBUG("FBX FOV unspecified. Computing from FilmWidth (", film_width_inches, "inches) and FocalLength (", focal_length_mm, "mm).");
|
||||||
|
double half_fov_rad = std::atan2(film_width_inches * 25.4 * 0.5, focal_length_mm);
|
||||||
|
out_camera->mHorizontalFOV = half_fov_rad;
|
||||||
|
} else {
|
||||||
|
// FBX fov is full-view degrees. We want half-view radians.
|
||||||
|
out_camera->mHorizontalFOV = AI_DEG_TO_RAD(fov_deg) * 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
out_camera->mHorizontalFOV = AI_DEG_TO_RAD(cam.FieldOfView());
|
|
||||||
out_camera->mClipPlaneNear = cam.NearPlane();
|
out_camera->mClipPlaneNear = cam.NearPlane();
|
||||||
out_camera->mClipPlaneFar = cam.FarPlane();
|
out_camera->mClipPlaneFar = cam.FarPlane();
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define _AI_CONCAT(a,b) a ## b
|
#define _AI_CONCAT(a,b) a ## b
|
||||||
#define AI_CONCAT(a,b) _AI_CONCAT(a,b)
|
#define AI_CONCAT(a,b) _AI_CONCAT(a,b)
|
||||||
|
|
||||||
|
/* Use an 'illegal' default FOV value to detect if the FBX camera has set the FOV. */
|
||||||
|
#define FBX_FOV_UNKNOWN -1.0f
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace FBX {
|
namespace FBX {
|
||||||
|
|
||||||
|
|
||||||
class Parser;
|
class Parser;
|
||||||
class Object;
|
class Object;
|
||||||
struct ImportSettings;
|
struct ImportSettings;
|
||||||
|
@ -247,7 +251,7 @@ public:
|
||||||
fbx_simple_property(FilmAspectRatio, float, 1.0f)
|
fbx_simple_property(FilmAspectRatio, float, 1.0f)
|
||||||
fbx_simple_property(ApertureMode, int, 0)
|
fbx_simple_property(ApertureMode, int, 0)
|
||||||
|
|
||||||
fbx_simple_property(FieldOfView, float, 1.0f)
|
fbx_simple_property(FieldOfView, float, FBX_FOV_UNKNOWN)
|
||||||
fbx_simple_property(FocalLength, float, 1.0f)
|
fbx_simple_property(FocalLength, float, 1.0f)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue