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

abc_customdata.h « alembic « pointcache « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9da3b92c5845e813aa16b903f1ad7b618ce14d37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * Copyright 2015, Blender Foundation.
 *
 * 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.
 */

#ifndef PTC_ABC_CUSTOMDATA_H
#define PTC_ABC_CUSTOMDATA_H

#include <map>

#include <Alembic/AbcGeom/IGeomParam.h>
#include <Alembic/AbcGeom/OGeomParam.h>
#include <Alembic/Abc/IBaseProperty.h>
#include <Alembic/Abc/TypedPropertyTraits.h>

#include "abc_reader.h"
#include "abc_writer.h"

extern "C" {
#include "BKE_customdata.h"

#include "DNA_customdata_types.h"
}

namespace PTC {

using namespace Alembic;

std::string abc_customdata_layer_name(CustomData *cdata, CustomDataType type, int n);

struct CustomDataWriter {
	typedef std::map<std::string, Abc::BasePropertyWriterPtr> LayerPropsMap;
	typedef std::pair<std::string, Abc::BasePropertyWriterPtr> LayerPropsPair;
	
	CustomDataWriter(const std::string &name, CustomDataMask cdmask);
	~CustomDataWriter();
	
	void init(Abc::TimeSamplingPtr time_sampling);
	
	void write_sample(CustomData *cdata, int num_data, Abc::OCompoundProperty &parent);
	
	Abc::OCompoundProperty &props() { return m_props; }
	
	template <typename PropertyT, typename ParentT>
	PropertyT add_scalar_property(const std::string &name, ParentT &parent)
	{
		LayerPropsMap::iterator it = m_layer_props.find(name);
		if (it == m_layer_props.end()) {
			PropertyT prop = PropertyT(parent, name, m_time_sampling);
			m_layer_props.insert(LayerPropsPair(name, prop.getPtr()));
			return prop;
		}
		else {
			return PropertyT(it->second->asScalarPtr(), Abc::kWrapExisting);
		}
	}
	
	template <typename PropertyT, typename ParentT>
	PropertyT add_array_property(const std::string &name, ParentT &parent)
	{
		LayerPropsMap::iterator it = m_layer_props.find(name);
		if (it == m_layer_props.end()) {
			PropertyT prop = PropertyT(parent, name, m_time_sampling);
			m_layer_props.insert(LayerPropsPair(name, prop.getPtr()));
			return prop;
		}
		else {
			return PropertyT(it->second->asArrayPtr(), Abc::kWrapExisting);
		}
	}
	
	template <typename PropertyT, typename ParentT>
	PropertyT add_compound_property(const std::string &name, ParentT &parent)
	{
		LayerPropsMap::iterator it = m_layer_props.find(name);
		if (it == m_layer_props.end()) {
			PropertyT prop = PropertyT(parent, name, m_time_sampling);
			m_layer_props.insert(LayerPropsPair(name, prop.getPtr()));
			return prop;
		}
		else {
			return PropertyT(it->second->asCompoundPtr(), Abc::kWrapExisting);
		}
	}
	
	std::string cdtype_to_name(CustomData *cdata, CustomDataType type, int n);
	
private:
	std::string m_name;
	CustomDataMask m_cdmask;
	
	Abc::TimeSamplingPtr m_time_sampling;
	Abc::OCompoundProperty m_props;
	LayerPropsMap m_layer_props;
};

struct CustomDataReader {
	typedef std::map<std::string, Abc::BasePropertyReaderPtr> LayerPropsMap;
	typedef std::pair<std::string, Abc::BasePropertyReaderPtr> LayerPropsPair;
	
	CustomDataReader(const std::string &name, CustomDataMask cdmask);
	~CustomDataReader();
	
	PTCReadSampleResult read_sample(const Abc::ISampleSelector &ss, CustomData *cdata, int num_data, Abc::ICompoundProperty &parent);
	
	Abc::ICompoundProperty &props() { return m_props; }
	
	template <typename PropertyT, typename ParentT>
	PropertyT add_scalar_property(const std::string &name, ParentT &parent)
	{
		LayerPropsMap::iterator it = m_layer_props.find(name);
		if (it == m_layer_props.end()) {
			PropertyT prop = PropertyT(parent, name, 0);
			m_layer_props.insert(LayerPropsPair(name, prop.getPtr()));
			return prop;
		}
		else {
			return PropertyT(it->second->asScalarPtr(), Abc::kWrapExisting);
		}
	}
	
	template <typename PropertyT, typename ParentT>
	PropertyT add_array_property(const std::string &name, ParentT &parent)
	{
		LayerPropsMap::iterator it = m_layer_props.find(name);
		if (it == m_layer_props.end()) {
			PropertyT prop = PropertyT(parent, name, 0);
			m_layer_props.insert(LayerPropsPair(name, prop.getPtr()));
			return prop;
		}
		else {
			return PropertyT(it->second->asArrayPtr(), Abc::kWrapExisting);
		}
	}
	
	template <typename PropertyT, typename ParentT>
	PropertyT add_compound_property(const std::string &name, ParentT &parent)
	{
		LayerPropsMap::iterator it = m_layer_props.find(name);
		if (it == m_layer_props.end()) {
			PropertyT prop = PropertyT(parent, name, 0);
			m_layer_props.insert(LayerPropsPair(name, prop.getPtr()));
			return prop;
		}
		else {
			return PropertyT(it->second->asCompoundPtr(), Abc::kWrapExisting);
		}
	}
	
	void cdtype_from_name(CustomData *cdata, const std::string &name, int type, int *n, char *layer_name, int max_layer_name);
	
private:
	std::string m_name;
	CustomDataMask m_cdmask;
	
	Abc::ICompoundProperty m_props;
	LayerPropsMap m_layer_props;
};

} /* namespace PTC */

#endif  /* PTC_CLOTH_H */