Example #1
0
        private Submesh3D ImportSubmesh(FbxSubmesh meshAttribute, FbxImporter.FbxNode node)
        {
            var sm = new Submesh3D();

            sm.Mesh = new Mesh <Mesh3D.Vertex> {
                Vertices           = meshAttribute.Vertices,
                Indices            = meshAttribute.Indices.Select(index => checked ((ushort)index)).ToArray(),
                AttributeLocations = new[] {
                    ShaderPrograms.Attributes.Pos1,
                    ShaderPrograms.Attributes.Color1,
                    ShaderPrograms.Attributes.UV1,
                    ShaderPrograms.Attributes.BlendIndices,
                    ShaderPrograms.Attributes.BlendWeights,
                    ShaderPrograms.Attributes.Normal
                }
            };

            sm.Material = meshAttribute.MaterialIndex != -1 ?
                          CreateLimeMaterial(node.Materials[meshAttribute.MaterialIndex], path, target) : FbxMaterial.Default;

            if (meshAttribute.Bones.Length > 0)
            {
                foreach (var bone in meshAttribute.Bones)
                {
                    sm.BoneNames.Add(bone.Name);
                    sm.BoneBindPoses.Add(bone.Offset);
                }
            }
            return(sm);
        }
Example #2
0
        public FbxScene(IntPtr ptr) : base(ptr)
        {
            var r = FbxSceneGetRootNode(NativePtr);

            if (r == IntPtr.Zero)
            {
                throw new FbxImportException("An error has occured while parsing root node");
            }
            Root       = new FbxNode(r);
            Animations = new FbxSceneAnimations(ptr);
        }
Example #3
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);
        }