Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/app/cycles_xml.cpp
| Context not available. | |||||
| return false; | return false; | ||||
| } | } | ||||
| static bool xml_read_float_array(vector<float> &value, xml_node node, const char *name) | static bool xml_read_float_array(array<float> &value, xml_node node, const char *name) | ||||
| { | { | ||||
| xml_attribute attr = node.attribute(name); | xml_attribute attr = node.attribute(name); | ||||
| Context not available. | |||||
| string_split(tokens, attr.value()); | string_split(tokens, attr.value()); | ||||
| foreach (const string &token, tokens) | foreach (const string &token, tokens) | ||||
| value.push_back((float)atof(token.c_str())); | value.push_back_slow((float)atof(token.c_str())); | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| static bool xml_read_float3(float3 *value, xml_node node, const char *name) | static bool xml_read_float3(float3 *value, xml_node node, const char *name) | ||||
| { | { | ||||
| vector<float> array; | array<float> array; | ||||
| if (xml_read_float_array(array, node, name) && array.size() == 3) { | if (xml_read_float_array(array, node, name) && array.size() == 3) { | ||||
| *value = make_float3(array[0], array[1], array[2]); | *value = make_float3(array[0], array[1], array[2]); | ||||
| Context not available. | |||||
| return false; | return false; | ||||
| } | } | ||||
| static bool xml_read_float3_array(vector<float3> &value, xml_node node, const char *name) | static bool xml_read_float3_array(array<float3> &value, xml_node node, const char *name) | ||||
| { | { | ||||
| vector<float> array; | array<float> array; | ||||
| if (xml_read_float_array(array, node, name)) { | if (xml_read_float_array(array, node, name)) { | ||||
| value.reserve(array.size() / 3); | |||||
| for (size_t i = 0; i < array.size(); i += 3) | for (size_t i = 0; i < array.size(); i += 3) | ||||
| value.push_back(make_float3(array[i + 0], array[i + 1], array[i + 2])); | value.push_back_reserved(make_float3(array[i + 0], array[i + 1], array[i + 2])); | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| static bool xml_read_float4(float4 *value, xml_node node, const char *name) | static bool xml_read_float4(float4 *value, xml_node node, const char *name) | ||||
| { | { | ||||
| vector<float> array; | array<float> array; | ||||
| if (xml_read_float_array(array, node, name) && array.size() == 4) { | if (xml_read_float_array(array, node, name) && array.size() == 4) { | ||||
| *value = make_float4(array[0], array[1], array[2], array[3]); | *value = make_float4(array[0], array[1], array[2], array[3]); | ||||
| Context not available. | |||||
| { | { | ||||
| Camera *cam = state.scene->camera; | Camera *cam = state.scene->camera; | ||||
| xml_read_int(&cam->width, node, "width"); | int width = 0, height = 0; | ||||
| xml_read_int(&cam->height, node, "height"); | xml_read_int(&width, node, "width"); | ||||
| xml_read_int(&height, node, "height"); | |||||
| cam->full_width = cam->width; | cam->set_screen_size_and_resolution(width, height, 1); | ||||
| cam->full_height = cam->height; | |||||
| xml_read_node(state, cam, node); | xml_read_node(state, cam, node); | ||||
| cam->matrix = state.tfm; | cam->set_matrix(state.tfm); | ||||
| cam->need_update = true; | |||||
| cam->update(state.scene); | cam->update(state.scene); | ||||
| } | } | ||||
| Context not available. | |||||
| if (node_name == "image_texture") { | if (node_name == "image_texture") { | ||||
| ImageTextureNode *img = (ImageTextureNode *)snode; | ImageTextureNode *img = (ImageTextureNode *)snode; | ||||
| img->filename = path_join(state.base, img->filename.string()); | img->set_filename(ustring(path_join(state.base, img->get_filename().string()))); | ||||
| } | } | ||||
| else if (node_name == "environment_texture") { | else if (node_name == "environment_texture") { | ||||
| EnvironmentTextureNode *env = (EnvironmentTextureNode *)snode; | EnvironmentTextureNode *env = (EnvironmentTextureNode *)snode; | ||||
| env->filename = path_join(state.base, env->filename.string()); | env->set_filename(ustring(path_join(state.base, env->get_filename().string()))); | ||||
| } | } | ||||
| if (snode) { | if (snode) { | ||||
| Context not available. | |||||
| /* create object*/ | /* create object*/ | ||||
| Object *object = new Object(); | Object *object = new Object(); | ||||
| object->geometry = mesh; | object->set_geometry(mesh); | ||||
| object->tfm = tfm; | object->set_tfm(tfm); | ||||
| scene->objects.push_back(object); | scene->objects.push_back(object); | ||||
| return mesh; | return mesh; | ||||
| Context not available. | |||||
| { | { | ||||
| /* add mesh */ | /* add mesh */ | ||||
| Mesh *mesh = xml_add_mesh(state.scene, state.tfm); | Mesh *mesh = xml_add_mesh(state.scene, state.tfm); | ||||
| mesh->used_shaders.push_back(state.shader); | mesh->get_used_shaders().push_back_slow(state.shader); | ||||
| /* read state */ | /* read state */ | ||||
| int shader = 0; | int shader = 0; | ||||
| bool smooth = state.smooth; | bool smooth = state.smooth; | ||||
| /* read vertices and polygons */ | /* read vertices and polygons */ | ||||
| vector<float3> P; | array<float3> P; | ||||
| vector<float> UV; | array<float> UV; | ||||
| vector<int> verts, nverts; | vector<int> verts, nverts; | ||||
| xml_read_float3_array(P, node, "P"); | xml_read_float3_array(P, node, "P"); | ||||
| Context not available. | |||||
| xml_read_int_array(nverts, node, "nverts"); | xml_read_int_array(nverts, node, "nverts"); | ||||
| if (xml_equal_string(node, "subdivision", "catmull-clark")) { | if (xml_equal_string(node, "subdivision", "catmull-clark")) { | ||||
| mesh->subdivision_type = Mesh::SUBDIVISION_CATMULL_CLARK; | mesh->set_subdivision_type(Mesh::SUBDIVISION_CATMULL_CLARK); | ||||
| } | } | ||||
| else if (xml_equal_string(node, "subdivision", "linear")) { | else if (xml_equal_string(node, "subdivision", "linear")) { | ||||
| mesh->subdivision_type = Mesh::SUBDIVISION_LINEAR; | mesh->set_subdivision_type(Mesh::SUBDIVISION_LINEAR); | ||||
| } | } | ||||
| if (mesh->subdivision_type == Mesh::SUBDIVISION_NONE) { | if (mesh->get_subdivision_type() == Mesh::SUBDIVISION_NONE) { | ||||
| /* create vertices */ | /* create vertices */ | ||||
| mesh->verts = P; | mesh->set_verts(P); | ||||
| size_t num_triangles = 0; | size_t num_triangles = 0; | ||||
| for (size_t i = 0; i < nverts.size(); i++) | for (size_t i = 0; i < nverts.size(); i++) | ||||
| num_triangles += nverts[i] - 2; | num_triangles += nverts[i] - 2; | ||||
| mesh->reserve_mesh(mesh->verts.size(), num_triangles); | mesh->reserve_mesh(mesh->get_verts().size(), num_triangles); | ||||
| /* create triangles */ | /* create triangles */ | ||||
| int index_offset = 0; | int index_offset = 0; | ||||
| Context not available. | |||||
| int v1 = verts[index_offset + j + 1]; | int v1 = verts[index_offset + j + 1]; | ||||
| int v2 = verts[index_offset + j + 2]; | int v2 = verts[index_offset + j + 2]; | ||||
| assert(v0 < (int)P.size()); | assert(v0 < (int)mesh->get_verts().size()); | ||||
| assert(v1 < (int)P.size()); | assert(v1 < (int)mesh->get_verts().size()); | ||||
| assert(v2 < (int)P.size()); | assert(v2 < (int)mesh->get_verts().size()); | ||||
| mesh->add_triangle(v0, v1, v2, shader, smooth); | mesh->add_triangle(v0, v1, v2, shader, smooth); | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| else { | else { | ||||
| /* create vertices */ | /* create vertices */ | ||||
| mesh->verts = P; | mesh->set_verts(P); | ||||
| size_t num_ngons = 0; | size_t num_ngons = 0; | ||||
| size_t num_corners = 0; | size_t num_corners = 0; | ||||
| Context not available. | |||||
| } | } | ||||
| /* setup subd params */ | /* setup subd params */ | ||||
| if (!mesh->subd_params) { | if (!mesh->get_subd_params()) { | ||||
| mesh->subd_params = new SubdParams(mesh); | mesh->set_subd_params(new SubdParams{mesh}); | ||||
| } | } | ||||
| SubdParams &sdparams = *mesh->subd_params; | SubdParams &sdparams = *mesh->get_subd_params(); | ||||
| sdparams.dicing_rate = state.dicing_rate; | sdparams.dicing_rate = state.dicing_rate; | ||||
| xml_read_float(&sdparams.dicing_rate, node, "dicing_rate"); | xml_read_float(&sdparams.dicing_rate, node, "dicing_rate"); | ||||
| Context not available. | |||||
| * coordinates as generated coordinates if requested */ | * coordinates as generated coordinates if requested */ | ||||
| if (mesh->need_attribute(state.scene, ATTR_STD_GENERATED)) { | if (mesh->need_attribute(state.scene, ATTR_STD_GENERATED)) { | ||||
| Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED); | Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED); | ||||
| memcpy(attr->data_float3(), mesh->verts.data(), sizeof(float3) * mesh->verts.size()); | memcpy(attr->data_float3(), mesh->get_verts().data(), sizeof(float3) * mesh->get_verts().size()); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| Light *light = new Light(); | Light *light = new Light(); | ||||
| light->shader = state.shader; | light->set_shader(state.shader); | ||||
| xml_read_node(state, light, node); | xml_read_node(state, light, node); | ||||
| state.scene->lights.push_back(light); | state.scene->lights.push_back(light); | ||||
| Context not available. | |||||
| static void xml_read_transform(xml_node node, Transform &tfm) | static void xml_read_transform(xml_node node, Transform &tfm) | ||||
| { | { | ||||
| if (node.attribute("matrix")) { | if (node.attribute("matrix")) { | ||||
| vector<float> matrix; | array<float> matrix; | ||||
| if (xml_read_float_array(matrix, node, "matrix") && matrix.size() == 16) { | if (xml_read_float_array(matrix, node, "matrix") && matrix.size() == 16) { | ||||
| ProjectionTransform projection = *(ProjectionTransform *)&matrix[0]; | ProjectionTransform projection = *(ProjectionTransform *)&matrix[0]; | ||||
| tfm = tfm * projection_to_transform(projection_transpose(projection)); | tfm = tfm * projection_to_transform(projection_transpose(projection)); | ||||
| Context not available. | |||||