Ejemplo n.º 1
0
        private Lime.Node ImportNodes(FbxImporter.Node root, Lime.Node parent = null)
        {
            Node3D node = null;

            if (root == null)
            {
                return(null);
            }
            switch (root.Attribute.Type)
            {
            case NodeAttribute.FbxNodeType.MESH:
                var meshAttribute = root.Attribute as MeshAttribute;
                var mesh          = new Mesh3D {
                    Id = root.Name
                };
                foreach (var submesh in meshAttribute.Submeshes)
                {
                    mesh.Submeshes.Add(ImportSubmesh(submesh, root));
                }
                if (platform == TargetPlatform.Unity)
                {
                    mesh.CullMode = CullMode.CullCounterClockwise;
                }
                node = mesh;
                if (mesh.Submeshes.Count != 0)
                {
                    mesh.SetLocalTransform(root.LocalTranform);
                    mesh.RecalcBounds();
                    mesh.RecalcCenter();
                }
                break;

            case NodeAttribute.FbxNodeType.CAMERA:
                var cam = root.Attribute as CameraAttribute;
                node = new Camera3D {
                    Id            = root.Name,
                    FieldOfView   = cam.FieldOfView * Mathf.DegToRad,
                    AspectRatio   = cam.AspectRatio,
                    NearClipPlane = cam.NearClipPlane,
                    FarClipPlane  = cam.FarClipPlane,
                };
                node.SetLocalTransform(CorrectCameraTransform(root.LocalTranform));
                break;

            default:
                node = new Node3D {
                    Id = root.Name
                };
                node.SetLocalTransform(root.LocalTranform);
                break;
            }

            if (node != null)
            {
                if (parent != null)
                {
                    parent.Nodes.Add(node);
                }
                foreach (var child in root.Children)
                {
                    ImportNodes(child, node);
                }
            }

            return(node);
        }
Ejemplo n.º 2
0
        private Lime.Node ImportNodes(FbxNode root, Node parent = null)
        {
            Node3D node = null;

            if (root == null)
            {
                return(null);
            }
            switch (root.Attribute.Type)
            {
            case FbxNodeAttribute.FbxNodeType.Mesh:
                var meshAttribute = root.Attribute as FbxMeshAttribute;
                var mesh          = new Mesh3D {
                    Id           = root.Name,
                    SkinningMode = meshAttribute.SkinningMode
                };
                foreach (var submesh in meshAttribute.Submeshes)
                {
                    mesh.Submeshes.Add(ImportSubmesh(submesh, root));
                }
                node = mesh;
                if (mesh.Submeshes.Count != 0)
                {
                    mesh.SetLocalTransform(root.LocalTranform);
                    mesh.RecalcBounds();
                    mesh.RecalcCenter();
                }
                break;

            case FbxNodeAttribute.FbxNodeType.Camera:
                var cam = root.Attribute as FbxCameraAttribute;
                node = new Camera3D {
                    Id               = root.Name,
                    FieldOfView      = cam.FieldOfView * Mathf.DegToRad,
                    AspectRatio      = cam.AspectRatio,
                    NearClipPlane    = cam.NearClipPlane,
                    FarClipPlane     = cam.FarClipPlane,
                    ProjectionMode   = cam.ProjectionMode,
                    OrthographicSize = cam.OrthoZoom,
                };
                node.SetLocalTransform(CorrectCameraTransform(root.LocalTranform));
                break;

            default:
                node = new Node3D {
                    Id = root.Name
                };
                node.SetLocalTransform(root.LocalTranform);
                break;
            }

            if (node != null)
            {
                if (parent != null)
                {
                    parent.Nodes.Add(node);
                }
                foreach (var child in root.Children)
                {
                    ImportNodes(child, node);
                }
            }

            return(node);
        }