55 const xml_attribute attr =
node.attribute(name);
58 *value = atoi(attr.value());
67 const xml_attribute attr =
node.attribute(name);
73 for (
const string &token : tokens) {
74 value.push_back(atoi(token.c_str()));
85 const xml_attribute attr =
node.attribute(name);
88 *value = (
float)atof(attr.value());
97 const xml_attribute attr =
node.attribute(name);
103 for (
const string &token : tokens) {
104 value.push_back((
float)atof(token.c_str()));
132 for (
size_t i = 0; i <
array.
size(); i += 3) {
156 const xml_attribute attr =
node.attribute(name);
168 const xml_attribute attr =
node.attribute(name);
188 cam->set_full_width(width);
189 cam->set_full_height(height);
193 cam->set_matrix(
state.tfm);
203 xml_read_node(
state, shader, graph_node);
208 XMLReader graph_reader;
209 graph_reader.node_map[ustring(
"output")] = graph->output();
211 for (xml_node
node = graph_node.first_child();
node;
node =
node.next_sibling()) {
212 ustring node_name(
node.name());
214 if (node_name ==
"connect") {
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]);
232 if (graph_reader.node_map.contains(from_node_name)) {
242 LOG_ERROR <<
"Unknown output socket name \"" << from_node_name <<
"\" on \""
243 << from_socket_name <<
"\".";
247 LOG_ERROR <<
"Unknown shader node name \"" << from_node_name <<
"\"";
250 if (graph_reader.node_map.contains(to_node_name)) {
254 if (
string_iequals(
in->socket_type.name.string(), to_socket_name.string())) {
260 LOG_ERROR <<
"Unknown input socket name \"" << to_socket_name <<
"\" on \""
261 << to_node_name <<
"\"";
265 LOG_ERROR <<
"Unknown shader node name \"" << to_node_name <<
"\"";
270 graph->connect(
output, input);
274 LOG_ERROR <<
"Invalid from or to value for connect node.";
283 if (node_name ==
"osl_shader") {
287 std::string filepath;
294 snode = OSLShaderManager::osl_node(graph.get(),
state.scene, filepath,
"");
297 LOG_ERROR <<
"Failed to create OSL node from \"" << filepath <<
"\"";
302 LOG_ERROR <<
"OSL node missing \"src\" attribute.";
307 LOG_ERROR <<
"OSL node without using --shadingsys osl.";
315 if (node_name ==
"background") {
316 node_name =
"background_shader";
322 LOG_ERROR <<
"Unknown shader node \"" <<
node.name() <<
"\"";
326 LOG_ERROR <<
"Node type \"" << node_type->
name <<
"\" is not a shader node";
329 if (node_type->
create ==
nullptr) {
330 LOG_ERROR <<
"Can't create abstract node type \""
335 snode = graph->create_node(node_type);
338 xml_read_node(graph_reader, snode,
node);
340 if (node_name ==
"image_texture") {
342 const ustring filename(
path_join(
state.base, img->get_filename().string()));
343 img->set_filename(filename);
345 else if (node_name ==
"environment_texture") {
347 const ustring filename(
path_join(
state.base, env->get_filename().string()));
348 env->set_filename(filename);
378 if (
object && object->get_geometry()->is_mesh()) {
380 object->set_tfm(tfm);
381 Geometry *geometry =
object->get_geometry();
382 return static_cast<Mesh *
>(geometry);
390 object->set_geometry(mesh);
402 mesh->set_used_shaders(used_shaders);
405 const int shader = 0;
431 size_t num_triangles = 0;
432 for (
size_t i = 0; i < nverts.size(); i++) {
433 num_triangles += nverts[i] - 2;
438 int *triangles = mesh->get_triangles().data();
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];
454 triangles[tri_index * 3 + 0] = v0;
455 triangles[tri_index * 3 + 1] = v1;
456 triangles[tri_index * 3 + 2] = v2;
460 index_offset += nverts[i];
462 std::ranges::fill(mesh->get_smooth(),
smooth);
463 std::ranges::fill(mesh->get_shader(), shader);
465 mesh->tag_triangles_modified();
466 mesh->tag_shader_modified();
467 mesh->tag_smooth_modified();
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;
496 assert(v0 * 2 + 1 < (
int)UV.size());
497 assert(v1 * 2 + 1 < (
int)UV.size());
498 assert(v2 * 2 + 1 < (
int)UV.size());
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]);
506 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 const int v0 = index_offset;
520 const int v1 = index_offset + j + 1;
521 const int v2 = index_offset + j + 2;
523 assert(v0 * 3 + 2 < (
int)
T.size());
524 assert(v1 * 3 + 2 < (
int)
T.size());
525 assert(v2 * 3 + 2 < (
int)
T.size());
532 index_offset += nverts[i];
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;
549 assert(v0 < (
int)TS.size());
550 assert(v1 < (
int)TS.size());
551 assert(v2 < (
int)TS.size());
558 index_offset += nverts[i];
566 size_t num_corners = 0;
567 for (
size_t i = 0; i < nverts.size(); i++) {
568 num_corners += nverts[i];
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();
581 std::ranges::fill(mesh->get_subd_shader(), shader);
582 std::ranges::fill(mesh->get_subd_smooth(),
smooth);
584 std::ranges::copy(verts, subd_face_corners);
587 int corner_index = 0;
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];
595 subd_ptex_offset[i] = ptex_offset;
596 const int num_ptex = (nverts[i] == 4) ? 1 : nverts[i];
597 ptex_offset += num_ptex;
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();
614 int index_offset = 0;
615 for (
size_t i = 0; i < nverts.size(); i++) {
616 for (
int j = 0; j < nverts[i]; j++) {
623 float dicing_rate =
state.dicing_rate;
625 dicing_rate = std::max(0.1f, dicing_rate);
627 mesh->set_subd_dicing_rate(dicing_rate);
628 mesh->set_subd_objecttoworld(
state.tfm);
652 if (light_type ==
"point") {
655 else if (light_type ==
"sun") {
658 else if (light_type ==
"background") {
661 else if (light_type ==
"area") {
665 assert(light_type ==
"spot");
671 light->set_used_shaders(used_shaders);
677 object->set_geometry(light);
686 if (
node.attribute(
"matrix")) {
694 if (
node.attribute(
"translate")) {
700 if (
node.attribute(
"rotate")) {
706 if (
node.attribute(
"scale")) {
724 if (shader->
name == shadername) {
725 state.shader = shader;
732 LOG_ERROR <<
"Unknown shader \"" << shadername <<
"\"";
743 if (object->
name == objectname) {
744 state.object = object;
751 LOG_ERROR <<
"Unknown object \"" << objectname <<
"\"";
762 state.smooth =
false;
777 object->set_geometry(mesh);
789 for (xml_node
node = scene_node.first_child();
node;
node =
node.next_sibling()) {
848 xml_parse_result parse_result;
851 parse_result = doc.load_file(path.c_str());
857 const xml_node cycles = doc.child(
"cycles");
861 LOG_ERROR <<
"\"" << src <<
"\" read error: " << parse_result.description();
875 state.smooth =
false;
876 state.dicing_rate = 1.0f;
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)
void update(Scene *scene)
const packed_float3 * get_position() const
bool need_attribute(const Scene *scene, AttributeStandard std)
packed_float3 * get_position_for_write()
NODE_DECLARE size_t num_verts() const
AttributeSet subd_attributes
@ SUBDIVISION_CATMULL_CLARK
void resize_subd_faces(const int numfaces, const int numcorners)
void resize_mesh(const int numverts, const int numtris)
void set_tfm(Transform tfm)
T * create_node(Args &&...)=delete
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_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
#define assert(assertion)
float3x3 scale(float3x3 mat, float2 scale)
float4x4 translate(float4x4 mat, float3 translation)
float3x3 rotate(float3x3 mat, AxisAngle rotation)
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_ALL
@ ATTR_STD_UV_TANGENT_SIGN
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()
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)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
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 NodeType * find(ustring name)