Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/alembic/intern/abc_nurbs.cc
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/alembic/intern/abc_nurbs.cc')
-rw-r--r--source/blender/alembic/intern/abc_nurbs.cc453
1 files changed, 226 insertions, 227 deletions
diff --git a/source/blender/alembic/intern/abc_nurbs.cc b/source/blender/alembic/intern/abc_nurbs.cc
index 463396c0b65..c78cc4570c9 100644
--- a/source/blender/alembic/intern/abc_nurbs.cc
+++ b/source/blender/alembic/intern/abc_nurbs.cc
@@ -40,9 +40,9 @@ extern "C" {
using Alembic::AbcGeom::bool_t;
using Alembic::AbcGeom::FloatArraySample;
using Alembic::AbcGeom::FloatArraySamplePtr;
+using Alembic::AbcGeom::kWrapExisting;
using Alembic::AbcGeom::MetaData;
using Alembic::AbcGeom::P3fArraySamplePtr;
-using Alembic::AbcGeom::kWrapExisting;
using Alembic::AbcGeom::IBoolProperty;
using Alembic::AbcGeom::ICompoundProperty;
@@ -64,132 +64,132 @@ AbcNurbsWriter::AbcNurbsWriter(Object *ob,
ExportSettings &settings)
: AbcObjectWriter(ob, time_sampling, settings, parent)
{
- m_is_animated = isAnimated();
+ m_is_animated = isAnimated();
- /* if the object is static, use the default static time sampling */
- if (!m_is_animated) {
- m_time_sampling = 0;
- }
+ /* if the object is static, use the default static time sampling */
+ if (!m_is_animated) {
+ m_time_sampling = 0;
+ }
- Curve *curve = static_cast<Curve *>(m_object->data);
- size_t numNurbs = BLI_listbase_count(&curve->nurb);
+ Curve *curve = static_cast<Curve *>(m_object->data);
+ size_t numNurbs = BLI_listbase_count(&curve->nurb);
- for (size_t i = 0; i < numNurbs; ++i) {
- std::stringstream str;
- str << m_name << '_' << i;
+ for (size_t i = 0; i < numNurbs; ++i) {
+ std::stringstream str;
+ str << m_name << '_' << i;
- while (parent->alembicXform().getChildHeader(str.str())) {
- str << "_";
- }
+ while (parent->alembicXform().getChildHeader(str.str())) {
+ str << "_";
+ }
- ONuPatch nurbs(parent->alembicXform(), str.str().c_str(), m_time_sampling);
- m_nurbs_schema.push_back(nurbs.getSchema());
- }
+ ONuPatch nurbs(parent->alembicXform(), str.str().c_str(), m_time_sampling);
+ m_nurbs_schema.push_back(nurbs.getSchema());
+ }
}
bool AbcNurbsWriter::isAnimated() const
{
- /* check if object has shape keys */
- Curve *cu = static_cast<Curve *>(m_object->data);
- return (cu->key != NULL);
+ /* check if object has shape keys */
+ Curve *cu = static_cast<Curve *>(m_object->data);
+ return (cu->key != NULL);
}
static void get_knots(std::vector<float> &knots, const int num_knots, float *nu_knots)
{
- if (num_knots <= 1) {
- return;
- }
+ if (num_knots <= 1) {
+ return;
+ }
- /* Add an extra knot at the beginning and end of the array since most apps
- * require/expect them. */
- knots.reserve(num_knots + 2);
+ /* Add an extra knot at the beginning and end of the array since most apps
+ * require/expect them. */
+ knots.reserve(num_knots + 2);
- knots.push_back(0.0f);
+ knots.push_back(0.0f);
- for (int i = 0; i < num_knots; ++i) {
- knots.push_back(nu_knots[i]);
- }
+ for (int i = 0; i < num_knots; ++i) {
+ knots.push_back(nu_knots[i]);
+ }
- knots[0] = 2.0f * knots[1] - knots[2];
- knots.push_back(2.0f * knots[num_knots] - knots[num_knots - 1]);
+ knots[0] = 2.0f * knots[1] - knots[2];
+ knots.push_back(2.0f * knots[num_knots] - knots[num_knots - 1]);
}
void AbcNurbsWriter::do_write()
{
- /* we have already stored a sample for this object. */
- if (!m_first_frame && !m_is_animated) {
- return;
- }
-
- if (!ELEM(m_object->type, OB_SURF, OB_CURVE)) {
- return;
- }
-
- Curve *curve = static_cast<Curve *>(m_object->data);
- ListBase *nulb;
-
- if (m_object->runtime.curve_cache->deformed_nurbs.first != NULL) {
- nulb = &m_object->runtime.curve_cache->deformed_nurbs;
- }
- else {
- nulb = BKE_curve_nurbs_get(curve);
- }
-
- size_t count = 0;
- for (Nurb *nu = static_cast<Nurb *>(nulb->first); nu; nu = nu->next, ++count) {
- std::vector<float> knotsU;
- get_knots(knotsU, KNOTSU(nu), nu->knotsu);
-
- std::vector<float> knotsV;
- get_knots(knotsV, KNOTSV(nu), nu->knotsv);
-
- const int size = nu->pntsu * nu->pntsv;
- std::vector<Imath::V3f> positions(size);
- std::vector<float> weights(size);
-
- const BPoint *bp = nu->bp;
-
- for (int i = 0; i < size; ++i, ++bp) {
- copy_yup_from_zup(positions[i].getValue(), bp->vec);
- weights[i] = bp->vec[3];
- }
-
- ONuPatchSchema::Sample sample;
- sample.setUOrder(nu->orderu + 1);
- sample.setVOrder(nu->orderv + 1);
- sample.setPositions(positions);
- sample.setPositionWeights(weights);
- sample.setUKnot(FloatArraySample(knotsU));
- sample.setVKnot(FloatArraySample(knotsV));
- sample.setNu(nu->pntsu);
- sample.setNv(nu->pntsv);
-
- /* TODO(kevin): to accommodate other software we should duplicate control
- * points to indicate that a NURBS is cyclic. */
- OCompoundProperty user_props = m_nurbs_schema[count].getUserProperties();
-
- if ((nu->flagu & CU_NURB_ENDPOINT) != 0) {
- OBoolProperty prop(user_props, "endpoint_u");
- prop.set(true);
- }
-
- if ((nu->flagv & CU_NURB_ENDPOINT) != 0) {
- OBoolProperty prop(user_props, "endpoint_v");
- prop.set(true);
- }
-
- if ((nu->flagu & CU_NURB_CYCLIC) != 0) {
- OBoolProperty prop(user_props, "cyclic_u");
- prop.set(true);
- }
-
- if ((nu->flagv & CU_NURB_CYCLIC) != 0) {
- OBoolProperty prop(user_props, "cyclic_v");
- prop.set(true);
- }
-
- m_nurbs_schema[count].set(sample);
- }
+ /* we have already stored a sample for this object. */
+ if (!m_first_frame && !m_is_animated) {
+ return;
+ }
+
+ if (!ELEM(m_object->type, OB_SURF, OB_CURVE)) {
+ return;
+ }
+
+ Curve *curve = static_cast<Curve *>(m_object->data);
+ ListBase *nulb;
+
+ if (m_object->runtime.curve_cache->deformed_nurbs.first != NULL) {
+ nulb = &m_object->runtime.curve_cache->deformed_nurbs;
+ }
+ else {
+ nulb = BKE_curve_nurbs_get(curve);
+ }
+
+ size_t count = 0;
+ for (Nurb *nu = static_cast<Nurb *>(nulb->first); nu; nu = nu->next, ++count) {
+ std::vector<float> knotsU;
+ get_knots(knotsU, KNOTSU(nu), nu->knotsu);
+
+ std::vector<float> knotsV;
+ get_knots(knotsV, KNOTSV(nu), nu->knotsv);
+
+ const int size = nu->pntsu * nu->pntsv;
+ std::vector<Imath::V3f> positions(size);
+ std::vector<float> weights(size);
+
+ const BPoint *bp = nu->bp;
+
+ for (int i = 0; i < size; ++i, ++bp) {
+ copy_yup_from_zup(positions[i].getValue(), bp->vec);
+ weights[i] = bp->vec[3];
+ }
+
+ ONuPatchSchema::Sample sample;
+ sample.setUOrder(nu->orderu + 1);
+ sample.setVOrder(nu->orderv + 1);
+ sample.setPositions(positions);
+ sample.setPositionWeights(weights);
+ sample.setUKnot(FloatArraySample(knotsU));
+ sample.setVKnot(FloatArraySample(knotsV));
+ sample.setNu(nu->pntsu);
+ sample.setNv(nu->pntsv);
+
+ /* TODO(kevin): to accommodate other software we should duplicate control
+ * points to indicate that a NURBS is cyclic. */
+ OCompoundProperty user_props = m_nurbs_schema[count].getUserProperties();
+
+ if ((nu->flagu & CU_NURB_ENDPOINT) != 0) {
+ OBoolProperty prop(user_props, "endpoint_u");
+ prop.set(true);
+ }
+
+ if ((nu->flagv & CU_NURB_ENDPOINT) != 0) {
+ OBoolProperty prop(user_props, "endpoint_v");
+ prop.set(true);
+ }
+
+ if ((nu->flagu & CU_NURB_CYCLIC) != 0) {
+ OBoolProperty prop(user_props, "cyclic_u");
+ prop.set(true);
+ }
+
+ if ((nu->flagv & CU_NURB_CYCLIC) != 0) {
+ OBoolProperty prop(user_props, "cyclic_v");
+ prop.set(true);
+ }
+
+ m_nurbs_schema[count].set(sample);
+ }
}
/* ************************************************************************** */
@@ -197,179 +197,178 @@ void AbcNurbsWriter::do_write()
AbcNurbsReader::AbcNurbsReader(const IObject &object, ImportSettings &settings)
: AbcObjectReader(object, settings)
{
- getNurbsPatches(m_iobject);
- get_min_max_time(m_iobject, m_schemas[0].first, m_min_time, m_max_time);
+ getNurbsPatches(m_iobject);
+ get_min_max_time(m_iobject, m_schemas[0].first, m_min_time, m_max_time);
}
bool AbcNurbsReader::valid() const
{
- if (m_schemas.empty()) {
- return false;
- }
+ if (m_schemas.empty()) {
+ return false;
+ }
- std::vector<std::pair<INuPatchSchema, IObject>>::const_iterator it;
- for (it = m_schemas.begin(); it != m_schemas.end(); ++it) {
- const INuPatchSchema &schema = it->first;
+ std::vector<std::pair<INuPatchSchema, IObject>>::const_iterator it;
+ for (it = m_schemas.begin(); it != m_schemas.end(); ++it) {
+ const INuPatchSchema &schema = it->first;
- if (!schema.valid()) {
- return false;
- }
- }
+ if (!schema.valid()) {
+ return false;
+ }
+ }
- return true;
+ return true;
}
static bool set_knots(const FloatArraySamplePtr &knots, float *&nu_knots)
{
- if (!knots || knots->size() == 0) {
- return false;
- }
+ if (!knots || knots->size() == 0) {
+ return false;
+ }
- /* Skip first and last knots, as they are used for padding. */
- const size_t num_knots = knots->size() - 2;
- nu_knots = static_cast<float *>(MEM_callocN(num_knots * sizeof(float), "abc_setsplineknotsu"));
+ /* Skip first and last knots, as they are used for padding. */
+ const size_t num_knots = knots->size() - 2;
+ nu_knots = static_cast<float *>(MEM_callocN(num_knots * sizeof(float), "abc_setsplineknotsu"));
- for (size_t i = 0; i < num_knots; ++i) {
- nu_knots[i] = (*knots)[i + 1];
- }
+ for (size_t i = 0; i < num_knots; ++i) {
+ nu_knots[i] = (*knots)[i + 1];
+ }
- return true;
+ return true;
}
void AbcNurbsReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
{
- Curve *cu = static_cast<Curve *>(BKE_curve_add(bmain, "abc_curve", OB_SURF));
- cu->actvert = CU_ACT_NONE;
-
- std::vector<std::pair<INuPatchSchema, IObject>>::iterator it;
+ Curve *cu = static_cast<Curve *>(BKE_curve_add(bmain, "abc_curve", OB_SURF));
+ cu->actvert = CU_ACT_NONE;
- for (it = m_schemas.begin(); it != m_schemas.end(); ++it) {
- Nurb *nu = static_cast<Nurb *>(MEM_callocN(sizeof(Nurb), "abc_getnurb"));
- nu->flag = CU_SMOOTH;
- nu->type = CU_NURBS;
- nu->resolu = cu->resolu;
- nu->resolv = cu->resolv;
+ std::vector<std::pair<INuPatchSchema, IObject>>::iterator it;
- const INuPatchSchema &schema = it->first;
- INuPatchSchema::Sample smp;
- try {
- smp = schema.getValue(sample_sel);
- }
- catch(Alembic::Util::Exception &ex) {
- printf("Alembic: error reading nurbs sample for '%s/%s' at time %f: %s\n",
- m_iobject.getFullName().c_str(),
- schema.getName().c_str(),
- sample_sel.getRequestedTime(),
- ex.what());
- return;
- }
+ for (it = m_schemas.begin(); it != m_schemas.end(); ++it) {
+ Nurb *nu = static_cast<Nurb *>(MEM_callocN(sizeof(Nurb), "abc_getnurb"));
+ nu->flag = CU_SMOOTH;
+ nu->type = CU_NURBS;
+ nu->resolu = cu->resolu;
+ nu->resolv = cu->resolv;
+ const INuPatchSchema &schema = it->first;
+ INuPatchSchema::Sample smp;
+ try {
+ smp = schema.getValue(sample_sel);
+ }
+ catch (Alembic::Util::Exception &ex) {
+ printf("Alembic: error reading nurbs sample for '%s/%s' at time %f: %s\n",
+ m_iobject.getFullName().c_str(),
+ schema.getName().c_str(),
+ sample_sel.getRequestedTime(),
+ ex.what());
+ return;
+ }
- nu->orderu = smp.getUOrder() - 1;
- nu->orderv = smp.getVOrder() - 1;
- nu->pntsu = smp.getNumU();
- nu->pntsv = smp.getNumV();
+ nu->orderu = smp.getUOrder() - 1;
+ nu->orderv = smp.getVOrder() - 1;
+ nu->pntsu = smp.getNumU();
+ nu->pntsv = smp.getNumV();
- /* Read positions and weights. */
+ /* Read positions and weights. */
- const P3fArraySamplePtr positions = smp.getPositions();
- const FloatArraySamplePtr weights = smp.getPositionWeights();
+ const P3fArraySamplePtr positions = smp.getPositions();
+ const FloatArraySamplePtr weights = smp.getPositionWeights();
- const size_t num_points = positions->size();
+ const size_t num_points = positions->size();
- nu->bp = static_cast<BPoint *>(MEM_callocN(num_points * sizeof(BPoint), "abc_setsplinetype"));
+ nu->bp = static_cast<BPoint *>(MEM_callocN(num_points * sizeof(BPoint), "abc_setsplinetype"));
- BPoint *bp = nu->bp;
- float posw_in = 1.0f;
+ BPoint *bp = nu->bp;
+ float posw_in = 1.0f;
- for (int i = 0; i < num_points; ++i, ++bp) {
- const Imath::V3f &pos_in = (*positions)[i];
+ for (int i = 0; i < num_points; ++i, ++bp) {
+ const Imath::V3f &pos_in = (*positions)[i];
- if (weights) {
- posw_in = (*weights)[i];
- }
+ if (weights) {
+ posw_in = (*weights)[i];
+ }
- copy_zup_from_yup(bp->vec, pos_in.getValue());
- bp->vec[3] = posw_in;
- bp->f1 = SELECT;
- bp->radius = 1.0f;
- bp->weight = 1.0f;
- }
+ copy_zup_from_yup(bp->vec, pos_in.getValue());
+ bp->vec[3] = posw_in;
+ bp->f1 = SELECT;
+ bp->radius = 1.0f;
+ bp->weight = 1.0f;
+ }
- /* Read knots. */
+ /* Read knots. */
- if (!set_knots(smp.getUKnot(), nu->knotsu)) {
- BKE_nurb_knot_calc_u(nu);
- }
+ if (!set_knots(smp.getUKnot(), nu->knotsu)) {
+ BKE_nurb_knot_calc_u(nu);
+ }
- if (!set_knots(smp.getVKnot(), nu->knotsv)) {
- BKE_nurb_knot_calc_v(nu);
- }
+ if (!set_knots(smp.getVKnot(), nu->knotsv)) {
+ BKE_nurb_knot_calc_v(nu);
+ }
- /* Read flags. */
+ /* Read flags. */
- ICompoundProperty user_props = schema.getUserProperties();
+ ICompoundProperty user_props = schema.getUserProperties();
- if (has_property(user_props, "enpoint_u")) {
- nu->flagu |= CU_NURB_ENDPOINT;
- }
+ if (has_property(user_props, "enpoint_u")) {
+ nu->flagu |= CU_NURB_ENDPOINT;
+ }
- if (has_property(user_props, "enpoint_v")) {
- nu->flagv |= CU_NURB_ENDPOINT;
- }
+ if (has_property(user_props, "enpoint_v")) {
+ nu->flagv |= CU_NURB_ENDPOINT;
+ }
- if (has_property(user_props, "cyclic_u")) {
- nu->flagu |= CU_NURB_CYCLIC;
- }
+ if (has_property(user_props, "cyclic_u")) {
+ nu->flagu |= CU_NURB_CYCLIC;
+ }
- if (has_property(user_props, "cyclic_v")) {
- nu->flagv |= CU_NURB_CYCLIC;
- }
+ if (has_property(user_props, "cyclic_v")) {
+ nu->flagv |= CU_NURB_CYCLIC;
+ }
- BLI_addtail(BKE_curve_nurbs_get(cu), nu);
- }
+ BLI_addtail(BKE_curve_nurbs_get(cu), nu);
+ }
- BLI_strncpy(cu->id.name + 2, m_data_name.c_str(), m_data_name.size() + 1);
+ BLI_strncpy(cu->id.name + 2, m_data_name.c_str(), m_data_name.size() + 1);
- m_object = BKE_object_add_only_object(bmain, OB_SURF, m_object_name.c_str());
- m_object->data = cu;
+ m_object = BKE_object_add_only_object(bmain, OB_SURF, m_object_name.c_str());
+ m_object->data = cu;
}
void AbcNurbsReader::getNurbsPatches(const IObject &obj)
{
- if (!obj.valid()) {
- return;
- }
+ if (!obj.valid()) {
+ return;
+ }
- const int num_children = obj.getNumChildren();
+ const int num_children = obj.getNumChildren();
- if (num_children == 0) {
- INuPatch abc_nurb(obj, kWrapExisting);
- INuPatchSchema schem = abc_nurb.getSchema();
- m_schemas.push_back(std::pair<INuPatchSchema, IObject>(schem, obj));
- return;
- }
+ if (num_children == 0) {
+ INuPatch abc_nurb(obj, kWrapExisting);
+ INuPatchSchema schem = abc_nurb.getSchema();
+ m_schemas.push_back(std::pair<INuPatchSchema, IObject>(schem, obj));
+ return;
+ }
- for (int i = 0; i < num_children; ++i) {
- bool ok = true;
- IObject child(obj, obj.getChildHeader(i).getName());
+ for (int i = 0; i < num_children; ++i) {
+ bool ok = true;
+ IObject child(obj, obj.getChildHeader(i).getName());
- if (!m_name.empty() && child.valid() && !begins_with(child.getFullName(), m_name)) {
- ok = false;
- }
+ if (!m_name.empty() && child.valid() && !begins_with(child.getFullName(), m_name)) {
+ ok = false;
+ }
- if (!child.valid()) {
- continue;
- }
+ if (!child.valid()) {
+ continue;
+ }
- const MetaData &md = child.getMetaData();
+ const MetaData &md = child.getMetaData();
- if (INuPatch::matches(md) && ok) {
- INuPatch abc_nurb(child, kWrapExisting);
- INuPatchSchema schem = abc_nurb.getSchema();
- m_schemas.push_back(std::pair<INuPatchSchema, IObject>(schem, child));
- }
+ if (INuPatch::matches(md) && ok) {
+ INuPatch abc_nurb(child, kWrapExisting);
+ INuPatchSchema schem = abc_nurb.getSchema();
+ m_schemas.push_back(std::pair<INuPatchSchema, IObject>(schem, child));
+ }
- getNurbsPatches(child);
- }
+ getNurbsPatches(child);
+ }
}