Blender V5.3
cycles_xml.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include <algorithm>
6#include <cstdio>
7
8#include "graph/node_xml.h"
9
10#include "scene/background.h"
11#include "scene/camera.h"
12#include "scene/film.h"
13#include "scene/integrator.h"
14#include "scene/light.h"
15#include "scene/mesh.h"
16#include "scene/object.h"
17#include "scene/osl.h"
18#include "scene/scene.h"
19#include "scene/shader.h"
20#include "scene/shader_graph.h"
21#include "scene/shader_nodes.h"
22
23#include "util/log.h"
24#include "util/path.h"
25#include "util/projection.h"
26#include "util/string.h"
27#include "util/transform.h"
28#include "util/xml.h"
29
30#include "app/cycles_xml.h"
31
33
34/* XML reading state */
35
36struct XMLReadState : public XMLReader {
37 Scene *scene = nullptr; /* Scene pointer. */
38 Transform tfm; /* Current transform state. */
39 bool smooth = false; /* Smooth normal state. */
40 Shader *shader = nullptr; /* Current shader. */
41 string base; /* Base path to current file. */
42 float dicing_rate = 1.0f; /* Current dicing rate. */
43 Object *object = nullptr; /* Current object. */
44
46 {
48 }
49};
50
51/* Attribute Reading */
52
53static bool xml_read_int(int *value, const xml_node node, const char *name)
54{
55 const xml_attribute attr = node.attribute(name);
56
57 if (attr) {
58 *value = atoi(attr.value());
59 return true;
60 }
61
62 return false;
63}
64
65static bool xml_read_int_array(vector<int> &value, const xml_node node, const char *name)
66{
67 const xml_attribute attr = node.attribute(name);
68
69 if (attr) {
70 vector<string> tokens;
71 string_split(tokens, attr.value());
72
73 for (const string &token : tokens) {
74 value.push_back(atoi(token.c_str()));
75 }
76
77 return true;
78 }
79
80 return false;
81}
82
83static bool xml_read_float(float *value, const xml_node node, const char *name)
84{
85 const xml_attribute attr = node.attribute(name);
86
87 if (attr) {
88 *value = (float)atof(attr.value());
89 return true;
90 }
91
92 return false;
93}
94
95static bool xml_read_float_array(vector<float> &value, const xml_node node, const char *name)
96{
97 const xml_attribute attr = node.attribute(name);
98
99 if (attr) {
100 vector<string> tokens;
101 string_split(tokens, attr.value());
102
103 for (const string &token : tokens) {
104 value.push_back((float)atof(token.c_str()));
105 }
106
107 return true;
108 }
109
110 return false;
111}
112
113static bool xml_read_float3(float3 *value, const xml_node node, const char *name)
114{
116
117 if (xml_read_float_array(array, node, name) && array.size() == 3) {
118 *value = make_float3(array[0], array[1], array[2]);
119 return true;
120 }
121
122 return false;
123}
124
126 const xml_node node,
127 const char *name)
128{
130
131 if (xml_read_float_array(array, node, name)) {
132 for (size_t i = 0; i < array.size(); i += 3) {
133 value.push_back(make_float3(array[i + 0], array[i + 1], array[i + 2]));
134 }
135
136 return true;
137 }
138
139 return false;
140}
141
142static bool xml_read_float4(float4 *value, const xml_node node, const char *name)
143{
145
146 if (xml_read_float_array(array, node, name) && array.size() == 4) {
147 *value = make_float4(array[0], array[1], array[2], array[3]);
148 return true;
149 }
150
151 return false;
152}
153
154static bool xml_read_string(string *str, const xml_node node, const char *name)
155{
156 const xml_attribute attr = node.attribute(name);
157
158 if (attr) {
159 *str = attr.value();
160 return true;
161 }
162
163 return false;
164}
165
166static bool xml_equal_string(const xml_node node, const char *name, const char *value)
167{
168 const xml_attribute attr = node.attribute(name);
169
170 if (attr) {
171 return string_iequals(attr.value(), value);
172 }
173
174 return false;
175}
176
177/* Camera */
178
179static void xml_read_camera(XMLReadState &state, const xml_node node)
180{
181 Camera *cam = state.scene->camera;
182
183 int width = -1;
184 int height = -1;
185 xml_read_int(&width, node, "width");
186 xml_read_int(&height, node, "height");
187
188 cam->set_full_width(width);
189 cam->set_full_height(height);
190
191 xml_read_node(state, cam, node);
192
193 cam->set_matrix(state.tfm);
194
195 cam->need_flags_update = true;
196 cam->update(state.scene);
197}
198
199/* Shader */
200
201static void xml_read_shader_graph(XMLReadState &state, Shader *shader, const xml_node graph_node)
202{
203 xml_read_node(state, shader, graph_node);
204
205 unique_ptr<ShaderGraph> graph = make_unique<ShaderGraph>();
206
207 /* local state, shader nodes can't link to nodes outside the shader graph */
208 XMLReader graph_reader;
209 graph_reader.node_map[ustring("output")] = graph->output();
210
211 for (xml_node node = graph_node.first_child(); node; node = node.next_sibling()) {
212 ustring node_name(node.name());
213
214 if (node_name == "connect") {
215 /* connect nodes */
216 vector<string> from_tokens;
217 vector<string> to_tokens;
218
219 string_split(from_tokens, node.attribute("from").value());
220 string_split(to_tokens, node.attribute("to").value());
221
222 if (from_tokens.size() == 2 && to_tokens.size() == 2) {
223 const ustring from_node_name(from_tokens[0]);
224 const ustring from_socket_name(from_tokens[1]);
225 const ustring to_node_name(to_tokens[0]);
226 const ustring to_socket_name(to_tokens[1]);
227
228 /* find nodes and sockets */
229 ShaderOutput *output = nullptr;
230 ShaderInput *input = nullptr;
231
232 if (graph_reader.node_map.contains(from_node_name)) {
233 ShaderNode *fromnode = (ShaderNode *)graph_reader.node_map[from_node_name];
234
235 for (ShaderOutput *out : fromnode->outputs) {
236 if (string_iequals(out->socket_type.name.string(), from_socket_name.string())) {
237 output = out;
238 }
239 }
240
241 if (!output) {
242 LOG_ERROR << "Unknown output socket name \"" << from_node_name << "\" on \""
243 << from_socket_name << "\".";
244 }
245 }
246 else {
247 LOG_ERROR << "Unknown shader node name \"" << from_node_name << "\"";
248 }
249
250 if (graph_reader.node_map.contains(to_node_name)) {
251 ShaderNode *tonode = (ShaderNode *)graph_reader.node_map[to_node_name];
252
253 for (ShaderInput *in : tonode->inputs) {
254 if (string_iequals(in->socket_type.name.string(), to_socket_name.string())) {
255 input = in;
256 }
257 }
258
259 if (!input) {
260 LOG_ERROR << "Unknown input socket name \"" << to_socket_name << "\" on \""
261 << to_node_name << "\"";
262 }
263 }
264 else {
265 LOG_ERROR << "Unknown shader node name \"" << to_node_name << "\"";
266 }
267
268 /* connect */
269 if (output && input) {
270 graph->connect(output, input);
271 }
272 }
273 else {
274 LOG_ERROR << "Invalid from or to value for connect node.";
275 }
276
277 continue;
278 }
279
280 ShaderNode *snode = nullptr;
281
282#ifdef WITH_OSL
283 if (node_name == "osl_shader") {
284 ShaderManager *manager = state.scene->shader_manager.get();
285
286 if (manager->use_osl()) {
287 std::string filepath;
288
289 if (xml_read_string(&filepath, node, "src")) {
290 if (path_is_relative(filepath)) {
291 filepath = path_join(state.base, filepath);
292 }
293
294 snode = OSLShaderManager::osl_node(graph.get(), state.scene, filepath, "");
295
296 if (!snode) {
297 LOG_ERROR << "Failed to create OSL node from \"" << filepath << "\"";
298 continue;
299 }
300 }
301 else {
302 LOG_ERROR << "OSL node missing \"src\" attribute.";
303 continue;
304 }
305 }
306 else {
307 LOG_ERROR << "OSL node without using --shadingsys osl.";
308 continue;
309 }
310 }
311 else
312#endif
313 {
314 /* exception for name collision */
315 if (node_name == "background") {
316 node_name = "background_shader";
317 }
318
319 const NodeType *node_type = NodeType::find(node_name);
320
321 if (!node_type) {
322 LOG_ERROR << "Unknown shader node \"" << node.name() << "\"";
323 continue;
324 }
325 if (node_type->type != NodeType::SHADER) {
326 LOG_ERROR << "Node type \"" << node_type->name << "\" is not a shader node";
327 continue;
328 }
329 if (node_type->create == nullptr) {
330 LOG_ERROR << "Can't create abstract node type \""
331 << "\"";
332 continue;
333 }
334
335 snode = graph->create_node(node_type);
336 }
337
338 xml_read_node(graph_reader, snode, node);
339
340 if (node_name == "image_texture") {
341 ImageTextureNode *img = (ImageTextureNode *)snode;
342 const ustring filename(path_join(state.base, img->get_filename().string()));
343 img->set_filename(filename);
344 }
345 else if (node_name == "environment_texture") {
347 const ustring filename(path_join(state.base, env->get_filename().string()));
348 env->set_filename(filename);
349 }
350 }
351
352 shader->set_graph(std::move(graph));
353 shader->tag_update(state.scene);
354}
355
356static void xml_read_shader(XMLReadState &state, const xml_node node)
357{
358 Shader *shader = state.scene->create_node<Shader>();
360}
361
362/* Background */
363
364static void xml_read_background(XMLReadState &state, const xml_node node)
365{
366 /* Background Settings */
367 xml_read_node(state, state.scene->background, node);
368
369 /* Background Shader */
370 Shader *shader = state.scene->default_background;
372}
373
374/* Mesh */
375
376static Mesh *xml_add_mesh(Scene *scene, const Transform &tfm, Object *object)
377{
378 if (object && object->get_geometry()->is_mesh()) {
379 /* Use existing object and mesh */
380 object->set_tfm(tfm);
381 Geometry *geometry = object->get_geometry();
382 return static_cast<Mesh *>(geometry);
383 }
384
385 /* Create mesh */
386 Mesh *mesh = scene->create_node<Mesh>();
387
388 /* Create object. */
389 object = scene->create_node<Object>();
390 object->set_geometry(mesh);
391 object->set_tfm(tfm);
392
393 return mesh;
394}
395
396static void xml_read_mesh(const XMLReadState &state, const xml_node node)
397{
398 /* add mesh */
399 Mesh *mesh = xml_add_mesh(state.scene, state.tfm, state.object);
400 array<Node *> used_shaders = mesh->get_used_shaders();
401 used_shaders.push_back_slow(state.shader);
402 mesh->set_used_shaders(used_shaders);
403
404 /* read state */
405 const int shader = 0;
406 const bool smooth = state.smooth;
407
408 /* read vertices and polygons */
410 vector<packed_float3> VN; /* Vertex normals */
411 vector<float> UV;
412 vector<float> T; /* UV tangents */
413 vector<float> TS; /* UV tangent signs */
414 vector<int> verts;
415 vector<int> nverts;
416
418 xml_read_int_array(verts, node, "verts");
419 xml_read_int_array(nverts, node, "nverts");
420
421 if (xml_equal_string(node, "subdivision", "catmull-clark")) {
422 mesh->set_subdivision_type(Mesh::SUBDIVISION_CATMULL_CLARK);
423 }
424 else if (xml_equal_string(node, "subdivision", "linear")) {
425 mesh->set_subdivision_type(Mesh::SUBDIVISION_LINEAR);
426 }
427
428 if (mesh->get_subdivision_type() == Mesh::SUBDIVISION_NONE) {
429 /* create vertices */
430
431 size_t num_triangles = 0;
432 for (size_t i = 0; i < nverts.size(); i++) {
433 num_triangles += nverts[i] - 2;
434 }
435 mesh->resize_mesh(P.size(), num_triangles);
436 std::copy_n(P.data(), P.size(), mesh->get_position_for_write());
437
438 int *triangles = mesh->get_triangles().data();
439
440 /* create triangles */
441 int tri_index = 0;
442 int index_offset = 0;
443
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];
449
450 assert(v0 < (int)P.size());
451 assert(v1 < (int)P.size());
452 assert(v2 < (int)P.size());
453
454 triangles[tri_index * 3 + 0] = v0;
455 triangles[tri_index * 3 + 1] = v1;
456 triangles[tri_index * 3 + 2] = v2;
457 tri_index++;
458 }
459
460 index_offset += nverts[i];
461 }
462 std::ranges::fill(mesh->get_smooth(), smooth);
463 std::ranges::fill(mesh->get_shader(), shader);
464
465 mesh->tag_triangles_modified();
466 mesh->tag_shader_modified();
467 mesh->tag_smooth_modified();
468
469 /* Vertex normals */
473
474 /* Loop over the normals */
475 for (auto n : VN) {
476 fdata[0] = packed_normal(n);
477 fdata++;
478 }
479 }
480
481 /* UV map */
482 if (xml_read_float_array(UV, node, "UV") ||
484 {
485 Attribute *attr = mesh->attributes.add(ATTR_STD_UV);
486 float2 *fdata = attr->data_for_write<float2>();
487
488 /* Loop over the triangles */
489 index_offset = 0;
490 for (size_t i = 0; i < nverts.size(); i++) {
491 for (int j = 0; j < nverts[i] - 2; j++) {
492 const int v0 = index_offset;
493 const int v1 = index_offset + j + 1;
494 const int v2 = index_offset + j + 2;
495
496 assert(v0 * 2 + 1 < (int)UV.size());
497 assert(v1 * 2 + 1 < (int)UV.size());
498 assert(v2 * 2 + 1 < (int)UV.size());
499
500 fdata[0] = make_float2(UV[v0 * 2], UV[v0 * 2 + 1]);
501 fdata[1] = make_float2(UV[v1 * 2], UV[v1 * 2 + 1]);
502 fdata[2] = make_float2(UV[v2 * 2], UV[v2 * 2 + 1]);
503 fdata += 3;
504 }
505
506 index_offset += nverts[i];
507 }
508 }
509
510 /* Tangents */
514
515 /* Loop over the triangles */
516 index_offset = 0;
517 for (size_t i = 0; i < nverts.size(); i++) {
518 for (int j = 0; j < nverts[i] - 2; j++) {
519 const int v0 = index_offset;
520 const int v1 = index_offset + j + 1;
521 const int v2 = index_offset + j + 2;
522
523 assert(v0 * 3 + 2 < (int)T.size());
524 assert(v1 * 3 + 2 < (int)T.size());
525 assert(v2 * 3 + 2 < (int)T.size());
526
527 fdata[0] = make_float3(T[v0 * 3], T[v0 * 3 + 1], T[v0 * 3 + 2]);
528 fdata[1] = make_float3(T[v1 * 3], T[v1 * 3 + 1], T[v1 * 3 + 2]);
529 fdata[2] = make_float3(T[v2 * 3], T[v2 * 3 + 1], T[v2 * 3 + 2]);
530 fdata += 3;
531 }
532 index_offset += nverts[i];
533 }
534 }
535
536 /* Tangent signs */
539 float *fdata = attr->data_for_write<float>();
540
541 /* Loop over the triangles */
542 index_offset = 0;
543 for (size_t i = 0; i < nverts.size(); i++) {
544 for (int j = 0; j < nverts[i] - 2; j++) {
545 const int v0 = index_offset;
546 const int v1 = index_offset + j + 1;
547 const int v2 = index_offset + j + 2;
548
549 assert(v0 < (int)TS.size());
550 assert(v1 < (int)TS.size());
551 assert(v2 < (int)TS.size());
552
553 fdata[0] = TS[v0];
554 fdata[1] = TS[v1];
555 fdata[2] = TS[v2];
556 fdata += 3;
557 }
558 index_offset += nverts[i];
559 }
560 }
561 }
562 else {
563 /* create vertices */
564 mesh->resize_mesh(P.size(), 0);
565
566 size_t num_corners = 0;
567 for (size_t i = 0; i < nverts.size(); i++) {
568 num_corners += nverts[i];
569 }
570 mesh->resize_subd_faces(nverts.size(), num_corners);
571
572 Attribute *subd_attr_P = mesh->subd_attributes.add(ATTR_STD_POSITION);
573 subd_attr_P->resize(P.size());
574 std::copy_n(P.data(), P.size(), subd_attr_P->data_for_write<packed_float3>());
575
576 int *subd_start_corner = mesh->get_subd_start_corner().data();
577 int *subd_num_corners = mesh->get_subd_num_corners().data();
578 int *subd_ptex_offset = mesh->get_subd_ptex_offset().data();
579 int *subd_face_corners = mesh->get_subd_face_corners().data();
580
581 std::ranges::fill(mesh->get_subd_shader(), shader);
582 std::ranges::fill(mesh->get_subd_smooth(), smooth);
583
584 std::ranges::copy(verts, subd_face_corners);
585
586 /* create subd_faces */
587 int corner_index = 0;
588 int ptex_offset = 0;
589
590 for (size_t i = 0; i < nverts.size(); i++) {
591 subd_start_corner[i] = corner_index;
592 subd_num_corners[i] = nverts[i];
593 corner_index += nverts[i];
594
595 subd_ptex_offset[i] = ptex_offset;
596 const int num_ptex = (nverts[i] == 4) ? 1 : nverts[i];
597 ptex_offset += num_ptex;
598 }
599
600 mesh->tag_subd_face_corners_modified();
601 mesh->tag_subd_start_corner_modified();
602 mesh->tag_subd_num_corners_modified();
603 mesh->tag_subd_shader_modified();
604 mesh->tag_subd_smooth_modified();
605 mesh->tag_subd_ptex_offset_modified();
606
607 /* UV map */
608 if (xml_read_float_array(UV, node, "UV") ||
610 {
613
614 int index_offset = 0;
615 for (size_t i = 0; i < nverts.size(); i++) {
616 for (int j = 0; j < nverts[i]; j++) {
617 *(fdata++) = make_float3(UV[index_offset++]);
618 }
619 }
620 }
621
622 /* setup subd params */
623 float dicing_rate = state.dicing_rate;
624 xml_read_float(&dicing_rate, node, "dicing_rate");
625 dicing_rate = std::max(0.1f, dicing_rate);
626
627 mesh->set_subd_dicing_rate(dicing_rate);
628 mesh->set_subd_objecttoworld(state.tfm);
629 }
630
631 /* we don't yet support arbitrary attributes, for now add vertex
632 * coordinates as generated coordinates if requested */
633 if (mesh->need_attribute(state.scene, ATTR_STD_GENERATED)) {
635 std::copy_n(mesh->get_position(), mesh->num_verts(), attr->data_for_write<packed_float3>());
636 }
637}
638
639/* Light */
640
641static void xml_read_light(XMLReadState &state, const xml_node node)
642{
643 Scene *scene = state.scene;
644
645 /* Create light. */
646 string light_type;
647 if (!xml_read_string(&light_type, node, "light_type")) {
648 return;
649 }
650
651 Light *light;
652 if (light_type == "point") {
653 light = scene->create_node<PointLight>();
654 }
655 else if (light_type == "sun") {
656 light = scene->create_node<SunLight>();
657 }
658 else if (light_type == "background") {
659 light = scene->create_node<BackgroundLight>();
660 }
661 else if (light_type == "area") {
662 light = scene->create_node<AreaLight>();
663 }
664 else {
665 assert(light_type == "spot");
666 light = scene->create_node<SpotLight>();
667 }
668
669 array<Node *> used_shaders;
670 used_shaders.push_back_slow(state.shader);
671 light->set_used_shaders(used_shaders);
672
673 /* Create object. */
674 Object *object = scene->create_node<Object>();
675 object->set_tfm(state.tfm);
676 object->set_visibility(PATH_RAY_VISIBILITY_ALL & ~PATH_RAY_VISIBILITY_CAMERA);
677 object->set_geometry(light);
678
679 xml_read_node(state, light, node);
680}
681
682/* Transform */
683
684static void xml_read_transform(const xml_node node, Transform &tfm)
685{
686 if (node.attribute("matrix")) {
687 vector<float> matrix;
688 if (xml_read_float_array(matrix, node, "matrix") && matrix.size() == 16) {
689 const ProjectionTransform projection = *(ProjectionTransform *)matrix.data();
690 tfm = tfm * projection_to_transform(projection_transpose(projection));
691 }
692 }
693
694 if (node.attribute("translate")) {
696 xml_read_float3(&translate, node, "translate");
697 tfm = tfm * transform_translate(translate);
698 }
699
700 if (node.attribute("rotate")) {
702 xml_read_float4(&rotate, node, "rotate");
704 }
705
706 if (node.attribute("scale")) {
708 xml_read_float3(&scale, node, "scale");
709 tfm = tfm * transform_scale(scale);
710 }
711}
712
713/* State */
714
715static void xml_read_state(XMLReadState &state, const xml_node node)
716{
717 /* Read shader */
718 string shadername;
719
720 if (xml_read_string(&shadername, node, "shader")) {
721 bool found = false;
722
723 for (Shader *shader : state.scene->shaders) {
724 if (shader->name == shadername) {
725 state.shader = shader;
726 found = true;
727 break;
728 }
729 }
730
731 if (!found) {
732 LOG_ERROR << "Unknown shader \"" << shadername << "\"";
733 }
734 }
735
736 /* Read object */
737 string objectname;
738
739 if (xml_read_string(&objectname, node, "object")) {
740 bool found = false;
741
742 for (Object *object : state.scene->objects) {
743 if (object->name == objectname) {
744 state.object = object;
745 found = true;
746 break;
747 }
748 }
749
750 if (!found) {
751 LOG_ERROR << "Unknown object \"" << objectname << "\"";
752 }
753 }
754
755 xml_read_float(&state.dicing_rate, node, "dicing_rate");
756
757 /* read smooth/flat */
758 if (xml_equal_string(node, "interpolation", "smooth")) {
759 state.smooth = true;
760 }
761 else if (xml_equal_string(node, "interpolation", "flat")) {
762 state.smooth = false;
763 }
764}
765
766/* Object */
767
768static void xml_read_object(XMLReadState &state, const xml_node node)
769{
770 Scene *scene = state.scene;
771
772 /* create mesh */
773 Mesh *mesh = scene->create_node<Mesh>();
774
775 /* create object */
776 Object *object = scene->create_node<Object>();
777 object->set_geometry(mesh);
778 object->set_tfm(state.tfm);
779
780 xml_read_node(state, object, node);
781}
782
783/* Scene */
784
785static void xml_read_include(XMLReadState &state, const string &src);
786
787static void xml_read_scene(XMLReadState &state, const xml_node scene_node)
788{
789 for (xml_node node = scene_node.first_child(); node; node = node.next_sibling()) {
790 if (string_iequals(node.name(), "film")) {
791 xml_read_node(state, state.scene->film, node);
792 }
793 else if (string_iequals(node.name(), "integrator")) {
794 xml_read_node(state, state.scene->integrator, node);
795 }
796 else if (string_iequals(node.name(), "camera")) {
798 }
799 else if (string_iequals(node.name(), "shader")) {
801 }
802 else if (string_iequals(node.name(), "background")) {
804 }
805 else if (string_iequals(node.name(), "mesh")) {
807 }
808 else if (string_iequals(node.name(), "light")) {
810 }
811 else if (string_iequals(node.name(), "transform")) {
812 XMLReadState substate = state;
813
814 xml_read_transform(node, substate.tfm);
815 xml_read_scene(substate, node);
816 }
817 else if (string_iequals(node.name(), "state")) {
818 XMLReadState substate = state;
819
820 xml_read_state(substate, node);
821 xml_read_scene(substate, node);
822 }
823 else if (string_iequals(node.name(), "include")) {
824 string src;
825
826 if (xml_read_string(&src, node, "src")) {
828 }
829 }
830 else if (string_iequals(node.name(), "object")) {
831 XMLReadState substate = state;
832
833 xml_read_object(substate, node);
834 xml_read_scene(substate, node);
835 }
836 else {
837 LOG_ERROR << "Unknown node \"" << node.name() << "\"";
838 }
839 }
840}
841
842/* Include */
843
844static void xml_read_include(XMLReadState &state, const string &src)
845{
846 /* open XML document */
847 xml_document doc;
848 xml_parse_result parse_result;
849
850 const string path = path_join(state.base, src);
851 parse_result = doc.load_file(path.c_str());
852
853 if (parse_result) {
854 XMLReadState substate = state;
855 substate.base = path_dirname(path);
856
857 const xml_node cycles = doc.child("cycles");
858 xml_read_scene(substate, cycles);
859 }
860 else {
861 LOG_ERROR << "\"" << src << "\" read error: " << parse_result.description();
862 exit(EXIT_FAILURE);
863 }
864}
865
866/* File */
867
868void xml_read_file(Scene *scene, const char *filepath)
869{
871
872 state.scene = scene;
874 state.shader = scene->default_surface;
875 state.smooth = false;
876 state.dicing_rate = 1.0f;
877 state.base = path_dirname(filepath);
878
880
882}
883
#define DEG2RADF(_deg)
#define output
Attribute * add(ustring name, const TypeDesc type, AttributeElement element)
void resize(Geometry *geom, AttributePrimitive prim)
T * data_for_write(const int step=0)
static const char * standard_name(AttributeStandard std)
bool need_flags_update
void update(Scene *scene)
const packed_float3 * get_position() const
AttributeSet attributes
bool need_attribute(const Scene *scene, AttributeStandard std)
packed_float3 * get_position_for_write()
NODE_DECLARE size_t num_verts() const
AttributeSet subd_attributes
Definition scene/mesh.h:169
@ SUBDIVISION_NONE
Definition scene/mesh.h:114
@ SUBDIVISION_LINEAR
Definition scene/mesh.h:115
@ SUBDIVISION_CATMULL_CLARK
Definition scene/mesh.h:116
void resize_subd_faces(const int numfaces, const int numcorners)
void resize_mesh(const int numverts, const int numtris)
void set_tfm(Transform tfm)
BVHType bvh_type
Definition scene.h:74
Definition scene.h:133
SceneParams params
Definition scene.h:190
Shader * default_surface
Definition scene.h:178
T * create_node(Args &&...)=delete
virtual bool use_osl()
unique_ptr_vector< ShaderInput > inputs
unique_ptr_vector< ShaderOutput > outputs
void set_graph(unique_ptr< ShaderGraph > &&graph)
void tag_update(Scene *scene)
size_t size() const
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_float3_array(vector< packed_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 void xml_read_shader(XMLReadState &state, const xml_node node)
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define str(s)
#define assert(assertion)
#define smooth
float3x3 scale(float3x3 mat, float2 scale)
float4x4 translate(float4x4 mat, float3 translation)
float3x3 rotate(float3x3 mat, AxisAngle rotation)
const int state
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_ALL
@ ATTR_STD_UV
@ ATTR_STD_VERTEX_NORMAL
@ ATTR_STD_UV_TANGENT
@ ATTR_STD_UV_TANGENT_SIGN
@ ATTR_STD_POSITION
@ ATTR_STD_GENERATED
#define LOG_ERROR
Definition log.h:101
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()
Definition math_float4.h:13
#define T
@ BVH_TYPE_STATIC
Definition params.h:40
string path_dirname(const string &path)
Definition path.cpp:422
bool path_is_relative(const string &path)
Definition path.cpp:475
string path_join(const string &dir, const string &file)
Definition path.cpp:436
string path_filename(const string &path)
Definition path.cpp:399
#define make_float2
#define make_float4
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bool string_iequals(const string &a, const string &b)
Definition string.cpp:57
void string_split(vector< string > &tokens, const string &str, const string &separators, bool skip_empty_tokens)
Definition string.cpp:72
Type type
Definition node_type.h:129
static const NodeType * find(ustring name)
CreateFunc create
Definition node_type.h:133
ustring name
Definition node_type.h:128
ustring name
Definition graph/node.h:178
Scene * scene
Transform tfm
Shader * shader
float dicing_rate
packed_normal()=default
ccl_device_inline Transform transform_rotate(const float angle, float3 axis)
Definition transform.h:323
ccl_device_inline Transform transform_identity()
Definition transform.h:355
ccl_device_inline Transform transform_scale(const float3 s)
Definition transform.h:313
ccl_device_inline Transform transform_translate(const float3 t)
Definition transform.h:296