Example #1
0
        /// <summary>
        /// the optional whitelist specifies a list of property names for which the caller
        /// wants animations for. If the curve node does not match one of these, std::range_error
        /// will be thrown.
        /// </summary>
        public AnimationCurveNode(ulong id, Element element, string name, Document doc, string[] targetPropWhitelist = null)
            : base(id, element, name)
        {
            this.doc = doc;
            this.target = null;
            curves = new Dictionary<string, AnimationCurve>();

            var sc = Parser.GetRequiredScope(element);

            // find target node
            var whitelist = new[] { "Model", "NodeAttribute" };
            var conns = doc.GetConnectionsBySourceSequenced(ID, whitelist);

            foreach(var con in conns)
            {
                // link should go for a property
                if (string.IsNullOrEmpty(con.PropertyName))
                {
                    continue;
                }

                if (targetPropWhitelist != null)
                {
                    var s = con.PropertyName;
                    var ok = false;
                    for(int i=0; i<whitelist.Length; ++i)
                    {
                        if (s == targetPropWhitelist[i])
                        {
                            ok = true;
                            break;
                        }
                    }

                    if (!ok)
                    {
                        throw (new ArgumentOutOfRangeException("AnimationCurveNode target property is not in whitelist"));
                    }
                }

                var ob = con.DestinationObject;
                if (ob == null)
                {
                    DocumentUtil.DOMWarning("failed to read destination object for AnimationCurveNode->Model link, ignoring", element);
                    continue;
                }

                // XXX support constraints as DOM class
                //ai_assert(dynamic_cast<const Model*>(ob) || dynamic_cast<const NodeAttribute*>(ob));
                target = ob;
                if (target == null)
                {
                    continue;
                }

                prop = con.PropertyName;
                break;
            }

            if (target == null)
            {
                DocumentUtil.DOMWarning("failed to resolve target Model/NodeAttribute/Constraint for AnimationCurveNode", element);
            }

            props = DocumentUtil.GetPropertyTable(doc, "AnimationCurveNode.FbxAnimCurveNode", element, sc, false);
        }