[579e538fea5] temp-sybren-alembic-customprops-read: Reading ABC properties → custom ID properties

Sybren A. Stüvel noreply at git.blender.org
Thu Dec 7 10:36:24 CET 2017


Commit: 579e538fea52ebf91a09df1d7b1666928f1ed1e4
Author: Sybren A. Stüvel
Date:   Wed Nov 1 22:46:13 2017 +0100
Branches: temp-sybren-alembic-customprops-read
https://developer.blender.org/rB579e538fea52ebf91a09df1d7b1666928f1ed1e4

Reading ABC properties → custom ID properties

===================================================================

M	source/blender/alembic/intern/abc_object.cc
M	source/blender/alembic/intern/abc_object.h

===================================================================

diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc
index 2d451f93689..a74850cfdec 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -236,7 +236,7 @@ Imath::M44d get_matrix(const IXformSchema &schema, const float time)
 }
 
 DerivedMesh *AbcObjectReader::read_derivedmesh(DerivedMesh *dm,
-                                               const Alembic::Abc::ISampleSelector &sample_sel,
+                                               const Alembic::Abc::ISampleSelector &UNUSED(sample_sel),
                                                int UNUSED(read_flag),
                                                const char **UNUSED(err_str))
 {
@@ -385,14 +385,19 @@ void AbcObjectReader::read_custom_properties(const Alembic::Abc::ISampleSelector
 		std::cerr << "Params for " << m_object_name << " invalid, skipping\n";
 		return;
 	}
-	IXform my_xform = xform();
+
+	ID *id = getID();
+	IDPropertyTemplate idval = { 0 };
+	char idproptype;
 
 	size_t pcount = params.getNumProperties();
 	std::cerr << "Found " << pcount << " properties on " << params.getName() << "\n";
 	for (size_t pidx=0; pidx < pcount; pidx++) {
 		PropertyHeader header = params.getPropertyHeader(pidx);
 		std::cerr << "Found property: " << header.getName() << "\n";
-		std::cerr << "    - data type is " << header.getDataType() << "\n";
+
+		/* The code below this point MUST set idproptype and idval correctly
+		 * for the current Alembic property, or use 'continue' to skip it. */
 
 		if (header.isCompound()) {
 			std::cerr << "Custom property " << header.getName() << " is compound, not supported yet.\n";
@@ -401,7 +406,9 @@ void AbcObjectReader::read_custom_properties(const Alembic::Abc::ISampleSelector
 		if (header.isArray()) {
 			Alembic::AbcGeom::IArrayProperty ap(params, header.getName());
 			if (!ap.isScalarLike()) {
-				std::cerr << "Custom property " << header.getName() << " is array of " << ap.getNumSamples() << " items, not supported yet.\n";
+				Alembic::Util::Dimensions dim;
+				ap.getDimensions(dim, sample_sel);
+				std::cerr << "Custom property " << header.getName() << " is array of " << dim << " items, not supported yet.\n";
 				continue;
 			}
 			std::cerr << "    - array is constant: " << ap.isConstant() << "\n";
@@ -410,39 +417,172 @@ void AbcObjectReader::read_custom_properties(const Alembic::Abc::ISampleSelector
 			ap.get(val, sample_sel);
 
 			/* Inspired by ArrayPropertiesTests.cpp in the Alembic source code. */
-			switch (ap.getDataType().getPod()) {
-//				case Alembic::Util::kBooleanPOD: break;
-//				case Alembic::Util::kUint8POD: break;
-//				case Alembic::Util::kInt8POD: break;
-//				case Alembic::Util::kUint16POD: break;
+			switch (header.getDataType().getPod()) {
+				case Alembic::Util::kBooleanPOD:
+				{
+					Alembic::Util::bool_t *data = (Alembic::Util::bool_t *)(val->getData());
+					idval.i = data[0];
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kUint8POD:
+				{
+					Alembic::Util::uint8_t *data = (Alembic::Util::uint8_t *)(val->getData());
+					idval.i = data[0];
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kInt8POD:
+				{
+					Alembic::Util::int8_t *data = (Alembic::Util::int8_t *)(val->getData());
+					idval.i = data[0];
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kUint16POD:
+				{
+					Alembic::Util::uint16_t *data = (Alembic::Util::uint16_t *)(val->getData());
+					idval.i = data[0];
+					idproptype = IDP_INT;
+					break;
+				}
 				case Alembic::Util::kInt16POD:
 				{
 					Alembic::Util::int16_t *data = (Alembic::Util::int16_t *)(val->getData());
-					std::cerr << "    - value is: " << data[0] << "\n";
+					idval.i = data[0];
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kUint32POD:
+				{
+					Alembic::Util::uint32_t *data = (Alembic::Util::uint32_t *)(val->getData());
+					idval.i = data[0];
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kInt32POD:
+				{
+					Alembic::Util::int32_t *data = (Alembic::Util::int32_t *)(val->getData());
+					idval.i = data[0];
+					idproptype = IDP_INT;
 					break;
 				}
-//				case Alembic::Util::kUint32POD: break;
-//				case Alembic::Util::kInt32POD: break;
 //				case Alembic::Util::kUint64POD: break;
 //				case Alembic::Util::kInt64POD: break;
-//				case Alembic::Util::kFloat16POD: break;
-//				case Alembic::Util::kFloat32POD: break;
+				case Alembic::Util::kFloat16POD:
+				{
+					Alembic::Util::float16_t *data = (Alembic::Util::float16_t *)(val->getData());
+					idval.f = data[0];
+					idproptype = IDP_FLOAT;
+					break;
+				}
+				case Alembic::Util::kFloat32POD:
+				{
+					Alembic::Util::float32_t *data = (Alembic::Util::float32_t *)(val->getData());
+					idval.f = data[0];
+					idproptype = IDP_FLOAT;
+					break;
+				}
 //				case Alembic::Util::kFloat64POD: break;
 				case Alembic::Util::kStringPOD:
 				{
 					Alembic::Util::string * data = (Alembic::Util::string *)(val->getData());
-					std::cerr << "    - value is: " << data[0] << "\n";
+					idval.string.str = data->c_str();
+					idval.string.len = data->size() + 1;
+					idval.string.subtype = IDP_STRING_SUB_UTF8; // big fat assumption the world is sane.
+					idproptype = IDP_STRING;
 					break;
 				}
-//				case Alembic::Util::kWstringPOD: break;
 				default:
-					std::cerr << "Custom property " << header.getName() << " is array of unknown data type " << header.getDataType() << "; not supported.\n";
+					std::cerr << "Custom property " << header.getName() << " is array of data type " << header.getDataType() << "; not supported.\n";
+					continue;
 			}
 		}
+		else {
+			/* There are only three types (Composite, Array, and Scalar), so this must be true. */
+			BLI_assert(header.isScalar());
 
-		Alembic::AbcGeom::XformSample samp = my_xform.getSchema().getValue(sample_sel);
-		std::cerr << "    - time sampling: " << header.getTimeSampling()->getTimeSamplingType() << "\n";
+			switch (header.getDataType().getPod()) {
+				case Alembic::Util::kBooleanPOD:
+				{
+					IBoolProperty abcprop(params, header.getName());
+					idval.i = abcprop.getValue(sample_sel);
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kUint8POD:
+				{
+					IUcharProperty abcprop(params, header.getName());
+					idval.i = abcprop.getValue(sample_sel);
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kInt8POD:
+				{
+					ICharProperty abcprop(params, header.getName());
+					idval.i = abcprop.getValue(sample_sel);
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kUint16POD:
+				{
+					IUInt16Property abcprop(params, header.getName());
+					idval.i = abcprop.getValue(sample_sel);
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kInt16POD:
+				{
+					IInt16Property abcprop(params, header.getName());
+					idval.i = abcprop.getValue(sample_sel);
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kUint32POD:
+				{
+					IUInt32Property abcprop(params, header.getName());
+					idval.i = abcprop.getValue(sample_sel);
+					idproptype = IDP_INT;
+					break;
+				}
+				case Alembic::Util::kInt32POD:
+				{
+					IInt32Property abcprop(params, header.getName());
+					idval.i = abcprop.getValue(sample_sel);
+					idproptype = IDP_INT;
+					break;
+				}
+//				case Alembic::Util::kUint64POD: break;
+//				case Alembic::Util::kInt64POD: break;
+				case Alembic::Util::kFloat16POD:
+				case Alembic::Util::kFloat32POD:
+				{
+					IFloatProperty abcprop(params, header.getName());
+					idval.i = abcprop.getValue(sample_sel);
+					idproptype = IDP_FLOAT;
+					break;
+				}
+//				case Alembic::Util::kFloat64POD: break;
+				case Alembic::Util::kStringPOD:
+				{
+					IStringProperty abcprop(params, header.getName());
+					const std::string &data = abcprop.getValue(sample_sel);
+					idval.string.str = data.c_str();
+					idval.string.len = data.size() + 1;
+					idval.string.subtype = IDP_STRING_SUB_UTF8; // big fat assumption the world is sane.
+					idproptype = IDP_STRING;
+					break;
+				}
+				default:
+					std::cerr << "Custom property " << header.getName() << " is array of data type " << header.getDataType() << "; not supported.\n";
+					continue;
+			}
+		}
 
+		/* If we go this far, idproptype and idval are set correctly. */
+		IDProperty *iddata = IDP_New(idproptype, &idval, header.getName().c_str());
+		IDProperty *idprops = IDP_GetProperties(id, true);
+		IDP_AddToGroup(idprops, iddata);
 	}
 }
 
@@ -456,3 +596,8 @@ ICompoundProperty AbcObjectReader::getArbGeomParams()
 
 	return my_xform.getSchema().getArbGeomParams();
 }
+
+ID *AbcObjectReader::getID()
+{
+	return &m_object->id;
+}
diff --git a/source/blender/alembic/intern/abc_object.h b/source/blender/alembic/intern/abc_object.h
index 4f9618bf4e9..28a274a8bf9 100644
--- a/source/blender/alembic/intern/abc_object.h
+++ b/source/blender/alembic/intern/abc_object.h
@@ -203,6 +203,7 @@ protected:
 	void determine_inherits_xform();
 
 	virtual Alembic::AbcGeom::ICompoundProperty getArbGeomParams();
+	virtual ID *getID();
 };
 
 Imath::M44d get_matrix(const Alembic::AbcGeom::IXformSchema &schema, const float time);



More information about the Bf-blender-cvs mailing list