예제 #1
0
        /// <summary>
        /// Bakes all node transforms of all skinned meshes into the geometry so that each node's
        /// transform is Identity. (Only bones and morph targets keep their transforms.)
        /// </summary>
        /// <param name="node">The node.</param>
        private static void BakeTransforms(NodeContent node)
        {
            if (node is BoneContent)
            {
                return;
            }
            if (ContentHelper.IsMorphTarget(node))
            {
                return;
            }

            if (ContentHelper.IsSkinned(node))
            {
                // Bake all transforms in this subtree.
                BakeAllTransforms(node);
            }
            else
            {
                // Bake transforms of skinned meshes.
                foreach (NodeContent child in node.Children)
                {
                    BakeTransforms(child);
                }
            }
        }
예제 #2
0
        private static void SetSkinnedMaterial(NodeContent node, Dictionary <MaterialContent, SkinnedMaterialContent> swappedMaterials, SkinnedMaterialContent defaultMaterial)
        {
            var mesh = node as MeshContent;

            if (mesh != null)
            {
                foreach (var geometry in mesh.Geometry)
                {
                    if (!ContentHelper.IsSkinned(geometry))
                    {
                        continue;
                    }

                    if (geometry.Material == null)
                    {
                        // Happens if the model is exported without a material. (XNA only!)
                        geometry.Material = defaultMaterial;
                        continue;
                    }

                    SkinnedMaterialContent skinnedMaterial;
                    if (!swappedMaterials.TryGetValue(geometry.Material, out skinnedMaterial))
                    {
                        // Convert BasicMaterialContent to SkinnedMaterialContent.
                        skinnedMaterial = ContentHelper.ConvertToSkinnedMaterial(geometry.Material);
                        if (skinnedMaterial == null)
                        {
                            continue;
                        }

                        swappedMaterials[geometry.Material] = skinnedMaterial;
                    }

                    geometry.Material = skinnedMaterial;
                }
            }

            foreach (var child in node.Children)
            {
                SetSkinnedMaterial(child, swappedMaterials, defaultMaterial);
            }
        }