Exemplo n.º 1
0
        /// <summary>
        /// collect all object dependencies for given animation clip
        /// </summary>
        public void CollectDependencies(
            AnimationClip animClip,
            GameObject rootObject,
            IExportOptions exportOptions
            )
        {
            Debug.Assert(rootObject != null);
            Debug.Assert(exportOptions != null);

            if (this.animationClips.ContainsKey(animClip))
            {
                // we have already exported gameobjects for this clip
                return;
            }

            // NOTE: the object (animationRootObject) containing the animation is not necessarily animated
            // when driven by an animator or animation component.
            this.animationClips.Add(animClip, rootObject);

            foreach (EditorCurveBinding uniCurveBinding in AnimationUtility.GetCurveBindings(animClip))
            {
                Object uniObj = AnimationUtility.GetAnimatedObject(rootObject, uniCurveBinding);
                if (!uniObj)
                {
                    continue;
                }

                GameObject unityGo = ModelExporter.GetGameObject(uniObj);
                if (!unityGo)
                {
                    continue;
                }

                if (!exportOptions.AnimateSkinnedMesh && unityGo.GetComponent <SkinnedMeshRenderer>())
                {
                    continue;
                }

                // If we have a clip driving a camera or light then force the export of FbxNodeAttribute
                // so that they point the right way when imported into Maya.
                if (unityGo.GetComponent <Light>())
                {
                    this.exportComponent[unityGo] = typeof(Light);
                }
                else if (unityGo.GetComponent <Camera>())
                {
                    this.exportComponent[unityGo] = typeof(Camera);
                }
                else if ((uniCurveBinding.type == typeof(SkinnedMeshRenderer)) && unityGo.GetComponent <SkinnedMeshRenderer>())
                {
                    // only export mesh if there are animation keys for it (e.g. for blendshapes)
                    if (FbxPropertyChannelPair.TryGetValue(uniCurveBinding.propertyName, out FbxPropertyChannelPair[] channelPairs))
        /// <summary>
        /// Map a Unity property name to the corresponding FBX property and
        /// channel names.
        /// </summary>
        public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPair[] prop, FbxConstraint constraint = null)
        {
            prop = new FbxPropertyChannelPair[] { };

            // spot angle is a special case as it returns two channel pairs instead of one
            System.StringComparison ct = System.StringComparison.CurrentCulture;
            if (uniPropertyName.StartsWith("m_SpotAngle", ct))
            {
                prop = new FbxPropertyChannelPair[] {
                    new FbxPropertyChannelPair("OuterAngle", null),
                    new FbxPropertyChannelPair("InnerAngle", null)
                };
                return(true);
            }

            var propertyMaps = new List <PropertyChannelMap>();

            // Try get constraint specific channel pairs first as we know this is a constraint
            if (constraint != null)
            {
                // Aim constraint shares the RotationOffset property with RotationConstraint, so make sure that the correct FBX property is returned
                if (constraint.GetConstraintType() == FbxConstraint.EType.eAim)
                {
                    propertyMaps.Add(AimConstraintPropertyMap);
                }

                propertyMaps.Add(ConstraintSourcePropertyMap);
                propertyMaps.Add(ConstraintSourceTransformPropertyMap);
            }

            // Check if this is a transform, color, or other property and return the channel pairs if they match.
            propertyMaps.Add(TransformPropertyMap);
            propertyMaps.Add(ColorPropertyMap);
            propertyMaps.Add(OtherPropertyMap);
            propertyMaps.Add(BlendshapeMap);

            foreach (var propMap in propertyMaps)
            {
                prop = GetChannelPairs(uniPropertyName, propMap, constraint);
                if (prop != null)
                {
                    return(true);
                }
            }
            return(false);
        }