コード例 #1
0
bool ModelImporter::ImportAnimation(const String& filename, const String& name, float startTime, float endTime)
{
    SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));

    //importer->SetVerboseLog(true);

    importer->SetScale(scale_);
    importer->SetExportAnimations(true);
    importer->SetStartTime(startTime);
    importer->SetEndTime(endTime);

    if (importer->Load(filename))
    {
        importer->ExportModel(asset_->GetCachePath(), name, true);

        const Vector<OpenAssetImporter::AnimationInfo>& infos = importer->GetAnimationInfos();

        for (unsigned i = 0; i < infos.Size(); i++)
        {
            const OpenAssetImporter::AnimationInfo& info = infos.At(i);

            String pathName, fileName, extension;

            SplitPath(info.cacheFilename_, pathName, fileName, extension);

            ResourceCache* cache = GetSubsystem<ResourceCache>();

            AnimatedModel* animatedModel = importNode_->GetComponent<AnimatedModel>();

            if (animatedModel)
            {
                Model* model = animatedModel->GetModel();

                if (model)
                {
                    SharedPtr<Animation> animation = cache->GetTempResource<Animation>(fileName + extension);
                    if (animation)
                        model->AddAnimationResource(animation);
                }

            }

            LOGINFOF("Import Info: %s : %s", info.name_.CString(), fileName.CString());
        }

        return true;
    }

    return false;

}
コード例 #2
0
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;
}