[Bf-blender-cvs] [17cabf491ca] usd-importer-T81257: USD importer: code formatting and style cleanup. Also, simplified code for setting object and data names.
makowalski
noreply at git.blender.org
Thu Oct 1 22:29:39 CEST 2020
Commit: 17cabf491ca3a6c5c4331342c61e89b7e85ad082
Author: makowalski
Date: Wed Sep 30 23:06:32 2020 -0400
Branches: usd-importer-T81257
https://developer.blender.org/rB17cabf491ca3a6c5c4331342c61e89b7e85ad082
USD importer: code formatting and style cleanup. Also, simplified code for setting object and data names.
===================================================================
M source/blender/editors/io/io_usd.c
M source/blender/io/usd/intern/usd_capi.cc
M source/blender/io/usd/intern/usd_reader_mesh.cc
M source/blender/io/usd/intern/usd_reader_mesh.h
M source/blender/io/usd/intern/usd_reader_object.cc
M source/blender/io/usd/intern/usd_reader_object.h
M source/blender/io/usd/intern/usd_util.cc
M source/blender/io/usd/intern/usd_util.h
M source/blender/io/usd/usd.h
===================================================================
diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c
index 6d6b8fe9850..feb0c8aa6af 100644
--- a/source/blender/editors/io/io_usd.c
+++ b/source/blender/editors/io/io_usd.c
@@ -244,7 +244,6 @@ void WM_OT_usd_export(struct wmOperatorType *ot)
"are different settings for viewport and rendering");
}
-
static int wm_usd_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
eUSDOperatorOptions *options = MEM_callocN(sizeof(eUSDOperatorOptions), "eUSDOperatorOptions");
@@ -280,18 +279,13 @@ static int wm_usd_import_exec(bContext *C, wmOperator *op)
ED_object_mode_set(C, OB_MODE_OBJECT);
}
- struct USDImportParams params = {
- import_uvs,
- scale,
- debug
- };
+ struct USDImportParams params = {import_uvs, scale, debug};
bool ok = USD_import(C, filename, ¶ms, as_background_job);
return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
-
static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
{
uiLayout *layout = op->layout;
@@ -307,7 +301,6 @@ static void wm_usd_import_draw(bContext *UNUSED(C), wmOperator *op)
col = uiLayoutColumn(box, true);
uiItemR(col, ptr, "import_uvs", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "debug", 0, NULL, ICON_NONE);
-
}
void WM_OT_usd_import(wmOperatorType *ot)
@@ -331,28 +324,21 @@ void WM_OT_usd_import(wmOperatorType *ot)
FILE_DEFAULTDISPLAY,
FILE_SORT_ALPHA);
- RNA_def_boolean(ot->srna,
- "import_uvs",
- true,
- "uvs",
- "When checked, import mesh uvs.");
+ RNA_def_boolean(ot->srna, "import_uvs", true, "uvs", "When checked, import mesh uvs.");
RNA_def_float(
- ot->srna,
- "scale",
- 1.0f,
- 0.0001f,
- 1000.0f,
- "Scale",
- "Value by which to enlarge or shrink the objects with respect to the world's origin",
- 0.0001f,
- 1000.0f);
+ ot->srna,
+ "scale",
+ 1.0f,
+ 0.0001f,
+ 1000.0f,
+ "Scale",
+ "Value by which to enlarge or shrink the objects with respect to the world's origin",
+ 0.0001f,
+ 1000.0f);
- RNA_def_boolean(ot->srna,
- "debug",
- false,
- "debug",
- "When checked, output debug information to the shell.");
+ RNA_def_boolean(
+ ot->srna, "debug", false, "debug", "When checked, output debug information to the shell.");
}
#endif /* WITH_USD */
diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc
index d18bf511985..94a300fd45b 100644
--- a/source/blender/io/usd/intern/usd_capi.cc
+++ b/source/blender/io/usd/intern/usd_capi.cc
@@ -25,9 +25,9 @@
#include <pxr/base/plug/registry.h>
#include <pxr/pxr.h>
-#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/primRange.h>
+#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdGeom/metrics.h>
#include <pxr/usd/usdGeom/tokens.h>
@@ -75,7 +75,6 @@
#include <iostream>
-
namespace blender::io::usd {
struct ExportJobData {
@@ -213,7 +212,6 @@ static void export_endjob(void *customdata)
WM_set_locked_interface(data->wm, false);
}
-
struct ImportJobData {
bContext *C;
Main *bmain;
@@ -255,17 +253,15 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
data->stage = pxr::UsdStage::Open(data->filename);
if (!data->stage) {
- WM_reportf(
- RPT_ERROR, "USD Export: couldn't open USD stage for file %s", data->filename);
+ WM_reportf(RPT_ERROR, "USD Export: couldn't open USD stage for file %s", data->filename);
return;
}
pxr::TfToken up_axis = pxr::UsdGeomGetStageUpAxis(data->stage);
- USDImporterContext import_ctx{ up_axis, data->params };
+ USDImporterContext import_ctx{up_axis, data->params};
// Optionally print the stage contents for debugging.
- if (data->params.debug)
- {
+ if (data->params.debug) {
debug_traverse_stage(data->stage);
}
@@ -335,7 +331,7 @@ static void import_endjob(void *user_data)
std::vector<UsdObjectReader *>::iterator iter;
- ///* Delete objects on cancellation. */
+ /* Delete objects on cancellation. */
if (data->was_cancelled) {
for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
Object *ob = (*iter)->object();
@@ -360,8 +356,7 @@ static void import_endjob(void *user_data)
for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
Object *ob = (*iter)->object();
- if (!ob)
- {
+ if (!ob) {
continue;
}
@@ -375,11 +370,11 @@ static void import_endjob(void *user_data)
DEG_id_tag_update_ex(data->bmain,
&ob->id,
ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION |
- ID_RECALC_BASE_FLAGS);
+ ID_RECALC_BASE_FLAGS);
}
- DEG_id_tag_update(&data->scene->id, ID_RECALC_BASE_FLAGS);
- DEG_relations_tag_update(data->bmain);
+ DEG_id_tag_update(&data->scene->id, ID_RECALC_BASE_FLAGS);
+ DEG_relations_tag_update(data->bmain);
if (data->is_background_job) {
/* Blender already returned from the import operator, so we need to store our own extra undo
@@ -466,9 +461,6 @@ bool USD_export(bContext *C,
return export_ok;
}
-
-
-
bool USD_import(bContext *C,
const char *filepath,
const struct USDImportParams *params,
@@ -500,7 +492,7 @@ bool USD_import(bContext *C,
job->scene,
"USD Import",
WM_JOB_PROGRESS,
- WM_JOB_TYPE_ALEMBIC); // XXX -- Here and above, why TYPE_ALEMBIC?
+ WM_JOB_TYPE_ALEMBIC); // XXX -- Here and above, why TYPE_ALEMBIC?
/* setup job */
WM_jobs_customdata_set(wm_job, job, blender::io::usd::import_freejob);
diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc
index 9cb5e19f6df..b6c51876bd2 100644
--- a/source/blender/io/usd/intern/usd_reader_mesh.cc
+++ b/source/blender/io/usd/intern/usd_reader_mesh.cc
@@ -12,6 +12,9 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2029 Blender Foundation.
+ * All rights reserved.
*/
#include "usd_reader_mesh.h"
@@ -37,8 +40,7 @@
namespace {
-struct MeshSampleData
-{
+struct MeshSampleData {
pxr::VtArray<pxr::GfVec3f> points;
pxr::VtArray<int> vertex_counts;
pxr::VtArray<int> vertex_indices;
@@ -50,7 +52,7 @@ struct MeshSampleData
bool reverse_vert_order;
};
-} // anonymous namespace
+} // anonymous namespace
static const pxr::TfToken st_primvar_name("st", pxr::TfToken::Immortal);
@@ -59,21 +61,17 @@ static void sample_uvs(const pxr::UsdGeomMesh &mesh,
pxr::TfToken primvar_name,
double time)
{
- if (!mesh)
- {
+ if (!mesh) {
return;
}
pxr::UsdGeomPrimvar st_primvar = mesh.GetPrimvar(primvar_name);
- if (st_primvar &&
- (st_primvar.GetTypeName() == pxr::SdfValueTypeNames->TexCoord2fArray ||
- st_primvar.GetTypeName() == pxr::SdfValueTypeNames->Float2Array))
- {
- if (!st_primvar.Get(&mesh_data.uv_values, time))
- {
- std::cerr << "WARNING: Couldn't get uvs from primvar "
- << primvar_name << " for prim " << mesh.GetPath() << std::endl;
+ if (st_primvar && (st_primvar.GetTypeName() == pxr::SdfValueTypeNames->TexCoord2fArray ||
+ st_primvar.GetTypeName() == pxr::SdfValueTypeNames->Float2Array)) {
+ if (!st_primvar.Get(&mesh_data.uv_values, time)) {
+ std::cerr << "WARNING: Couldn't get uvs from primvar " << primvar_name << " for prim "
+ << mesh.GetPath() << std::endl;
}
st_primvar.GetIndices(&mesh_data.uv_indices, time);
@@ -81,22 +79,19 @@ static void sample_uvs(const pxr::UsdGeomMesh &mesh,
}
}
-
static void read_mverts(MVert *mverts, const MeshSampleData &mesh_data)
{
for (int i = 0; i < mesh_data.points.size(); i++) {
MVert &mvert = mverts[i];
pxr::GfVec3f pt = mesh_data.points[i];
- if (mesh_data.y_up)
- {
+ if (mesh_data.y_up) {
// Convert from y-up to z-up.
mvert.co[0] = pt[0];
mvert.co[1] = -pt[2];
mvert.co[2] = pt[1];
}
- else
- {
+ else {
mvert.co[0] = pt[0];
mvert.co[1] = pt[1];
mvert.co[2] = pt[2];
@@ -104,7 +99,6 @@ static void read_mverts(MVert *mverts, const MeshSampleData &mesh_data)
}
}
-
static void *add_customdata(Mesh *mesh, const char *name, int data_type)
{
CustomDataType cd_data_type = static_cast<CustomDataType>(data_type);
@@ -130,11 +124,9 @@ static void *add_customdata(Mesh *mesh, const char *name, int data_type)
return cd_ptr;
}
-
static void read_mpolys(Mesh *mesh, const MeshSampleData &mesh_data)
{
- if (!mesh || mesh->totloop == 0)
- {
+ if (!mesh || mesh->totloop == 0) {
return;
}
@@ -144,10 +136,9 @@ static void read_mpolys(Mesh *mesh, const MeshSampleData &mesh_data)
bool do_uvs = (mesh_data.uv_interpolation == pxr::UsdGeomTokens->faceVarying ||
mesh_data.uv_interpolation == pxr::UsdGeomTokens->vertex) &&
- !(mesh_data.uv_indices.empty() && mesh_data.uv_values.empty());
+ !(mesh_data.uv_indices.empty() && mesh_data.uv_values.empty());
- if (do_uvs)
- {
+ if (do_uvs) {
void *cd_ptr = add_customdata(mesh, "uvMap", CD_MLOOPUV);
mloopuvs = static_cast<MLoopUV *>(cd_ptr);
}
@@ -167,12 +158,10 @@ static void read_mpolys(Mesh *mesh, const MeshSampleData &mesh_data)
int loop_index = loop_start;
- if (mesh_data.reverse_vert_order)
- {
+ if (mesh_data.reverse_vert_order) {
loop_index += face_size - 1 - f;
}
- else
- {
+ else {
loop_index += f;
}
@@ -182,11 +171,12 @@ static void read_mpolys(Mesh *mesh,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list