static PyObject *py_ue_spython_editor_viewport_set_light_direction(ue_PySPythonEditorViewport *self, PyObject * args)
{
	ue_py_slate_cast(SPythonEditorViewport);
	float roll = 0, pitch = 0, yaw = 0;

	FRotator rot;

	if (PyTuple_Size(args) == 1)
	{
		ue_PyFRotator *ue_py_rot = py_ue_is_frotator(PyTuple_GetItem(args, 0));
		if (!ue_py_rot)
		{
			return PyErr_Format(PyExc_Exception, "argument is not a FRotator");
		}
		rot = ue_py_rot->rot;
	}
	else
	{
		if (!PyArg_ParseTuple(args, "fff", &roll, &pitch, &yaw))
		{
			return nullptr;;
		}
		rot.Roll = roll;
		rot.Pitch = pitch;
		rot.Yaw = yaw;
	}

	py_SPythonEditorViewport->GetPreviewScene()->SetLightDirection(rot);

	Py_RETURN_SLATE_SELF;
}
static PyObject *ue_py_frotator_sub(ue_PyFRotator *self, PyObject *value) {
	FRotator rot = self->rot;
	ue_PyFRotator *py_rot = py_ue_is_frotator(value);
	if (py_rot) {
		rot -= py_rot->rot;
	}
	else if (PyNumber_Check(value)) {
		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);
}
static int py_ue_ffoliage_instance_set_rotation(ue_PyFFoliageInstance *self, PyObject *value, void *closure)
{
	set_instance(self);
	if (value)
	{
		ue_PyFRotator *rot = py_ue_is_frotator(value);
		if (rot)
		{
			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->Rotation = rot->rot;
			info.PostMoveInstances(self->foliage_actor.Get(), instances);
			return 0;
		}
	}
	PyErr_SetString(PyExc_TypeError, "value is not an FRotator");
	return -1;
}
bool py_ue_rotator_arg(PyObject *args, FRotator &rot) {

	if (PyTuple_Size(args) == 1) {
		PyObject *arg = PyTuple_GetItem(args, 0);
		ue_PyFRotator *py_rot = py_ue_is_frotator(arg);
		if (!py_rot) {
			PyErr_Format(PyExc_TypeError, "argument is not a FRotator");
			return false;
		}
		rot = py_rot->rot;
		return true;
	}

	float pitch, yaw, roll;
	if (!PyArg_ParseTuple(args, "fff", &roll, &pitch, &yaw))
		return false;
	rot.Pitch = pitch;
	rot.Yaw = yaw;
	rot.Roll = roll;
	return true;
}
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);

}
Example #6
-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;
}