Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Feb 11, 2018
1 parent 1b47a10 commit 3203b14
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
42 changes: 21 additions & 21 deletions Plugin/abci/Importer/aiCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ aiCameraSample::aiCameraSample(aiCamera *schema)

void aiCameraSample::getData(aiCameraData &dst) const
{
dst = m_data;
dst = data;
}


Expand All @@ -31,53 +31,53 @@ void aiCamera::readSampleBody(Sample& sample, uint64_t idx)
{
auto ss = aiIndexToSampleSelector(idx);
auto ss2 = aiIndexToSampleSelector(idx + 1);
readVisibility(sample, ss);

m_schema.get(sample.m_sample, ss);
m_schema.get(sample.m_next_sample, ss2);
readVisibility(sample, ss);
m_schema.get(sample.cam_sp, ss);
m_schema.get(sample.cam_sp2, ss2);
}

void aiCamera::cookSampleBody(Sample& sample)
{
auto& config = getConfig();
auto& cs = sample.m_sample;
auto& cs_next = sample.m_next_sample;
auto& dst = sample.m_data;
auto& sp = sample.cam_sp;
auto& dst = sample.data;

dst.visibility = sample.visibility;

// Note: CameraSample::getFieldOfView() returns the horizontal field of view, we need the verical one
static float sRad2Deg = 180.0f / float(M_PI);
float focal_length = (float)cs.getFocalLength();
float vertical_aperture = (float)cs.getVerticalAperture();
float focal_length = (float)sp.getFocalLength();
float vertical_aperture = (float)sp.getVerticalAperture();
if (config.aspect_ratio > 0.0f)
vertical_aperture = (float)cs.getHorizontalAperture() / config.aspect_ratio;
vertical_aperture = (float)sp.getHorizontalAperture() / config.aspect_ratio;

dst.near_clipping_plane = (float)cs.getNearClippingPlane();
dst.far_clipping_plane = (float)cs.getFarClippingPlane();
dst.near_clipping_plane = (float)sp.getNearClippingPlane();
dst.far_clipping_plane = (float)sp.getFarClippingPlane();
dst.field_of_view = 2.0f * atanf(vertical_aperture * 10.0f / (2.0f * focal_length)) * sRad2Deg;

dst.focus_distance = (float)cs.getFocusDistance();
dst.focus_distance = (float)sp.getFocusDistance();
dst.focal_length = focal_length;
dst.aperture = vertical_aperture;
dst.aspect_ratio = float(cs.getHorizontalAperture() / vertical_aperture);
dst.aspect_ratio = float(sp.getHorizontalAperture() / vertical_aperture);

if (config.interpolate_samples && m_current_time_offset != 0) {
auto& sp2 = sample.cam_sp2;
float time_offset = (float)m_current_time_offset;
float focal_length2 = (float)cs_next.getFocalLength();
float vertical_aperture2 = (float)cs_next.getVerticalAperture();
float focal_length2 = (float)sp2.getFocalLength();
float vertical_aperture2 = (float)sp2.getVerticalAperture();
if (config.aspect_ratio > 0.0f)
vertical_aperture2 = (float)cs_next.getHorizontalAperture() / config.aspect_ratio;
vertical_aperture2 = (float)sp2.getHorizontalAperture() / config.aspect_ratio;

float fov2 = 2.0f * atanf(vertical_aperture2 * 10.0f / (2.0f * focal_length2)) * sRad2Deg;
dst.near_clipping_plane += time_offset * (float)(cs_next.getNearClippingPlane() - cs.getNearClippingPlane());
dst.far_clipping_plane += time_offset * (float)(cs_next.getFarClippingPlane() - cs.getFarClippingPlane());
dst.near_clipping_plane += time_offset * (float)(sp2.getNearClippingPlane() - sp.getNearClippingPlane());
dst.far_clipping_plane += time_offset * (float)(sp2.getFarClippingPlane() - sp.getFarClippingPlane());
dst.field_of_view += time_offset * (fov2 - dst.field_of_view);

dst.focus_distance += time_offset * (float)(cs_next.getFocusDistance() - cs.getFocusDistance());
dst.focus_distance += time_offset * (float)(sp2.getFocusDistance() - sp.getFocusDistance());
dst.focal_length += time_offset * (focal_length2 - focal_length);
dst.aperture += time_offset * (vertical_aperture2 - vertical_aperture);
dst.aspect_ratio += time_offset * (float(cs_next.getHorizontalAperture() / vertical_aperture2) - dst.aspect_ratio);
dst.aspect_ratio += time_offset * (float(sp2.getHorizontalAperture() / vertical_aperture2) - dst.aspect_ratio);
}

if (dst.near_clipping_plane == 0.0f)
Expand Down
4 changes: 2 additions & 2 deletions Plugin/abci/Importer/aiCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ using super = aiSample;
void getData(aiCameraData &dst) const;

public:
AbcGeom::CameraSample m_sample, m_next_sample;
aiCameraData m_data;
AbcGeom::CameraSample cam_sp, cam_sp2;
aiCameraData data;
};


Expand Down
16 changes: 6 additions & 10 deletions Plugin/abci/Importer/aiXForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@


aiXformSample::aiXformSample(aiXform *schema)
: super(schema), inherits(true)
: super(schema)
{
}

void aiXformSample::getData(aiXformData &dst) const
{
dst = m_data;
dst = data;
}


Expand Down Expand Up @@ -41,22 +41,18 @@ void aiXform::cookSampleBody(Sample& sample)
{
auto& config = getConfig();

sample.inherits = sample.xf_sp.getInheritsXforms();
sample.m_matrix = sample.xf_sp.getMatrix();
sample.m_next_matrix = sample.xf_sp2.getMatrix();

Imath::V3d scale;
Imath::V3d shear;
Imath::Quatd rot;
Imath::V3d trans;
decompose(sample.m_matrix, scale, shear, rot, trans);
decompose(sample.xf_sp.getMatrix(), scale, shear, rot, trans);

if (config.interpolate_samples && m_current_time_offset != 0)
{
Imath::V3d scale2;
Imath::Quatd rot2;
Imath::V3d trans2;
decompose(sample.m_next_matrix, scale2, shear, rot2, trans2);
decompose(sample.xf_sp2.getMatrix(), scale2, shear, rot2, trans2);
scale += (scale2 - scale)* m_current_time_offset;
trans += (trans2 - trans)* m_current_time_offset;
rot = Imath::slerpShortestArc(rot, rot2, (double)m_current_time_offset);
Expand All @@ -75,9 +71,9 @@ void aiXform::cookSampleBody(Sample& sample)
rot_final.x = -rot_final.x;
rot_final.w = -rot_final.w;
}
auto& dst = sample.m_data;
auto& dst = sample.data;
dst.visibility = sample.visibility;
dst.inherits = sample.inherits;
dst.inherits = sample.xf_sp.getInheritsXforms();
dst.translation = trans;
dst.rotation = rot_final;
dst.scale = scale;
Expand Down
4 changes: 1 addition & 3 deletions Plugin/abci/Importer/aiXForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ using super = aiSample;

public:
AbcGeom::XformSample xf_sp, xf_sp2;
AbcGeom::M44d m_matrix, m_next_matrix;
bool inherits;
aiXformData m_data;
aiXformData data;
};


Expand Down

0 comments on commit 3203b14

Please sign in to comment.