Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous last minute fixes and improvements #1735

Merged
merged 16 commits into from
Nov 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sandbox/samples/python/studio/plugins/basicenumerator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Installation
============

To install this plugin, copy the `basicenumerator` directory into the `studio/plugins/` directory of your appleseed installation.

It should look like this:

<root appleseed directory>
bin/
...
studio/
plugins/
basicenumerator/
__init__.py


Usage
=====

To use this plugin, run the following commands in appleseed.studio's Python console:

import basicenumerator
basicenumerator.list_objects()
57 changes: 57 additions & 0 deletions sandbox/samples/python/studio/plugins/basicenumerator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

#
# This source file is part of appleseed.
# Visit http://appleseedhq.net/ for additional information and resources.
#
# This software is released under the MIT license.
#
# Copyright (c) 2017 Francois Beaune, The appleseedhq Organization
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

from appleseed.studio import *


def register():
# In the future, this plugin will be able to add menus or panels to appleseed.studio.
pass


def list_objects():
"""Print names of all objects in the scene."""

scene = current_project().get_scene()
assemblies = scene.assemblies()

for ass_key in assemblies:
list_objects_in_assembly(assemblies[ass_key])


def list_objects_in_assembly(ass):
"""Print names of objects in a given assembly and all its child assemblies."""

# Print names of objects inside this assembly.
for obj in ass.objects():
print(obj.get_name())

# Recurse into child assemblies.
child_assemblies = ass.assemblies()
for sub_ass_key in child_assemblies:
list_objects_in_assembly(child_assemblies[sub_ass_key])
26 changes: 26 additions & 0 deletions sandbox/samples/python/studio/plugins/textureprocessor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Warning
=======

This plugin will currently only work on Linux. It requires either the PySide or the PyQt4 Python module. It will be fully supported in the next release of appleseed.


Installation
============

To install this plugin, copy the `textureprocessor` directory into the `studio/plugins/` directory of your appleseed installation.

It should look like this:

<root appleseed directory>
bin/
...
studio/
plugins/
textureprocessor/
__init__.py


Usage
=====

To use this plugin, open the *Plugins* menu and choose *Convert Textures* in appleseed.studio.
1 change: 1 addition & 0 deletions sandbox/studio/plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
2 changes: 1 addition & 1 deletion scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
stripped/
appleseed/
appleseed.package.configuration.xml
10 changes: 7 additions & 3 deletions src/appleseed.python/studio/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@

def load_plugins(bundled_plugins_path):
if os.path.isdir(bundled_plugins_path):
print("Loading Python plugins from {0}...".format(bundled_plugins_path))
load_plugins_from_dir(bundled_plugins_path)

user_plugins_path = os.environ.get('APPLESEED_STUDIO_PLUGIN_PATH')
if user_plugins_path is not None:
print("Loading Python plugins from {0}...".format(user_plugins_path))
load_plugins_from_dir(user_plugins_path)


Expand All @@ -56,16 +58,18 @@ def load_plugin(plugin_path):
file, filename, data = imp.find_module(name, [path])
plugin_module = imp.load_module(name, file, filename, data)
except ImportError as e:
print "Plugin '{}' could not be imported: {}".format(name, e)
print("Plugin '{0}' could not be imported: {1}".format(name, e))
return

if not hasattr(plugin_module, 'register'):
print "Plugin '{}' has no register function.".format(name)
print("Plugin '{0}' has no register function.".format(name))
return

try:
plugin_module.register()
except Exception as e:
print "Could not initialize plugin '{}': {}".format(plugin_module, e)
print("Could not initialize plugin '{0}': {1}".format(name, e))
traceback.print_exc()
return

print("Plugin '{0}' successfully imported.".format(name))
13 changes: 7 additions & 6 deletions src/appleseed.studio/python/pythoninterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace
// Compute full path.
lib_path = base_path / lib_path / "python2.7";

return lib_path.string();
return canonical(lib_path).make_preferred().string();
}

string compute_bundled_plugins_path()
Expand All @@ -131,8 +131,9 @@ namespace
base_path = base_path.parent_path();

// Compute full path.
bf::path plugins_path = base_path / "studio" / "plugins";
return plugins_path.string();
const bf::path plugins_path = base_path / "studio" / "plugins";

return canonical(plugins_path).make_preferred().string();
}
}

Expand Down Expand Up @@ -181,13 +182,13 @@ void PythonInterpreter::initialize(OutputRedirector redirector)

void PythonInterpreter::import_python_module(const char* module_name, const char* alias_name)
{
const string s = format("import {0}\n{1} = {0}\n", module_name, alias_name);
execute(s.c_str());
const string command = format("import {0}\n{1} = {0}\n", module_name, alias_name);
execute(command.c_str());
}

void PythonInterpreter::load_plugins()
{
string bundled_plugins_path = compute_bundled_plugins_path();
const string bundled_plugins_path = compute_bundled_plugins_path();
const string command = format(
"import appleseed.studio.plugins\n"
"appleseed.studio.plugins.load_plugins('{0}')\n",
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed/foundation/math/microfacet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ float GTR1MDF::pdf(
const float alpha_y,
const float gamma) const
{
return D(h, alpha_x, alpha_y, gamma) * h.y;
return D(h, alpha_x, alpha_y, gamma) * std::abs(h.y);
}


Expand Down Expand Up @@ -838,7 +838,7 @@ float StdMDF::pdf(
const float alpha_y,
const float gamma) const
{
return D(h, alpha_x, alpha_y, gamma) * h.y;
return D(h, alpha_x, alpha_y, gamma) * std::abs(h.y);
}

Vector3f StdMDF::sample(
Expand Down
6 changes: 5 additions & 1 deletion src/appleseed/main/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ namespace

fprintf(
s_log_file,
"[%s] Deallocated %s at %s\n\n",
"[%s] Deallocated %s at %s\n",
get_timestamp_string().c_str(),
pretty_size(size).c_str(),
to_string(ptr).c_str());

#ifdef DUMP_CALLSTACK_ON_ALLOCATION
fprintf(s_log_file, "\n");
#endif
}

uint64 compute_leaked_memory_size()
Expand Down
13 changes: 9 additions & 4 deletions src/appleseed/renderer/kernel/lighting/lighttree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,15 @@ float LightTree::compute_node_probability(
const float rcp_surface_area = 1.0f / r2;

// Triangle centroid is a more precise position than the center of the bbox.
const Item& item = m_items[node.get_item_index()];
const Vector3d position = (node.is_leaf() && item.m_light_type == EmittingTriangleType)
? emitting_triangle_centroid(item.m_light_index)
: bbox.center();
Vector3d position;
if (node.is_leaf())
{
const Item& item = m_items[node.get_item_index()];
if (item.m_light_type == EmittingTriangleType)
position = emitting_triangle_centroid(item.m_light_index);
else position = bbox.center();
}
else position = bbox.center();

const Vector3d& surface_point = shading_point.get_point();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ namespace
if (m_inf_volume_ray_warnings < MaxInfVolumeRayWarnings)
RENDERER_LOG_WARNING("volume ray of infinite length encountered.");
else if (m_inf_volume_ray_warnings == MaxInfVolumeRayWarnings)
RENDERER_LOG_WARNING("there are more volume rays of infinite length, "
RENDERER_LOG_WARNING("more volume rays of infinite length found, "
"omitting warning messages for brevity.");
++m_inf_volume_ray_warnings;
}
Expand Down
8 changes: 4 additions & 4 deletions src/appleseed/renderer/modeling/edf/coneedf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ DictionaryArray ConeEDFFactory::get_input_metadata() const
.insert("type", "numeric")
.insert("min",
Dictionary()
.insert("value", "-360.0")
.insert("type", "soft"))
.insert("value", "0.0")
.insert("type", "hard"))
.insert("max",
Dictionary()
.insert("value", "360.0")
.insert("type", "soft"))
.insert("value", "180.0")
.insert("type", "hard"))
.insert("use", "required")
.insert("default", "90.0"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ void EntityFactoryRegistrar::register_factories_from_plugins(
entity_type_name.c_str());

// Iterate over all files in this directory.
for (bf::directory_iterator i(search_path), e; i != e; ++i)
for (bf::directory_iterator j(search_path), f; j != f; ++j)
{
// Only consider shared library files.
if (!bf::is_regular_file(*i) ||
i->path().extension() != foundation::SharedLibrary::get_default_file_extension())
if (!bf::is_regular_file(*j) ||
j->path().extension() != foundation::SharedLibrary::get_default_file_extension())
continue;

const std::string plugin_path = i->path().string();
const std::string plugin_path = j->path().string();

// Only consider libraries that can be loaded and define the right magic symbol.
try
Expand Down
4 changes: 2 additions & 2 deletions src/appleseed/renderer/modeling/frame/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ namespace

void add_chromaticities(ImageAttributes& image_attributes)
{
// Scene linear sRGB Rec 709 chromaticities.
// Scene-linear sRGB / Rec. 709 chromaticities.
image_attributes.insert("white_xy_chromaticity", Vector2f(0.3127f, 0.3290f));
image_attributes.insert("red_xy_chromaticity", Vector2f(0.64f, 0.33f));
image_attributes.insert("green_xy_chromaticity", Vector2f(0.30f, 0.60f));
Expand Down Expand Up @@ -542,8 +542,8 @@ void Frame::write_main_and_aov_images_to_multipart_exr(const char* file_path) co
writer.begin_multipart_exr();

// Always save the main image as half floats.
const Image& image = *impl->m_image;
{
const Image& image = *impl->m_image;
const CanvasProperties& props = image.properties();
images.emplace_back(image, props.m_tile_width, props.m_tile_height, PixelFormatHalf);
static const char* ChannelNames[] = {"R", "G", "B", "A"};
Expand Down
4 changes: 3 additions & 1 deletion src/appleseed/renderer/modeling/scene/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ bool Scene::on_frame_begin(
success = success && invoke_on_frame_begin(project, this, texture_instances(), recorder, abort_switch);
success = success && invoke_on_frame_begin(project, this, shader_groups(), recorder, abort_switch);

success = success && invoke_on_frame_begin(project, this, cameras(), recorder, abort_switch);
success = success && invoke_on_frame_begin(project, this, environment_edfs(), recorder, abort_switch);
success = success && invoke_on_frame_begin(project, this, environment_shaders(), recorder, abort_switch);

Expand All @@ -434,6 +433,9 @@ bool Scene::on_frame_begin(
success = success && invoke_on_frame_begin(project, this, assemblies(), recorder, abort_switch);
success = success && invoke_on_frame_begin(project, this, assembly_instances(), recorder, abort_switch);

// Call on_frame_begin() on cameras last because some of them cast rays to sense depth in their autofocus mechanism.
success = success && invoke_on_frame_begin(project, this, cameras(), recorder, abort_switch);

return success;
}

Expand Down
10 changes: 8 additions & 2 deletions src/appleseed/renderer/utility/testutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,16 @@ TestSceneContext::TestSceneContext(TestSceneBase& base)
input_binder.bind(m_base.m_scene);
assert(input_binder.get_error_count() == 0);

bool success = m_base.m_scene.on_render_begin(m_base.m_project);
#ifndef NDEBUG
bool success =
#endif
m_base.m_scene.on_render_begin(m_base.m_project);
assert(success);

success = m_base.m_scene.on_frame_begin(m_base.m_project, nullptr, m_recorder);
#ifndef NDEBUG
success =
#endif
m_base.m_scene.on_frame_begin(m_base.m_project, nullptr, m_recorder);
assert(success);
}

Expand Down