Example #1
0
static void Model_copy (LIScrArgs* args)
{
	int shape_keys = 1;
	LIMaiProgram* program;
	LIMdlModel* self;
	LIScrData* data;

	/* Get arguments. */
	program = liscr_script_get_userdata (args->script, LISCR_SCRIPT_PROGRAM);
	liscr_args_geti_bool (args, 0, &shape_keys);

	/* Allocate the model. */
	self = limdl_model_new_copy (args->self, shape_keys);
	if (self == NULL)
		return;

	/* Allocate the unique ID. */
	if (!limdl_manager_add_model (program->models, self))
	{
		limdl_model_free (self);
		return;
	}

	/* Allocate userdata. */
	data = liscr_data_new (args->script, args->lua, self, LISCR_SCRIPT_MODEL, limdl_manager_free_model);
	if (data == NULL)
	{
		limdl_model_free (self);
		return;
	}
	liscr_args_seti_stack (args);
}
Example #2
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;
}
Example #3
0
static void Terrain_build_chunk_model (LIScrArgs* args)
{
	int grid_x;
	int grid_z;
	LIExtTerrain* self;
	LIExtTerrainModule* module;
	LIMatVector offset;
	LIMdlModel* model;
	LIScrData* data;

	/* Get the arguments. */
	self = args->self;
	module = liscr_script_get_userdata (args->script, LIEXT_SCRIPT_TERRAIN);
	if (!liscr_args_geti_int (args, 0, &grid_x) || grid_x < 0)
		return;
	if (!liscr_args_geti_int (args, 1, &grid_z) || grid_z < 0)
		return;
	if (!liscr_args_geti_vector (args, 2, &offset))
		offset = limat_vector_init (grid_x * self->grid_size, 0.0f, grid_z * self->grid_size);

	/* Build the model. */
	model = liext_terrain_build_chunk_model (self, grid_x, grid_z, &offset);
	if (model == NULL)
		return;

	/* Copy the model. */
	model = limdl_model_new_copy (model, 0);
	if (model == NULL)
		return;

	/* Allocate the unique ID. */
	if (!limdl_manager_add_model (module->program->models, model))
	{
		limdl_model_free (model);
		return;
	}

	/* Allocate the userdata. */
	data = liscr_data_new (args->script, args->lua, model, LISCR_SCRIPT_MODEL, limdl_manager_free_model);
	if (data == NULL)
	{
		limdl_model_free (model);
		return;
	}
	liscr_args_seti_stack (args);
}
Example #4
0
void limai_message_free (
	LIMaiMessage* self)
{
	switch (self->type)
	{
		case LIMAI_MESSAGE_TYPE_EMPTY:
			break;
		case LIMAI_MESSAGE_TYPE_MODEL:
			if (self->model != NULL)
				limdl_model_free (self->model);
			break;
		case LIMAI_MESSAGE_TYPE_STRING:
			lisys_free (self->string);
			break;
		default:
			lisys_assert (0);
			break;
	}
	lisys_free (self->name);
	lisys_free (self);
}
Example #5
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);
}