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_DECODER_WEBIDL_WRAPPER_H_ 16 #define DRACO_JAVASCRIPT_EMSCRIPTEN_ANIMATION_DECODER_WEBIDL_WRAPPER_H_ 17 18 #include <vector> 19 20 #include "draco/animation/keyframe_animation_decoder.h" 21 #include "draco/attributes/attribute_transform_type.h" 22 #include "draco/attributes/point_attribute.h" 23 #include "draco/compression/config/compression_shared.h" 24 #include "draco/compression/decode.h" 25 #include "draco/core/decoder_buffer.h" 26 27 typedef draco::AttributeTransformType draco_AttributeTransformType; 28 typedef draco::GeometryAttribute draco_GeometryAttribute; 29 typedef draco_GeometryAttribute::Type draco_GeometryAttribute_Type; 30 typedef draco::EncodedGeometryType draco_EncodedGeometryType; 31 typedef draco::Status draco_Status; 32 typedef draco::Status::Code draco_StatusCode; 33 34 class DracoFloat32Array { 35 public: 36 DracoFloat32Array(); 37 float GetValue(int index) const; 38 39 // In case |values| is nullptr, the data is allocated but not initialized. 40 bool SetValues(const float *values, int count); 41 42 // Directly sets a value for a specific index. The array has to be already 43 // allocated at this point (using SetValues() method). SetValue(int index,float val)44 void SetValue(int index, float val) { values_[index] = val; } 45 size()46 int size() const { return values_.size(); } 47 48 private: 49 std::vector<float> values_; 50 }; 51 52 // Class used by emscripten WebIDL Binder [1] to wrap calls to decode animation 53 // data. 54 class AnimationDecoder { 55 public: 56 AnimationDecoder(); 57 58 // Decodes animation data from the provided buffer. 59 const draco::Status *DecodeBufferToKeyframeAnimation( 60 draco::DecoderBuffer *in_buffer, draco::KeyframeAnimation *animation); 61 62 static bool GetTimestamps(const draco::KeyframeAnimation &animation, 63 DracoFloat32Array *timestamp); 64 65 static bool GetKeyframes(const draco::KeyframeAnimation &animation, 66 int keyframes_id, DracoFloat32Array *animation_data); 67 68 private: 69 draco::KeyframeAnimationDecoder decoder_; 70 draco::Status last_status_; 71 }; 72 73 #endif // DRACO_JAVASCRIPT_EMSCRIPTEN_ANIMATION_DECODER_WEBIDL_WRAPPER_H_ 74