예제 #1
0
        private AnimationFrame CreateFrame(Transform frame, AnimatorEditor editor, HashSet<string> extractFrames, HashSet<string> meshNames, Device device, List<AnimationFrame> meshFrames, Dictionary<string, Tuple<Matrix, Matrix>> extractMatrices)
        {
            AnimationFrame animationFrame = new AnimationFrame();
            animationFrame.Name = frame.GetTransformPath();
            animationFrame.TransformationMatrix = Matrix.Scaling(frame.m_LocalScale) * Matrix.RotationQuaternion(frame.m_LocalRotation) * Matrix.Translation(frame.m_LocalPosition);
            animationFrame.OriginalTransform = animationFrame.TransformationMatrix;
            animationFrame.CombinedTransform = extractMatrices[animationFrame.Name].Item1;

            if (meshNames.Contains(animationFrame.Name))
            {
                MeshRenderer meshR = frame.m_GameObject.instance.FindLinkedComponent(UnityClassID.SkinnedMeshRenderer);
                if (meshR == null)
                {
                    meshR = frame.m_GameObject.instance.FindLinkedComponent(UnityClassID.MeshRenderer);
                }
                if (meshR != null)
                {
                    Mesh mesh = Operations.GetMesh(meshR);
                    if (mesh != null)
                    {
                        SkinnedMeshRenderer smr = meshR as SkinnedMeshRenderer;
                        List<PPtr<Transform>> boneList = null;
                        string[] boneNames = null;
                        Matrix[] boneOffsets = null;
                        if (smr != null && smr.m_Bones.Count > 0)
                        {
                            boneList = smr.m_Bones;

                            int numBones = boneList.Count > 0 ? extractFrames.Count : 0;
                            boneNames = new string[numBones];
                            boneOffsets = new Matrix[numBones];
                            if (numBones > 0)
                            {
                                string[] extractArray = new string[numBones];
                                extractFrames.CopyTo(extractArray);
                                HashSet<string> extractCopy = new HashSet<string>(extractArray);
                                int invalidBones = 0;
                                for (int i = 0; i < boneList.Count; i++)
                                {
                                    Transform bone = boneList[i].instance;
                                    if (bone == null || bone.m_GameObject.instance == null || !extractCopy.Remove(bone.GetTransformPath()))
                                    {
                                        invalidBones++;
                                    }
                                    else if (i < numBones)
                                    {
                                        boneNames[i] = bone.GetTransformPath();
                                        boneOffsets[i] = Operations.Mirror(Matrix.Transpose(mesh.m_BindPose[i]));
                                    }
                                }
                                extractCopy.CopyTo(boneNames, boneList.Count - invalidBones);
                                for (int i = boneList.Count; i < extractFrames.Count; i++)
                                {
                                    boneOffsets[i] = extractMatrices[boneNames[i]].Item2;
                                }
                            }
                        }

                        AnimationMeshContainer[] meshContainers = new AnimationMeshContainer[mesh.m_SubMeshes.Count];
                        Vector3 min = new Vector3(Single.MaxValue);
                        Vector3 max = new Vector3(Single.MinValue);
                        Operations.vMesh vMesh = new Operations.vMesh(meshR, true, true);
                        for (int i = 0; i < mesh.m_SubMeshes.Count; i++)
                        {
                            Operations.vSubmesh submesh = vMesh.submeshes[i];
                            List<Operations.vFace> faceList = submesh.faceList;
                            List<Operations.vVertex> vertexList = submesh.vertexList;

                            SlimDX.Direct3D9.Mesh animationMesh = null;
                            PositionBlendWeightsIndexedColored[] normalLines = null;
                            try
                            {
                                animationMesh = new SlimDX.Direct3D9.Mesh(device, faceList.Count, vertexList.Count, MeshFlags.Managed, PositionBlendWeightsIndexedNormalTexturedColoured.Format);

                                using (DataStream indexStream = animationMesh.LockIndexBuffer(LockFlags.None))
                                {
                                    for (int j = 0; j < faceList.Count; j++)
                                    {
                                        ushort[] indices = faceList[j].index;
                                        indexStream.Write(indices[0]);
                                        indexStream.Write(indices[2]);
                                        indexStream.Write(indices[1]);
                                    }
                                    animationMesh.UnlockIndexBuffer();
                                }

                                FillVertexBuffer(animationMesh, vertexList, -1);

                                normalLines = new PositionBlendWeightsIndexedColored[vertexList.Count * 2];
                                for (int j = 0; j < vertexList.Count; j++)
                                {
                                    Operations.vVertex vertex = vertexList[j];

                                    byte[] bIdx;
                                    float[] bWeights;
                                    if (vertex.boneIndices != null)
                                    {
                                        bIdx = new byte[4] { (byte)vertex.boneIndices[0], (byte)vertex.boneIndices[1], (byte)vertex.boneIndices[2], (byte)vertex.boneIndices[3] };
                                        bWeights = vertex.weights;
                                    }
                                    else
                                    {
                                        bIdx = new byte[4];
                                        bWeights = new float[4];
                                    }
                                    normalLines[j * 2] = new PositionBlendWeightsIndexedColored(vertex.position, bWeights, bIdx, Color.Yellow.ToArgb());
                                    normalLines[(j * 2) + 1] = new PositionBlendWeightsIndexedColored(vertex.position + (vertex.normal / 64), bWeights, bIdx, Color.Yellow.ToArgb());

                                    min = Vector3.Minimize(min, vertex.position);
                                    max = Vector3.Maximize(max, vertex.position);
                                }
                            }
                            catch
                            {
                                Report.ReportLog("No display of submeshes with more than 64k vertices!");
                            }

                            AnimationMeshContainer meshContainer = new AnimationMeshContainer();
                            if (animationMesh != null)
                            {
                                meshContainer.Name = animationFrame.Name;
                                meshContainer.MeshData = new MeshData(animationMesh);
                                meshContainer.NormalLines = normalLines;
                            }
                            meshContainers[i] = meshContainer;

                            if (submesh.matList.Count > 0 && submesh.matList[0].instance != null)
                            {
                                Material mat = submesh.matList[0].instance;
                                int matIdx = editor.Materials.IndexOf(mat);
                                int texIdx;
                                if (!MatTexIndices.TryGetValue(matIdx, out texIdx))
                                {
                                    texIdx = -1;

                                    SlimDX.Direct3D9.Material materialD3D = new SlimDX.Direct3D9.Material();
                                    materialD3D.Ambient = GetColour(mat, "_SColor");
                                    materialD3D.Diffuse = GetColour(mat, "_Color");
                                    materialD3D.Emissive = GetColour(mat, "_ReflectColor");
                                    materialD3D.Specular = GetColour(mat, "_SpecColor");
                                    materialD3D.Power = GetFloat(mat, "_Shininess");
                                    Materials[matIdx] = materialD3D;

                                    Texture2D matTex = GetTexture(mat, "_MainTex");
                                    if (matTex != null)
                                    {
                                        texIdx = editor.Textures.IndexOf(matTex);
                                        if (Textures[texIdx] == null)
                                        {
                                            using (MemoryStream mem = new MemoryStream())
                                            {
                                                matTex.Export(mem);
                                                mem.Position = 0;
                                                ImportedTexture image = new ImportedTexture(mem, matTex.m_Name);
                                                Textures[texIdx] = Texture.FromMemory(device, image.Data);
                                            }
                                        }
                                    }

                                    MatTexIndices.Add(matIdx, texIdx);
                                }

                                meshContainer.MaterialIndex = matIdx;
                                meshContainer.TextureIndex = texIdx;
                            }
                        }

                        for (int i = 0; i < (meshContainers.Length - 1); i++)
                        {
                            meshContainers[i].NextMeshContainer = meshContainers[i + 1];
                        }
                        if (boneList != null)
                        {
                            for (int i = 0; i < meshContainers.Length; i++)
                            {
                                meshContainers[i].BoneNames = boneNames;
                                meshContainers[i].BoneOffsets = boneOffsets;
                                meshContainers[i].RealBones = boneList.Count;
                            }
                        }

                        Matrix mirrorCombined = Operations.Mirror(animationFrame.CombinedTransform);
                        min = Vector3.TransformCoordinate(min, mirrorCombined);
                        max = Vector3.TransformCoordinate(max, mirrorCombined);
                        animationFrame.Bounds = new BoundingBox(min, max);
                        animationFrame.MeshContainer = meshContainers[0];
                        meshFrames.Add(animationFrame);
                    }
                }
            }

            for (int i = 0; i < frame.Count; i++)
            {
                Transform child = frame[i];
                if (extractFrames.Contains(child.GetTransformPath()))
                {
                    AnimationFrame childAnimationFrame = CreateFrame(child, editor, extractFrames, meshNames, device, meshFrames, extractMatrices);
                    childAnimationFrame.Parent = animationFrame;
                    animationFrame.AppendChild(childAnimationFrame);
                }
            }

            numFrames++;
            return animationFrame;
        }
예제 #2
0
        private SkelletalMesh GetMesh(GMeshContainer meshContainer, Bone root, VertexDescriptor vd)
        {
            SlimDX.Direct3D9.Mesh d3dMesh = meshContainer.Mesh;

            var adjacency                 = meshContainer.GetAdjacency();
            var meshMaterials             = meshContainer.GetMaterials();
            List <MeshMaterial> materials = new List <MeshMaterial>();

            for (int i = 0; i < meshMaterials.Length; i++)
            {
                var matd3d = meshMaterials[i].MaterialD3D;

                string textureFilename = meshMaterials[i].TextureFileName;
                if (textureFilename != null && !Path.IsPathRooted(textureFilename))
                {
                    textureFilename = Path.Combine(Path.GetDirectoryName(xFile), textureFilename);
                }

                materials.Add(new MeshMaterial()
                {
                    Name          = root.Name + "_material" + i,
                    Alpha         = matd3d.Diffuse.Alpha,
                    Diffuse       = matd3d.Diffuse.ToVector3(),
                    Specular      = matd3d.Specular.ToVector3(),
                    SpecularPower = Math.Max(1, matd3d.Power),
                    Reflectivity  = 0,
                    Refractitity  = 0,
                    EmissiveColor = matd3d.Emissive.ToVector3(),
                    DiffuseMap    = textureFilename
                });
            }


            SkelletalMesh mesh = new SkelletalMesh(vd);

            mesh.Adjacency = adjacency;
            SkinVertex[] vertexes = new SkinVertex[d3dMesh.VertexCount];
            Array        indices;

            if (d3dMesh.IndexBuffer.Description.Format == Format.Index16)
            {
                indices = new ushort[d3dMesh.FaceCount * 3];
            }
            else
            {
                indices = new uint[d3dMesh.FaceCount * 3];
            }

            VertexDescriptor meshVD = new VertexDescriptor(d3dMesh.GetDeclaration());
            int positionOffset      = meshVD.GetOffset(DeclarationUsage.Position, 0);
            int normalOffset        = meshVD.GetOffset(DeclarationUsage.Normal, 0);
            int texCoordOffset      = meshVD.GetOffset(DeclarationUsage.TextureCoordinate, 0);
            int blendIndicesOffset  = meshVD.GetOffset(DeclarationUsage.BlendIndices, 0);
            int blendIndicesSize    = meshVD.SizeOfElement(DeclarationUsage.BlendIndices, 0);
            int blendWeightsOffset  = meshVD.GetOffset(DeclarationUsage.BlendWeight, 0);
            int blendWeightSize     = meshVD.SizeOfElement(DeclarationUsage.BlendWeight, 0);

            byte[] buffer;
            unsafe
            {
                DataStream vertexStream = d3dMesh.LockVertexBuffer(0);
                buffer = new byte[vertexStream.Length];
                vertexStream.Read(buffer, 0, (int)vertexStream.Length);
                fixed(byte *_pter = buffer)
                {
                    fixed(SkinVertex *pVertexes = vertexes)
                    {
                        byte *pter = _pter;
                        int   j    = 0;

                        for (int i = 0; i < d3dMesh.VertexCount; i++)
                        {
                            pVertexes[i].Position = *((Vector3 *)(pter + positionOffset));

                            if (normalOffset >= 0)
                            {
                                pVertexes[i].Normal = *((Vector3 *)(pter + normalOffset));
                            }
                            if (texCoordOffset >= 0)
                            {
                                pVertexes[i].TexCoord = *((Vector2 *)(pter + texCoordOffset));
                            }
                            if (blendIndicesOffset >= 0)
                            {
                                byte *indicesPter = (pter + blendIndicesOffset);
                                uint *pDest       = (uint *)&(pVertexes[i].BlendIndices);
                                for (j = 0; j < blendIndicesSize; j++)
                                {
                                    *(((byte *)pDest) + j) = *(indicesPter + j);
                                }
                            }
                            if (blendWeightsOffset >= 0)
                            {
                                byte *   weightsPter = (pter + blendWeightsOffset);
                                Vector4 *pDest       = &(pVertexes[i].BlendWeights);

                                for (j = 0; j < blendWeightSize; j++)
                                {
                                    *(((byte *)pDest) + j) = *(weightsPter + j);
                                }
                            }

                            pter += d3dMesh.BytesPerVertex;
                        }
                    }
                }

                d3dMesh.UnlockVertexBuffer();

                DataStream indexStream = d3dMesh.LockIndexBuffer(0);
                GCHandle   handler     = GCHandle.Alloc(indices, GCHandleType.Pinned);
                IntPtr     indexPter   = Marshal.UnsafeAddrOfPinnedArrayElement(indices, 0);

                buffer = new byte[indexStream.Length];
                indexStream.Read(buffer, 0, (int)indexStream.Length);
                Marshal.Copy(buffer, 0, indexPter, buffer.Length);

                handler.Free();
                d3dMesh.UnlockIndexBuffer();
            }

            mesh.CreateVertexBuffer(vertexes);
            if (d3dMesh.IndexBuffer.Description.Format == Format.Index16)
            {
                mesh.CreateIndexBuffer((ushort[])indices);
            }
            else
            {
                mesh.CreateIndexBuffer((uint[])indices);
            }

            List <MeshLayer> layers = new List <MeshLayer>();

            if (meshContainer.BoneCombinations == null || meshContainer.BoneCombinations.Length == 0)
            {
                MeshLayer component = new MeshLayer();
                materials.Add(MeshMaterial.CreateDefaultMaterial(meshContainer.Name + "_default"));
                component.materialIndex  = 0;
                component.primitiveCount = mesh.FaceCount;
                component.startIndex     = 0;
                component.startVertex    = 0;
                component.vertexCount    = mesh.VertexCount;
                layers.Add(component);
            }
            else
            {
                for (int i = 0; i < meshContainer.BoneCombinations.Length; i++)
                {
                    BoneCombination comb = meshContainer.BoneCombinations[i];

                    MeshLayer component = new MeshLayer();
                    component.materialIndex  = comb.AttributeId;
                    component.primitiveCount = comb.FaceCount;
                    component.startIndex     = comb.FaceStart * 3;
                    component.startVertex    = comb.VertexStart;
                    component.vertexCount    = comb.VertexCount;

                    layers.Add(component);
                }
            }

            var layerArray = layers.ToArray();

            mesh.Materials = materials.ToArray();
            mesh.SetLayers(layerArray);

            var skinInfo = meshContainer.SkinInfo;

            mesh.MaxVertexInfluences = skinInfo.MaximumVertexInfluences;

            var bones = new Bone[skinInfo.BoneCount];
            var boneOffsetMatrices = new Matrix[bones.Length];

            for (int i = 0; i < bones.Length; i++)
            {
                bones[i] = root.FindChild(skinInfo.GetBoneName(i));
                boneOffsetMatrices[i] = skinInfo.GetBoneOffsetMatrix(i);
            }

            mesh.Bones = bones;
            mesh.BoneBindingMatrices = boneOffsetMatrices;

            if (meshContainer.BoneCombinations != null && meshContainer.BoneCombinations.Length > 0)
            {
                for (int layerIndex = 0; layerIndex < layerArray.Length; layerIndex++)
                {
                    mesh.SetLayerBones(layerIndex, meshContainer.BoneCombinations[layerIndex].BoneIds);
                }
            }

            mesh.LockVertexBuffer();
            int[]   vertices;
            float[] weights;
            for (int i = 0; i < mesh.bones.Length; i++)
            {
                skinInfo.GetBoneInfluence(i, out vertices, out weights);
                VertexStreamView <Vector3> positions = mesh.GetVertexViewStream <Vector3>(DeclarationUsage.Position, 0, vertices);
            }
            mesh.UnlockVertexBuffer();

            meshVD.Dispose();

            if (normalOffset < 0)
            {
                mesh.ComputeNormals();
            }
            if (texCoordOffset < 0)
            {
                mesh.ComputeTextureCoords(CoordMappingType.Spherical);
            }

            mesh.ComputeTangents();

            return(mesh);
        }
예제 #3
0
        public static void BuildFromMesh(DX.Mesh mesh, MeshData <Material> data, Material[][] mats)
        {
            void *src = mesh.LockVertexBuffer(DX.LockFlags.None).DataPointer.ToPointer();

            byte[] buffer = new byte[mesh.VertexCount * mesh.BytesPerVertex];

            fixed(byte *dst = &buffer[0])
            {
                Memory.Copy(src, dst, buffer.Length);
                data.SetData(dst, buffer.Length);
            }

            mesh.UnlockVertexBuffer();

            data.Materials         = mats;
            data.MaterialAnimation = new MaterialAnimationInstance[mats.Length]; //{ new MaterialAnimationInstance(matAnimData) };
            for (int i = 0; i < mats.Length; i++)
            {
                MaterialAnimation matAnimData = new MaterialAnimation(mats[i].Length, 0.025f);
                data.MaterialAnimation[i] = new MaterialAnimationInstance(matAnimData);
            }
            data.VertexSize  = mesh.BytesPerVertex;
            data.VertexCount = mesh.VertexCount;

            DX.VertexElement[] elements = DX.D3DX.DeclaratorFromFVF(mesh.VertexFormat);

            data.VertexElements = new VertexElement[elements.Length];
            for (int i = 0; i < elements.Length - 1; i++)
            {
                data.VertexElements[i] = new VertexElement(elements[i].Offset, Convert(elements[i].Type), Convert(elements[i].Usage), elements[i].UsageIndex);
                //data.VertexElements [i]= new VertexElement (elements[i].Offset,
                //data.VertexElements[i].Index = elements[i].UsageIndex;
                //data.VertexElements[i].Offset = elements[i].Offset;
                //data.VertexElements[i].s
            }
            //Array.Copy(elements, data.VertexElements, elements.Length);

            int faceCount = mesh.FaceCount;

            data.Faces = new MeshFace[faceCount];

            uint *ab = (uint *)mesh.LockAttributeBuffer(DX.LockFlags.ReadOnly).DataPointer.ToPointer();

            if ((mesh.CreationOptions & DX.MeshFlags.Use32Bit) == DX.MeshFlags.Use32Bit)
            {
                uint *ib = (uint *)mesh.LockIndexBuffer(DX.LockFlags.ReadOnly).DataPointer.ToPointer();
                for (int i = 0; i < faceCount; i++)
                {
                    int idxId = i * 3;

                    data.Faces[i] = new MeshFace((int)ib[idxId], (int)ib[idxId + 1], (int)ib[idxId + 2], (int)ab[i]);
                }
                mesh.UnlockIndexBuffer();
            }
            else
            {
                ushort *ib = (ushort *)mesh.LockIndexBuffer(DX.LockFlags.ReadOnly).DataPointer.ToPointer();
                for (int i = 0; i < faceCount; i++)
                {
                    int idxId = i * 3;

                    data.Faces[i] = new MeshFace(ib[idxId], ib[idxId + 1], ib[idxId + 2], (int)ab[i]);
                }
                mesh.UnlockIndexBuffer();
            }

            mesh.UnlockAttributeBuffer();
        }
예제 #4
0
        public SceneImportResult LoadStaticMesh(string filename)
        {
            var file                = new FileInfo(filename);
            VertexDescriptor vd     = VertexDescriptor.Get <ModelVertex>();
            List <MeshLayer> layers = new List <MeshLayer>();

            int[] adjacency;
            ExtendedMaterial[] meshMaterials;
            Mesh mesh = new Mesh(vd);
            List <MeshMaterial> material = new List <MeshMaterial>();

            using (SlimDX.Direct3D9.Mesh d3dMesh = SlimDX.Direct3D9.Mesh.FromFile(Engine.Graphics, filename, MeshFlags.Managed))
            {
                adjacency     = d3dMesh.GetAdjacency();
                meshMaterials = d3dMesh.GetMaterials();

                for (int i = 0; i < meshMaterials.Length; i++)
                {
                    var    matd3d          = meshMaterials[i].MaterialD3D;
                    string textureFilename = meshMaterials[i].TextureFileName;
                    if (textureFilename != null && !Path.IsPathRooted(textureFilename))
                    {
                        textureFilename = Path.Combine(Path.GetDirectoryName(filename), textureFilename);
                    }
                    material.Add(new MeshMaterial()
                    {
                        Name          = file.Name + "_material" + i,
                        Alpha         = matd3d.Diffuse.Alpha,
                        Diffuse       = matd3d.Diffuse.ToVector3(),
                        Specular      = matd3d.Specular.ToVector3(),
                        SpecularPower = Math.Max(1, matd3d.Power),
                        Reflectivity  = 0,
                        Refractitity  = 0,
                        EmissiveColor = matd3d.Emissive.ToVector3(),
                        DiffuseMap    = textureFilename != null && File.Exists(textureFilename) ?
                                        textureFilename : null
                    });
                }

                ModelVertex[] vertexes = new ModelVertex[d3dMesh.VertexCount];
                Array         indices;

                if (d3dMesh.IndexBuffer.Description.Format == Format.Index16)
                {
                    indices = new ushort[d3dMesh.FaceCount * 3];
                }
                else
                {
                    indices = new uint[d3dMesh.FaceCount * 3];
                }

                DataStream       vertexStream = d3dMesh.LockVertexBuffer(0);
                VertexDescriptor meshVD       = new VertexDescriptor(d3dMesh.GetDeclaration());
                int    positionOffset         = meshVD.GetOffset(DeclarationUsage.Position, 0);
                int    normalOffset           = meshVD.GetOffset(DeclarationUsage.Normal, 0);
                int    texCoordOffset         = meshVD.GetOffset(DeclarationUsage.TextureCoordinate, 0);
                byte[] buffer;
                unsafe
                {
                    buffer = new byte[vertexStream.Length];
                    vertexStream.Read(buffer, 0, (int)vertexStream.Length);
                    fixed(byte *_pter = buffer)
                    {
                        byte *pter = _pter;

                        for (int i = 0; i < d3dMesh.VertexCount; i++)
                        {
                            vertexes[i].Position = *((Vector3 *)(pter + positionOffset));
                            if (normalOffset > 0)
                            {
                                vertexes[i].Normal = *((Vector3 *)(pter + normalOffset));
                            }
                            if (texCoordOffset > 0)
                            {
                                vertexes[i].TexCoord = *((Vector2 *)(pter + texCoordOffset));
                            }

                            pter += d3dMesh.BytesPerVertex;
                        }
                    }

                    d3dMesh.UnlockVertexBuffer();

                    DataStream indexStream = d3dMesh.LockIndexBuffer(0);
                    GCHandle   handler     = GCHandle.Alloc(indices, GCHandleType.Pinned);
                    byte *     indexPter   = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(indices, 0);

                    buffer = new byte[indexStream.Length];
                    indexStream.Read(buffer, 0, (int)indexStream.Length);
                    for (int i = 0; i < indexStream.Length; i++)
                    {
                        indexPter[i] = buffer[i];
                    }
                    handler.Free();
                    d3dMesh.UnlockIndexBuffer();
                }

                mesh.CreateVertexBuffer(vertexes);
                if (d3dMesh.IndexBuffer.Description.Format == Format.Index16)
                {
                    mesh.CreateIndexBuffer((ushort[])indices);
                }
                else
                {
                    mesh.CreateIndexBuffer((uint[])indices);
                }

                var d3dComponents = d3dMesh.GetAttributeTable();
                if (d3dComponents == null)
                {
                    MeshLayer component = new MeshLayer();
                    layers.Add(component);
                    material.Add(MeshMaterial.CreateDefaultMaterial(file.Name + "_default"));

                    component.materialIndex  = 0;
                    component.primitiveCount = mesh.FaceCount;
                    component.startIndex     = 0;
                    component.startVertex    = 0;
                    component.vertexCount    = mesh.VertexCount;
                }
                else
                {
                    for (int i = 0; i < d3dComponents.Length; i++)
                    {
                        AttributeRange ar = d3dComponents[i];

                        MeshLayer component = new MeshLayer();
                        layers.Add(component);

                        component.materialIndex  = ar.AttribId;
                        component.primitiveCount = ar.FaceCount;
                        component.startIndex     = ar.FaceStart * 3;
                        component.startVertex    = ar.VertexStart;
                        component.vertexCount    = ar.VertexCount;
                    }
                }

                mesh.Materials = material.ToArray();
                mesh.SetLayers(layers.ToArray());

                if (normalOffset < 0)
                {
                    mesh.ComputeNormals();
                }
                if (texCoordOffset < 0)
                {
                    mesh.ComputeTextureCoords(CoordMappingType.Spherical);
                }

                mesh.ComputeTangents();

                meshVD.Dispose();
            }

            StaticMeshSceneNode meshNode = new StaticMeshSceneNode(file.Name, mesh);

            return(new SceneImportResult {
                VisualSceneRoot = meshNode, VisualMaterials = material
            });
        }