summaryrefslogtreecommitdiffstats
path: root/o3d/plugin/idl/skin.idl
blob: 762358d853ed096494a28370cb3322eddb851c9c (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * Copyright 2009, Google Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


// This file contains the idlglue declaration of Skin and SkinEval.

namespace o3d {

%[
  A Skin holds an array of matrix indices and influences for vertices in a skin.
  A Skin is data only and can be used by one or more SkinEvals to implement
  skinning.
%]
[nocpp, include="core/cross/skin.h"] class Skin
    : NamedObject {

  %[
    Sets the influences for an individual vertex.

    \param vertex_index The index of the vertex to set influences for
    \param influences An array of pairs of numbers where the first number
        is the index of the matrix to influence the vertex and the second
        number is the amount of influence where 0 = no influence and 1 = 100%
        influence.
  %]
  [userglue] void SetVertexInfluences(unsigned int vertex_index,
                                      NumberArray influences);

  %[
    Gets the influences for an individual vertex.
    \param vertex_index the index of the vertex to get influences from.
    \return Returns an Array of number pairs where the first number of each
        pair is the index of a matrix that influences this vertex and the
        second number is the amount of influence where 0 = no influence
        and 1 = 100% influcence.
  %]
  [const, userglue] NumberArray GetVertexInfluences(unsigned int vertex_index);

  %[
    An array with one element per vertex, where each element is an array of
    influences consisting of a number pair, where the first number is a
    matrix index and the second is the amount of influence.
  %]
  [getter,userglue_getter,setter,userglue_setter]
  NumberArray[] influences_;

  %[
    Sets the inverse bind pose matrix for a particular joint/bone/transform.
    \param index index of bone/joint/transform.
    \param matrix Inverse bind pose matrix for that joint.
  %]
  void SetInverseBindPoseMatrix(unsigned int index,
                                Vectormath::Aos::Matrix4 matrix);

  %[
    The array of inverse bone matrices
  %]
  [getter,setter] Vectormath::Aos::Matrix4[]
      inverse_bind_pose_matrices_;

  // TODO: Add setter that takes an array of matrices and sets all
  //   of the matrix arrays.
  // TODO: Add SetNumberInverseBindPoseMatrices
  // TODO: Add SetNumberVertexInflucences

  %[
    Deserializes from the skin data given a RawData object.

    \param raw_data contains skin data
    \param offset is a byte offset from the start of raw_data
    \param length is the byte length of the data to set
    \return True if operation was successful.
  %]
  bool Set(o3d::RawData raw_data,
           size_t offset,
           size_t length);

  %[
    Deserializes from the skin data given a RawData object.
    \param raw_data entire contents contains skin data
    \return True if operation was successful.
  %]
  bool Set(o3d::RawData raw_data);

  [verbatim=cpp_glue] %{
    void userglue_method_SetVertexInfluences(o3d::Skin* self,
                                             unsigned int vertex_index,
                                             const std::vector<float>& values) {
      if (values.size() % 2 != 0) {
        O3D_ERROR(self->service_locator())
            << "odd number of values passed into SetVertexInfluence. "
            << "Even number required as they are pairs.";
      } else {
        o3d::Skin::Influences influences;
        for (unsigned ii = 0; ii < values.size(); ii += 2) {
          influences.push_back(o3d::Skin::Influence(
              static_cast<unsigned int>(values[ii]),
              values[ii + 1]));
        }
        self->SetVertexInfluences(vertex_index, influences);
      }
    }
    std::vector<std::vector<float> > userglue_getter_influences_(
        o3d::Skin* _this) {
      const o3d::Skin::InfluencesArray& influences = _this->influences();
      std::vector<std::vector<float> > result(influences.size());
      for (int i = 0; i != influences.size(); ++i) {
        const o3d::Skin::Influences& vertex_influences = influences[i];
        for (int j = 0; j != vertex_influences.size(); ++j) {
          const o3d::Skin::Influence& influence = vertex_influences[j];
          result[i].push_back(static_cast<float>(influence.matrix_index));
          result[i].push_back(influence.weight);
        }
      }
      return result;
    }
    void userglue_setter_influences_(
        o3d::Skin* _this,
        const std::vector<std::vector<float> >& input) {
      for (int i = 0; i != input.size(); ++i) {
        const std::vector<float>& vertex_input = input[i];
        o3d::Skin::Influences influences(vertex_input.size() / 2);
        for (int j = 0; j != vertex_input.size() / 2; ++j) {
          influences[j] = o3d::Skin::Influence(
              static_cast<int>(vertex_input[j * 2]),
              vertex_input[j * 2 + 1]);
        }
        _this->SetVertexInfluences(i, influences);
      }
    }
    std::vector<float> userglue_method_GetVertexInfluences(
        o3d::Skin* self,
        unsigned int vertex_index) {
      std::vector<float> values;
      const o3d::Skin::Influences* influences =
          self->GetVertexInfluences(vertex_index);
      if (influences) {
        values.resize(influences->size() * 2);
        for (unsigned ii = 0; ii < influences->size(); ++ii) {
          values[ii * 2 + 0] =
              static_cast<float>((*influences)[ii].matrix_index);
          values[ii * 2 + 1] = (*influences)[ii].weight;
        }
      }
      return values;
    }
  %}

};  // Skin

%[
  A SkinEval is a VertexSource that takes its Streams, a ParamArray of 4-by-4
  matrices and a Skin and skins the vertices in its streams storing the results
  in bound output streams.
%]
[nocpp, include="core/cross/skin.h"] class SkinEval
    : VertexSource {

  %[
    The Skin to use for skinning.
  %]
  [getter, setter] Skin? skin;

  %[
    The array of matrices to use for skinning.
  %]
  [getter, setter] ParamArray matrices;

  %[
    The base matrix to subtract from the matrices before skinning.
  %]
  [getter, setter] Vectormath::Aos::Matrix4 base;

  %[
    Binds a SourceBuffer field to the SkinEval and defines how the data in the
    field should be interpreted. The field's buffer must be of a
    compatible type otherwise the binding fails and the function returns false.
    \param semantic The particular use of this stream.
    \param semantic_index Which index of a particular semantic to use.
    \param field The field containing information for this stream.
    \param start_index The first element to use.
    \return True if successful.
  %]
  [virtual] bool SetVertexStream(Stream::Semantic semantic,
                                 int semantic_index,
                                 Field field,
                                 unsigned int start_index);


  %[
    Removes a vertex stream from this SkinEval.
    \param semantic The particular use of this stream.
    \param semantic_index Which index of a particular semantic to use.
    \return true if the specified stream existed.
  %]
  bool RemoveVertexStream(Stream::Semantic semantic, int semantic_index);

  %[
    Searches the vertex streams bound to the SkinEval for one with the given
    stream semantic.
    \param semantic The particular use of this stream.
    \param semantic_index Which index of a particular semantic to use.
    \return The found stream or NULL if it does not exist.
  %]
  [userglue]
  Stream GetVertexStream(Stream::Semantic semantic, int semantic_index);

  %[
    A vector of the vertex streams on this SkinEval.
  %]
  [userglue_getter, getter] StreamVector vertex_streams;

  [verbatim=cpp_glue] %{
    std::vector<o3d::Stream*> userglue_getter_vertex_streams(
        o3d::SkinEval* self) {
      std::vector<o3d::Stream*> streams;
      const o3d::StreamParamVector& stream_params =
          self->vertex_stream_params();
      streams.reserve(stream_params.size());
      for (unsigned ii = 0; ii < stream_params.size(); ++ii) {
        streams.push_back(
            const_cast<o3d::Stream*>(&stream_params[ii]->stream()));
      }
      return streams;
    }
    o3d::Stream* userglue_method_GetVertexStream(
        o3d::SkinEval* self,
        o3d::Stream::Semantic semantic,
        int semantic_index) {
      return const_cast<o3d::Stream*>(
          self->GetVertexStream(semantic, semantic_index));
    }
  %}
};  // SkinEval

%[
  A Param which stores a Skin.
%]
[nocpp, include="core/cross/skin.h"] class ParamSkin : Param {
  %[
    The Skin stored by the Param.
  %]
  [getter, setter] Skin? value_;
};

}  // namespace o3d