Jump to content

Import system


photo

Recommended Posts

Hello.

I use Import system in runtime (https://developer.unigine.com/en/docs/2.7.3/principles/import_system/?words=import%2Csystem#customize). Now I use standart FbxImporter from Unigine sdk 2.7.

I almost everything figured out thanks to technical support, import is working, but there is another question.

The source fbx file has many meshes with the same name (for example, "3d body"). When importing, .mesh files with the same names are created, but since the names are the same, each new file created overwrites the old one and as a result I have only one "3d body.mesh" file in the output folder and the model turns out to be incorrect. Perhaps I can edit the FbxImporter so when it add unique ID to importing mesh name and then created files will have different names?

This problem does not occur when you manually import through Unigine Editor.

Tell me how else you can solve this problem.

 

By the way, for some reason I can't send a message to Private Support. The website is broken?

Edited by kzaharov
Link to comment

kzaharov

Quote

By the way, for some reason I can't send a message to Private Support. The website is broken?

There is an issue with Chrome browser and support form, we plan to fix this tomorrow.

 

Quote

 Perhaps I can edit the FbxImporter so when it add unique ID to importing mesh name and then created files will have different names?

I belive that would be the best solution. We do not use file names directly in Editor2 and for each mesh we generate uniq guid instead of name and copying that file to the .runtimes directory. Maybe you can use the same approach in your case.

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
Yes, you can:
void make_unique_names(const Vector<String> &input, Vector<String> &output)
{
	output.resize(input.size());
	Map<String, Vector<int>> map;
	int num_inputs = input.size();
	for (int i = 0; i < num_inputs; ++i)
		map[input[i]].append(i);

	for (auto it = map.begin(); it != map.end(); ++it)
	{
		String name = it->key;
		int shift = 0;

		int index = name.rfind('_');
		if (index != -1 && String::isdigit(name.last()))
		{
			name.remove(index, name.size() - index);
			shift = String::atoi(name.get() + index + 1);
		}

		const Vector<int> &indices = it->data;
		output[indices[0]] = input[indices[0]];
		int num_indices = indices.size();
		for (int i = 1; i < num_indices; ++i)
			output[indices[i]] = name + "_" + String::itoa(i - 1 + shift);
	}
}

void create_unique_meshes_names(ImportScene *scene)
{
	Vector<String> inputs;
	inputs.allocate(scene->getNumMeshes());

	Vector<String> outputs;
	for (ImportMesh *mesh : scene->getMeshes())
		inputs.appendFast(String(mesh->name).lower());

	make_unique_names(inputs, outputs);

	int num_outputs = outputs.size();
	for (int i = 0; i < num_outputs; ++i)
		scene->getMesh(i)->name = std::move(outputs[i]);
}

void import()
{
  	const char *import_path = "test.fbx";
	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");
		}
	}
}

 

Link to comment
×
×
  • Create New...