// --------------------------------------------------------------------

        private void ImportMeshes()
        {
            mLoadedMeshes = new int[mCurrentModel.MeshCount];


            List <ModelSupportData.MeshData> previousMeshes = new List <ModelSupportData.MeshData>(mSupportFile.Meshes);

            mSupportFile.Meshes.Clear();

            for (int i = 0; i < mCurrentModel.MeshCount; ++i)
            {
                Onyx3D.Mesh onyxMesh = mCurrentModel.Meshes[i].ToOnyx3D();
                onyxMesh.Scale(sMeshScalar);
                string name     = mCurrentModel.Meshes[i].Name;
                string meshPath = ProjectContent.GetMeshPath(name);
                AssetLoader <Onyx3D.Mesh> .Save(onyxMesh, meshPath, false);

                int id = -1;
                for (int prevIndex = 0; prevIndex < previousMeshes.Count; ++prevIndex)
                {
                    ModelSupportData.MeshData mesh = previousMeshes[prevIndex];
                    if (mesh.Name == name)
                    {
                        id = mesh.Id;
                        previousMeshes.Remove(mesh);
                        break;
                    }
                }

                if (id < 0)
                {
                    id = ProjectManager.Instance.Content.AddMesh(meshPath, false, onyxMesh).Guid;
                }

                mLoadedMeshes[i] = id;

                ModelSupportData.MeshData data = new ModelSupportData.MeshData();
                data.Id   = id;
                data.Name = name;
                mSupportFile.Meshes.Add(data);

                Onyx3DEngine.Instance.Resources.GetMesh(id).IsDirty = true;
            }

            foreach (ModelSupportData.MeshData meshData in previousMeshes)
            {
                if (mSupportFile.GetMeshId(meshData.Name) < 0)
                {
                    if (MessageBox.Show("Mesh " + meshData.Name + " is no longer part of the new model. Do you want to keep it in the project?", "Mesh Disappeared", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        ProjectManager.Instance.Content.RemoveMesh(meshData.Id);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // --------------------------------------------------------------------

        private int ImportMesh(Assimp.Mesh newMesh, List<ModelSupportData.MeshData> previousMeshes)
        {
            Onyx3D.Mesh onyxMesh = newMesh.ToOnyx3D();
            onyxMesh.Scale(sMeshScalar);
            string name = GetSafeFileName(newMesh.Name);
            string meshPath = ProjectContent.GetMeshPath(name);
            AssetLoader<Onyx3D.Mesh>.Save(onyxMesh, meshPath, false);

            int id = -1;
            for (int prevIndex = 0; prevIndex < previousMeshes.Count; ++prevIndex)
            {
                ModelSupportData.MeshData mesh = previousMeshes[prevIndex];
                if (mesh.Name == name)
                {
                    id = mesh.Id;
                    previousMeshes.Remove(mesh);
                    break;
                }
            }

            if (id < 0)
            {
                id = ProjectManager.Instance.Content.AddMesh(meshPath, false, onyxMesh).Guid;
            }
            else
            {
                OnyxProjectAsset asset = ProjectManager.Instance.Content.GetAsset(id);
                if (asset == null)
                {
                    ProjectManager.Instance.Content.AddObject(meshPath, false, ProjectManager.Instance.Content.Meshes, id, onyxMesh);
                }
                else
                {
                    onyxMesh.LinkedProjectAsset = asset;
                }
            }


            ModelSupportData.MeshData data = new ModelSupportData.MeshData();
            data.Id = id;
            data.Name = name;
            mSupportFile.Meshes.Add(data);
            
            ProjectManager.Instance.Content.MarkDirty(id);

            return id;
        }