Skip to content

Commit 3b1f00c

Browse files
committed
Script Attachment shader/texture changing support
Added support for getting/setting/resetting Script Attachment model shaders/textures
1 parent 7ec5b1c commit 3b1f00c

File tree

4 files changed

+142
-7
lines changed

4 files changed

+142
-7
lines changed

gamedata/scripts/lua_help_ex.script

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@
659659
function set_ui_position();
660660
function set_ui_rotation(vector);
661661
function set_ui_rotation(number, number, number);
662+
function get_shaders()
663+
function get_default_shaders()
664+
function set_shader(number, string, string)
665+
function reset_shader(number)
662666
}
663667

664668
flags:

src/xrGame/script_attachment_manager.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,4 +624,126 @@ Fvector script_attachment::GetCenter()
624624
return m_model->getVisData().sphere.P;
625625

626626
return { 0,0,0 };
627+
}
628+
629+
luabind::object script_attachment::GetShaders()
630+
{
631+
luabind::object table = luabind::newtable(ai().script_engine().lua());
632+
633+
if (!m_model)
634+
{
635+
table["error"] = true;
636+
return table;
637+
}
638+
639+
xr_vector<IRenderVisual*>* children = m_model->get_children();
640+
641+
if (!children)
642+
{
643+
luabind::object subtable = luabind::newtable(ai().script_engine().lua());
644+
subtable["shader"] = m_model->getDebugShader();
645+
subtable["texture"] = m_model->getDebugTexture();
646+
table[1] = subtable;
647+
return table;
648+
}
649+
650+
int i = 1;
651+
652+
for (auto* child : *children)
653+
{
654+
luabind::object subtable = luabind::newtable(ai().script_engine().lua());
655+
subtable["shader"] = child->getDebugShader();
656+
subtable["texture"] = child->getDebugTexture();
657+
table[i] = subtable;
658+
++i;
659+
}
660+
661+
return table;
662+
}
663+
664+
luabind::object script_attachment::GetDefaultShaders()
665+
{
666+
luabind::object table = luabind::newtable(ai().script_engine().lua());
667+
668+
if (!m_model)
669+
{
670+
table["error"] = true;
671+
return table;
672+
}
673+
674+
xr_vector<IRenderVisual*>* children = m_model->get_children();
675+
676+
if (!children)
677+
{
678+
luabind::object subtable = luabind::newtable(ai().script_engine().lua());
679+
subtable["shader"] = m_model->getDebugShaderDef();
680+
subtable["texture"] = m_model->getDebugTextureDef();
681+
table[1] = subtable;
682+
return table;
683+
}
684+
685+
int i = 1;
686+
687+
for (auto* child : *children)
688+
{
689+
luabind::object subtable = luabind::newtable(ai().script_engine().lua());
690+
subtable["shader"] = child->getDebugShaderDef();
691+
subtable["texture"] = child->getDebugTextureDef();
692+
table[i] = subtable;
693+
++i;
694+
}
695+
696+
return table;
697+
}
698+
699+
void script_attachment::SetShaderTexture(int id, LPCSTR shader, LPCSTR texture)
700+
{
701+
if (!m_model) return;
702+
xr_vector<IRenderVisual*>* children = m_model->get_children();
703+
704+
if (!children)
705+
{
706+
m_model->SetShaderTexture(shader, texture);
707+
return;
708+
}
709+
710+
if (id == -1)
711+
{
712+
for (auto* child : *children)
713+
{
714+
child->SetShaderTexture(shader, texture);
715+
}
716+
return;
717+
}
718+
719+
id--;
720+
721+
if (id >= 0 && children->size() > id)
722+
children->at(id)->SetShaderTexture(shader, texture);
723+
}
724+
725+
void script_attachment::ResetShaderTexture(int id)
726+
{
727+
if (!m_model) return;
728+
xr_vector<IRenderVisual*>* children = m_model->get_children();
729+
730+
if (!children)
731+
{
732+
m_model->ResetShaderTexture();
733+
return;
734+
}
735+
736+
if (id == -1)
737+
{
738+
for (auto* child : *children)
739+
{
740+
child->ResetShaderTexture();
741+
}
742+
return;
743+
}
744+
745+
id--;
746+
747+
if (id >= 0 && children->size() > id)
748+
children->at(id)->ResetShaderTexture();
627749
}

src/xrGame/script_attachment_manager.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ enum script_attachment_flags
1313
struct script_attachment_bone_cb
1414
{
1515
u16 m_bone_id, m_attachment_bone_id;
16-
luabind::functor<Fmatrix>* m_func;
16+
::luabind::functor<Fmatrix>* m_func;
1717
script_attachment* m_attachment;
1818
Fmatrix m_mat;
1919
bool m_overwrite;
2020

21-
script_attachment_bone_cb(const luabind::functor<Fmatrix>& func, script_attachment* att, u16 id, bool overwrite)
21+
script_attachment_bone_cb(const ::luabind::functor<Fmatrix>& func, script_attachment* att, u16 id, bool overwrite)
2222
{
2323
m_attachment = att;
2424
m_attachment_bone_id = id;
25-
m_func = xr_new<luabind::functor<Fmatrix>>(func);
25+
m_func = xr_new<::luabind::functor<Fmatrix>>(func);
2626
m_mat = Fidentity;
2727
m_bone_id = BI_NONE;
2828
m_overwrite = overwrite;
@@ -111,7 +111,7 @@ class script_attachment
111111
void SetParent(script_attachment* att);
112112
void SetParent(CGameObject* obj);
113113
void SetParent(CScriptGameObject* obj);
114-
luabind::object GetParent();
114+
::luabind::object GetParent();
115115

116116
void SetParentBone(u16 bone_id) { m_parent_bone = bone_id; }
117117
u16 GetParentBone() { return m_parent_bone; }
@@ -149,13 +149,18 @@ class script_attachment
149149

150150
static void _BCL ScriptAttachmentBoneCallback(CBoneInstance* B);
151151
void SetBoneCallback(u16 bone_id, u16 parent_bone, bool overwrite = false);
152-
void SetBoneCallback(u16 bone_id, const luabind::functor<Fmatrix>& func, bool overwrite = false);
152+
void SetBoneCallback(u16 bone_id, const ::luabind::functor<Fmatrix>& func, bool overwrite = false);
153153
void RemoveBoneCallback(u16 bone_id);
154154

155155
Fmatrix GetBoneMatrix(u16 bone_id);
156156
Fmatrix GetTransform() { return m_transform; };
157157
Fvector GetCenter();
158158

159+
::luabind::object GetShaders();
160+
::luabind::object GetDefaultShaders();
161+
void SetShaderTexture(int id, LPCSTR shader, LPCSTR texture);
162+
void ResetShaderTexture(int id);
163+
159164
DECLARE_SCRIPT_REGISTER_FUNCTION
160165
};
161166

src/xrGame/script_attachment_script.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "pch_script.h"
33
#include "script_attachment_manager.h"
44

5-
using namespace luabind;
5+
using namespace ::luabind;
66

77
#pragma optimize("s",on)
88
void script_attachment::script_register(lua_State* L)
@@ -57,6 +57,10 @@ void script_attachment::script_register(lua_State* L)
5757
.def("get_transform", &script_attachment::GetTransform)
5858
.def("get_center", &script_attachment::GetCenter)
5959
.def("bone_callback", (void (script_attachment::*)(u16,u16,bool)) &script_attachment::SetBoneCallback)
60-
.def("bone_callback", (void (script_attachment::*)(u16, const luabind::functor<Fmatrix>&,bool)) &script_attachment::SetBoneCallback)
60+
.def("bone_callback", (void (script_attachment::*)(u16, const ::luabind::functor<Fmatrix>&,bool)) &script_attachment::SetBoneCallback)
61+
.def("get_shaders", &script_attachment::GetShaders)
62+
.def("get_default_shaders", &script_attachment::GetDefaultShaders)
63+
.def("set_shader", &script_attachment::SetShaderTexture)
64+
.def("reset_shader", &script_attachment::ResetShaderTexture)
6165
];
6266
}

0 commit comments

Comments
 (0)