56 const xml_attribute attr = node.attribute(
name);
59 *value = atoi(attr.value());
68 const xml_attribute attr = node.attribute(
name);
74 for (
const string &token : tokens) {
75 value.push_back(atoi(token.c_str()));
86 const xml_attribute attr = node.attribute(
name);
89 *value = (
float)atof(attr.value());
98 const xml_attribute attr = node.attribute(
name);
104 for (
const string &token : tokens) {
105 value.push_back((
float)atof(token.c_str()));
155 const xml_attribute attr = node.attribute(
name);
167 const xml_attribute attr = node.attribute(
name);
187 cam->set_full_width(width);
188 cam->set_full_height(height);
190 xml_read_node(
state, cam, node);
192 cam->set_matrix(
state.tfm);
202 xml_read_node(
state, shader, graph_node);
207 XMLReader graph_reader;
208 graph_reader.node_map[ustring(
"output")] = graph->output();
210 for (xml_node node = graph_node.first_child(); node; node = node.next_sibling()) {
211 ustring node_name(node.name());
213 if (node_name ==
"connect") {
218 string_split(from_tokens, node.attribute(
"from").value());
221 if (from_tokens.size() == 2 && to_tokens.size() == 2) {
222 const ustring from_node_name(from_tokens[0]);
223 const ustring from_socket_name(from_tokens[1]);
224 const ustring to_node_name(to_tokens[0]);
225 const ustring to_socket_name(to_tokens[1]);
231 if (graph_reader.node_map.find(from_node_name) != graph_reader.node_map.end()) {
241 LOG_ERROR <<
"Unknown output socket name \"" << from_node_name <<
"\" on \""
242 << from_socket_name <<
"\".";
246 LOG_ERROR <<
"Unknown shader node name \"" << from_node_name <<
"\"";
249 if (graph_reader.node_map.find(to_node_name) != graph_reader.node_map.end()) {
253 if (
string_iequals(
in->socket_type.name.string(), to_socket_name.string())) {
259 LOG_ERROR <<
"Unknown input socket name \"" << to_socket_name <<
"\" on \""
260 << to_node_name <<
"\"";
264 LOG_ERROR <<
"Unknown shader node name \"" << to_node_name <<
"\"";
273 LOG_ERROR <<
"Invalid from or to value for connect node.";
282 if (node_name ==
"osl_shader") {
286 std::string filepath;
293 snode = OSLShaderManager::osl_node(graph.get(),
state.scene, filepath,
"");
296 LOG_ERROR <<
"Failed to create OSL node from \"" << filepath <<
"\"";
301 LOG_ERROR <<
"OSL node missing \"src\" attribute.";
306 LOG_ERROR <<
"OSL node without using --shadingsys osl.";
314 if (node_name ==
"background") {
315 node_name =
"background_shader";
321 LOG_ERROR <<
"Unknown shader node \"" << node.name() <<
"\"";
325 LOG_ERROR <<
"Node type \"" << node_type->
name <<
"\" is not a shader node";
328 if (node_type->
create ==
nullptr) {
329 LOG_ERROR <<
"Can't create abstract node type \""
334 snode = graph->create_node(node_type);
337 xml_read_node(graph_reader, snode, node);
339 if (node_name ==
"image_texture") {
341 const ustring filename(
path_join(
state.base, img->get_filename().string()));
342 img->set_filename(filename);
344 else if (node_name ==
"environment_texture") {
346 const ustring filename(
path_join(
state.base, env->get_filename().string()));
347 env->set_filename(filename);
366 xml_read_node(
state,
state.scene->background, node);
377 if (
object && object->get_geometry()->is_mesh()) {
379 object->set_tfm(tfm);
380 Geometry *geometry =
object->get_geometry();
381 return static_cast<Mesh *
>(geometry);
389 object->set_geometry(mesh);
390 object->set_tfm(tfm);
401 mesh->set_used_shaders(used_shaders);
404 const int shader = 0;
405 const bool smooth =
state.smooth;
433 mesh->set_verts(P_array);
435 size_t num_triangles = 0;
436 for (
size_t i = 0;
i < nverts.size();
i++) {
437 num_triangles += nverts[
i] - 2;
439 mesh->
reserve_mesh(mesh->get_verts().size(), num_triangles);
442 int index_offset = 0;
444 for (
size_t i = 0;
i < nverts.size();
i++) {
445 for (
int j = 0; j < nverts[
i] - 2; j++) {
446 const int v0 =
verts[index_offset];
447 const int v1 =
verts[index_offset + j + 1];
448 const int v2 =
verts[index_offset + j + 2];
457 index_offset += nverts[
i];
481 for (
size_t i = 0;
i < nverts.size();
i++) {
482 for (
int j = 0; j < nverts[
i] - 2; j++) {
483 const int v0 = index_offset;
484 const int v1 = index_offset + j + 1;
485 const int v2 = index_offset + j + 2;
487 assert(v0 * 2 + 1 < (
int)UV.size());
488 assert(v1 * 2 + 1 < (
int)UV.size());
489 assert(
v2 * 2 + 1 < (
int)UV.size());
491 fdata[0] =
make_float2(UV[v0 * 2], UV[v0 * 2 + 1]);
492 fdata[1] =
make_float2(UV[v1 * 2], UV[v1 * 2 + 1]);
497 index_offset += nverts[
i];
508 for (
size_t i = 0;
i < nverts.size();
i++) {
509 for (
int j = 0; j < nverts[
i] - 2; j++) {
510 const int v0 = index_offset;
511 const int v1 = index_offset + j + 1;
512 const int v2 = index_offset + j + 2;
514 assert(v0 * 3 + 2 < (
int)
T.size());
515 assert(v1 * 3 + 2 < (
int)
T.size());
523 index_offset += nverts[
i];
534 for (
size_t i = 0;
i < nverts.size();
i++) {
535 for (
int j = 0; j < nverts[
i] - 2; j++) {
536 const int v0 = index_offset;
537 const int v1 = index_offset + j + 1;
538 const int v2 = index_offset + j + 2;
540 assert(v0 < (
int)TS.size());
541 assert(v1 < (
int)TS.size());
549 index_offset += nverts[
i];
555 mesh->set_verts(P_array);
557 size_t num_corners = 0;
558 for (
size_t i = 0;
i < nverts.size();
i++) {
559 num_corners += nverts[
i];
564 int index_offset = 0;
566 for (
size_t i = 0;
i < nverts.size();
i++) {
568 index_offset += nverts[
i];
579 for (
size_t i = 0;
i < nverts.size();
i++) {
580 for (
int j = 0; j < nverts[
i]; j++) {
587 float dicing_rate =
state.dicing_rate;
589 dicing_rate = std::max(0.1f, dicing_rate);
591 mesh->set_subd_dicing_rate(dicing_rate);
592 mesh->set_subd_objecttoworld(
state.tfm);
599 std::copy_n(mesh->get_verts().data(), mesh->get_verts().size(), attr->
data_float3());
614 light->set_used_shaders(used_shaders);
618 object->set_tfm(
state.tfm);
620 object->set_geometry(light);
622 xml_read_node(
state, light, node);
629 if (node.attribute(
"matrix")) {
637 if (node.attribute(
"translate")) {
643 if (node.attribute(
"rotate")) {
649 if (node.attribute(
"scale")) {
667 if (shader->
name == shadername) {
668 state.shader = shader;
675 LOG_ERROR <<
"Unknown shader \"" << shadername <<
"\"";
686 if (object->
name == objectname) {
687 state.object = object;
694 LOG_ERROR <<
"Unknown object \"" << objectname <<
"\"";
705 state.smooth =
false;
720 object->set_geometry(mesh);
721 object->set_tfm(
state.tfm);
723 xml_read_node(
state,
object, node);
732 for (xml_node node = scene_node.first_child(); node; node = node.next_sibling()) {
734 xml_read_node(
state,
state.scene->film, node);
737 xml_read_node(
state,
state.scene->integrator, node);
780 LOG_ERROR <<
"Unknown node \"" << node.name() <<
"\"";
791 xml_parse_result parse_result;
794 parse_result = doc.load_file(path.c_str());
800 const xml_node cycles = doc.child(
"cycles");
804 LOG_ERROR <<
"\"" << src <<
"\" read error: " << parse_result.description();
818 state.smooth =
false;
819 state.dicing_rate = 1.0f;
ATTR_WARN_UNUSED_RESULT const BMVert * v2
Attribute * add(ustring name, const TypeDesc type, AttributeElement element)
bool need_attribute(Scene *scene, AttributeStandard std)
unique_ptr_vector< ShaderInput > inputs
unique_ptr_vector< ShaderOutput > outputs
void set_graph(unique_ptr< ShaderGraph > &&graph)
void tag_update(Scene *scene)
void push_back_slow(const T &t)
ccl_device_inline Transform projection_to_transform(const ProjectionTransform &a)
ccl_device_inline ProjectionTransform projection_transpose(const ProjectionTransform a)
static void xml_read_object(XMLReadState &state, const xml_node node)
static bool xml_read_float3(float3 *value, const xml_node node, const char *name)
static bool xml_read_int_array(vector< int > &value, const xml_node node, const char *name)
static bool xml_read_float(float *value, const xml_node node, const char *name)
static void xml_read_include(XMLReadState &state, const string &src)
static void xml_read_background(XMLReadState &state, const xml_node node)
static bool xml_read_string(string *str, const xml_node node, const char *name)
static void xml_read_transform(const xml_node node, Transform &tfm)
static bool xml_read_int(int *value, const xml_node node, const char *name)
static Mesh * xml_add_mesh(Scene *scene, const Transform &tfm, Object *object)
void xml_read_file(Scene *scene, const char *filepath)
static void xml_read_scene(XMLReadState &state, const xml_node scene_node)
static bool xml_read_float4(float4 *value, const xml_node node, const char *name)
static void xml_read_state(XMLReadState &state, const xml_node node)
static void xml_read_shader_graph(XMLReadState &state, Shader *shader, const xml_node graph_node)
static bool xml_read_float_array(vector< float > &value, const xml_node node, const char *name)
static void xml_read_camera(XMLReadState &state, const xml_node node)
static void xml_read_light(XMLReadState &state, const xml_node node)
static bool xml_equal_string(const xml_node node, const char *name, const char *value)
static void xml_read_mesh(const XMLReadState &state, const xml_node node)
static bool xml_read_float3_array(vector< float3 > &value, const xml_node node, const char *name)
static void xml_read_shader(XMLReadState &state, const xml_node node)
#define CCL_NAMESPACE_END
#define assert(assertion)
@ ATTR_STD_UV_TANGENT_SIGN
@ PATH_RAY_ALL_VISIBILITY
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()
static void rotate(float new_co[3], float a, const float ax[3], const float co[3])
string path_dirname(const string &path)
bool path_is_relative(const string &path)
string path_join(const string &dir, const string &file)
string path_filename(const string &path)
bool string_iequals(const string &a, const string &b)
void string_split(vector< string > &tokens, const string &str, const string &separators, bool skip_empty_tokens)
static const char * standard_name(AttributeStandard std)
void update(Scene *scene)
void add_triangle(const int v0, const int v1, const int v2, const int shader, bool smooth)
AttributeSet subd_attributes
void reserve_mesh(const int numverts, const int numtris)
@ SUBDIVISION_CATMULL_CLARK
void add_subd_face(const int *corners, const int num_corners, const int shader_, bool smooth_)
void reserve_subd_faces(const int numfaces, const int numcorners)
static const NodeType * find(ustring name)
T * create_node(Args &&...)=delete