Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/attribute.cpp
| Show First 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | size_t Attribute::element_size(Geometry *geom, AttributePrimitive prim) const | ||||
| switch (element) { | switch (element) { | ||||
| case ATTR_ELEMENT_OBJECT: | case ATTR_ELEMENT_OBJECT: | ||||
| case ATTR_ELEMENT_MESH: | case ATTR_ELEMENT_MESH: | ||||
| case ATTR_ELEMENT_VOXEL: | case ATTR_ELEMENT_VOXEL: | ||||
| size = 1; | size = 1; | ||||
| break; | break; | ||||
| case ATTR_ELEMENT_VERTEX: | case ATTR_ELEMENT_VERTEX: | ||||
| if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) { | if (geom->is_mesh() || geom->is_volume()) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| size = mesh->get_verts().size() + mesh->get_num_ngons(); | size = mesh->get_verts().size() + mesh->get_num_ngons(); | ||||
| if (prim == ATTR_PRIM_SUBD) { | if (prim == ATTR_PRIM_SUBD) { | ||||
| size -= mesh->get_num_subd_verts(); | size -= mesh->get_num_subd_verts(); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case ATTR_ELEMENT_VERTEX_MOTION: | case ATTR_ELEMENT_VERTEX_MOTION: | ||||
| if (geom->geometry_type == Geometry::MESH) { | if (geom->is_mesh()) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| size = (mesh->get_verts().size() + mesh->get_num_ngons()) * (mesh->get_motion_steps() - 1); | size = (mesh->get_verts().size() + mesh->get_num_ngons()) * (mesh->get_motion_steps() - 1); | ||||
| if (prim == ATTR_PRIM_SUBD) { | if (prim == ATTR_PRIM_SUBD) { | ||||
| size -= mesh->get_num_subd_verts() * (mesh->get_motion_steps() - 1); | size -= mesh->get_num_subd_verts() * (mesh->get_motion_steps() - 1); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case ATTR_ELEMENT_FACE: | case ATTR_ELEMENT_FACE: | ||||
| if (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME) { | if (geom->is_mesh() || geom->is_volume()) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| if (prim == ATTR_PRIM_GEOMETRY) { | if (prim == ATTR_PRIM_GEOMETRY) { | ||||
| size = mesh->num_triangles(); | size = mesh->num_triangles(); | ||||
| } | } | ||||
| else { | else { | ||||
| size = mesh->get_num_subd_faces() + mesh->get_num_ngons(); | size = mesh->get_num_subd_faces() + mesh->get_num_ngons(); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case ATTR_ELEMENT_CORNER: | case ATTR_ELEMENT_CORNER: | ||||
| case ATTR_ELEMENT_CORNER_BYTE: | case ATTR_ELEMENT_CORNER_BYTE: | ||||
| if (geom->geometry_type == Geometry::MESH) { | if (geom->is_mesh()) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| if (prim == ATTR_PRIM_GEOMETRY) { | if (prim == ATTR_PRIM_GEOMETRY) { | ||||
| size = mesh->num_triangles() * 3; | size = mesh->num_triangles() * 3; | ||||
| } | } | ||||
| else { | else { | ||||
| size = mesh->get_subd_face_corners().size() + mesh->get_num_ngons(); | size = mesh->get_subd_face_corners().size() + mesh->get_num_ngons(); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case ATTR_ELEMENT_CURVE: | case ATTR_ELEMENT_CURVE: | ||||
| if (geom->geometry_type == Geometry::HAIR) { | if (geom->is_hair()) { | ||||
| Hair *hair = static_cast<Hair *>(geom); | Hair *hair = static_cast<Hair *>(geom); | ||||
| size = hair->num_curves(); | size = hair->num_curves(); | ||||
| } | } | ||||
| break; | break; | ||||
| case ATTR_ELEMENT_CURVE_KEY: | case ATTR_ELEMENT_CURVE_KEY: | ||||
| if (geom->geometry_type == Geometry::HAIR) { | if (geom->is_hair()) { | ||||
| Hair *hair = static_cast<Hair *>(geom); | Hair *hair = static_cast<Hair *>(geom); | ||||
| size = hair->get_curve_keys().size(); | size = hair->get_curve_keys().size(); | ||||
| } | } | ||||
| break; | break; | ||||
| case ATTR_ELEMENT_CURVE_KEY_MOTION: | case ATTR_ELEMENT_CURVE_KEY_MOTION: | ||||
| if (geom->geometry_type == Geometry::HAIR) { | if (geom->is_hair()) { | ||||
| Hair *hair = static_cast<Hair *>(geom); | Hair *hair = static_cast<Hair *>(geom); | ||||
| size = hair->get_curve_keys().size() * (hair->get_motion_steps() - 1); | size = hair->get_curve_keys().size() * (hair->get_motion_steps() - 1); | ||||
| } | } | ||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element) | Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element) | ||||
| { | { | ||||
| Attribute *attr = find(name); | Attribute *attr = find(name); | ||||
| if (attr) { | if (attr) { | ||||
| /* return if same already exists */ | /* return if same already exists */ | ||||
| if (attr->type == type && attr->element == element) | if (attr->get_type() == type && attr->get_element() == element) | ||||
| return attr; | return attr; | ||||
| /* overwrite attribute with same name but different type/element */ | /* overwrite attribute with same name but different type/element */ | ||||
| remove(name); | remove(name); | ||||
| } | } | ||||
| Attribute new_attr(name, type, element, geometry, prim); | Attribute new_attr(name, type, element, geometry, prim); | ||||
| attributes.emplace_back(std::move(new_attr)); | attributes.emplace_back(std::move(new_attr)); | ||||
| return &attributes.back(); | return &attributes.back(); | ||||
| } | } | ||||
| Attribute *AttributeSet::find(ustring name) const | Attribute *AttributeSet::find(ustring name) const | ||||
| { | { | ||||
| foreach (const Attribute &attr, attributes) | foreach (const Attribute &attr, attributes) | ||||
| if (attr.name == name) | if (attr.get_name() == name) | ||||
| return (Attribute *)&attr; | return (Attribute *)&attr; | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| void AttributeSet::remove(ustring name) | void AttributeSet::remove(ustring name) | ||||
| { | { | ||||
| Attribute *attr = find(name); | Attribute *attr = find(name); | ||||
| Show All 12 Lines | |||||
| Attribute *AttributeSet::add(AttributeStandard std, ustring name) | Attribute *AttributeSet::add(AttributeStandard std, ustring name) | ||||
| { | { | ||||
| Attribute *attr = NULL; | Attribute *attr = NULL; | ||||
| if (name == ustring()) | if (name == ustring()) | ||||
| name = Attribute::standard_name(std); | name = Attribute::standard_name(std); | ||||
| if (geometry->geometry_type == Geometry::MESH) { | if (geometry->is_mesh()) { | ||||
| switch (std) { | switch (std) { | ||||
| case ATTR_STD_VERTEX_NORMAL: | case ATTR_STD_VERTEX_NORMAL: | ||||
| attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX); | attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX); | ||||
| break; | break; | ||||
| case ATTR_STD_FACE_NORMAL: | case ATTR_STD_FACE_NORMAL: | ||||
| attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE); | attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE); | ||||
| break; | break; | ||||
| case ATTR_STD_UV: | case ATTR_STD_UV: | ||||
| Show All 34 Lines | switch (std) { | ||||
| case ATTR_STD_RANDOM_PER_ISLAND: | case ATTR_STD_RANDOM_PER_ISLAND: | ||||
| attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_FACE); | attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_FACE); | ||||
| break; | break; | ||||
| default: | default: | ||||
| assert(0); | assert(0); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (geometry->geometry_type == Geometry::VOLUME) { | else if (geometry->is_volume()) { | ||||
| switch (std) { | switch (std) { | ||||
| case ATTR_STD_VERTEX_NORMAL: | case ATTR_STD_VERTEX_NORMAL: | ||||
| attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX); | attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX); | ||||
| break; | break; | ||||
| case ATTR_STD_FACE_NORMAL: | case ATTR_STD_FACE_NORMAL: | ||||
| attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE); | attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE); | ||||
| break; | break; | ||||
| case ATTR_STD_VOLUME_DENSITY: | case ATTR_STD_VOLUME_DENSITY: | ||||
| case ATTR_STD_VOLUME_FLAME: | case ATTR_STD_VOLUME_FLAME: | ||||
| case ATTR_STD_VOLUME_HEAT: | case ATTR_STD_VOLUME_HEAT: | ||||
| case ATTR_STD_VOLUME_TEMPERATURE: | case ATTR_STD_VOLUME_TEMPERATURE: | ||||
| attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL); | attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL); | ||||
| break; | break; | ||||
| case ATTR_STD_VOLUME_COLOR: | case ATTR_STD_VOLUME_COLOR: | ||||
| attr = add(name, TypeDesc::TypeColor, ATTR_ELEMENT_VOXEL); | attr = add(name, TypeDesc::TypeColor, ATTR_ELEMENT_VOXEL); | ||||
| break; | break; | ||||
| case ATTR_STD_VOLUME_VELOCITY: | case ATTR_STD_VOLUME_VELOCITY: | ||||
| attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_VOXEL); | attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_VOXEL); | ||||
| break; | break; | ||||
| default: | default: | ||||
| assert(0); | assert(0); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (geometry->geometry_type == Geometry::HAIR) { | else if (geometry->is_hair()) { | ||||
| switch (std) { | switch (std) { | ||||
| case ATTR_STD_UV: | case ATTR_STD_UV: | ||||
| attr = add(name, TypeFloat2, ATTR_ELEMENT_CURVE); | attr = add(name, TypeFloat2, ATTR_ELEMENT_CURVE); | ||||
| break; | break; | ||||
| case ATTR_STD_GENERATED: | case ATTR_STD_GENERATED: | ||||
| attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE); | attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE); | ||||
| break; | break; | ||||
| case ATTR_STD_MOTION_VERTEX_POSITION: | case ATTR_STD_MOTION_VERTEX_POSITION: | ||||
| Show All 15 Lines | switch (std) { | ||||
| attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_FACE); | attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_FACE); | ||||
| break; | break; | ||||
| default: | default: | ||||
| assert(0); | assert(0); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| attr->std = std; | attr->set_std(std); | ||||
| return attr; | return attr; | ||||
| } | } | ||||
| Attribute *AttributeSet::find(AttributeStandard std) const | Attribute *AttributeSet::find(AttributeStandard std) const | ||||
| { | { | ||||
| foreach (const Attribute &attr, attributes) | foreach (const Attribute &attr, attributes) | ||||
| if (attr.std == std) | if (attr.get_std() == std) | ||||
| return (Attribute *)&attr; | return (Attribute *)&attr; | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| void AttributeSet::remove(AttributeStandard std) | void AttributeSet::remove(AttributeStandard std) | ||||
| { | { | ||||
| Attribute *attr = find(std); | Attribute *attr = find(std); | ||||
| if (attr) { | if (attr) { | ||||
| list<Attribute>::iterator it; | list<Attribute>::iterator it; | ||||
| for (it = attributes.begin(); it != attributes.end(); it++) { | for (it = attributes.begin(); it != attributes.end(); it++) { | ||||
| if (&*it == attr) { | if (&*it == attr) { | ||||
| attributes.erase(it); | attributes.erase(it); | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Attribute *AttributeSet::find(AttributeRequest &req) | Attribute *AttributeSet::find(const AttributeRequest &req) | ||||
| { | { | ||||
| if (req.std == ATTR_STD_NONE) | if (req.get_std() == ATTR_STD_NONE) | ||||
| return find(req.name); | return find(req.get_name()); | ||||
| else | else | ||||
| return find(req.std); | return find(req.get_std()); | ||||
| } | } | ||||
| void AttributeSet::remove(Attribute *attribute) | void AttributeSet::remove(Attribute *attribute) | ||||
| { | { | ||||
| if (attribute->std == ATTR_STD_NONE) { | if (attribute->get_std() == ATTR_STD_NONE) { | ||||
| remove(attribute->name); | remove(attribute->get_name()); | ||||
| } | } | ||||
| else { | else { | ||||
| remove(attribute->std); | remove(attribute->get_std()); | ||||
| } | } | ||||
| } | } | ||||
| void AttributeSet::resize(bool reserve_only) | void AttributeSet::resize(bool reserve_only) | ||||
| { | { | ||||
| foreach (Attribute &attr, attributes) { | foreach (Attribute &attr, attributes) { | ||||
| attr.resize(geometry, prim, reserve_only); | attr.resize(geometry, prim, reserve_only); | ||||
| } | } | ||||
| } | } | ||||
| void AttributeSet::clear(bool preserve_voxel_data) | void AttributeSet::clear(bool preserve_voxel_data) | ||||
| { | { | ||||
| if (preserve_voxel_data) { | if (preserve_voxel_data) { | ||||
| list<Attribute>::iterator it; | list<Attribute>::iterator it; | ||||
| for (it = attributes.begin(); it != attributes.end();) { | for (it = attributes.begin(); it != attributes.end();) { | ||||
| if (it->element == ATTR_ELEMENT_VOXEL || it->std == ATTR_STD_GENERATED_TRANSFORM) { | if (it->get_element() == ATTR_ELEMENT_VOXEL || | ||||
| it->get_std() == ATTR_STD_GENERATED_TRANSFORM) { | |||||
| it++; | it++; | ||||
| } | } | ||||
| else { | else { | ||||
| attributes.erase(it++); | attributes.erase(it++); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| if (requests.size() != other.requests.size()) | if (requests.size() != other.requests.size()) | ||||
| return true; | return true; | ||||
| for (size_t i = 0; i < requests.size(); i++) { | for (size_t i = 0; i < requests.size(); i++) { | ||||
| bool found = false; | bool found = false; | ||||
| for (size_t j = 0; j < requests.size() && !found; j++) | for (size_t j = 0; j < requests.size() && !found; j++) | ||||
| if (requests[i].name == other.requests[j].name && requests[i].std == other.requests[j].std) { | if (requests[i].get_name() == other.requests[j].get_name() && | ||||
| requests[i].get_std() == other.requests[j].get_std()) { | |||||
| found = true; | found = true; | ||||
| } | } | ||||
| if (!found) { | if (!found) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void AttributeRequestSet::add(ustring name) | void AttributeRequestSet::add(ustring name) | ||||
| { | { | ||||
| foreach (AttributeRequest &req, requests) { | foreach (AttributeRequest &req, requests) { | ||||
| if (req.name == name) { | if (req.get_name() == name) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| requests.push_back(AttributeRequest(name)); | requests.push_back(AttributeRequest(name)); | ||||
| } | } | ||||
| void AttributeRequestSet::add(AttributeStandard std) | void AttributeRequestSet::add(AttributeStandard std) | ||||
| { | { | ||||
| foreach (AttributeRequest &req, requests) | foreach (AttributeRequest &req, requests) | ||||
| if (req.std == std) | if (req.get_std() == std) | ||||
| return; | return; | ||||
| requests.push_back(AttributeRequest(std)); | requests.push_back(AttributeRequest(std)); | ||||
| } | } | ||||
| void AttributeRequestSet::add(AttributeRequestSet &reqs) | void AttributeRequestSet::add(AttributeRequestSet &reqs) | ||||
| { | { | ||||
| foreach (AttributeRequest &req, reqs.requests) { | foreach (AttributeRequest &req, reqs.requests) { | ||||
| if (req.std == ATTR_STD_NONE) | if (req.get_std() == ATTR_STD_NONE) | ||||
| add(req.name); | add(req.get_name()); | ||||
| else | else | ||||
| add(req.std); | add(req.get_std()); | ||||
| } | } | ||||
| } | } | ||||
| void AttributeRequestSet::add_standard(ustring name) | void AttributeRequestSet::add_standard(ustring name) | ||||
| { | { | ||||
| if (name.empty()) { | if (name.empty()) { | ||||
| return; | return; | ||||
| } | } | ||||
| AttributeStandard std = Attribute::name_standard(name.c_str()); | AttributeStandard std = Attribute::name_standard(name.c_str()); | ||||
| if (std) { | if (std) { | ||||
| add(std); | add(std); | ||||
| } | } | ||||
| else { | else { | ||||
| add(name); | add(name); | ||||
| } | } | ||||
| } | } | ||||
| bool AttributeRequestSet::find(ustring name) | bool AttributeRequestSet::find(ustring name) | ||||
| { | { | ||||
| foreach (AttributeRequest &req, requests) | foreach (AttributeRequest &req, requests) | ||||
| if (req.name == name) | if (req.get_name() == name) | ||||
| return true; | return true; | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool AttributeRequestSet::find(AttributeStandard std) | bool AttributeRequestSet::find(AttributeStandard std) | ||||
| { | { | ||||
| foreach (AttributeRequest &req, requests) | foreach (AttributeRequest &req, requests) | ||||
| if (req.std == std) | if (req.get_std() == std) | ||||
| return true; | return true; | ||||
| return false; | return false; | ||||
| } | } | ||||
| size_t AttributeRequestSet::size() | size_t AttributeRequestSet::size() | ||||
| { | { | ||||
| return requests.size(); | return requests.size(); | ||||
| } | } | ||||
| void AttributeRequestSet::clear() | void AttributeRequestSet::clear() | ||||
| { | { | ||||
| requests.clear(); | requests.clear(); | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||