59static bool xml_read_int(
int *value, xml_node node,
const char *name)
61 xml_attribute attr = node.attribute(name);
64 *value = atoi(attr.value());
73 xml_attribute attr = node.attribute(name);
79 foreach (
const string &token, tokens)
80 value.push_back(atoi(token.c_str()));
90 xml_attribute attr = node.attribute(name);
93 *value = (
float)atof(attr.value());
102 xml_attribute attr = node.attribute(name);
108 foreach (
const string &token, tokens)
109 value.push_back((
float)atof(token.c_str()));
134 for (
size_t i = 0; i <
array.
size(); i += 3) {
158 xml_attribute attr = node.attribute(name);
170 xml_attribute attr = node.attribute(name);
185 int width = -1, height = -1;
189 cam->set_full_width(width);
190 cam->set_full_height(height);
194 cam->set_matrix(
state.tfm);
205 AlembicProcedural *proc =
state.scene->create_node<AlembicProcedural>();
208 for (xml_node node = graph_node.first_child();
node; node = node.next_sibling()) {
212 ustring object_path(path, 0);
213 AlembicObject *
object =
static_cast<AlembicObject *
>(
214 proc->get_or_create_object(object_path));
218 object->set_used_shaders(used_shaders);
235 graph_reader.
node_map[ustring(
"output")] = graph->output();
237 for (xml_node node = graph_node.first_child();
node; node = node.next_sibling()) {
238 ustring node_name(node.name());
240 if (node_name ==
"connect") {
244 string_split(from_tokens, node.attribute(
"from").value());
247 if (from_tokens.size() == 2 && to_tokens.size() == 2) {
248 ustring from_node_name(from_tokens[0]);
249 ustring from_socket_name(from_tokens[1]);
250 ustring to_node_name(to_tokens[0]);
251 ustring to_socket_name(to_tokens[1]);
257 if (graph_reader.
node_map.find(from_node_name) != graph_reader.
node_map.end()) {
261 if (
string_iequals(out->socket_type.name.string(), from_socket_name.string())) {
267 "Unknown output socket name \"%s\" on \"%s\".\n",
268 from_node_name.c_str(),
269 from_socket_name.c_str());
273 fprintf(stderr,
"Unknown shader node name \"%s\".\n", from_node_name.c_str());
276 if (graph_reader.
node_map.find(to_node_name) != graph_reader.
node_map.end()) {
280 if (
string_iequals(in->socket_type.name.string(), to_socket_name.string())) {
286 "Unknown input socket name \"%s\" on \"%s\".\n",
287 to_socket_name.c_str(),
288 to_node_name.c_str());
292 fprintf(stderr,
"Unknown shader node name \"%s\".\n", to_node_name.c_str());
296 if (output && input) {
297 graph->connect(output, input);
301 fprintf(stderr,
"Invalid from or to value for connect node.\n");
310 if (node_name ==
"osl_shader") {
314 std::string filepath;
321 snode = OSLShaderManager::osl_node(graph, manager, filepath,
"");
324 fprintf(stderr,
"Failed to create OSL node from \"%s\".\n", filepath.c_str());
329 fprintf(stderr,
"OSL node missing \"src\" attribute.\n");
334 fprintf(stderr,
"OSL node without using --shadingsys osl.\n");
342 if (node_name ==
"background") {
343 node_name =
"background_shader";
349 fprintf(stderr,
"Unknown shader node \"%s\".\n", node.name());
353 fprintf(stderr,
"Node type \"%s\" is not a shader node.\n", node_type->
name.c_str());
357 fprintf(stderr,
"Can't create abstract node type \"%s\".\n", node_type->
name.c_str());
367 if (node_name ==
"image_texture") {
369 ustring filename(
path_join(
state.base, img->get_filename().string()));
370 img->set_filename(filename);
372 else if (node_name ==
"environment_texture") {
374 ustring filename(
path_join(
state.base, env->get_filename().string()));
375 env->set_filename(filename);
384 shader->set_graph(graph);
385 shader->tag_update(
state.scene);
392 state.scene->shaders.push_back(shader);
411 if (
object && object->get_geometry()->is_mesh()) {
413 object->set_tfm(tfm);
414 Geometry *geometry =
object->get_geometry();
415 return static_cast<Mesh *
>(geometry);
420 scene->geometry.push_back(mesh);
424 object->set_geometry(mesh);
425 object->set_tfm(tfm);
426 scene->objects.push_back(
object);
438 mesh->set_used_shaders(used_shaders);
442 bool smooth =
state.smooth;
469 mesh->set_verts(P_array);
471 size_t num_triangles = 0;
472 for (
size_t i = 0; i < nverts.size(); i++) {
473 num_triangles += nverts[i] - 2;
475 mesh->reserve_mesh(mesh->get_verts().size(), num_triangles);
478 int index_offset = 0;
480 for (
size_t i = 0; i < nverts.size(); i++) {
481 for (
int j = 0; j < nverts[i] - 2; j++) {
482 int v0 =
verts[index_offset];
483 int v1 =
verts[index_offset + j + 1];
484 int v2 =
verts[index_offset + j + 2];
486 assert(v0 < (
int)
P.size());
487 assert(v1 < (
int)
P.size());
488 assert(
v2 < (
int)
P.size());
490 mesh->add_triangle(v0, v1,
v2, shader, smooth);
493 index_offset += nverts[i];
517 for (
size_t i = 0; i < nverts.size(); i++) {
518 for (
int j = 0; j < nverts[i] - 2; j++) {
519 int v0 = index_offset;
520 int v1 = index_offset + j + 1;
521 int v2 = index_offset + j + 2;
523 assert(v0 * 2 + 1 < (
int)UV.size());
524 assert(v1 * 2 + 1 < (
int)UV.size());
525 assert(
v2 * 2 + 1 < (
int)UV.size());
527 fdata[0] =
make_float2(UV[v0 * 2], UV[v0 * 2 + 1]);
528 fdata[1] =
make_float2(UV[v1 * 2], UV[v1 * 2 + 1]);
533 index_offset += nverts[i];
544 for (
size_t i = 0; i < nverts.size(); i++) {
545 for (
int j = 0; j < nverts[i] - 2; j++) {
546 int v0 = index_offset;
547 int v1 = index_offset + j + 1;
548 int v2 = index_offset + j + 2;
550 assert(v0 * 3 + 2 < (
int)T.size());
551 assert(v1 * 3 + 2 < (
int)T.size());
552 assert(
v2 * 3 + 2 < (
int)T.size());
554 fdata[0] =
make_float3(T[v0 * 3], T[v0 * 3 + 1], T[v0 * 3 + 2]);
555 fdata[1] =
make_float3(T[v1 * 3], T[v1 * 3 + 1], T[v1 * 3 + 2]);
559 index_offset += nverts[i];
570 for (
size_t i = 0; i < nverts.size(); i++) {
571 for (
int j = 0; j < nverts[i] - 2; j++) {
572 int v0 = index_offset;
573 int v1 = index_offset + j + 1;
574 int v2 = index_offset + j + 2;
576 assert(v0 < (
int)TS.size());
577 assert(v1 < (
int)TS.size());
578 assert(
v2 < (
int)TS.size());
585 index_offset += nverts[i];
591 mesh->set_verts(P_array);
593 size_t num_ngons = 0;
594 size_t num_corners = 0;
595 for (
size_t i = 0; i < nverts.size(); i++) {
596 num_ngons += (nverts[i] == 4) ? 0 : 1;
597 num_corners += nverts[i];
599 mesh->reserve_subd_faces(nverts.size(), num_ngons, num_corners);
602 int index_offset = 0;
604 for (
size_t i = 0; i < nverts.size(); i++) {
605 mesh->add_subd_face(&
verts[index_offset], nverts[i], shader, smooth);
606 index_offset += nverts[i];
623 for (
size_t i = 0; i < nverts.size(); i++) {
624 for (
int j = 0; j < nverts[i]; j++) {
631 float dicing_rate =
state.dicing_rate;
633 dicing_rate = std::max(0.1f, dicing_rate);
635 mesh->set_subd_dicing_rate(dicing_rate);
636 mesh->set_subd_objecttoworld(
state.tfm);
644 attr->
data_float3(), mesh->get_verts().data(),
sizeof(
float3) * mesh->get_verts().size());
654 light->set_shader(
state.shader);
657 state.scene->lights.push_back(light);
664 if (node.attribute(
"matrix")) {
672 if (node.attribute(
"translate")) {
678 if (node.attribute(
"rotate")) {
684 if (node.attribute(
"scale")) {
702 if (shader->name == shadername) {
703 state.shader = shader;
710 fprintf(stderr,
"Unknown shader \"%s\".\n", shadername.c_str());
721 if (object->name == objectname) {
722 state.object = object;
729 fprintf(stderr,
"Unknown object \"%s\".\n", objectname.c_str());
740 state.smooth =
false;
752 scene->geometry.push_back(mesh);
756 object->set_geometry(mesh);
757 object->set_tfm(
state.tfm);
761 scene->objects.push_back(
object);
770 for (xml_node node = scene_node.first_child();
node; node = node.next_sibling()) {
819 xml_read_alembic(
state, node);
823 fprintf(stderr,
"Unknown node \"%s\".\n", node.name());
834 xml_parse_result parse_result;
837 parse_result = doc.load_file(path.c_str());
843 xml_node cycles = doc.child(
"cycles");
847 fprintf(stderr,
"%s read error: %s\n", src.c_str(), parse_result.description());
860 state.shader = scene->default_surface;
861 state.smooth =
false;
862 state.dicing_rate = 1.0f;
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static const char * standard_name(AttributeStandard std)
vector< ShaderOutput * > outputs
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 bool xml_read_float4(float4 *value, xml_node node, const char *name)
static bool xml_read_float3(float3 *value, xml_node node, const char *name)
static void xml_read_include(XMLReadState &state, const string &src)
static void xml_read_object(XMLReadState &state, xml_node node)
static void xml_read_shader_graph(XMLReadState &state, Shader *shader, xml_node graph_node)
static bool xml_read_int_array(vector< int > &value, xml_node node, const char *name)
static bool xml_read_int(int *value, xml_node node, const char *name)
static bool xml_read_float_array(vector< float > &value, 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 bool xml_read_string(string *str, xml_node node, const char *name)
static void xml_read_mesh(const XMLReadState &state, xml_node node)
static bool xml_equal_string(xml_node node, const char *name, const char *value)
static bool xml_read_float3_array(vector< float3 > &value, xml_node node, const char *name)
static void xml_read_light(XMLReadState &state, xml_node node)
static void xml_read_state(XMLReadState &state, xml_node node)
static void xml_read_camera(XMLReadState &state, xml_node node)
static void xml_read_transform(xml_node node, Transform &tfm)
static bool xml_read_float(float *value, xml_node node, const char *name)
static void xml_read_scene(XMLReadState &state, xml_node scene_node)
static void xml_read_shader(XMLReadState &state, xml_node node)
static void xml_read_background(XMLReadState &state, xml_node node)
#define CCL_NAMESPACE_END
draw_view in_light_buf[] float
@ ATTR_STD_UV_TANGENT_SIGN
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()
void xml_read_node(XMLReader &reader, Node *node, xml_node xml_node)
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)
void update(Scene *scene)
@ SUBDIVISION_CATMULL_CLARK
static const NodeType * find(ustring name)
void set_owner(const NodeOwner *owner_)
map< ustring, Node * > node_map