feat(scripting): add mesh component script wrappers
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include "Components/CameraComponent.h"
|
||||
#include "Components/GameObject.h"
|
||||
#include "Components/LightComponent.h"
|
||||
#include "Components/MeshFilterComponent.h"
|
||||
#include "Components/MeshRendererComponent.h"
|
||||
#include "Components/TransformComponent.h"
|
||||
#include "Debug/Logger.h"
|
||||
#include "Scene/Scene.h"
|
||||
@@ -39,6 +41,8 @@ enum class ManagedComponentKind {
|
||||
Transform,
|
||||
Camera,
|
||||
Light,
|
||||
MeshFilter,
|
||||
MeshRenderer,
|
||||
};
|
||||
|
||||
MonoRootState& GetMonoRootState() {
|
||||
@@ -116,6 +120,12 @@ ManagedComponentKind ResolveManagedComponentKind(MonoReflectionType* reflectionT
|
||||
if (namespaceName == "XCEngine" && className == "Light") {
|
||||
return ManagedComponentKind::Light;
|
||||
}
|
||||
if (namespaceName == "XCEngine" && className == "MeshFilter") {
|
||||
return ManagedComponentKind::MeshFilter;
|
||||
}
|
||||
if (namespaceName == "XCEngine" && className == "MeshRenderer") {
|
||||
return ManagedComponentKind::MeshRenderer;
|
||||
}
|
||||
|
||||
return ManagedComponentKind::Unknown;
|
||||
}
|
||||
@@ -200,6 +210,10 @@ bool HasNativeComponent(Components::GameObject* gameObject, ManagedComponentKind
|
||||
return gameObject->GetComponent<Components::CameraComponent>() != nullptr;
|
||||
case ManagedComponentKind::Light:
|
||||
return gameObject->GetComponent<Components::LightComponent>() != nullptr;
|
||||
case ManagedComponentKind::MeshFilter:
|
||||
return gameObject->GetComponent<Components::MeshFilterComponent>() != nullptr;
|
||||
case ManagedComponentKind::MeshRenderer:
|
||||
return gameObject->GetComponent<Components::MeshRendererComponent>() != nullptr;
|
||||
case ManagedComponentKind::Unknown:
|
||||
return false;
|
||||
}
|
||||
@@ -217,6 +231,16 @@ Components::LightComponent* FindLightComponent(uint64_t gameObjectUUID) {
|
||||
return gameObject ? gameObject->GetComponent<Components::LightComponent>() : nullptr;
|
||||
}
|
||||
|
||||
Components::MeshFilterComponent* FindMeshFilterComponent(uint64_t gameObjectUUID) {
|
||||
Components::GameObject* gameObject = FindGameObjectByUUID(gameObjectUUID);
|
||||
return gameObject ? gameObject->GetComponent<Components::MeshFilterComponent>() : nullptr;
|
||||
}
|
||||
|
||||
Components::MeshRendererComponent* FindMeshRendererComponent(uint64_t gameObjectUUID) {
|
||||
Components::GameObject* gameObject = FindGameObjectByUUID(gameObjectUUID);
|
||||
return gameObject ? gameObject->GetComponent<Components::MeshRendererComponent>() : nullptr;
|
||||
}
|
||||
|
||||
Components::Space ResolveManagedSpace(int32_t value) {
|
||||
return value == static_cast<int32_t>(Components::Space::World)
|
||||
? Components::Space::World
|
||||
@@ -827,6 +851,94 @@ void InternalCall_Light_SetCastsShadows(uint64_t gameObjectUUID, mono_bool value
|
||||
component->SetCastsShadows(value != 0);
|
||||
}
|
||||
|
||||
MonoString* InternalCall_MeshFilter_GetMeshPath(uint64_t gameObjectUUID) {
|
||||
Components::MeshFilterComponent* component = FindMeshFilterComponent(gameObjectUUID);
|
||||
return mono_string_new(
|
||||
mono_domain_get(),
|
||||
component ? component->GetMeshPath().c_str() : "");
|
||||
}
|
||||
|
||||
void InternalCall_MeshFilter_SetMeshPath(uint64_t gameObjectUUID, MonoString* path) {
|
||||
Components::MeshFilterComponent* component = FindMeshFilterComponent(gameObjectUUID);
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
|
||||
component->SetMeshPath(MonoStringToUtf8(path));
|
||||
}
|
||||
|
||||
int32_t InternalCall_MeshRenderer_GetMaterialCount(uint64_t gameObjectUUID) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
return component ? static_cast<int32_t>(component->GetMaterialCount()) : 0;
|
||||
}
|
||||
|
||||
MonoString* InternalCall_MeshRenderer_GetMaterialPath(uint64_t gameObjectUUID, int32_t index) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
const std::string path =
|
||||
(component && index >= 0) ? component->GetMaterialPath(static_cast<size_t>(index)) : std::string();
|
||||
return mono_string_new(mono_domain_get(), path.c_str());
|
||||
}
|
||||
|
||||
void InternalCall_MeshRenderer_SetMaterialPath(uint64_t gameObjectUUID, int32_t index, MonoString* path) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
if (!component || index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
component->SetMaterialPath(static_cast<size_t>(index), MonoStringToUtf8(path));
|
||||
}
|
||||
|
||||
void InternalCall_MeshRenderer_ClearMaterials(uint64_t gameObjectUUID) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
|
||||
component->ClearMaterials();
|
||||
}
|
||||
|
||||
mono_bool InternalCall_MeshRenderer_GetCastShadows(uint64_t gameObjectUUID) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
return (component && component->GetCastShadows()) ? 1 : 0;
|
||||
}
|
||||
|
||||
void InternalCall_MeshRenderer_SetCastShadows(uint64_t gameObjectUUID, mono_bool value) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
|
||||
component->SetCastShadows(value != 0);
|
||||
}
|
||||
|
||||
mono_bool InternalCall_MeshRenderer_GetReceiveShadows(uint64_t gameObjectUUID) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
return (component && component->GetReceiveShadows()) ? 1 : 0;
|
||||
}
|
||||
|
||||
void InternalCall_MeshRenderer_SetReceiveShadows(uint64_t gameObjectUUID, mono_bool value) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
|
||||
component->SetReceiveShadows(value != 0);
|
||||
}
|
||||
|
||||
int32_t InternalCall_MeshRenderer_GetRenderLayer(uint64_t gameObjectUUID) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
return component ? static_cast<int32_t>(component->GetRenderLayer()) : 0;
|
||||
}
|
||||
|
||||
void InternalCall_MeshRenderer_SetRenderLayer(uint64_t gameObjectUUID, int32_t value) {
|
||||
Components::MeshRendererComponent* component = FindMeshRendererComponent(gameObjectUUID);
|
||||
if (!component) {
|
||||
return;
|
||||
}
|
||||
|
||||
component->SetRenderLayer(static_cast<uint32_t>(std::max(value, 0)));
|
||||
}
|
||||
|
||||
void RegisterInternalCalls() {
|
||||
if (GetInternalCallRegistrationState()) {
|
||||
return;
|
||||
@@ -893,6 +1005,18 @@ void RegisterInternalCalls() {
|
||||
mono_add_internal_call("XCEngine.InternalCalls::Light_SetSpotAngle", reinterpret_cast<const void*>(&InternalCall_Light_SetSpotAngle));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::Light_GetCastsShadows", reinterpret_cast<const void*>(&InternalCall_Light_GetCastsShadows));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::Light_SetCastsShadows", reinterpret_cast<const void*>(&InternalCall_Light_SetCastsShadows));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshFilter_GetMeshPath", reinterpret_cast<const void*>(&InternalCall_MeshFilter_GetMeshPath));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshFilter_SetMeshPath", reinterpret_cast<const void*>(&InternalCall_MeshFilter_SetMeshPath));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_GetMaterialCount", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_GetMaterialCount));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_GetMaterialPath", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_GetMaterialPath));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_SetMaterialPath", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_SetMaterialPath));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_ClearMaterials", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_ClearMaterials));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_GetCastShadows", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_GetCastShadows));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_SetCastShadows", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_SetCastShadows));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_GetReceiveShadows", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_GetReceiveShadows));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_SetReceiveShadows", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_SetReceiveShadows));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_GetRenderLayer", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_GetRenderLayer));
|
||||
mono_add_internal_call("XCEngine.InternalCalls::MeshRenderer_SetRenderLayer", reinterpret_cast<const void*>(&InternalCall_MeshRenderer_SetRenderLayer));
|
||||
|
||||
GetInternalCallRegistrationState() = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user