[Bf-blender-cvs] [6a4a8941cc9] sybren-usd: USD: Start of hair export support
Sybren A. Stüvel
noreply at git.blender.org
Fri Jun 28 18:57:29 CEST 2019
Commit: 6a4a8941cc9abc75d79a9edeff9bba6c83d1c3b0
Author: Sybren A. Stüvel
Date: Fri Jun 28 14:36:05 2019 +0200
Branches: sybren-usd
https://developer.blender.org/rB6a4a8941cc9abc75d79a9edeff9bba6c83d1c3b0
USD: Start of hair export support
Only the parent strands are exported, and only with a constant colour.
No UV coordinates, no information about the normals.
===================================================================
M source/blender/usd/CMakeLists.txt
M source/blender/usd/intern/abstract_hierarchy_iterator.cc
M source/blender/usd/intern/abstract_hierarchy_iterator.h
M source/blender/usd/intern/usd_hierarchy_iterator.cc
M source/blender/usd/intern/usd_hierarchy_iterator.h
A source/blender/usd/intern/usd_writer_hair.cc
A source/blender/usd/intern/usd_writer_hair.h
===================================================================
diff --git a/source/blender/usd/CMakeLists.txt b/source/blender/usd/CMakeLists.txt
index 09298f898fb..3694e85e3a2 100644
--- a/source/blender/usd/CMakeLists.txt
+++ b/source/blender/usd/CMakeLists.txt
@@ -51,6 +51,7 @@ set(SRC
intern/usd_capi.cc
intern/usd_hierarchy_iterator.cc
intern/usd_writer_abstract.cc
+ intern/usd_writer_hair.cc
intern/usd_writer_mesh.cc
intern/usd_writer_transform.cc
@@ -58,6 +59,7 @@ set(SRC
intern/abstract_hierarchy_iterator.h
intern/usd_hierarchy_iterator.h
intern/usd_writer_abstract.h
+ intern/usd_writer_hair.h
intern/usd_writer_mesh.h
intern/usd_writer_transform.h
)
diff --git a/source/blender/usd/intern/abstract_hierarchy_iterator.cc b/source/blender/usd/intern/abstract_hierarchy_iterator.cc
index 0cbd3dfebcd..fc40178365f 100644
--- a/source/blender/usd/intern/abstract_hierarchy_iterator.cc
+++ b/source/blender/usd/intern/abstract_hierarchy_iterator.cc
@@ -4,6 +4,7 @@
extern "C" {
#include "BKE_anim.h"
+#include "BKE_particle.h"
#include "BLI_assert.h"
#include "BLI_math_matrix.h"
@@ -11,6 +12,7 @@ extern "C" {
#include "DNA_ID.h"
#include "DNA_layer_types.h"
#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
#include "DEG_depsgraph_query.h"
}
@@ -280,7 +282,6 @@ void AbstractHierarchyIterator::make_writers(const HierarchyContext &parent_cont
AbstractHierarchyWriter *parent_writer)
{
AbstractHierarchyWriter *xform_writer = nullptr;
- AbstractHierarchyWriter *data_writer = nullptr;
float parent_matrix_inv_world[4][4];
if (parent_context.object == nullptr) {
@@ -315,27 +316,74 @@ void AbstractHierarchyIterator::make_writers(const HierarchyContext &parent_cont
BLI_assert(DEG_is_evaluated_object(context.object));
xform_writer->write(context);
- // Get or create the object data writer, but only if it is needed.
- if (!context.weak_export && context.object->data != nullptr) {
- HierarchyContext data_context = context;
- ID *object_data = static_cast<ID *>(context.object->data);
- std::string data_path = path_concatenate(export_path, get_id_name(object_data));
-
- data_context.export_path = data_path;
- data_context.parent_writer = xform_writer;
-
- data_writer = ensure_writer(data_context, &AbstractHierarchyIterator::create_data_writer);
- if (data_writer != nullptr) {
- data_writer->write(data_context);
- }
+ if (!context.weak_export) {
+ make_writers_particle_systems(context, xform_writer);
+ make_writer_object_data(context, xform_writer);
}
+ // Recurse into this object's children.
make_writers(context, xform_writer);
}
// TODO(Sybren): iterate over all unused writers and call unused_during_iteration() or something.
}
+void AbstractHierarchyIterator::make_writers_particle_systems(
+ const HierarchyContext &xform_context, AbstractHierarchyWriter *xform_writer)
+{
+ Object *object = xform_context.object;
+ ParticleSystem *psys = static_cast<ParticleSystem *>(object->particlesystem.first);
+ for (; psys; psys = psys->next) {
+ if (!psys_check_enabled(object, psys, true)) {
+ continue;
+ }
+
+ HierarchyContext hair_context = xform_context;
+ hair_context.export_path = path_concatenate(xform_context.export_path,
+ get_id_name(&psys->part->id));
+ hair_context.parent_writer = xform_writer;
+ hair_context.particle_system = psys;
+
+ AbstractHierarchyWriter *writer = nullptr;
+ switch (psys->part->type) {
+ case PART_HAIR:
+ writer = ensure_writer(hair_context, &AbstractHierarchyIterator::create_hair_writer);
+ break;
+ case PART_EMITTER:
+ writer = ensure_writer(hair_context, &AbstractHierarchyIterator::create_particle_writer);
+ break;
+ }
+
+ if (writer != nullptr) {
+ writer->write(hair_context);
+ }
+ }
+}
+
+void AbstractHierarchyIterator::make_writer_object_data(const HierarchyContext &context,
+ AbstractHierarchyWriter *xform_writer)
+{
+ if (context.object->data == nullptr) {
+ return;
+ }
+
+ HierarchyContext data_context = context;
+ ID *object_data = static_cast<ID *>(context.object->data);
+ std::string data_path = path_concatenate(context.export_path, get_id_name(object_data));
+
+ data_context.export_path = data_path;
+ data_context.parent_writer = xform_writer;
+
+ AbstractHierarchyWriter *data_writer;
+
+ data_writer = ensure_writer(data_context, &AbstractHierarchyIterator::create_data_writer);
+ if (data_writer == nullptr) {
+ return;
+ }
+
+ data_writer->write(data_context);
+}
+
std::string AbstractHierarchyIterator::get_object_name(const Object *object) const
{
if (object == nullptr) {
diff --git a/source/blender/usd/intern/abstract_hierarchy_iterator.h b/source/blender/usd/intern/abstract_hierarchy_iterator.h
index bbbe9e01c7c..00b5ba4a425 100644
--- a/source/blender/usd/intern/abstract_hierarchy_iterator.h
+++ b/source/blender/usd/intern/abstract_hierarchy_iterator.h
@@ -1,3 +1,38 @@
+/*
+ * 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) 2019 Blender Foundation.
+ * All rights reserved.
+ */
+
+/*
+ * This file contains the AbstractHierarchyIterator. It is intended for exporters for file
+ * formats that concern an entire hierarchy of objects (rather than, for example, an OBJ file that
+ * contains only a single mesh). Examples are Universal Scene Description (USD) and Alembic.
+ * AbstractHierarchyIterator is intended to be subclassed to support concrete file formats.
+ *
+ * The AbstractHierarchyIterator makes a distinction between the actual object hierarchy and the
+ * export hierarchy. The former is the parent/child structure in Blender, which can have multiple
+ * parent-like objects. For example, a duplicated object can have both a duplicator and a parent,
+ * both determining the final transform. The export hierarchy is the hierarchy as written to the
+ * file, and every object has only one export-parent.
+ *
+ * Currently the AbstractHierarchyIterator does not make any decisions about *what* to export.
+ * Selections like "selected only" or "no hair systems" are left to concrete subclasses.
+ */
+
#ifndef __USD__ABSTRACT_HIERARCHY_ITERATOR_H__
#define __USD__ABSTRACT_HIERARCHY_ITERATOR_H__
@@ -10,6 +45,7 @@ struct Depsgraph;
struct DupliObject;
struct ID;
struct Object;
+struct ParticleSystem;
struct ViewLayer;
class AbstractHierarchyWriter;
@@ -33,6 +69,7 @@ struct HierarchyContext {
float parent_matrix_inv_world[4][4]; /* Inverse of the parent's world matrix. */
std::string export_path; // Hierarchical path, such as "/grandparent/parent/objectname".
AbstractHierarchyWriter *parent_writer; // The parent of this object during the export.
+ ParticleSystem *particle_system; // Only set for particle/hair writers.
// For making the struct insertable into a std::set<>.
bool operator<(const HierarchyContext &other) const
@@ -82,6 +119,10 @@ class AbstractHierarchyIterator {
void make_writers(const HierarchyContext &parent_context,
AbstractHierarchyWriter *parent_writer);
+ void make_writer_object_data(const HierarchyContext &context,
+ AbstractHierarchyWriter *xform_writer);
+ void make_writers_particle_systems(const HierarchyContext &context,
+ AbstractHierarchyWriter *xform_writer);
std::string get_object_name(const Object *object) const;
@@ -98,6 +139,8 @@ class AbstractHierarchyIterator {
virtual AbstractHierarchyWriter *create_xform_writer(const HierarchyContext &context) = 0;
virtual AbstractHierarchyWriter *create_data_writer(const HierarchyContext &context) = 0;
+ virtual AbstractHierarchyWriter *create_hair_writer(const HierarchyContext &context) = 0;
+ virtual AbstractHierarchyWriter *create_particle_writer(const HierarchyContext &context) = 0;
virtual void delete_object_writer(AbstractHierarchyWriter *writer) = 0;
diff --git a/source/blender/usd/intern/usd_hierarchy_iterator.cc b/source/blender/usd/intern/usd_hierarchy_iterator.cc
index b0587e5ed54..31beaeeb9e9 100644
--- a/source/blender/usd/intern/usd_hierarchy_iterator.cc
+++ b/source/blender/usd/intern/usd_hierarchy_iterator.cc
@@ -1,6 +1,8 @@
#include "../usd.h"
+
#include "usd_hierarchy_iterator.h"
#include "usd_writer_abstract.h"
+#include "usd_writer_hair.h"
#include "usd_writer_mesh.h"
#include "usd_writer_transform.h"
@@ -61,21 +63,22 @@ const pxr::UsdTimeCode &USDHierarchyIterator::get_export_time_code() const
return export_time;
}
+USDExporterContext USDHierarchyIterator::create_usd_export_context(const HierarchyContext &context)
+{
+ return USDExporterContext{depsgraph, stage, pxr::SdfPath(context.export_path), this, params};
+}
+
AbstractHierarchyWriter *USDHierarchyIterator::create_xform_writer(const HierarchyContext &context)
{
// printf(
// "\033[32;1mCREATE\033[0m %s at %s\n", context.object->id.name,
// context.export_path.c_str());
-
- USDExporterContext usd_export_context = {
- depsgraph, stage, pxr::SdfPath(context.export_path), this, params};
- return new USDTransformWriter(usd_export_context);
+ return new USDTransformWriter(create_usd_export_context(context));
}
AbstractHierarchyWriter *USDHierarchyIterator::create_data_writer(const HierarchyContext &context)
{
- USDExporterCo
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list