Skip to content

Commit

Permalink
Renderer, MeshRenderer and SkinnedMeshRenderer defs
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Jun 5, 2023
1 parent b1764cd commit 595c6f8
Show file tree
Hide file tree
Showing 7 changed files with 1,389 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CVRLua/CVRLua.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<Compile Include="Lua\LuaDefs\CVRInteractableDefs.cs" />
<Compile Include="Lua\LuaDefs\CVRPickupObjectDefs.cs" />
<Compile Include="Lua\LuaDefs\CVRVideoPlayerDefs.cs" />
<Compile Include="Lua\LuaDefs\MeshRendererDefs.cs" />
<Compile Include="Lua\LuaDefs\NavMeshAgentDefs.cs" />
<Compile Include="Lua\LuaDefs\NavMeshHitDefs.cs" />
<Compile Include="Lua\LuaDefs\NavMeshPathDefs.cs" />
Expand All @@ -128,8 +129,10 @@
<Compile Include="Lua\LuaDefs\RandomDefs.cs" />
<Compile Include="Lua\LuaDefs\RaycastHitDefs.cs" />
<Compile Include="Lua\LuaDefs\RayDefs.cs" />
<Compile Include="Lua\LuaDefs\RendererDefs.cs" />
<Compile Include="Lua\LuaDefs\RenderSettingsDefs.cs" />
<Compile Include="Lua\LuaDefs\RigidbodyDefs.cs" />
<Compile Include="Lua\LuaDefs\SkinnedMeshRendererDefs.cs" />
<Compile Include="Lua\LuaDefs\TerrainColliderDefs.cs" />
<Compile Include="Lua\LuaDefs\TextMeshProDefs.cs" />
<Compile Include="Lua\LuaDefs\UtilityDefs.cs" />
Expand Down
68 changes: 68 additions & 0 deletions CVRLua/Lua/LuaDefs/MeshRendererDefs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace CVRLua.Lua.LuaDefs
{
static class MeshRendererDefs
{
const string c_destroyed = "MeshRenderer is destroyed";

static readonly List<(string, LuaInterop.lua_CFunction)> ms_metaMethods = new List<(string, LuaInterop.lua_CFunction)>();
static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_staticProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_staticMethods = new List<(string, LuaInterop.lua_CFunction)>();
static readonly List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))> ms_instanceProperties = new List<(string, (LuaInterop.lua_CFunction, LuaInterop.lua_CFunction))>();
static readonly List<(string, LuaInterop.lua_CFunction)> ms_instanceMethods = new List<(string, LuaInterop.lua_CFunction)>();

internal static void Init()
{
ms_staticMethods.Add((nameof(IsMeshRenderer), IsMeshRenderer));

//ms_instanceProperties.Add(("additionalVertexStreams", (?,?)));
ms_instanceProperties.Add(("subMeshStartIndex", (GetSubMeshStartIndex, null)));

RendererDefs.InheritTo(ms_metaMethods, ms_staticProperties, ms_staticMethods, ms_instanceProperties, ms_instanceMethods);
}

internal static void RegisterInVM(LuaVM p_vm)
{
p_vm.RegisterClass(typeof(MeshRenderer), null, ms_staticProperties, ms_staticMethods, ms_metaMethods, ms_instanceProperties, ms_instanceMethods);
}

// Static methods
static int IsMeshRenderer(IntPtr p_state)
{
var l_argReader = new LuaArgReader(p_state);
MeshRenderer l_render = null;
l_argReader.ReadNextObject(ref l_render);
l_argReader.PushBoolean(l_render != null);
return l_argReader.GetReturnValue();
}

// Instance properties
static int GetSubMeshStartIndex(IntPtr p_state)
{
var l_argReader = new LuaArgReader(p_state);
MeshRenderer l_render = null;
l_argReader.ReadObject(ref l_render);
if(!l_argReader.HasErrors())
{
if(l_render != null)
l_argReader.PushInteger(l_render.subMeshStartIndex);
else
{
l_argReader.SetError(c_destroyed);
l_argReader.PushBoolean(false);
}
}
else
l_argReader.PushBoolean(false);

l_argReader.LogError();
return 1;
}
}
}
Loading

0 comments on commit 595c6f8

Please sign in to comment.