COLLADA: Better import and export of cameras.
This commit is contained in:
@@ -1905,15 +1905,15 @@ public:
|
||||
}
|
||||
void operator()(Object *ob, Scene *sce)
|
||||
{
|
||||
// XXX add other params later
|
||||
// TODO: shiftx, shifty, YF_dofdist
|
||||
Camera *cam = (Camera*)ob->data;
|
||||
std::string cam_id(get_camera_id(ob));
|
||||
std::string cam_name(id_name(cam));
|
||||
|
||||
if (cam->type == CAM_PERSP) {
|
||||
COLLADASW::PerspectiveOptic persp(mSW);
|
||||
persp.setXFov(1.0);
|
||||
persp.setAspectRatio(0.1);
|
||||
persp.setXFov(lens_to_angle(cam->lens)*(180.0f/M_PI));
|
||||
persp.setAspectRatio(1.0);
|
||||
persp.setZFar(cam->clipend);
|
||||
persp.setZNear(cam->clipsta);
|
||||
COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
|
||||
@@ -1921,8 +1921,8 @@ public:
|
||||
}
|
||||
else {
|
||||
COLLADASW::OrthographicOptic ortho(mSW);
|
||||
ortho.setXMag(1.0);
|
||||
ortho.setAspectRatio(0.1);
|
||||
ortho.setXMag(cam->ortho_scale);
|
||||
ortho.setAspectRatio(1.0);
|
||||
ortho.setZFar(cam->clipend);
|
||||
ortho.setZNear(cam->clipsta);
|
||||
COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
|
||||
|
||||
@@ -3526,11 +3526,12 @@ public:
|
||||
// XXX empty node may not mean it is empty object, not sure about this
|
||||
else {
|
||||
ob = add_object(sce, OB_EMPTY);
|
||||
rename_id(&ob->id, (char*)node->getOriginalId().c_str());
|
||||
}
|
||||
|
||||
// check if object is not NULL
|
||||
if (!ob) return;
|
||||
|
||||
rename_id(&ob->id, (char*)node->getOriginalId().c_str());
|
||||
|
||||
object_map[node->getUniqueId()] = ob;
|
||||
node_map[node->getUniqueId()] = node;
|
||||
@@ -3836,6 +3837,75 @@ public:
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch(camera->getDescriptionType()) {
|
||||
case COLLADAFW::Camera::ASPECTRATIO_AND_Y:
|
||||
{
|
||||
switch(cam->type) {
|
||||
case CAM_ORTHO:
|
||||
{
|
||||
double ymag = camera->getYMag().getValue();
|
||||
double aspect = camera->getAspectRatio().getValue();
|
||||
double xmag = aspect*ymag;
|
||||
cam->ortho_scale = (float)xmag;
|
||||
}
|
||||
break;
|
||||
case CAM_PERSP:
|
||||
default:
|
||||
{
|
||||
double yfov = camera->getYFov().getValue();
|
||||
double aspect = camera->getAspectRatio().getValue();
|
||||
double xfov = aspect*yfov;
|
||||
// xfov is in degrees, cam->lens is in millimiters
|
||||
cam->lens = angle_to_lens((float)xfov*(M_PI/180.0f));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
/* XXX correct way to do following four is probably to get also render
|
||||
size and determine proper settings from that somehow */
|
||||
case COLLADAFW::Camera::ASPECTRATIO_AND_X:
|
||||
case COLLADAFW::Camera::SINGLE_X:
|
||||
case COLLADAFW::Camera::X_AND_Y:
|
||||
{
|
||||
switch(cam->type) {
|
||||
case CAM_ORTHO:
|
||||
cam->ortho_scale = (float)camera->getXMag().getValue();
|
||||
break;
|
||||
case CAM_PERSP:
|
||||
default:
|
||||
{
|
||||
double x = camera->getXFov().getValue();
|
||||
// x is in degrees, cam->lens is in millimiters
|
||||
cam->lens = angle_to_lens((float)x*(M_PI/180.0f));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case COLLADAFW::Camera::SINGLE_Y:
|
||||
{
|
||||
switch(cam->type) {
|
||||
case CAM_ORTHO:
|
||||
cam->ortho_scale = (float)camera->getYMag().getValue();
|
||||
break;
|
||||
case CAM_PERSP:
|
||||
default:
|
||||
{
|
||||
double yfov = camera->getYFov().getValue();
|
||||
// yfov is in degrees, cam->lens is in millimiters
|
||||
cam->lens = angle_to_lens((float)yfov*(M_PI/180.0f));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case COLLADAFW::Camera::UNDEFINED:
|
||||
// read nothing, use blender defaults.
|
||||
break;
|
||||
}
|
||||
|
||||
this->uid_camera_map[camera->getUniqueId()] = cam;
|
||||
// XXX import camera options
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user