Skip to content

Commit

Permalink
Merge pull request #1217 from dictoon/master
Browse files Browse the repository at this point in the history
Miscellaneous fixes and improvements
  • Loading branch information
est77 authored Jan 17, 2017
2 parents 4a8dcd1 + b56c6fd commit a2205ae
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@
<frame name="beauty">
<parameter name="camera" value="Camera" />
<parameter name="color_space" value="srgb" />
<parameter name="crop_window" value="401 180 572 368" />
<parameter name="resolution" value="640 480" />
</frame>
</output>
Expand Down
20 changes: 20 additions & 0 deletions scripts/mitsuba2appleseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,24 @@ def convert_sphere_shape(scene, assembly, element):
assembly.objects().insert(object)


def convert_cube_shape(scene, assembly, element):
# Object.
object_name = make_new_object_name(assembly)
object = asr.create_primitive_mesh(object_name, {"primitive": "cube"})

# Instance transform.
matrix_element = element.find("transform[@name='toWorld']/matrix")
matrix = get_matrix(matrix_element) if matrix_element is not None else asr.Matrix4d.identity()
transform = asr.Transformd(matrix)

# Instance material.
material_name = process_shape_material(scene, assembly, object_name, element)

instance = make_object_instance(assembly, object, material_name, transform)
assembly.object_instances().insert(instance)
assembly.objects().insert(object)


def convert_shape(project, scene, assembly, element):
type = element.attrib["type"]
if type == "obj":
Expand All @@ -775,6 +793,8 @@ def convert_shape(project, scene, assembly, element):
convert_disk_shape(scene, assembly, element)
elif type == "sphere":
convert_sphere_shape(scene, assembly, element)
elif type == "cube":
convert_cube_shape(scene, assembly, element)
else:
warning("Don't know how to convert shape of type {0}".format(type))

Expand Down
43 changes: 28 additions & 15 deletions src/appleseed.studio/mainwindow/rendering/cameracontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "renderer/api/utility.h"

// appleseed.foundation headers.
#include "foundation/math/matrix.h"
#include "foundation/math/transform.h"
#include "foundation/utility/iostreamop.h"

Expand Down Expand Up @@ -106,7 +107,9 @@ void CameraController::slot_entity_picked(ScenePicker::PickingResult result)
m_pivot = Vector3d(object_instance_world_bbox.center());
}
else
{
m_pivot = Vector3d(m_project.get_scene()->compute_bbox().center());
}
}

void CameraController::slot_frame_modified()
Expand Down Expand Up @@ -144,29 +147,39 @@ bool CameraController::eventFilter(QObject* object, QEvent* event)

void CameraController::configure_controller()
{
Camera* camera = m_project.get_uncached_active_camera();
// By default, the pivot point is the scene's center.
m_pivot = Vector3d(m_project.get_scene()->compute_bbox().center());

if (!camera)
return;
Camera* camera = m_project.get_uncached_active_camera();

// Set the controller orientation and position based on the scene camera.
m_controller.set_transform(
camera->transform_sequence().get_earliest_transform().get_local_to_parent());
// Set the controller orientation and position.
if (camera)
{
// Use the scene's camera.
m_controller.set_transform(
camera->transform_sequence().get_earliest_transform().get_local_to_parent());
}
else
{
// Otherwise use a default orientation and position.
m_controller.set_transform(
Matrix4d::make_lookat(
Vector3d(1.0, 1.0, 1.0), // origin
Vector3d(0.0, 0.0, 0.0), // target
Vector3d(0.0, 1.0, 0.0))); // up
}

if (camera->get_parameters().strings().exist("controller_target"))
// Set the controller target.
if (camera && camera->get_parameters().strings().exist("controller_target"))
{
// The camera already has a target position, use it.
// The scene's camera already has a target position, use it.
m_controller.set_target(
camera->get_parameters().get_optional<Vector3d>(
"controller_target",
Vector3d(0.0)));
camera->get_parameters().get<Vector3d>("controller_target"));
}
else
{
// Otherwise, if the scene is not empty, use its center as the target position.
const GAABB3 scene_bbox = m_project.get_scene()->compute_bbox();
if (scene_bbox.is_valid())
m_controller.set_target(Vector3d(scene_bbox.center()));
// Otherwise use the pivot point.
m_controller.set_target(m_pivot);
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/appleseed/foundation/image/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define APPLESEED_FOUNDATION_IMAGE_COLOR_H

// appleseed.foundation headers.
#include "foundation/math/fp.h"
#include "foundation/math/scalar.h"
#include "foundation/platform/types.h"
#include "foundation/utility/poison.h"
Expand Down Expand Up @@ -164,6 +165,9 @@ template <typename T, size_t N> T average_value(const Color<T, N>& c);
// Return true if a color contains at least one NaN value.
template <typename T, size_t N> bool has_nan(const Color<T, N>& c);

// Return true if all components of a color are finite (not NaN, not infinite).
template <typename T, size_t N> bool is_finite(const Color<T, N>& c);


//
// RGB color class of arbitrary type.
Expand Down Expand Up @@ -813,6 +817,18 @@ inline bool has_nan(const Color<T, N>& c)
return false;
}

template <typename T, size_t N>
inline bool is_finite(const Color<T, N>& c)
{
for (size_t i = 0; i < N; ++i)
{
if (!FP<T>::is_finite(c[i]))
return false;
}

return true;
}


//
// RGB color implementation.
Expand Down
16 changes: 16 additions & 0 deletions src/appleseed/foundation/image/regularspectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define APPLESEED_FOUNDATION_IMAGE_REGULARSPECTRUM_H

// appleseed.foundation headers.
#include "foundation/math/fp.h"
#include "foundation/math/scalar.h"
#include "foundation/platform/compiler.h"
#ifdef APPLESEED_USE_SSE
Expand Down Expand Up @@ -159,6 +160,9 @@ template <typename T, size_t N> T average_value(const RegularSpectrum<T, N>& s);
// Return true if a spectrum contains at least one NaN value.
template <typename T, size_t N> bool has_nan(const RegularSpectrum<T, N>& s);

// Return true if all components of a spectrum are finite (not NaN, not infinite).
template <typename T, size_t N> bool is_finite(const RegularSpectrum<T, N>& s);


//
// Full specializations for spectra of type float and double.
Expand Down Expand Up @@ -867,6 +871,18 @@ inline bool has_nan(const RegularSpectrum<T, N>& s)
return false;
}

template <typename T, size_t N>
inline bool is_finite(const RegularSpectrum<T, N>& s)
{
for (size_t i = 0; i < N; ++i)
{
if (!FP<T>::is_finite(s[i]))
return false;
}

return true;
}

} // namespace foundation

#endif // !APPLESEED_FOUNDATION_IMAGE_REGULARSPECTRUM_H
Loading

0 comments on commit a2205ae

Please sign in to comment.