PyObject *py_ue_draw_debug_line(ue_PyUObject * self, PyObject * args)
{

	ue_py_check(self);

	PyObject *py_obj_start;
	PyObject *py_obj_end;
	PyObject *py_color;
	float duration = 0;
	float thickness = 0;

	UWorld *world = ue_get_uworld(self);
	if (!world)
		return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");


	if (!PyArg_ParseTuple(args, "OOO|ff:draw_debug_line", &py_obj_start, &py_obj_end, &py_color, &duration, &thickness))
	{
		return NULL;
	}

	ue_PyFVector *start = py_ue_is_fvector(py_obj_start);
	ue_PyFVector *end = py_ue_is_fvector(py_obj_end);

	if (!start || !end)
		return PyErr_Format(PyExc_Exception, "start and end location must be vectors");

	ue_PyFLinearColor *py_linear_color = py_ue_is_flinearcolor(py_color);
	if (!py_linear_color)
		return PyErr_Format(PyExc_Exception, "argument is not a FLinearColor");

	UKismetSystemLibrary::DrawDebugLine(world, start->vec, end->vec, py_linear_color->color, duration, thickness);

	Py_RETURN_NONE;
}
static int py_ue_fraw_anim_sequence_track_set_scale_keys(ue_PyFRawAnimSequenceTrack *self, PyObject *value, void *closure)
{
	TArray<FVector> scale;
	if (value)
	{
		PyObject *py_iter = PyObject_GetIter(value);
		if (py_iter)
		{
			bool failed = false;
			while (PyObject *py_item = PyIter_Next(py_iter))
			{
				ue_PyFVector *py_vec = py_ue_is_fvector(py_item);
				if (!py_vec)
				{
					failed = true;
					break;
				}
				scale.Add(py_vec->vec);
			}
			Py_DECREF(py_iter);
			if (!failed)
			{
				self->raw_anim_sequence_track.ScaleKeys = scale;
				return 0;
			}
		}
	}
	PyErr_SetString(PyExc_TypeError, "value is not an iterable of FVector's");
	return -1;
}
static PyObject *py_ue_spython_editor_viewport_set_view_location(ue_PySPythonEditorViewport *self, PyObject * args)
{
	ue_py_slate_cast(SPythonEditorViewport);
	float x = 0, y = 0, z = 0;

	FVector vec;

	if (PyTuple_Size(args) == 1)
	{
		ue_PyFVector *ue_py_vec = py_ue_is_fvector(PyTuple_GetItem(args, 0));
		if (!ue_py_vec)
		{
			return PyErr_Format(PyExc_Exception, "argument is not a FVector");
		}
		vec = ue_py_vec->vec;
	}
	else
	{
		if (!PyArg_ParseTuple(args, "fff", &x, &y, &z))
		{
			return nullptr;;
		}
		vec.X = x;
		vec.Y = y;
		vec.Z = z;
	}

	py_SPythonEditorViewport->GetViewportClient()->SetViewLocation(vec);

	Py_RETURN_SLATE_SELF;
}
PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject * args)
{

	ue_py_check(self);

	PyObject *py_obj_start;
	PyObject *py_obj_end;
	int channel;

	UWorld *world = ue_get_uworld(self);
	if (!world)
		return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");


	if (!PyArg_ParseTuple(args, "OOi:line_trace_multi_by_channel", &py_obj_start, &py_obj_end, &channel))
	{
		return NULL;
	}

	ue_PyFVector *start = py_ue_is_fvector(py_obj_start);
	ue_PyFVector *end = py_ue_is_fvector(py_obj_end);

	if (!start || !end)
		return PyErr_Format(PyExc_Exception, "start and end location must be vectors");

	TArray<struct FHitResult> hits;
	hits.Reset();

	PyObject *hits_list = PyList_New(0);

	bool got_hits = world->LineTraceMultiByChannel(hits, start->vec, end->vec, (ECollisionChannel)channel);

	if (got_hits)
	{
		for (int i = 0; i < hits.Num(); i++)
		{
			FHitResult hit = hits[i];
			PyList_Append(hits_list, py_ue_new_fhitresult(hit));
		}
	}
	return hits_list;

}
static PyObject *py_ue_frandomstream_vrand_cone(ue_PyFRandomStream *self, PyObject * args) {
	PyObject *py_obj;
	float horizontal = 0;
	float vertical = -1;
	if (!PyArg_ParseTuple(args, "Of|f:vrand_cone", &py_obj, &horizontal, &vertical))
		return NULL;
	ue_PyFVector *py_vec = py_ue_is_fvector(py_obj);
	if (!py_vec)
		return PyErr_Format(PyExc_TypeError, "argument is not a FVector");
	if (vertical < 0)
		vertical = horizontal;
	return py_ue_new_fvector(self->rstream.VRandCone(py_vec->vec, horizontal, vertical));
}
PyObject *py_ue_line_trace_single_by_channel(ue_PyUObject * self, PyObject * args)
{

	ue_py_check(self);

	PyObject *py_obj_start;
	PyObject *py_obj_end;
	int channel;

	UWorld *world = ue_get_uworld(self);
	if (!world)
		return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");


	if (!PyArg_ParseTuple(args, "OOi:line_trace_single_by_channel", &py_obj_start, &py_obj_end, &channel))
	{
		return NULL;
	}

	ue_PyFVector *start = py_ue_is_fvector(py_obj_start);
	ue_PyFVector *end = py_ue_is_fvector(py_obj_end);

	if (!start || !end)
		return PyErr_Format(PyExc_Exception, "start and end location must be vectors");

	FHitResult hit;

	bool got_hit = world->LineTraceSingleByChannel(hit, start->vec, end->vec, (ECollisionChannel)channel);

	if (got_hit)
	{
		return py_ue_new_fhitresult(hit);
	}

	Py_RETURN_NONE;

}
static PyObject *ue_py_frotator_mul(ue_PyFRotator *self, PyObject *value) {
	ue_PyFVector *py_vec = py_ue_is_fvector(value);
	if (py_vec) {
		FVector vec = self->rot.RotateVector(py_vec->vec);
		return py_ue_new_fvector(vec);
	}
	else if (PyNumber_Check(value)) {
		FRotator rot = self->rot;
		PyObject *f_value = PyNumber_Float(value);
		float f = PyFloat_AsDouble(f_value);
		rot.Pitch *= f;
		rot.Yaw *= f;
		rot.Roll *= f;
		Py_DECREF(f_value);
		return py_ue_new_frotator(rot);
	}
	return PyErr_Format(PyExc_TypeError, "unsupported argument type");
}
static int py_ue_ffoliage_instance_set_location(ue_PyFFoliageInstance *self, PyObject *value, void *closure)
{
	set_instance(self);
	if (value)
	{
		ue_PyFVector *vec = py_ue_is_fvector(value);
		if (vec)
		{
			TArray<int32> instances;
			instances.Add(self->instance_id);
			FFoliageMeshInfo& info = self->foliage_actor->FoliageMeshes[self->foliage_type.Get()].Get();
			info.PreMoveInstances(self->foliage_actor.Get(), instances);
			instance->Location = vec->vec;
			info.PostMoveInstances(self->foliage_actor.Get(), instances);
			return 0;
		}
	}
	PyErr_SetString(PyExc_TypeError, "value is not an FVector");
	return -1;
}
static PyObject *py_ue_ffoliage_instance_align_to_normal(ue_PyFFoliageInstance *self, PyObject * args)
{
	get_instance(self);

	PyObject *py_vec;
	float align_max_angle = 0;

	if (!PyArg_ParseTuple(args, "O|f:align_to_normal", &py_vec, &align_max_angle))
		return nullptr;

	ue_PyFVector *vec = py_ue_is_fvector(py_vec);
	if (!vec)
	{
		return PyErr_Format(PyExc_Exception, "argument is not an FVector");
	}

	instance->AlignToNormal(vec->vec, align_max_angle);

	Py_RETURN_NONE;
}
Esempio n. 10
0
PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args, PyObject *kwargs)
{

	ue_py_check(self);

	PyObject *py_class;

	PyObject *py_obj_location = nullptr;
	PyObject *py_obj_rotation = nullptr;

	if (!PyArg_ParseTuple(args, "O|OO:actor_spawn", &py_class, &py_obj_location, &py_obj_rotation))
	{
		return nullptr;
	}

	UWorld *world = ue_get_uworld(self);
	if (!world)
		return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");


	UClass *u_class = ue_py_check_type<UClass>(py_class);
	if (!u_class)
		return PyErr_Format(PyExc_Exception, "argument is not a UClass");


	if (!u_class->IsChildOf<AActor>())
	{
		return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor");
	}

	FVector location = FVector(0, 0, 0);
	FRotator rotation = FRotator(0, 0, 0);

	if (py_obj_location)
	{
		ue_PyFVector *py_location = py_ue_is_fvector(py_obj_location);
		if (!py_location)
			return PyErr_Format(PyExc_Exception, "location must be an FVector");
		location = py_location->vec;
	}

	if (py_obj_rotation)
	{
		ue_PyFRotator *py_rotation = py_ue_is_frotator(py_obj_rotation);
		if (!py_rotation)
			return PyErr_Format(PyExc_Exception, "location must be an FRotator");
		rotation = py_rotation->rot;
	}

	if (kwargs && PyDict_Size(kwargs) > 0)
	{
		FTransform transform;
		transform.SetTranslation(location);
		transform.SetRotation(rotation.Quaternion());
		AActor *actor = world->SpawnActorDeferred<AActor>(u_class, transform);
		if (!actor)
			return PyErr_Format(PyExc_Exception, "unable to spawn a new Actor");
		ue_PyUObject *py_actor = ue_get_python_uobject_inc(actor);
		if (!py_actor)
			return PyErr_Format(PyExc_Exception, "uobject is in invalid state");

		PyObject *py_iter = PyObject_GetIter(kwargs);

		while (PyObject *py_key = PyIter_Next(py_iter))
		{
			PyObject *void_ret = py_ue_set_property(py_actor, Py_BuildValue("OO", py_key, PyDict_GetItem(kwargs, py_key)));
			if (!void_ret)
			{
				Py_DECREF(py_iter);
				return PyErr_Format(PyExc_Exception, "unable to set property for new Actor");
			}
		}
		Py_DECREF(py_iter);
		UGameplayStatics::FinishSpawningActor(actor, transform);
		return (PyObject *)py_actor;
	}

	AActor *actor = world->SpawnActor(u_class, &location, &rotation);
	if (!actor)
		return PyErr_Format(PyExc_Exception, "unable to spawn a new Actor");
	Py_RETURN_UOBJECT(actor);

}
Esempio n. 11
-1
PyObject *py_ue_actor_spawn(ue_PyUObject * self, PyObject * args) {

	ue_py_check(self);

	PyObject *py_obj_location = nullptr;
	PyObject *py_obj_rotation = nullptr;

	UWorld *world = ue_get_uworld(self);
	if (!world)
		return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");

	PyObject *obj;
	if (!PyArg_ParseTuple(args, "O|OO:actor_spawn", &obj, &py_obj_location, &py_obj_rotation)) {
		return NULL;
	}

	if (!ue_is_pyuobject(obj)) {
		return PyErr_Format(PyExc_Exception, "argument is not a UObject");
	}

	ue_PyUObject *py_obj = (ue_PyUObject *)obj;

	if (!py_obj->ue_object->IsA<UClass>()) {
		return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor");
	}

	UClass *u_class = (UClass *)py_obj->ue_object;

	if (!u_class->IsChildOf<AActor>()) {
		return PyErr_Format(PyExc_Exception, "argument is not a UClass derived from AActor");
	}

	FVector location = FVector(0, 0, 0);
	FRotator rotation = FRotator(0, 0, 0);

	if (py_obj_location) {
		ue_PyFVector *py_location = py_ue_is_fvector(py_obj_location);
		if (!py_location)
			return PyErr_Format(PyExc_Exception, "location must be an FVector");
		location = py_location->vec;
	}

	if (py_obj_rotation) {
		ue_PyFRotator *py_rotation = py_ue_is_frotator(py_obj_rotation);
		if (!py_rotation)
			return PyErr_Format(PyExc_Exception, "location must be an FRotator");
		rotation = py_rotation->rot;
	}

	AActor *actor = world->SpawnActor((UClass *)py_obj->ue_object, &location, &rotation);

	PyObject *ret = (PyObject *)ue_get_python_wrapper(actor);
	if (!ret)
		return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
	Py_INCREF(ret);
	return ret;
}