1 | |
2 | // |
3 | // This source file is part of appleseed. |
4 | // Visit http://appleseedhq.net/ for additional information and resources. |
5 | // |
6 | // This software is released under the MIT license. |
7 | // |
8 | // Copyright (c) 2012-2013 Esteban Tovagliari, Jupiter Jazz Limited |
9 | // Copyright (c) 2014-2017 Esteban Tovagliari, The appleseedhq Organization |
10 | // |
11 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
12 | // of this software and associated documentation files (the "Software"), to deal |
13 | // in the Software without restriction, including without limitation the rights |
14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
15 | // copies of the Software, and to permit persons to whom the Software is |
16 | // furnished to do so, subject to the following conditions: |
17 | // |
18 | // The above copyright notice and this permission notice shall be included in |
19 | // all copies or substantial portions of the Software. |
20 | // |
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
27 | // THE SOFTWARE. |
28 | // |
29 | |
30 | // appleseed.python headers. |
31 | #include "pyseed.h" // has to be first, to avoid redefinition warnings |
32 | #include "bindentitycontainers.h" |
33 | #include "dict2dict.h" |
34 | #include "metadata.h" |
35 | |
36 | // appleseed.renderer headers. |
37 | #include "renderer/api/environment.h" |
38 | #include "renderer/api/environmentedf.h" |
39 | #include "renderer/api/environmentshader.h" |
40 | |
41 | namespace bpy = boost::python; |
42 | using namespace foundation; |
43 | using namespace renderer; |
44 | using namespace std; |
45 | |
46 | // Work around a regression in Visual Studio 2015 Update 3. |
47 | #if defined(_MSC_VER) && _MSC_VER == 1900 |
48 | namespace boost |
49 | { |
50 | template <> EnvironmentEDF const volatile* get_pointer<EnvironmentEDF const volatile>(EnvironmentEDF const volatile* p) { return p; } |
51 | template <> EnvironmentShader const volatile* get_pointer<EnvironmentShader const volatile>(EnvironmentShader const volatile* p) { return p; } |
52 | template <> Environment const volatile* get_pointer<Environment const volatile>(Environment const volatile* p) { return p; } |
53 | } |
54 | #endif |
55 | |
56 | namespace |
57 | { |
58 | auto_release_ptr<EnvironmentEDF> create_environment_edf( |
59 | const string& model, |
60 | const string& name, |
61 | const bpy::dict& params) |
62 | { |
63 | EnvironmentEDFFactoryRegistrar factories; |
64 | const IEnvironmentEDFFactory* factory = factories.lookup(model.c_str()); |
65 | |
66 | if (factory) |
67 | return factory->create(name.c_str(), bpy_dict_to_param_array(params)); |
68 | else |
69 | { |
70 | PyErr_SetString(PyExc_RuntimeError, "EnvironmentEDF model not found" ); |
71 | bpy::throw_error_already_set(); |
72 | } |
73 | |
74 | return auto_release_ptr<EnvironmentEDF>(); |
75 | } |
76 | |
77 | TransformSequence* environment_edf_get_transform_sequence(EnvironmentEDF* environment) |
78 | { |
79 | return &(environment->transform_sequence()); |
80 | } |
81 | |
82 | auto_release_ptr<EnvironmentShader> create_environment_shader( |
83 | const string& env_shader_type, |
84 | const string& name, |
85 | const bpy::dict& params) |
86 | { |
87 | EnvironmentShaderFactoryRegistrar factories; |
88 | const IEnvironmentShaderFactory* factory = factories.lookup(env_shader_type.c_str()); |
89 | |
90 | if (factory) |
91 | return factory->create(name.c_str(), bpy_dict_to_param_array(params)); |
92 | else |
93 | { |
94 | PyErr_SetString(PyExc_RuntimeError, "EnvironmentShader type not found" ); |
95 | bpy::throw_error_already_set(); |
96 | } |
97 | |
98 | return auto_release_ptr<EnvironmentShader>(); |
99 | } |
100 | |
101 | auto_release_ptr<Environment> create_environment( |
102 | const string& name, |
103 | const bpy::dict& params) |
104 | { |
105 | return EnvironmentFactory::create(name.c_str(), bpy_dict_to_param_array(params)); |
106 | } |
107 | } |
108 | |
109 | void bind_environment() |
110 | { |
111 | bpy::class_<EnvironmentEDF, auto_release_ptr<EnvironmentEDF>, bpy::bases<ConnectableEntity>, boost::noncopyable >("EnvironmentEDF" , bpy::no_init) |
112 | .def("get_model_metadata" , &detail::get_entity_model_metadata<EnvironmentEDFFactoryRegistrar>).staticmethod("get_model_metadata" ) |
113 | .def("get_input_metadata" , &detail::get_entity_input_metadata<EnvironmentEDFFactoryRegistrar>).staticmethod("get_input_metadata" ) |
114 | .def("__init__" , bpy::make_constructor(create_environment_edf)) |
115 | .def("get_model" , &EnvironmentEDF::get_model) |
116 | .def("transform_sequence" , environment_edf_get_transform_sequence, bpy::return_value_policy<bpy::reference_existing_object>()) |
117 | ; |
118 | |
119 | bind_typed_entity_vector<EnvironmentEDF>("EnvironmentEDFContainer" ); |
120 | |
121 | bpy::class_<EnvironmentShader, auto_release_ptr<EnvironmentShader>, bpy::bases<ConnectableEntity>, boost::noncopyable >("EnvironmentShader" , bpy::no_init) |
122 | .def("get_model_metadata" , &detail::get_entity_model_metadata<EnvironmentShaderFactoryRegistrar>).staticmethod("get_model_metadata" ) |
123 | .def("get_input_metadata" , &detail::get_entity_input_metadata<EnvironmentShaderFactoryRegistrar>).staticmethod("get_input_metadata" ) |
124 | .def("__init__" , bpy::make_constructor(create_environment_shader)) |
125 | .def("get_model" , &EnvironmentShader::get_model) |
126 | ; |
127 | |
128 | bind_typed_entity_vector<EnvironmentShader>("EnvironmentShaderContainer" ); |
129 | |
130 | bpy::class_<Environment, auto_release_ptr<Environment>, bpy::bases<Entity>, boost::noncopyable >("Environment" , bpy::no_init) |
131 | .def("__init__" , bpy::make_constructor(create_environment)) |
132 | .def("get_environment_edf" , &Environment::get_environment_edf, bpy::return_value_policy<bpy::reference_existing_object>()) |
133 | .def("get_environment_shader" , &Environment::get_environment_shader, bpy::return_value_policy<bpy::reference_existing_object>()) |
134 | .def("get_model" , &Environment::get_model) |
135 | ; |
136 | } |
137 | |