Jump to content

[SOLVED] How to import DAE file in C++ code


photo

Recommended Posts

Posted

My Unigine version is 2.7 .

I can drag and drop a dae file into asset browser and it can works in editor and scene with no problem.

And now I need to do same thing in the C++ code by using below code sample ,but failed .

These codes are copied from offical documents.

			Unigine::String filepath_node;
			bool ret = Unigine::Import::get()->import("D:\\test.dae", "../data/", filepath_node);
			// create a node reference using the .node file generated
			Unigine::NodeReferencePtr noderef = Unigine::NodeReference::create(filepath_node.get());
			noderef.get()->setWorldPosition(Unigine::Math::Vec3(1,2,3));

But the return value is 0 and it seems no objects generated in the scene .

Thanks for any suggestion and reply .

Especailly @silent

 

Posted
On 6/4/2024 at 9:40 PM, ramendeus.chris said:

My Unigine version is 2.7 .

I can drag and drop a dae file into asset browser and it can works in editor and scene with no problem.

And now I need to do same thing in the C++ code by using below code sample ,but failed .

These codes are copied from offical documents.

			Unigine::String filepath_node;
			bool ret = Unigine::Import::get()->import("D:\\test.dae", "../data/", filepath_node);
			// create a node reference using the .node file generated
			Unigine::NodeReferencePtr noderef = Unigine::NodeReference::create(filepath_node.get());
			noderef.get()->setWorldPosition(Unigine::Math::Vec3(1,2,3));

But the return value is 0 and it seems no objects generated in the scene .

Thanks for any suggestion and reply .

Especailly @silent

 

Hello!

The log file might help shed light on this issue but most likely the FbxImporter plugin is not initialized for some reason. Therefore, make sure you run it properly using the following argument: -extern_plugin "FbxImporter". Moreover, runtime import through the API is a SIM feature which might not be available for the edition you have.

Thanks!

  • Like 1
Posted

Thanks .

My Unigine version is SIM .And added -extern_plugin "Collada,FbxImporter" 

image.png.829bfb46448d52267ea621bc80b43a45.png

However , can't find importer 

image.png.56ee51ce0f648720287510dcdb3652fa.png

 

related codes are :

			const char* import_path = "d:\\material_ball.dae";
			const char* output_dir = "../data/";
			Importer* importer = Import::get()->createImporterByFileName(import_path);
			if (importer)
			{
				if (importer->init(import_path, ~0))
				{
					create_unique_meshes_names(importer->getScene());
					if (importer->import(output_dir))
						Log::message("Import done.\n");
				}
			}

 

Posted (edited)

Thanks bmyagkov.

  • You are correct.
  • I found that my version is SIM ,however evaluation version. I fixed that ,and the import plugin can work fine now.

 

The new problem ,is I try to add node reference to editor ,however the scene seems no object added.

			bool ret = Unigine::Import::get()->import(import_path, output_dir, filepath_node);
			Unigine::NodeReferencePtr noderef = Unigine::NodeReference::create(filepath_node.get());
			
			//noderef.get()->setWorldPosition(Unigine::Math::Vec3(block.origin.x, block.origin.y, block.origin.z));
			noderef.get()->setWorldPosition(Unigine::Math::Vec3(10.0,0.0,0.0));
			noderef.get()->release();
			Editor::get()->addNode(noderef.get()->getNode());

 

Thanks for reply

 

 

Edited by ramendeus.chris
  • Like 1
  • bmyagkov changed the title to [SOLVED] How to import DAE file in C++ code
Posted
3 hours ago, ramendeus.chris said:

The new problem ,is I try to add node reference to editor ,however the scene seems no object added.

This might be related to the "scale" parameter, so it would be advisable to give it a comprehensive check :)

Posted

Спасибо .

Очень полезно .

 

×
×
  • Create New...