feat(scripting): add mesh component script wrappers
This commit is contained in:
@@ -15,6 +15,16 @@ std::string ToStdString(const Containers::String& value) {
|
||||
|
||||
} // namespace
|
||||
|
||||
void MeshFilterComponent::SetMeshPath(const std::string& meshPath) {
|
||||
m_meshPath = meshPath;
|
||||
if (m_meshPath.empty()) {
|
||||
m_mesh.Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
m_mesh = Resources::ResourceManager::Get().Load<Resources::Mesh>(m_meshPath.c_str());
|
||||
}
|
||||
|
||||
void MeshFilterComponent::SetMesh(const Resources::ResourceHandle<Resources::Mesh>& mesh) {
|
||||
m_mesh = mesh;
|
||||
m_meshPath = mesh.Get() != nullptr ? ToStdString(mesh->GetPath()) : std::string();
|
||||
@@ -52,10 +62,7 @@ void MeshFilterComponent::Deserialize(std::istream& is) {
|
||||
const std::string value = token.substr(eqPos + 1);
|
||||
|
||||
if (key == "mesh") {
|
||||
m_meshPath = value;
|
||||
if (!m_meshPath.empty()) {
|
||||
m_mesh = Resources::ResourceManager::Get().Load<Resources::Mesh>(m_meshPath.c_str());
|
||||
}
|
||||
SetMeshPath(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,22 @@ const Resources::ResourceHandle<Resources::Material>& MeshRendererComponent::Get
|
||||
return index < m_materials.size() ? m_materials[index] : kNullHandle;
|
||||
}
|
||||
|
||||
const std::string& MeshRendererComponent::GetMaterialPath(size_t index) const {
|
||||
static const std::string kEmptyPath;
|
||||
return index < m_materialPaths.size() ? m_materialPaths[index] : kEmptyPath;
|
||||
}
|
||||
|
||||
void MeshRendererComponent::SetMaterialPath(size_t index, const std::string& materialPath) {
|
||||
EnsureMaterialSlot(index);
|
||||
m_materialPaths[index] = materialPath;
|
||||
if (materialPath.empty()) {
|
||||
m_materials[index].Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
m_materials[index] = Resources::ResourceManager::Get().Load<Resources::Material>(materialPath.c_str());
|
||||
}
|
||||
|
||||
void MeshRendererComponent::SetMaterial(size_t index, const Resources::ResourceHandle<Resources::Material>& material) {
|
||||
EnsureMaterialSlot(index);
|
||||
m_materials[index] = material;
|
||||
@@ -100,9 +116,7 @@ void MeshRendererComponent::Deserialize(std::istream& is) {
|
||||
m_materialPaths = SplitMaterialPaths(value);
|
||||
m_materials.resize(m_materialPaths.size());
|
||||
for (size_t i = 0; i < m_materialPaths.size(); ++i) {
|
||||
if (!m_materialPaths[i].empty()) {
|
||||
m_materials[i] = Resources::ResourceManager::Get().Load<Resources::Material>(m_materialPaths[i].c_str());
|
||||
}
|
||||
SetMaterialPath(i, m_materialPaths[i]);
|
||||
}
|
||||
} else if (key == "castShadows") {
|
||||
m_castShadows = (std::stoi(value) != 0);
|
||||
|
||||
Reference in New Issue
Block a user