예제 #1
0
bool SceneLoader::LoadScene(const std::string& file_name, Scene& scene,
                            std::string& status) {
    Assimp::Importer importer;
    importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE,
                                aiPrimitiveType_POINT | aiPrimitiveType_LINE);
    const aiScene* assimp_scene = importer.ReadFile(file_name,
                                  aiProcess_Triangulate | aiProcess_JoinIdenticalVertices
                                  | aiProcess_FixInfacingNormals | aiProcess_FindDegenerates
                                  | aiProcess_ValidateDataStructure);
    // | aiProcess_ImproveCacheLocality
    //  | aiProcess_RemoveRedundantMaterials
    //  | aiProcess_FixInfacingNormals | aiProcess_FindDegenerates
    // | aiProcess_OptimizeGraph | aiProcess_OptimizeMeshes);
    status = std::string(importer.GetErrorString());
    if (!status.empty() || NULL == assimp_scene) {
        return false;
    }
    status = "OK";
    for (uint32_t i = 0; i < assimp_scene->mNumCameras; ++i) {
        ImportCamera(scene, assimp_scene->mCameras[i]);
    }
    for (uint32_t i = 0; i < assimp_scene->mNumLights; ++i) {
        ImportLight(scene, assimp_scene->mLights[i]);
    }
    std::cout << "mNumMaterials = " << assimp_scene->mNumMaterials << std::endl;
    for (uint32_t i = 0; i < assimp_scene->mNumMaterials; ++i) {
        ImportMaterial(scene, assimp_scene->mMaterials[i]);
    }
    std::cout << "mNumMeshes = " << assimp_scene->mNumMeshes << std::endl;
    for (uint32_t i = 0; i < assimp_scene->mNumMeshes; ++i) {
        ImportMesh(scene, assimp_scene->mMeshes[i]);
    }
    return true;
}
예제 #2
0
// Start the importer!
int AsciiImp::DoImport(const TCHAR *name,ImpInterface *ii,Interface *i, BOOL suppressPrompts) 
{
	int		status = 1;
	int		lastProgress = 0;
	int		progress;
	BOOL	fileValid = FALSE;

	mtlTab.ZeroCount();
	mtlTab.Shrink();

	// Grab the interface pointer.
	ip = i;
	impip = ii;
	
	// Prompt the user with our dialogbox.
	if (!DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_ASCIIIMPORT_DLG),
		ip->GetMAXHWnd(), ImportDlgProc, (LPARAM)this)) {
		return 1;
	}
	
	// Open the stream
	pStream = _tfopen(name,_T("rt"));
	if (!pStream) {
		return 0;
	}

	// Get the file size
	fseek(pStream, 0, SEEK_END);
	long fsize = ftell(pStream);
	fseek(pStream, 0, SEEK_SET);

	if(resetScene) {
		impip->NewScene();
	}

	TCHAR* token = NULL;

	
	token = GetToken();
	if (token) {
		if (Compare(token, ID_FILEID)) {
			fileVersion = (int)GetFloat();
			if (fileVersion >= 200 && fileVersion <= 200) {
				fileValid = TRUE;
			}
		}
	}

	if (!fileValid) {
		BadFile();
		fclose(pStream);
		return FALSE;
	}

#ifndef USE_IMPNODES
	ip->DisableSceneRedraw();
#endif

	// Startup the progress bar.
	ip->ProgressStart(_T("Importing file..."), TRUE, fn, NULL);

	long fpos = 0;
	while ((token = GetToken()) != NULL) {

		if (ip->GetCancel()) {
			status = 0;
			break;
		}

		// Update the progress meter
		// We will eliminate flicker by only calling this when it changes.
		fpos = ftell(pStream);
		progress = 100*fpos/fsize;
		if (progress != lastProgress) {
			ip->ProgressUpdate(progress);
		}
		lastProgress = progress;

		DebugPrint(_T("Token: %s\n"), token);

		if (Compare(token, ID_SCENE)) {
			ImportSceneParams();
		}
		else if (Compare(token, ID_MATERIAL_LIST)) {
			ImportMaterialList();
		}
		else if (Compare(token, ID_GEOMETRY)) {
			ImportGeomObject();
		}
		else if (Compare(token, ID_SHAPE)) {
			ImportShape();
		}
		else if (Compare(token, ID_HELPER)) {
			ImportHelper();
		}
		else if (Compare(token, ID_CAMERA)) {
			ImportCamera();
		}
		else if (Compare(token, ID_LIGHT)) {
			ImportLight();
		}
		else if (Compare(token, ID_COMMENT)) {
			GetToken();
		}
#ifndef USE_IMPNODES
		// ImpNodes doesn't support group creation!

		else if (Compare(token, ID_GROUP)) {
			groupMgr.BeginGroup(GetString());
			GetToken();		// BlockBegin
			GetToken();		// GroupDummy HelperObject
			GetToken();		// GroupDummy BlockBegin
			SkipBlock();	// GroupDummy
		}
		else if (Compare(token, _T("}"))) {
			groupMgr.EndGroup(ip);
		}
#endif
	}
	
	ip->ProgressEnd();

#ifndef USE_IMPNODES
	ip->EnableSceneRedraw();
#endif

	// Close the stream
	fclose(pStream);
	return status;
}