[Bf-blender-cvs] [33e14428456] usd-importer-T81257: New USDMaterialImporter class
Michael A. Kowalski
noreply at git.blender.org
Sun Nov 22 04:11:55 CET 2020
Commit: 33e144284567407c300b833aae8bfac6ac6be1cc
Author: Michael A. Kowalski
Date: Wed Nov 18 13:52:04 2020 -0500
Branches: usd-importer-T81257
https://developer.blender.org/rB33e144284567407c300b833aae8bfac6ac6be1cc
New USDMaterialImporter class
===================================================================
M source/blender/io/usd/CMakeLists.txt
A source/blender/io/usd/import/usd_material_importer.cc
A source/blender/io/usd/import/usd_material_importer.h
M source/blender/io/usd/import/usd_reader_mesh.cc
===================================================================
diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt
index f9990a972b9..dc22045476a 100644
--- a/source/blender/io/usd/CMakeLists.txt
+++ b/source/blender/io/usd/CMakeLists.txt
@@ -55,6 +55,7 @@ set(INC_SYS
set(SRC
import/usd_import_util.cc
+ import/usd_material_importer.cc
import/usd_prim_iterator.cc
import/usd_reader_camera.cc
import/usd_reader_light.cc
@@ -76,6 +77,7 @@ set(SRC
usd.h
import/usd_importer_context.h
import/usd_import_util.h
+ import/usd_material_importer.h
import/usd_prim_iterator.h
import/usd_reader_camera.h
import/usd_reader_light.h
diff --git a/source/blender/io/usd/import/usd_material_importer.cc b/source/blender/io/usd/import/usd_material_importer.cc
new file mode 100644
index 00000000000..b347cdd488d
--- /dev/null
+++ b/source/blender/io/usd/import/usd_material_importer.cc
@@ -0,0 +1,60 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+#include "usd_material_importer.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_lib_id.h"
+#include "BKE_main.h"
+#include "BKE_material.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+
+
+
+#include <iostream>
+
+namespace blender::io::usd {
+
+USDMaterialImporter::USDMaterialImporter(const USDImporterContext &context, Main *bmain)
+ : context_(context)
+ , bmain_(bmain)
+{
+}
+
+USDMaterialImporter::~USDMaterialImporter()
+{
+}
+
+
+Material *USDMaterialImporter::add_material(const pxr::UsdShadeMaterial &usd_material) const
+{
+ if (!(bmain_ && usd_material)) {
+ return nullptr;
+ }
+
+ std::string mtl_name = usd_material.GetPrim().GetName().GetString().c_str();
+
+ return BKE_material_add(bmain_, mtl_name.c_str());
+}
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/import/usd_material_importer.h b/source/blender/io/usd/import/usd_material_importer.h
new file mode 100644
index 00000000000..bdb5c9fca76
--- /dev/null
+++ b/source/blender/io/usd/import/usd_material_importer.h
@@ -0,0 +1,48 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "usd_importer_context.h"
+
+#include <pxr/usd/usdShade/material.h>
+
+struct Main;
+struct Material;
+
+namespace blender::io::usd {
+
+/* Implements logic to create Blender materials
+ * from USD materials. */
+
+class USDMaterialImporter {
+ protected:
+
+ USDImporterContext context_;
+
+ Main *bmain_;
+
+ public:
+ USDMaterialImporter(const USDImporterContext &context, Main *bmain);
+
+ ~USDMaterialImporter();
+
+ Material *add_material(const pxr::UsdShadeMaterial &usd_material) const;
+};
+
+} // namespace blender::io::usd
diff --git a/source/blender/io/usd/import/usd_reader_mesh.cc b/source/blender/io/usd/import/usd_reader_mesh.cc
index 4f97a901c81..cbfae578581 100644
--- a/source/blender/io/usd/import/usd_reader_mesh.cc
+++ b/source/blender/io/usd/import/usd_reader_mesh.cc
@@ -19,6 +19,7 @@
#include "usd_reader_mesh.h"
#include "usd_import_util.h"
+#include "usd_material_importer.h"
#include "MEM_guardedalloc.h"
@@ -453,6 +454,10 @@ void USDMeshReader::assign_materials(Main *bmain, Mesh *mesh, double time)
}
}
+ USDMaterialImporter mtl_importer(this->context_, bmain);
+
+ /* TODO(makowalski): Move more of the material creation logic inot USDMaterialImporter. */
+
if (subset_mtls.empty()) {
/* No material subsets. See if there is a material bound to the mesh. */
@@ -490,7 +495,7 @@ void USDMeshReader::assign_materials(Main *bmain, Mesh *mesh, double time)
if (!blen_mtl) {
/* No existing material, so add it now. */
- blen_mtl = BKE_material_add(bmain, mtl_name.c_str());
+ blen_mtl = mtl_importer.add_material(bound_mtl);
}
if (!blen_mtl) {
@@ -546,7 +551,7 @@ void USDMeshReader::assign_materials(Main *bmain, Mesh *mesh, double time)
blen_mtl = blen_mtl_iter->second;
}
else {
- blen_mtl = BKE_material_add(bmain, mtl_name.c_str());
+ blen_mtl = mtl_importer.add_material(usd_mtl_iter->second);
if (blen_mtl) {
blen_mtl_map.insert(std::make_pair(mtl_name, blen_mtl));
More information about the Bf-blender-cvs
mailing list