From 08ba782bd5fd1d0392b70e675db99702ff349b7f Mon Sep 17 00:00:00 2001 From: George Papadopoulos Date: Thu, 26 Mar 2015 00:43:41 +0200 Subject: [PATCH 1/5] [FBX] add support for multiple animations (by using LocalStart/LocalStop in takes) + change key type from uint to int (fixes bugs from negative int_t becoming a junk uint_t value ) + detect and ignore channels with no keys in the specified take start/stop window + add test model with multiple animations --- code/FBXConverter.cpp | 158 ++++++++++++++---- code/FBXDocument.h | 10 +- code/FBXParser.cpp | 106 ++++++++++++ code/FBXParser.h | 3 + code/FBXProperties.cpp | 7 +- .../2013_BINARY/multiple_animations_test.fbx | Bin 0 -> 34576 bytes 6 files changed, 243 insertions(+), 41 deletions(-) create mode 100644 test/models-nonbsd/FBX/2013_BINARY/multiple_animations_test.fbx diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 7bd15736f..1698d6d93 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -1968,9 +1968,12 @@ private: // strip AnimationStack:: prefix std::string name = st.Name(); - if(name.substr(0,16) == "AnimationStack::") { + if (name.substr(0, 16) == "AnimationStack::") { name = name.substr(16); } + else if (name.substr(0, 11) == "AnimStack::") { + name = name.substr(11); + } anim->mName.Set(name); @@ -2014,12 +2017,18 @@ private: double min_time = 1e10; double max_time = -1e10; + int64_t start_time = st.LocalStart(); + int64_t stop_time = st.LocalStop(); + double start_timeF = CONVERT_FBX_TIME(start_time); + double stop_timeF = CONVERT_FBX_TIME(stop_time); + try { BOOST_FOREACH(const NodeMap::value_type& kv, node_map) { GenerateNodeAnimations(node_anims, kv.first, kv.second, layer_map, + start_time, stop_time, max_time, min_time); } @@ -2043,9 +2052,27 @@ private: return; } + //adjust relative timing for animation + { + double start_fps = start_timeF * anim_fps; + + for (unsigned int c = 0; c < anim->mNumChannels; c++) + { + aiNodeAnim* channel = anim->mChannels[c]; + for (uint32_t i = 0; i < channel->mNumPositionKeys; i++) + channel->mPositionKeys[i].mTime -= start_fps; + for (uint32_t i = 0; i < channel->mNumRotationKeys; i++) + channel->mRotationKeys[i].mTime -= start_fps; + for (uint32_t i = 0; i < channel->mNumScalingKeys; i++) + channel->mScalingKeys[i].mTime -= start_fps; + } + + max_time -= min_time; + } + // for some mysterious reason, mDuration is simply the maximum key -- the // validator always assumes animations to start at zero. - anim->mDuration = max_time /*- min_time */; + anim->mDuration = (stop_timeF - start_timeF) * anim_fps; anim->mTicksPerSecond = anim_fps; } @@ -2055,6 +2082,7 @@ private: const std::string& fixed_name, const std::vector& curves, const LayerMap& layer_map, + int64_t start, int64_t stop, double& max_time, double& min_time) { @@ -2147,13 +2175,19 @@ private: aiNodeAnim* const nd = GenerateSimpleNodeAnim(fixed_name, target, chain, node_property_map.end(), layer_map, + start, stop, max_time, min_time, true // input is TRS order, assimp is SRT ); ai_assert(nd); - node_anims.push_back(nd); + if (nd->mNumPositionKeys == 0 && nd->mNumRotationKeys == 0 && nd->mNumScalingKeys == 0) { + delete nd; + } + else { + node_anims.push_back(nd); + } return; } @@ -2185,6 +2219,7 @@ private: target, (*chain[i]).second, layer_map, + start, stop, max_time, min_time); @@ -2200,6 +2235,7 @@ private: target, (*chain[i]).second, layer_map, + start, stop, max_time, min_time); @@ -2212,12 +2248,18 @@ private: target, (*chain[i]).second, layer_map, + start, stop, max_time, min_time, true); ai_assert(inv); - node_anims.push_back(inv); + if (inv->mNumPositionKeys == 0 && inv->mNumRotationKeys == 0 && inv->mNumScalingKeys == 0) { + delete inv; + } + else { + node_anims.push_back(inv); + } ai_assert(TransformationComp_RotationPivotInverse > i); flags |= bit << (TransformationComp_RotationPivotInverse - i); @@ -2230,12 +2272,18 @@ private: target, (*chain[i]).second, layer_map, + start, stop, max_time, min_time, true); ai_assert(inv); - node_anims.push_back(inv); + if (inv->mNumPositionKeys == 0 && inv->mNumRotationKeys == 0 && inv->mNumScalingKeys == 0) { + delete inv; + } + else { + node_anims.push_back(inv); + } ai_assert(TransformationComp_RotationPivotInverse > i); flags |= bit << (TransformationComp_RotationPivotInverse - i); @@ -2249,6 +2297,7 @@ private: target, (*chain[i]).second, layer_map, + start, stop, max_time, min_time); @@ -2259,7 +2308,12 @@ private: } ai_assert(na); - node_anims.push_back(na); + if (na->mNumPositionKeys == 0 && na->mNumRotationKeys == 0 && na->mNumScalingKeys == 0) { + delete na; + } + else { + node_anims.push_back(na); + } continue; } } @@ -2320,13 +2374,14 @@ private: const Model& target, const std::vector& curves, const LayerMap& layer_map, + int64_t start, int64_t stop, double& max_time, double& min_time) { ScopeGuard na(new aiNodeAnim()); na->mNodeName.Set(name); - ConvertRotationKeys(na, curves, layer_map, max_time,min_time, target.RotationOrder()); + ConvertRotationKeys(na, curves, layer_map, start, stop, max_time, min_time, target.RotationOrder()); // dummy scaling key na->mScalingKeys = new aiVectorKey[1]; @@ -2351,13 +2406,14 @@ private: const Model& /*target*/, const std::vector& curves, const LayerMap& layer_map, + int64_t start, int64_t stop, double& max_time, double& min_time) { ScopeGuard na(new aiNodeAnim()); na->mNodeName.Set(name); - ConvertScaleKeys(na, curves, layer_map, max_time,min_time); + ConvertScaleKeys(na, curves, layer_map, start, stop, max_time, min_time); // dummy rotation key na->mRotationKeys = new aiQuatKey[1]; @@ -2382,6 +2438,7 @@ private: const Model& /*target*/, const std::vector& curves, const LayerMap& layer_map, + int64_t start, int64_t stop, double& max_time, double& min_time, bool inverse = false) @@ -2389,7 +2446,7 @@ private: ScopeGuard na(new aiNodeAnim()); na->mNodeName.Set(name); - ConvertTranslationKeys(na, curves, layer_map, max_time,min_time); + ConvertTranslationKeys(na, curves, layer_map, start, stop, max_time, min_time); if (inverse) { for (unsigned int i = 0; i < na->mNumPositionKeys; ++i) { @@ -2422,6 +2479,7 @@ private: NodeMap::const_iterator chain[TransformationComp_MAXIMUM], NodeMap::const_iterator iter_end, const LayerMap& layer_map, + int64_t start, int64_t stop, double& max_time, double& min_time, bool reverse_order = false) @@ -2443,21 +2501,21 @@ private: KeyFrameListList rotation; if(chain[TransformationComp_Scaling] != iter_end) { - scaling = GetKeyframeList((*chain[TransformationComp_Scaling]).second); + scaling = GetKeyframeList((*chain[TransformationComp_Scaling]).second, start, stop); } else { def_scale = PropertyGet(props,"Lcl Scaling",aiVector3D(1.f,1.f,1.f)); } if(chain[TransformationComp_Translation] != iter_end) { - translation = GetKeyframeList((*chain[TransformationComp_Translation]).second); + translation = GetKeyframeList((*chain[TransformationComp_Translation]).second, start, stop); } else { def_translate = PropertyGet(props,"Lcl Translation",aiVector3D(0.f,0.f,0.f)); } if(chain[TransformationComp_Rotation] != iter_end) { - rotation = GetKeyframeList((*chain[TransformationComp_Rotation]).second); + rotation = GetKeyframeList((*chain[TransformationComp_Rotation]).second, start, stop); } else { def_rot = EulerToQuaternion(PropertyGet(props,"Lcl Rotation",aiVector3D(0.f,0.f,0.f)), @@ -2475,17 +2533,20 @@ private: aiVectorKey* out_scale = new aiVectorKey[times.size()]; aiVectorKey* out_translation = new aiVectorKey[times.size()]; - ConvertTransformOrder_TRStoSRT(out_quat, out_scale, out_translation, - scaling, - translation, - rotation, - times, - max_time, - min_time, - target.RotationOrder(), - def_scale, - def_translate, - def_rot); + if (times.size()) + { + ConvertTransformOrder_TRStoSRT(out_quat, out_scale, out_translation, + scaling, + translation, + rotation, + times, + max_time, + min_time, + target.RotationOrder(), + def_scale, + def_translate, + def_rot); + } // XXX remove duplicates / redundant keys which this operation did // likely produce if not all three channels were equally dense. @@ -2507,6 +2568,7 @@ private: if(chain[TransformationComp_Scaling] != iter_end) { ConvertScaleKeys(na, (*chain[TransformationComp_Scaling]).second, layer_map, + start, stop, max_time, min_time); } @@ -2522,6 +2584,7 @@ private: if(chain[TransformationComp_Rotation] != iter_end) { ConvertRotationKeys(na, (*chain[TransformationComp_Rotation]).second, layer_map, + start, stop, max_time, min_time, target.RotationOrder()); @@ -2539,6 +2602,7 @@ private: if(chain[TransformationComp_Translation] != iter_end) { ConvertTranslationKeys(na, (*chain[TransformationComp_Translation]).second, layer_map, + start, stop, max_time, min_time); } @@ -2558,17 +2622,21 @@ private: // key (time), value, mapto (component index) - typedef boost::tuple< const KeyTimeList*, const KeyValueList*, unsigned int > KeyFrameList; + typedef boost::tuple, boost::shared_ptr, unsigned int > KeyFrameList; typedef std::vector KeyFrameListList; // ------------------------------------------------------------------------------------------------ - KeyFrameListList GetKeyframeList(const std::vector& nodes) + KeyFrameListList GetKeyframeList(const std::vector& nodes, int64_t start, int64_t stop) { KeyFrameListList inputs; inputs.reserve(nodes.size()*3); + //give some breathing room for rounding errors + int64_t adj_start = start - 10000; + int64_t adj_stop = stop + 10000; + BOOST_FOREACH(const AnimationCurveNode* node, nodes) { ai_assert(node); @@ -2593,7 +2661,23 @@ private: const AnimationCurve* const curve = kv.second; ai_assert(curve->GetKeys().size() == curve->GetValues().size() && curve->GetKeys().size()); - inputs.push_back(boost::make_tuple(&curve->GetKeys(), &curve->GetValues(), mapto)); + //get values within the start/stop time window + boost::shared_ptr Keys(new KeyTimeList()); + boost::shared_ptr Values(new KeyValueList()); + const int count = curve->GetKeys().size(); + Keys->reserve(count); + Values->reserve(count); + for (int n = 0; n < count; n++) + { + int64_t k = curve->GetKeys().at(n); + if (k >= adj_start && k <= adj_stop) + { + Keys->push_back(k); + Values->push_back(curve->GetValues().at(n)); + } + } + + inputs.push_back(boost::make_tuple(Keys, Values, mapto)); } } return inputs; // pray for NRVO :-) @@ -2623,7 +2707,7 @@ private: const size_t count = inputs.size(); while(true) { - uint64_t min_tick = std::numeric_limits::max(); + int64_t min_tick = std::numeric_limits::max(); for (size_t i = 0; i < count; ++i) { const KeyFrameList& kfl = inputs[i]; @@ -2632,7 +2716,7 @@ private: } } - if (min_tick == std::numeric_limits::max()) { + if (min_tick == std::numeric_limits::max()) { break; } keys.push_back(min_tick); @@ -2832,6 +2916,7 @@ private: // ------------------------------------------------------------------------------------------------ void ConvertScaleKeys(aiNodeAnim* na, const std::vector& nodes, const LayerMap& /*layers*/, + int64_t start, int64_t stop, double& maxTime, double& minTime) { @@ -2841,36 +2926,40 @@ private: // layers should be multiplied with each other). There is a FBX // property in the layer to specify the behaviour, though. - const KeyFrameListList& inputs = GetKeyframeList(nodes); + const KeyFrameListList& inputs = GetKeyframeList(nodes, start, stop); const KeyTimeList& keys = GetKeyTimeList(inputs); na->mNumScalingKeys = static_cast(keys.size()); na->mScalingKeys = new aiVectorKey[keys.size()]; - InterpolateKeys(na->mScalingKeys, keys, inputs, true, maxTime, minTime); + if (keys.size() > 0) + InterpolateKeys(na->mScalingKeys, keys, inputs, true, maxTime, minTime); } // ------------------------------------------------------------------------------------------------ void ConvertTranslationKeys(aiNodeAnim* na, const std::vector& nodes, const LayerMap& /*layers*/, + int64_t start, int64_t stop, double& maxTime, double& minTime) { ai_assert(nodes.size()); // XXX see notes in ConvertScaleKeys() - const KeyFrameListList& inputs = GetKeyframeList(nodes); + const KeyFrameListList& inputs = GetKeyframeList(nodes, start, stop); const KeyTimeList& keys = GetKeyTimeList(inputs); na->mNumPositionKeys = static_cast(keys.size()); na->mPositionKeys = new aiVectorKey[keys.size()]; - InterpolateKeys(na->mPositionKeys, keys, inputs, false, maxTime, minTime); + if (keys.size() > 0) + InterpolateKeys(na->mPositionKeys, keys, inputs, false, maxTime, minTime); } // ------------------------------------------------------------------------------------------------ void ConvertRotationKeys(aiNodeAnim* na, const std::vector& nodes, const LayerMap& /*layers*/, + int64_t start, int64_t stop, double& maxTime, double& minTime, Model::RotOrder order) @@ -2878,12 +2967,13 @@ private: ai_assert(nodes.size()); // XXX see notes in ConvertScaleKeys() - const std::vector< KeyFrameList >& inputs = GetKeyframeList(nodes); + const std::vector< KeyFrameList >& inputs = GetKeyframeList(nodes, start, stop); const KeyTimeList& keys = GetKeyTimeList(inputs); na->mNumRotationKeys = static_cast(keys.size()); na->mRotationKeys = new aiQuatKey[keys.size()]; - InterpolateKeys(na->mRotationKeys, keys, inputs, false, maxTime, minTime, order); + if (keys.size() > 0) + InterpolateKeys(na->mRotationKeys, keys, inputs, false, maxTime, minTime, order); } diff --git a/code/FBXDocument.h b/code/FBXDocument.h index b4099550b..9f1849132 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -871,7 +871,7 @@ private: std::vector mappings; }; -typedef std::vector KeyTimeList; +typedef std::vector KeyTimeList; typedef std::vector KeyValueList; /** Represents a FBX animation curve (i.e. a 1-dimensional set of keyframes and values therefor) */ @@ -1015,10 +1015,10 @@ public: public: - fbx_simple_property(LocalStart, uint64_t, 0L) - fbx_simple_property(LocalStop, uint64_t, 0L) - fbx_simple_property(ReferenceStart, uint64_t, 0L) - fbx_simple_property(ReferenceStop, uint64_t, 0L) + fbx_simple_property(LocalStart, int64_t, 0L) + fbx_simple_property(LocalStop, int64_t, 0L) + fbx_simple_property(ReferenceStart, int64_t, 0L) + fbx_simple_property(ReferenceStop, int64_t, 0L) diff --git a/code/FBXParser.cpp b/code/FBXParser.cpp index 62f8d9c0c..a9fe97a5e 100644 --- a/code/FBXParser.cpp +++ b/code/FBXParser.cpp @@ -431,6 +431,43 @@ int ParseTokenAsInt(const Token& t, const char*& err_out) } +// ------------------------------------------------------------------------------------------------ +int64_t ParseTokenAsInt64(const Token& t, const char*& err_out) +{ + err_out = NULL; + + if (t.Type() != TokenType_DATA) { + err_out = "expected TOK_DATA token"; + return 0L; + } + + if (t.IsBinary()) + { + const char* data = t.begin(); + if (data[0] != 'L') { + err_out = "failed to parse Int64, unexpected data type"; + return 0L; + } + + BE_NCONST int64_t id = SafeParse(data + 1, t.end()); + AI_SWAP8(id); + return id; + } + + // XXX: should use size_t here + unsigned int length = static_cast(t.end() - t.begin()); + ai_assert(length > 0); + + const char* out; + const int64_t id = strtoul10_64(t.begin(), &out, &length); + if (out > t.end()) { + err_out = "failed to parse Int64 (text)"; + return 0L; + } + + return id; +} + // ------------------------------------------------------------------------------------------------ std::string ParseTokenAsString(const Token& t, const char*& err_out) { @@ -1062,6 +1099,63 @@ void ParseVectorDataArray(std::vector& out, const Element& el) } } +// ------------------------------------------------------------------------------------------------ +// read an array of int64_ts +void ParseVectorDataArray(std::vector& out, const Element& el) +{ + out.clear(); + const TokenList& tok = el.Tokens(); + if (tok.empty()) { + ParseError("unexpected empty element", &el); + } + + if (tok[0]->IsBinary()) { + const char* data = tok[0]->begin(), *end = tok[0]->end(); + + char type; + uint32_t count; + ReadBinaryDataArrayHead(data, end, type, count, el); + + if (!count) { + return; + } + + if (type != 'l') { + ParseError("expected long array (binary)", &el); + } + + std::vector buff; + ReadBinaryDataArray(type, count, data, end, buff, el); + + ai_assert(data == end); + ai_assert(buff.size() == count * 8); + + out.reserve(count); + + const int64_t* ip = reinterpret_cast(&buff[0]); + for (unsigned int i = 0; i < count; ++i, ++ip) { + BE_NCONST int64_t val = *ip; + AI_SWAP8(val); + out.push_back(val); + } + + return; + } + + const size_t dim = ParseTokenAsDim(*tok[0]); + + // see notes in ParseVectorDataArray() + out.reserve(dim); + + const Scope& scope = GetRequiredScope(el); + const Element& a = GetRequiredElement(scope, "a", &el); + + for (TokenList::const_iterator it = a.Tokens().begin(), end = a.Tokens().end(); it != end;) { + const int64_t ival = ParseTokenAsInt64(**it++); + + out.push_back(ival); + } +} // ------------------------------------------------------------------------------------------------ aiMatrix4x4 ReadMatrix(const Element& element) @@ -1205,6 +1299,18 @@ int ParseTokenAsInt(const Token& t) +// ------------------------------------------------------------------------------------------------ +// wrapper around ParseTokenAsInt64() with ParseError handling +int64_t ParseTokenAsInt64(const Token& t) +{ + const char* err; + const int64_t i = ParseTokenAsInt64(t, err); + if (err) { + ParseError(err, t); + } + return i; +} + } // !FBX } // !Assimp diff --git a/code/FBXParser.h b/code/FBXParser.h index e6fa25d22..150b6267a 100644 --- a/code/FBXParser.h +++ b/code/FBXParser.h @@ -206,6 +206,7 @@ size_t ParseTokenAsDim(const Token& t, const char*& err_out); float ParseTokenAsFloat(const Token& t, const char*& err_out); int ParseTokenAsInt(const Token& t, const char*& err_out); +int64_t ParseTokenAsInt64(const Token& t, const char*& err_out); std::string ParseTokenAsString(const Token& t, const char*& err_out); @@ -214,6 +215,7 @@ uint64_t ParseTokenAsID(const Token& t); size_t ParseTokenAsDim(const Token& t); float ParseTokenAsFloat(const Token& t); int ParseTokenAsInt(const Token& t); +int64_t ParseTokenAsInt64(const Token& t); std::string ParseTokenAsString(const Token& t); /* read data arrays */ @@ -224,6 +226,7 @@ void ParseVectorDataArray(std::vector& out, const Element& el); void ParseVectorDataArray(std::vector& out, const Element& el); void ParseVectorDataArray(std::vector& out, const Element& el); void ParseVectorDataArray(std::vector& out, const Element& e); +void ParseVectorDataArray(std::vector& out, const Element& el); diff --git a/code/FBXProperties.cpp b/code/FBXProperties.cpp index 13b354442..5676d9d5e 100644 --- a/code/FBXProperties.cpp +++ b/code/FBXProperties.cpp @@ -88,9 +88,12 @@ Property* ReadTypedProperty(const Element& element) else if (!strcmp(cs, "int") || !strcmp(cs, "Int") || !strcmp(cs, "enum") || !strcmp(cs, "Enum")) { return new TypedProperty(ParseTokenAsInt(*tok[4])); } - else if (!strcmp(cs,"ULongLong")) { + else if (!strcmp(cs, "ULongLong")) { return new TypedProperty(ParseTokenAsID(*tok[4])); } + else if (!strcmp(cs, "KTime")) { + return new TypedProperty(ParseTokenAsInt64(*tok[4])); + } else if (!strcmp(cs,"Vector3D") || !strcmp(cs,"ColorRGB") || !strcmp(cs,"Vector") || @@ -105,7 +108,7 @@ Property* ReadTypedProperty(const Element& element) ParseTokenAsFloat(*tok[6])) ); } - else if (!strcmp(cs,"double") || !strcmp(cs,"Number") || !strcmp(cs,"KTime") || !strcmp(cs,"Float") || !strcmp(cs,"FieldOfView")) { + else if (!strcmp(cs,"double") || !strcmp(cs,"Number") || !strcmp(cs,"Float") || !strcmp(cs,"FieldOfView")) { return new TypedProperty(ParseTokenAsFloat(*tok[4])); } return NULL; diff --git a/test/models-nonbsd/FBX/2013_BINARY/multiple_animations_test.fbx b/test/models-nonbsd/FBX/2013_BINARY/multiple_animations_test.fbx new file mode 100644 index 0000000000000000000000000000000000000000..7999e690c566d3c4a77c58f9cb46305b55bc7ecf GIT binary patch literal 34576 z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){vrdb%*VdQKBPSO#pMl$s=Z&ZX}SG(kX z^6qm+Ode1VF8$;^-9~ct-au3-uavpfNUk2Y`N_Kpk<9Jw6xksoncLkc zvRNNAS*~_pqe`rD)Fno8HF@%rclVpgWj*UB@A(@ex!O*OD&>_jPaDbAD$GybeZ)wv zHbMO4J&Q2$;IMlJ4mH8(jH+i9QH6_AW}BH@wnzQs-5)lRtCfkLyypRsPlO`g?nQwZ zRloTHibC3YOW}GFe~2je6G*8-Ca0?SaV7g--Ns1tm7ARc4q4UqFAH;W?fhiYLMfYt zoLcw4*H4x5tCuaw$9Hc8%>?Ak!7;`Dg&uy%=}y9;>c@z#*XU-rzhh*ky;tfzk@dD@ z`uU5mxfp9G{)r`I7ShOv0*zVzMz}G{Y0N3$HyERS)+efdo@cE_=QE~=HYYk&Y)m^q zBxGEUI>=Pxia+b~n24N#`vNYtQc6R9tSP9WqShNx_0jBX)S(Ra8B#>MTJ)*d5a<<< zjy(3@q~{MjyZh_c9{I%aN6yBMtuGxu)tB)nynUpz?RqrtyiH0}QY DHi)xP literal 0 HcmV?d00001 From 9e4a49938365ba68f7eef8b1ee8958296cd7e981 Mon Sep 17 00:00:00 2001 From: Ser Lev Arris Date: Fri, 27 Mar 2015 11:04:23 +0100 Subject: [PATCH 2/5] Fixes assimp/assimp#509 --- .../jassimp/src/jassimp/AiNodeAnim.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java b/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java index 43b4ce66b..34fcb5097 100644 --- a/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java +++ b/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java @@ -3,7 +3,7 @@ Open Asset Import Library - Java Binding (jassimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2012, assimp team +Copyright (c) 2006-2015, assimp team All rights reserved. @@ -68,9 +68,9 @@ import java.nio.ByteOrder; */ public final class AiNodeAnim { /** - * Size of one position key entry (includes padding). + * Size of one position key entry. */ - private static final int POS_KEY_SIZE = 24; + private static final int POS_KEY_SIZE = 20; /** * Size of one rotation key entry. @@ -78,9 +78,9 @@ public final class AiNodeAnim { private static final int ROT_KEY_SIZE = 24; /** - * Size of one scaling key entry (includes padding). + * Size of one scaling key entry. */ - private static final int SCALE_KEY_SIZE = 24; + private static final int SCALE_KEY_SIZE = 20; /** @@ -103,14 +103,13 @@ public final class AiNodeAnim { m_preState = AiAnimBehavior.fromRawValue(preBehavior); m_postState = AiAnimBehavior.fromRawValue(postBehavior); - /* c data is padded -> 24 bytes with 20 bytes data */ m_posKeys = ByteBuffer.allocateDirect(numPosKeys * POS_KEY_SIZE); m_posKeys.order(ByteOrder.nativeOrder()); - m_rotKeys = ByteBuffer.allocateDirect(numRotKeys * 24); + m_rotKeys = ByteBuffer.allocateDirect(numRotKeys * ROT_KEY_SIZE); m_rotKeys.order(ByteOrder.nativeOrder()); - m_scaleKeys = ByteBuffer.allocateDirect(numScaleKeys * 24); + m_scaleKeys = ByteBuffer.allocateDirect(numScaleKeys * SCALE_KEY_SIZE); m_scaleKeys.order(ByteOrder.nativeOrder()); } @@ -141,7 +140,7 @@ public final class AiNodeAnim { * Returns the buffer with position keys of this animation channel.

* * Position keys consist of a time value (double) and a position (3D vector - * of floats), resulting in a total of 24 bytes per entry with padding. + * of floats), resulting in a total of 20 bytes per entry. * The buffer contains {@link #getNumPosKeys()} of these entries.

* * If there are position keys, there will also be at least one @@ -340,7 +339,7 @@ public final class AiNodeAnim { * Returns the buffer with scaling keys of this animation channel.

* * Scaling keys consist of a time value (double) and a 3D vector of floats, - * resulting in a total of 24 bytes per entry with padding. The buffer + * resulting in a total of 20 bytes per entry. The buffer * contains {@link #getNumScaleKeys()} of these entries.

* * If there are scaling keys, there will also be at least one From bdf813ecf0532c13423019a33ebb435a3d5dd42b Mon Sep 17 00:00:00 2001 From: Ser Lev Arris Date: Fri, 27 Mar 2015 18:09:39 +0100 Subject: [PATCH 3/5] new function to get aiVectorKey size --- port/jassimp/jassimp-native/src/jassimp.cpp | 8 ++++++++ port/jassimp/jassimp/src/jassimp/AiNodeAnim.java | 4 ++-- port/jassimp/jassimp/src/jassimp/Jassimp.java | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/port/jassimp/jassimp-native/src/jassimp.cpp b/port/jassimp/jassimp-native/src/jassimp.cpp index 14d9cb2d4..710168e98 100644 --- a/port/jassimp/jassimp-native/src/jassimp.cpp +++ b/port/jassimp/jassimp-native/src/jassimp.cpp @@ -1340,6 +1340,14 @@ static bool loadCameras(JNIEnv *env, const aiScene* cScene, jobject& jScene) } +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getVKeysize + (JNIEnv *env, jclass jClazz) +{ + const int res = sizeof(aiVectorKey); + + return res; +} + JNIEXPORT jstring JNICALL Java_jassimp_Jassimp_getErrorString (JNIEnv *env, jclass jClazz) { diff --git a/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java b/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java index 34fcb5097..c084accd6 100644 --- a/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java +++ b/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java @@ -70,7 +70,7 @@ public final class AiNodeAnim { /** * Size of one position key entry. */ - private static final int POS_KEY_SIZE = 20; + private static final int POS_KEY_SIZE = Jassimp.getVKeysize(); /** * Size of one rotation key entry. @@ -80,7 +80,7 @@ public final class AiNodeAnim { /** * Size of one scaling key entry. */ - private static final int SCALE_KEY_SIZE = 20; + private static final int SCALE_KEY_SIZE = Jassimp.getVKeysize(); /** diff --git a/port/jassimp/jassimp/src/jassimp/Jassimp.java b/port/jassimp/jassimp/src/jassimp/Jassimp.java index 238456c1d..25b8f6371 100644 --- a/port/jassimp/jassimp/src/jassimp/Jassimp.java +++ b/port/jassimp/jassimp/src/jassimp/Jassimp.java @@ -96,6 +96,13 @@ public final class Jassimp { } + /** + * Returns the size of a struct.

+ * + * @return the result of sizeof call + */ + public static native int getVKeysize(); + /** * Returns a human readable error description.

* From d2d41a8aee2704c849c34dec31abc43871a68338 Mon Sep 17 00:00:00 2001 From: Ser Lev Arris Date: Fri, 27 Mar 2015 19:03:58 +0100 Subject: [PATCH 4/5] jni header update due new function --- port/jassimp/jassimp-native/src/jassimp.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/port/jassimp/jassimp-native/src/jassimp.h b/port/jassimp/jassimp-native/src/jassimp.h index 6f90bb3b6..fadea4fe6 100644 --- a/port/jassimp/jassimp-native/src/jassimp.h +++ b/port/jassimp/jassimp-native/src/jassimp.h @@ -7,6 +7,9 @@ #ifdef __cplusplus extern "C" { #endif +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getVKeysize + (JNIEnv *, jclass); + /* * Class: jassimp_Jassimp * Method: getErrorString From 11b9d83d4c1da81c9564c5e6baf0fe9e56a4b915 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 28 Mar 2015 10:50:32 +0100 Subject: [PATCH 5/5] openddlparser: latest greatest ( contains fix for correct handling of data array lists ). Signed-off-by: Kim Kulling --- contrib/openddlparser/code/OpenDDLParser.cpp | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/contrib/openddlparser/code/OpenDDLParser.cpp b/contrib/openddlparser/code/OpenDDLParser.cpp index 1c9006f38..104471965 100644 --- a/contrib/openddlparser/code/OpenDDLParser.cpp +++ b/contrib/openddlparser/code/OpenDDLParser.cpp @@ -856,6 +856,14 @@ char *OpenDDLParser::parseDataList( char *in, char *end, Value **data, size_t &n return in; } +DataArrayList *createDataArrayList( Value *currentValue, size_t numValues ) { + DataArrayList *dataList = new DataArrayList; + dataList->m_dataList = currentValue; + dataList->m_numItems = numValues; + + return dataList; + +} char *OpenDDLParser::parseDataArrayList( char *in, char *end, DataArrayList **dataList ) { *dataList = ddl_nullptr; if( ddl_nullptr == in || in == end ) { @@ -865,20 +873,19 @@ char *OpenDDLParser::parseDataArrayList( char *in, char *end, DataArrayList **da in = lookForNextToken( in, end ); if( *in == Grammar::OpenBracketToken[ 0 ] ) { in++; - Value *current( ddl_nullptr ); + Value *currentValue( ddl_nullptr ); Reference *refs( ddl_nullptr ); DataArrayList *prev( ddl_nullptr ), *currentDataList( ddl_nullptr ); do { size_t numRefs( 0 ), numValues( 0 ); - in = parseDataList( in, end, ¤t, numValues, &refs, numRefs ); - if( ddl_nullptr != current ) { + currentValue = ddl_nullptr; + in = parseDataList( in, end, ¤tValue, numValues, &refs, numRefs ); + if( ddl_nullptr != currentValue ) { if( ddl_nullptr == prev ) { - *dataList = new DataArrayList; - ( *dataList )->m_dataList = current; - ( *dataList )->m_numItems = numValues; + *dataList = createDataArrayList( currentValue, numValues ); prev = *dataList; } else { - currentDataList = new DataArrayList; + currentDataList = createDataArrayList( currentValue, numValues ); if( ddl_nullptr != prev ) { prev->m_next = currentDataList; prev = currentDataList;