bool ModelImporter::Import()
{
    String modelAssetFilename = asset_->GetPath();

    importNode_ = new Node(context_);

    // skip external animations, they will be brought in when importing their
    // corresponding model
    if (!modelAssetFilename.Contains("@"))
    {
        ImportModel();

        if (importAnimations_)
        {
            ImportAnimations();
        }

    }

    File outFile(context_);

    if (!outFile.Open(asset_->GetCachePath(), FILE_WRITE))
        ErrorExit("Could not open output file " + asset_->GetCachePath());

    importNode_->SaveXML(outFile);

    importNode_ = 0;

    return true;
}
bool ModelImporter::Import()
{

    String ext = asset_->GetExtension();
    String modelAssetFilename = asset_->GetPath();

    importNode_ = new Node(context_);

    if (ext == ".mdl")
    {
        FileSystem* fs = GetSubsystem<FileSystem>();
        ResourceCache* cache = GetSubsystem<ResourceCache>();

        // mdl files are native file format that doesn't need to be converted
        // doesn't allow scale, animations legacy primarily for ToonTown

        if (!fs->Copy(asset_->GetPath(), asset_->GetCachePath() + ".mdl"))
        {
            importNode_= 0;
            return false;
        }

        Model* mdl = cache->GetResource<Model>( asset_->GetCachePath() + ".mdl");

        if (!mdl)
        {
            importNode_= 0;
            return false;
        }

        // Force a reload, though file watchers will catch this delayed and load again
        cache->ReloadResource(mdl);

        importNode_->CreateComponent<StaticModel>()->SetModel(mdl);
    }
    else
    {
        // skip external animations, they will be brought in when importing their
        // corresponding model

        if (!modelAssetFilename.Contains("@"))
        {
            ImportModel();

            if (importAnimations_)
            {
                ImportAnimations();
            }

            AnimatedModel* animatedModel = importNode_->GetComponent<AnimatedModel>();
            if (animatedModel)
            {
                Model* model = animatedModel->GetModel();
                if (model && model->GetAnimationCount())
                {
                    // resave with animation info

                    File mdlFile(context_);
                    if (!mdlFile.Open(asset_->GetCachePath() + ".mdl", FILE_WRITE))
                    {
                        ErrorExit("Could not open output file " + asset_->GetCachePath() + ".mdl");
                        return false;
                    }

                    model->Save(mdlFile);
                }
            }
        }
    }


    File outFile(context_);

    if (!outFile.Open(asset_->GetCachePath(), FILE_WRITE))
        ErrorExit("Could not open output file " + asset_->GetCachePath());

    importNode_->SaveXML(outFile);

    importNode_ = 0;

    return true;
}