Skip to content

Commit a2205ae

Browse files
authored
Merge pull request #1217 from dictoon/master
Miscellaneous fixes and improvements
2 parents 4a8dcd1 + b56c6fd commit a2205ae

File tree

18 files changed

+257
-147
lines changed

18 files changed

+257
-147
lines changed

sandbox/tests/test scenes/bsdf/plasticbrdf/01 - plasticbrdf.appleseed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@
289289
<frame name="beauty">
290290
<parameter name="camera" value="Camera" />
291291
<parameter name="color_space" value="srgb" />
292-
<parameter name="crop_window" value="401 180 572 368" />
293292
<parameter name="resolution" value="640 480" />
294293
</frame>
295294
</output>

scripts/mitsuba2appleseed.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,24 @@ def convert_sphere_shape(scene, assembly, element):
765765
assembly.objects().insert(object)
766766

767767

768+
def convert_cube_shape(scene, assembly, element):
769+
# Object.
770+
object_name = make_new_object_name(assembly)
771+
object = asr.create_primitive_mesh(object_name, {"primitive": "cube"})
772+
773+
# Instance transform.
774+
matrix_element = element.find("transform[@name='toWorld']/matrix")
775+
matrix = get_matrix(matrix_element) if matrix_element is not None else asr.Matrix4d.identity()
776+
transform = asr.Transformd(matrix)
777+
778+
# Instance material.
779+
material_name = process_shape_material(scene, assembly, object_name, element)
780+
781+
instance = make_object_instance(assembly, object, material_name, transform)
782+
assembly.object_instances().insert(instance)
783+
assembly.objects().insert(object)
784+
785+
768786
def convert_shape(project, scene, assembly, element):
769787
type = element.attrib["type"]
770788
if type == "obj":
@@ -775,6 +793,8 @@ def convert_shape(project, scene, assembly, element):
775793
convert_disk_shape(scene, assembly, element)
776794
elif type == "sphere":
777795
convert_sphere_shape(scene, assembly, element)
796+
elif type == "cube":
797+
convert_cube_shape(scene, assembly, element)
778798
else:
779799
warning("Don't know how to convert shape of type {0}".format(type))
780800

src/appleseed.studio/mainwindow/rendering/cameracontroller.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "renderer/api/utility.h"
3737

3838
// appleseed.foundation headers.
39+
#include "foundation/math/matrix.h"
3940
#include "foundation/math/transform.h"
4041
#include "foundation/utility/iostreamop.h"
4142

@@ -106,7 +107,9 @@ void CameraController::slot_entity_picked(ScenePicker::PickingResult result)
106107
m_pivot = Vector3d(object_instance_world_bbox.center());
107108
}
108109
else
110+
{
109111
m_pivot = Vector3d(m_project.get_scene()->compute_bbox().center());
112+
}
110113
}
111114

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

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

149-
if (!camera)
150-
return;
153+
Camera* camera = m_project.get_uncached_active_camera();
151154

152-
// Set the controller orientation and position based on the scene camera.
153-
m_controller.set_transform(
154-
camera->transform_sequence().get_earliest_transform().get_local_to_parent());
155+
// Set the controller orientation and position.
156+
if (camera)
157+
{
158+
// Use the scene's camera.
159+
m_controller.set_transform(
160+
camera->transform_sequence().get_earliest_transform().get_local_to_parent());
161+
}
162+
else
163+
{
164+
// Otherwise use a default orientation and position.
165+
m_controller.set_transform(
166+
Matrix4d::make_lookat(
167+
Vector3d(1.0, 1.0, 1.0), // origin
168+
Vector3d(0.0, 0.0, 0.0), // target
169+
Vector3d(0.0, 1.0, 0.0))); // up
170+
}
155171

156-
if (camera->get_parameters().strings().exist("controller_target"))
172+
// Set the controller target.
173+
if (camera && camera->get_parameters().strings().exist("controller_target"))
157174
{
158-
// The camera already has a target position, use it.
175+
// The scene's camera already has a target position, use it.
159176
m_controller.set_target(
160-
camera->get_parameters().get_optional<Vector3d>(
161-
"controller_target",
162-
Vector3d(0.0)));
177+
camera->get_parameters().get<Vector3d>("controller_target"));
163178
}
164179
else
165180
{
166-
// Otherwise, if the scene is not empty, use its center as the target position.
167-
const GAABB3 scene_bbox = m_project.get_scene()->compute_bbox();
168-
if (scene_bbox.is_valid())
169-
m_controller.set_target(Vector3d(scene_bbox.center()));
181+
// Otherwise use the pivot point.
182+
m_controller.set_target(m_pivot);
170183
}
171184
}
172185

src/appleseed/foundation/image/color.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define APPLESEED_FOUNDATION_IMAGE_COLOR_H
3232

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

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

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

820+
template <typename T, size_t N>
821+
inline bool is_finite(const Color<T, N>& c)
822+
{
823+
for (size_t i = 0; i < N; ++i)
824+
{
825+
if (!FP<T>::is_finite(c[i]))
826+
return false;
827+
}
828+
829+
return true;
830+
}
831+
816832

817833
//
818834
// RGB color implementation.

src/appleseed/foundation/image/regularspectrum.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define APPLESEED_FOUNDATION_IMAGE_REGULARSPECTRUM_H
3232

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

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

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

874+
template <typename T, size_t N>
875+
inline bool is_finite(const RegularSpectrum<T, N>& s)
876+
{
877+
for (size_t i = 0; i < N; ++i)
878+
{
879+
if (!FP<T>::is_finite(s[i]))
880+
return false;
881+
}
882+
883+
return true;
884+
}
885+
870886
} // namespace foundation
871887

872888
#endif // !APPLESEED_FOUNDATION_IMAGE_REGULARSPECTRUM_H

0 commit comments

Comments
 (0)