示例#1
0
int main (int argc, char** argv)
{
	int i;
	LIMdlBuilder* builder;
	LIMdlModel* model;

	if (!argc || !strcmp (argv[1], "--help") || !strcmp (argv[1], "-h"))
	{
		printf ("Usage: %s [lmdl...]\n", argv[0]);
		return 0;
	}

	for (i = 1 ; i < argc ; i++)
	{
		/* Load the model. */
		model = limdl_model_new_from_file (argv[i], 1);
		if (model == NULL)
		{
			lisys_error_report ();
			continue;
		}

		/* Check for existing LOD. */
		if (!model->lod.array[0].indices.count)
		{
			printf ("      Unneeded %s\n", argv[i]);
			continue;
		}
		if (model->lod.count > 1)
		{
			printf ("%3d%%: Existing %s\n", 100 - 100 *
				model->lod.array[model->lod.count - 1].indices.count /
				model->lod.array[0].indices.count, argv[i]);
			limdl_model_free (model);
			continue;
		}

		/* Build the detail levels. */
		builder = limdl_builder_new (model);
		if (builder == NULL)
		{
			lisys_error_report ();
			limdl_model_free (model);
			continue;
		}
		limdl_builder_calculate_lod (builder, 5, 0.05f);
		limdl_builder_finish (builder);
		limdl_builder_free (builder);

		/* Save the modified model. */
		printf ("%3d%%: Built    %s\n", 100 - 100 *
			model->lod.array[model->lod.count - 1].indices.count /
			model->lod.array[0].indices.count, argv[i]);
		limdl_model_write_file (model, argv[i]);
		limdl_model_free (model);
	}

	return 0;
}
示例#2
0
static void Model_load (LIScrArgs* args)
{
	int mesh = 1;
	char* file;
	const char* name;
	const char* path;
	LIMdlModel* tmpmdl;
	LIMaiProgram* program;

	program = liscr_script_get_userdata (args->script, LISCR_SCRIPT_PROGRAM);
	if (!liscr_args_geti_string (args, 0, &name) &&
	    !liscr_args_gets_string (args, "file", &name))
		return;
	if (!liscr_args_geti_bool (args, 1, &mesh))
		liscr_args_gets_bool (args, "mesh", &mesh);

	/* Find the absolute path. */
	file = lisys_string_concat (name, ".lmdl");
	if (file == NULL)
		return;
	path = lipth_paths_find_file (program->paths, file);
	if (path == NULL)
	{
		lisys_free (file);
		return;
	}
	lisys_free (file);

	/* Load the new model data. */
	tmpmdl = limdl_model_new_from_file (path, mesh);
	if (tmpmdl == NULL)
		return;

	/* Replace the old model data. */
	if (limdl_model_replace (args->self, tmpmdl))
		liscr_args_seti_bool (args, 1);
	limdl_model_free (tmpmdl);
}