1 // Copyright 2017 The Draco Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 #ifndef DRACO_JAVASCRIPT_EMSCRIPTEN_ANIMATION_ENCODER_WEBIDL_WRAPPER_H_
16 #define DRACO_JAVASCRIPT_EMSCRIPTEN_ANIMATION_ENCODER_WEBIDL_WRAPPER_H_
17 
18 #include <vector>
19 
20 #include "draco/animation/keyframe_animation_encoder.h"
21 #include "draco/attributes/point_attribute.h"
22 #include "draco/compression/config/compression_shared.h"
23 #include "draco/compression/config/encoder_options.h"
24 #include "draco/compression/encode.h"
25 
26 class DracoInt8Array {
27  public:
28   DracoInt8Array();
29   int GetValue(int index) const;
30   bool SetValues(const char *values, int count);
31 
size()32   size_t size() { return values_.size(); }
33 
34  private:
35   std::vector<int> values_;
36 };
37 
38 class AnimationBuilder {
39  public:
40   AnimationBuilder();
41 
42   bool SetTimestamps(draco::KeyframeAnimation *animation, long num_frames,
43                      const float *timestamps);
44 
45   int AddKeyframes(draco::KeyframeAnimation *animation, long num_frames,
46                    long num_components, const float *animation_data);
47 };
48 
49 class AnimationEncoder {
50  public:
51   AnimationEncoder();
52 
53   void SetTimestampsQuantization(long quantization_bits);
54   // TODO: Use expert encoder to set per attribute quantization.
55   void SetKeyframesQuantization(long quantization_bits);
56   int EncodeAnimationToDracoBuffer(draco::KeyframeAnimation *animation,
57                                    DracoInt8Array *draco_buffer);
58 
59  private:
60   draco::KeyframeAnimationEncoder encoder_;
61   long timestamps_quantization_bits_;
62   long keyframes_quantization_bits_;
63   draco::EncoderOptions options_;
64 };
65 
66 #endif  // DRACO_JAVASCRIPT_EMSCRIPTEN_ANIMATION_ENCODER_WEBIDL_WRAPPER_H_
67