@@ -30,13 +30,8 @@ public: | |||
UNUSED(arg_nb); | |||
return new DemoObject(); | |||
} | |||
static const char* GetClassName() { static const char name[] = "LoluaDemo"; return name; } | |||
static const char* GetClassLibName() { static const char name[] = "LoluaDemoLib"; return name; } | |||
static const char* GetClassInstName() { static const char name[] = "LoluaDemoInst"; return name; } | |||
static const Lolua::ClassMethod* GetStaticMethods(); | |||
static const Lolua::ClassMethod* GetInstanceMethods(); | |||
//------------------------------------------------------------------------- | |||
static int AddFive(Lolua::State* l) | |||
{ | |||
Lolua::Var<int> i(l, 1); | |||
@@ -54,13 +49,35 @@ public: | |||
{ | |||
return (f + 10); | |||
} | |||
}; | |||
//----------------------------------------------------------------------------- | |||
static const Lolua::ClassMethod loluademo_statics[] = { { "AddFive", &DemoObject::AddFive }, { NULL, NULL } }; | |||
static const Lolua::ClassMethod loluademo_methods[] = { { "AddTenInstance", &DemoObject::AddTenInstance }, { NULL, NULL } }; | |||
const Lolua::ClassMethod* DemoObject::GetStaticMethods() { return loluademo_statics; } | |||
const Lolua::ClassMethod* DemoObject::GetInstanceMethods() { return loluademo_methods; } | |||
static int GetX(Lolua::State* l) | |||
{ | |||
Lolua::VarPtr<DemoObject> obj(l, 1); | |||
Lolua::Var<int32_t> i; | |||
i = obj.V()->m_x; | |||
return i.Return(l); | |||
} | |||
static int SetX(Lolua::State* l) | |||
{ | |||
Lolua::VarPtr<DemoObject> obj(l, 1); | |||
Lolua::Var<int32_t> i(l, 2); | |||
obj.V()->m_x = i.V(); | |||
return 0; | |||
} | |||
//------------------------------------------------------------------------- | |||
static const Lolua::ObjectLib* GetLib() | |||
{ | |||
static const Lolua::ObjectLib lib = Lolua::ObjectLib( | |||
"LoluaDemo", | |||
{ { "AddFive", &DemoObject::AddFive } }, | |||
{ { "AddTenInstance", &DemoObject::AddTenInstance } }, | |||
{ { "X", &DemoObject::GetX, &DemoObject::SetX } }); | |||
return &lib; | |||
} | |||
int m_x = 0; | |||
}; | |||
//----------------------------------------------------------------------------- | |||
static int GlobalAddString(Lolua::State* l) | |||
@@ -88,6 +105,29 @@ public: | |||
{ | |||
} | |||
void TestStuff() | |||
{ | |||
Lolua::State* l = GetLuaState(); | |||
/* | |||
//create property | |||
lua_pushnumber(l, 5.0); | |||
lua_setfield(l, -2, "x"); | |||
lua_getglobal(l, "vector"); | |||
int table = lua_istable(l, -1); | |||
lua_getfield(l, -1, "x"); | |||
Lolua::Var<float> var(l, -1); | |||
lua_pop(l, 2); | |||
vec3 t; | |||
*/ | |||
//table = lua_isuserdata(l, -1); | |||
//Var<T> var(m_lua_state, -1); | |||
//lua_pop(m_lua_state, 1); | |||
//lua_getfield (lua_State *L, int index, const char *k); | |||
//return var.V(); | |||
} | |||
}; | |||
//----------------------------------------------------------------------------- | |||
@@ -106,6 +146,7 @@ public: | |||
//Execute script | |||
demo_loader->ExecLua("14_lol_lua.lua"); | |||
demo_loader->TestStuff(); | |||
//Grab global test values | |||
float testvalue_num = demo_loader->GetVar<float>("testvalue_num"); | |||
@@ -118,17 +159,16 @@ public: | |||
//Grab global values modified with DemoObject | |||
int32_t loluademo_return = demo_loader->GetVar<int32_t>("loluademo_return"); | |||
int32_t loluademo_getx = demo_loader->GetVar<int32_t>("loluademo_getx"); | |||
float loluademo_inst_return = demo_loader->GetVar<float>("loluademo_inst_return"); | |||
DemoObject* loluademo_inst = demo_loader->GetPtr<DemoObject>("loluademo_inst"); | |||
String loluademo_inst_name = loluademo_inst->GetClassName(); | |||
Log::Info("Lua Vars: \ | |||
testvalue_num: %.2f, testvalue_int: %i, testvalue_uint: %i, testvalue_str: %s.\n", | |||
testvalue_num, testvalue_int, testvalue_uint, testvalue_str.C()); | |||
Log::Info("Lua Vars: \ | |||
function_return: %s, loluademo_return: %i, loluademo_inst_return: %.f, loluademo_inst_name: %s.\n", | |||
function_return.C(), loluademo_return, loluademo_inst_return, loluademo_inst_name.C()); | |||
function_return: %s, loluademo_return: %i, loluademo_inst_return: %.f, loluademo_getx: %i, loluademo_inst->m_x: %i.\n", | |||
function_return.C(), loluademo_return, loluademo_inst_return, loluademo_getx, loluademo_inst->m_x); | |||
delete demo_loader; | |||
@@ -11,4 +11,6 @@ function_return = GlobalAddString("test"); | |||
loluademo_return = LoluaDemo.AddFive(1); | |||
loluademo_inst = LoluaDemo.New(); | |||
loluademo_inst:SetX(10); | |||
loluademo_getx = loluademo_inst:GetX(); | |||
loluademo_inst_return = loluademo_inst:AddTenInstance(2.0); |
@@ -75,6 +75,7 @@ liblolcore_sources = \ | |||
easymesh/easymeshinternal.cpp easymesh/easymeshcsg.cpp \ | |||
easymesh/easymeshprimitive.cpp easymesh/easymeshtransform.cpp \ | |||
easymesh/easymeshcursor.cpp easymesh/easymesh.h \ | |||
easymesh/easymeshlua.cpp easymesh/easymeshlua.h \ | |||
easymesh/csgbsp.cpp easymesh/csgbsp.h \ | |||
easymesh/shiny.lolfx easymesh/shinyflat.lolfx \ | |||
easymesh/shinydebugwireframe.lolfx \ | |||
@@ -25,8 +25,75 @@ namespace Lolua | |||
//----------------------------------------------------------------------------- | |||
typedef luaL_Reg ClassMethod; | |||
typedef struct ClassVar | |||
{ | |||
const char *name; | |||
lua_CFunction get; | |||
lua_CFunction set; | |||
} ClassVar; | |||
typedef lua_State State; | |||
//----------------------------------------------------------------------------- | |||
struct ObjectLib | |||
{ | |||
typedef struct ClassVarStr | |||
{ | |||
ClassVarStr() { } | |||
ClassVarStr(String var_name, lua_CFunction get, lua_CFunction set) | |||
{ | |||
m_get_name = String("Get") + var_name; | |||
m_set_name = String("Set") + var_name; | |||
m_get = get; | |||
m_set = set; | |||
} | |||
String m_get_name = ""; | |||
String m_set_name = ""; | |||
lua_CFunction m_get = nullptr; | |||
lua_CFunction m_set = nullptr; | |||
} ClassVarStr; | |||
ObjectLib(String class_name, | |||
array<ClassMethod> statics, | |||
array<ClassMethod> methods, | |||
array<ClassVar> variables) | |||
{ | |||
m_class_name = class_name; | |||
m_static_name = class_name + "_lib"; | |||
m_method_name = class_name + "_inst"; | |||
m_statics = statics; | |||
if (m_statics.Count() == 0 | |||
|| m_statics.Last().name != nullptr | |||
|| m_statics.Last().func != nullptr) | |||
m_statics.Push({ nullptr, nullptr }); | |||
m_methods = methods; | |||
if (m_methods.Count() == 0 | |||
|| m_methods.Last().name != nullptr | |||
|| m_methods.Last().func != nullptr) | |||
m_methods.Push({ nullptr, nullptr }); | |||
for (ClassVar& cv : variables) | |||
{ | |||
if (cv.name && cv.get && cv.set) | |||
{ | |||
m_variables.Push({ cv.name, cv.get, cv.set }); | |||
} | |||
} | |||
if (m_variables.Count() == 0 | |||
|| variables.Last().name != nullptr | |||
|| variables.Last().get != nullptr | |||
|| variables.Last().set != nullptr) | |||
m_variables.Push(ClassVarStr()); | |||
} | |||
String m_class_name = ""; | |||
String m_static_name = ""; | |||
String m_method_name = ""; | |||
array<ClassMethod> m_statics; | |||
array<ClassMethod> m_methods; | |||
array<ClassVarStr> m_variables; | |||
}; | |||
//----------------------------------------------------------------------------- | |||
class ObjectDef | |||
{ | |||
@@ -40,11 +107,7 @@ public: | |||
ASSERT(false); | |||
return nullptr; | |||
} | |||
static const char* GetClassName() { ASSERT(false); return nullptr; } | |||
static const char* GetClassLibName() { ASSERT(false); return nullptr;; } | |||
static const char* GetClassInstName() { ASSERT(false); return nullptr; } | |||
static const ClassMethod* GetStaticMethods() { ASSERT(false); return nullptr; } | |||
static const ClassMethod* GetInstanceMethods() { ASSERT(false); return nullptr; } | |||
static const ObjectLib* GetLib() { ASSERT(false); return nullptr; } | |||
}; | |||
//----------------------------------------------------------------------------- | |||
@@ -64,7 +127,7 @@ public: | |||
//Default statics | |||
static const luaL_Reg default_statics[] | |||
{ | |||
{ "New", New<TLuaClass> }, | |||
{ "New", New<TLuaClass> }, | |||
{ "__gc", Del<TLuaClass> }, | |||
{ NULL, NULL } | |||
}; | |||
@@ -82,26 +145,66 @@ public: | |||
//__le : Less than or equal to(<= ) | |||
//Create Static metatable | |||
luaL_newmetatable(l, TLuaClass::GetClassLibName()); | |||
luaL_newmetatable(l, GetStaticName<TLuaClass>()); | |||
//Register default statics and template one | |||
luaL_setfuncs(l, default_statics, 0); | |||
luaL_setfuncs(l, TLuaClass::GetStaticMethods(), 0); | |||
//Push funcs on metatable | |||
luaL_setfuncs(l, GetStaticMethods<TLuaClass>(), 0); | |||
//Push metatable on stack | |||
lua_pushvalue(l, -1); | |||
//Set the "__index" field of the metatable to point to itself, pops the stack | |||
lua_setfield(l, -1, "__index"); | |||
//Set it global to validate the operation | |||
lua_setglobal(l, TLuaClass::GetClassName()); | |||
lua_setglobal(l, GetObjectName<TLuaClass>()); | |||
//Repeat all the operations for instance metatable | |||
luaL_newmetatable(l, TLuaClass::GetClassInstName()); | |||
luaL_setfuncs(l, TLuaClass::GetInstanceMethods(), 0); | |||
luaL_newmetatable(l, GetMethodName<TLuaClass>()); | |||
luaL_setfuncs(l, GetInstanceMethods<TLuaClass>(), 0); | |||
lua_pushvalue(l, -1); | |||
lua_setfield(l, -1, "__index"); | |||
//Create variables Get/Set | |||
const array<ObjectLib::ClassVarStr>& variables = GetVariables<TLuaClass>(); | |||
for (const ObjectLib::ClassVarStr& var : variables) | |||
{ | |||
if (!var.m_get || !var.m_set) | |||
continue; | |||
//Add getter | |||
lua_pushcfunction(l, var.m_get); | |||
lua_setfield(l, -2, var.m_get_name.C()); | |||
//Add setter | |||
lua_pushcfunction(l, var.m_set); | |||
lua_setfield(l, -2, var.m_set_name.C()); | |||
} | |||
//Don't set it to global, but pop the stack to hide the metatable | |||
lua_pop(l, 1); | |||
} | |||
private: | |||
template <typename TLuaClass> | |||
static const ObjectLib* GetLib() | |||
{ | |||
const ObjectLib* lib = TLuaClass::GetLib(); | |||
ASSERT(lib); | |||
return lib; | |||
} | |||
public: | |||
template <typename TLuaClass> | |||
static const char* GetObjectName() { return GetLib<TLuaClass>()->m_class_name.C(); } | |||
template <typename TLuaClass> | |||
static const char* GetStaticName() { return GetLib<TLuaClass>()->m_static_name.C(); } | |||
template <typename TLuaClass> | |||
static const char* GetMethodName() { return GetLib<TLuaClass>()->m_method_name.C(); } | |||
template <typename TLuaClass> | |||
static const ClassMethod* GetStaticMethods() { return GetLib<TLuaClass>()->m_statics.Data(); } | |||
template <typename TLuaClass> | |||
static const ClassMethod* GetInstanceMethods() { return GetLib<TLuaClass>()->m_methods.Data(); } | |||
template <typename TLuaClass> | |||
static const array<ObjectLib::ClassVarStr>& GetVariables() { return GetLib<TLuaClass>()->m_variables; } | |||
protected: | |||
//------------------------------------------------------------------------- | |||
template <typename TLuaClass> | |||
@@ -115,7 +218,7 @@ protected: | |||
*data = TLuaClass::New(l, n_args); | |||
//Retrieve instance table | |||
luaL_getmetatable(l, TLuaClass::GetClassInstName()); | |||
luaL_getmetatable(l, GetMethodName<TLuaClass>()); | |||
//Set metatable to instance | |||
lua_setmetatable(l, -2); | |||
//Return 1 so Lua will get the UserData and clean the stack. | |||
@@ -134,10 +237,9 @@ protected: | |||
}; | |||
//----------------------------------------------------------------------------- | |||
// | |||
//-- | |||
struct Function | |||
class Function | |||
{ | |||
public: | |||
Function(State* l, const char* name, int(*function)(State*)) | |||
{ | |||
lua_pushcfunction(l, function); | |||
@@ -147,7 +249,7 @@ struct Function | |||
//----------------------------------------------------------------------------- | |||
template<typename T> | |||
struct VarPtr | |||
class VarPtr | |||
{ | |||
protected: | |||
T* m_value = nullptr; | |||
@@ -155,15 +257,15 @@ protected: | |||
public: | |||
VarPtr() { } | |||
VarPtr(T* value) { m_value = value; } | |||
VarPtr(State* l, int index) { InnerGet(l, index); } | |||
VarPtr(State* l, int index) { InnerGet(l, index); } | |||
inline T* V() { return m_value; } | |||
inline T* operator=(T* value) { m_value = value; } | |||
inline int Return(State* l) { InnerPush(l); return 1; } | |||
inline int Return(State* l) { InnerPush(l); return 1; } | |||
protected: | |||
virtual void InnerGet(State* l, int index) | |||
{ | |||
T** obj = static_cast<T**>(luaL_checkudata(l, index, T::GetClassInstName())); | |||
T** obj = static_cast<T**>(luaL_checkudata(l, index, Object::GetMethodName<T>())); | |||
m_value = obj ? *obj : nullptr; | |||
} | |||
void InnerPush(State* l) | |||
@@ -174,7 +276,7 @@ protected: | |||
}; | |||
//----------------------------------------------------------------------------- | |||
template<typename T> | |||
struct VarPtrLight | |||
class VarPtrLight | |||
{ | |||
public: | |||
VarPtrLight() : VarPtr() { } | |||
@@ -183,14 +285,14 @@ public: | |||
protected: | |||
virtual void InnerGet(State* l, int index) | |||
{ | |||
T** obj = static_cast<T**>(luaL_testudata(l, index, T::GetClassInstName())); | |||
T** obj = static_cast<T**>(luaL_testudata(l, index, Object::GetMethodName<T>())); | |||
m_value = obj ? *obj : nullptr; | |||
} | |||
}; | |||
//----------------------------------------------------------------------------- | |||
template<typename T> | |||
struct Var | |||
class Var | |||
{ | |||
private: | |||
T m_value; | |||
@@ -201,20 +303,20 @@ public: | |||
Var(State* l, int index) { InnerGet(l, index); } | |||
inline T& V() { return m_value; } | |||
inline int Return(State* l) { InnerPush(l); return 1; } | |||
inline Var<T>& operator-(const T& value) { m_value - value; return *this; } | |||
inline Var<T>& operator+(const T& value) { m_value + value; return *this; } | |||
inline Var<T>& operator-(const T& value) { m_value - value; return *this; } | |||
inline Var<T>& operator+(const T& value) { m_value + value; return *this; } | |||
inline Var<T>& operator*(const T& value) { m_value * value; return *this; } | |||
inline Var<T>& operator/(const T& value) { m_value / value; return *this; } | |||
inline Var<T>& operator=(const T& value) { m_value = value; return *this; } | |||
inline Var<T>& operator/(const T& value) { m_value / value; return *this; } | |||
inline Var<T>& operator=(const T& value) { m_value = value; return *this; } | |||
inline Var<T>& operator-=(const T& value) { m_value -= value; return *this; } | |||
inline Var<T>& operator+=(const T& value) { m_value += value; return *this; } | |||
inline Var<T>& operator*=(const T& value) { m_value *= value; return *this; } | |||
inline Var<T>& operator/=(const T& value) { m_value /= value; return *this; } | |||
inline Var<T>& operator-(const Var<T>& o) { m_value - o.m_value; return *this; } | |||
inline Var<T>& operator+(const Var<T>& o) { m_value + o.m_value; return *this; } | |||
inline Var<T>& operator-(const Var<T>& o) { m_value - o.m_value; return *this; } | |||
inline Var<T>& operator+(const Var<T>& o) { m_value + o.m_value; return *this; } | |||
inline Var<T>& operator*(const Var<T>& o) { m_value * o.m_value; return *this; } | |||
inline Var<T>& operator/(const Var<T>& o) { m_value / o.m_value; return *this; } | |||
inline Var<T>& operator=(const Var<T>& o) { m_value = o.m_value; return *this; } | |||
inline Var<T>& operator/(const Var<T>& o) { m_value / o.m_value; return *this; } | |||
inline Var<T>& operator=(const Var<T>& o) { m_value = o.m_value; return *this; } | |||
inline Var<T>& operator-=(const Var<T>& o) { m_value -= o.m_value; return *this; } | |||
inline Var<T>& operator+=(const Var<T>& o) { m_value += o.m_value; return *this; } | |||
inline Var<T>& operator*=(const Var<T>& o) { m_value *= o.m_value; return *this; } | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Csg: The code belonging to CSG operations | |||
// | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2010-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
@@ -9,11 +9,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Csg: The code belonging to CSG operations | |||
// | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2010-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
@@ -11,11 +11,6 @@ | |||
#pragma once | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
namespace lol | |||
{ | |||
@@ -1,5 +1,6 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh: A class about generating 3D mesh without using the hands | |||
// Mesh can be generated using C++ or lua code | |||
// | |||
// Copyright: (c) 2010-2015 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2015 Cédric Lecacheur <jordx@free.fr> | |||
@@ -10,11 +11,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
LOLFX_RESOURCE_DECLARE(shiny); | |||
@@ -45,170 +41,6 @@ EasyMesh::EasyMesh(const EasyMesh& em) | |||
m_state = MeshRender::NeedData; | |||
} | |||
//----------------------------------------------------------------------------- | |||
bool EasyMesh::Compile(char const *command, bool Execute) | |||
{ | |||
bool res = false; | |||
// FIXME: make this work again | |||
#if 0 | |||
EasyMeshCompiler mc(*this); | |||
BD()->Enable(MeshBuildOperation::CommandRecording); | |||
if ((res = mc.ParseString(command))) | |||
{ | |||
BD()->Disable(MeshBuildOperation::CommandRecording); | |||
if (Execute) | |||
ExecuteCmdStack(); | |||
} | |||
#endif | |||
return res; | |||
} | |||
//----------------------------------------------------------------------------- | |||
#define EZSET(M0) BD()->CmdStack().GetValue(M0); | |||
#define EZDEF_1(T0) T0 m0; EZSET(m0) | |||
#define EZDEF_2(T0, T1) EZDEF_1(T0) T1 m1; EZSET(m1) | |||
#define EZDEF_3(T0, T1, T2) EZDEF_2(T0, T1) T2 m2; EZSET(m2) | |||
#define EZDEF_4(T0, T1, T2, T3) EZDEF_3(T0, T1, T2) T3 m3; EZSET(m3) | |||
#define EZDEF_5(T0, T1, T2, T3, T4) EZDEF_4(T0, T1, T2, T3) T4 m4; EZSET(m4) | |||
#define EZDEF_6(T0, T1, T2, T3, T4, T5) EZDEF_5(T0, T1, T2, T3, T4) T5 m5; EZSET(m5) | |||
#define EZDEF_7(T0, T1, T2, T3, T4, T5, T6) EZDEF_6(T0, T1, T2, T3, T4, T5) T6 m6; EZSET(m6) | |||
#define EZDEF_8(T0, T1, T2, T3, T4, T5, T6, T7) EZDEF_7(T0, T1, T2, T3, T4, T5, T6) T7 m7; EZSET(m7) | |||
#define EZDEF_9(T0, T1, T2, T3, T4, T5, T6, T7, T8) EZDEF_8(T0, T1, T2, T3, T4, T5, T6, T7) T8 m8; EZSET(m8) | |||
#define EZDEF_10(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) EZDEF_9(T0, T1, T2, T3, T4, T5, T6, T7, T8) T9 m9; EZSET(m9) | |||
//---- | |||
#define EZCALL_1(F) F(); | |||
#define EZCALL_2(F, T0) EZDEF_1(T0) F(m0); | |||
#define EZCALL_3(F, T0, T1) EZDEF_2(T0, T1) F(m0, m1); | |||
#define EZCALL_4(F, T0, T1, T2) EZDEF_3(T0, T1, T2) F(m0, m1, m2); | |||
#define EZCALL_5(F, T0, T1, T2, T3) EZDEF_4(T0, T1, T2, T3) F(m0, m1, m2, m3); | |||
#define EZCALL_6(F, T0, T1, T2, T3, T4) EZDEF_5(T0, T1, T2, T3, T4) F(m0, m1, m2, m3, m4); | |||
#define EZCALL_7(F, T0, T1, T2, T3, T4, T5) EZDEF_6(T0, T1, T2, T3, T4, T5) F(m0, m1, m2, m3, m4, m5); | |||
#define EZCALL_8(F, T0, T1, T2, T3, T4, T5, T6) EZDEF_7(T0, T1, T2, T3, T4, T5, T6) F(m0, m1, m2, m3, m4, m5, m6); | |||
#define EZCALL_9(F, T0, T1, T2, T3, T4, T5, T6, T7) EZDEF_8(T0, T1, T2, T3, T4, T5, T6, T7) F(m0, m1, m2, m3, m4, m5, m6, m7); | |||
#define EZCALL_10(F, T0, T1, T2, T3, T4, T5, T6, T7, T8) EZDEF_9(T0, T1, T2, T3, T4, T5, T6, T7, T8) F(m0, m1, m2, m3, m4, m5, m6, m7, m8); | |||
#define EZCALL_11(F, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) EZDEF_10(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) F(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9); | |||
//---- | |||
#define EZM_CALL_FUNC(...) \ | |||
LOL_CALL(LOL_CAT(EZCALL_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__)) | |||
//----------------------------------------------------------------------------- | |||
void EasyMesh::ExecuteCmdStack(bool ExecAllStack) | |||
{ | |||
#define DO_EXEC_CMD(MESH_CMD, FUNC_PARAMS) \ | |||
case EasyMeshCmdType::MESH_CMD: \ | |||
{ EZM_CALL_FUNC FUNC_PARAMS; break; } | |||
BD()->Enable(MeshBuildOperation::CommandExecution); | |||
if (ExecAllStack) | |||
BD()->Cmdi() = 0; | |||
for (; BD()->Cmdi() < BD()->CmdStack().GetCmdNb() && BD()->CmdExecNb() != 0; ++BD()->Cmdi()) | |||
{ | |||
if (BD()->CmdExecNb() > 0) | |||
--BD()->CmdExecNb(); | |||
switch (BD()->CmdStack().GetCmd(BD()->Cmdi())) | |||
{ | |||
DO_EXEC_CMD(MeshCsg, (MeshCsg, CSGUsage)) | |||
DO_EXEC_CMD(LoopStart, (LoopStart, int)) | |||
DO_EXEC_CMD(LoopEnd, (LoopEnd)) | |||
DO_EXEC_CMD(OpenBrace, (OpenBrace)) | |||
DO_EXEC_CMD(CloseBrace, (CloseBrace)) | |||
DO_EXEC_CMD(ScaleWinding, (ToggleScaleWinding)) | |||
DO_EXEC_CMD(QuadWeighting, (ToggleQuadWeighting)) | |||
DO_EXEC_CMD(PostBuildNormal, (TogglePostBuildNormal)) | |||
DO_EXEC_CMD(PreventVertCleanup, (ToggleVerticeNoCleanup)) | |||
DO_EXEC_CMD(VerticesMerge, (VerticesMerge)) | |||
DO_EXEC_CMD(VerticesSeparate, (VerticesSeparate)) | |||
DO_EXEC_CMD(SetColorA, (SetCurColorA, vec4)) | |||
DO_EXEC_CMD(SetColorB, (SetCurColorB, vec4)) | |||
DO_EXEC_CMD(SetVertColor, (SetVertColor, vec4)) | |||
DO_EXEC_CMD(Translate, (Translate, vec3)) | |||
DO_EXEC_CMD(Rotate, (Rotate, float, vec3)) | |||
DO_EXEC_CMD(RadialJitter, (RadialJitter, float)) | |||
DO_EXEC_CMD(MeshTranform, (DoMeshTransform, MeshTransform, Axis, Axis, float, float, float, bool)) | |||
DO_EXEC_CMD(Scale, (Scale, vec3)) | |||
DO_EXEC_CMD(DupAndScale, (DupAndScale, vec3, bool)) | |||
DO_EXEC_CMD(Chamfer, (Chamfer, float)) | |||
DO_EXEC_CMD(SplitTriangles, (SplitTriangles, int)) | |||
DO_EXEC_CMD(SmoothMesh, (SmoothMesh, int, int, int)) | |||
DO_EXEC_CMD(AppendCylinder, (AppendCylinder, int, float, float, float, bool, bool, bool)) | |||
DO_EXEC_CMD(AppendCapsule, (AppendCapsule, int, float, float)) | |||
DO_EXEC_CMD(AppendTorus, (AppendTorus, int, float, float)) | |||
DO_EXEC_CMD(AppendBox, (AppendBox, vec3, float, bool)) | |||
DO_EXEC_CMD(AppendStar, (AppendStar, int, float, float, bool, bool)) | |||
DO_EXEC_CMD(AppendExpandedStar, (AppendExpandedStar, int, float, float, float)) | |||
DO_EXEC_CMD(AppendDisc, (AppendDisc, int, float, bool)) | |||
DO_EXEC_CMD(AppendSimpleTriangle, (AppendSimpleTriangle, float, bool)) | |||
DO_EXEC_CMD(AppendSimpleQuad, (AppendSimpleQuad, vec2, vec2, float, bool)) | |||
DO_EXEC_CMD(AppendCog, (AppendCog, int, float, float, float, float, float, float, float, float, bool)) | |||
default: | |||
ASSERT(0, "Unknown command pseudo bytecode"); | |||
} | |||
} | |||
BD()->Disable(MeshBuildOperation::CommandExecution); | |||
if (!BD()->IsEnabled(MeshBuildOperation::PreventVertCleanup)) | |||
VerticesCleanup(); | |||
if (BD()->IsEnabled(MeshBuildOperation::PostBuildComputeNormals)) | |||
ComputeNormals(0, (int)m_indices.Count()); | |||
BD()->Disable(MeshBuildOperation::PostBuildComputeNormals); | |||
BD()->Disable(MeshBuildOperation::PreventVertCleanup); | |||
if (BD()->CmdExecNb() > 0) | |||
BD()->CmdExecNb() = -1; | |||
} | |||
//----------------------------------------------------------------------------- | |||
void EasyMesh::MeshConvert() | |||
{ | |||
/* Default material */ | |||
Shader *shader = Shader::Create(LOLFX_RESOURCE_NAME(shiny)); | |||
/* Push index buffer to GPU */ | |||
IndexBuffer *ibo = new IndexBuffer(m_indices.Count() * sizeof(uint16_t)); | |||
uint16_t *indices = (uint16_t *)ibo->Lock(0, 0); | |||
for (int i = 0; i < m_indices.Count(); ++i) | |||
indices[i] = m_indices[i]; | |||
ibo->Unlock(); | |||
/* Push vertex buffer to GPU */ | |||
struct Vertex | |||
{ | |||
vec3 pos, normal; | |||
u8vec4 color; | |||
vec4 texcoord; | |||
}; | |||
VertexDeclaration *vdecl = new VertexDeclaration( | |||
VertexStream<vec3, vec3, u8vec4, vec4>(VertexUsage::Position, | |||
VertexUsage::Normal, | |||
VertexUsage::Color, | |||
VertexUsage::TexCoord)); | |||
VertexBuffer *vbo = new VertexBuffer(m_vert.Count() * sizeof(Vertex)); | |||
Vertex *vert = (Vertex *)vbo->Lock(0, 0); | |||
for (int i = 0; i < m_vert.Count(); ++i) | |||
{ | |||
vert[i].pos = m_vert[i].m_coord, | |||
vert[i].normal = m_vert[i].m_normal, | |||
vert[i].color = (u8vec4)(m_vert[i].m_color * 255.f); | |||
vert[i].texcoord = m_vert[i].m_texcoord; | |||
} | |||
vbo->Unlock(); | |||
/* Reference our new data in our submesh */ | |||
m_submeshes.Push(new SubMesh(shader, vdecl)); | |||
m_submeshes.Last()->SetIndexBuffer(ibo); | |||
m_submeshes.Last()->SetVertexBuffer(0, vbo); | |||
m_state = MeshRender::CanRender; | |||
} | |||
//----------------------------------------------------------------------------- | |||
bool EasyMesh::SetRender(bool should_render) | |||
{ | |||
@@ -1,5 +1,6 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh: A class about generating 3D mesh without using the hands | |||
// Mesh can be generated using C++ or lua code | |||
// | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2013 Cédric Lecacheur <jordx@free.fr> | |||
@@ -12,14 +13,10 @@ | |||
#pragma once | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include "commandstack.h" | |||
#include "easymeshrender.h" | |||
#include "easymeshbuild.h" | |||
#include "easymeshlua.h" | |||
namespace lol | |||
{ | |||
@@ -81,12 +78,19 @@ class EasyMesh : public Mesh | |||
public: | |||
EasyMesh(); | |||
EasyMesh(const EasyMesh& em); | |||
MeshRender GetMeshState() { return m_state; } | |||
bool SetRender(bool should_render); | |||
//------------------------------------------------------------------------- | |||
//Render-build operation | |||
//------------------------------------------------------------------------- | |||
void MeshConvert(); | |||
//------------------------------------------------------------------------- | |||
//Command-build (lua now) operations | |||
//------------------------------------------------------------------------- | |||
bool Compile(char const *command, bool Execute = true); | |||
void ExecuteCmdStack(bool ExecAllStack = true); | |||
void MeshConvert(); | |||
MeshRender GetMeshState() { return m_state; } | |||
bool SetRender(bool should_render); | |||
private: | |||
void UpdateVertexDict(array< int, int > &vertex_dict); | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Build: The code belonging to Vertex build operations | |||
// | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2013 Cédric Lecacheur <jordx@free.fr> | |||
@@ -10,11 +10,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Build: The code belonging to Vertex build operations | |||
// | |||
// Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
// (c) 2010-2014 Sam Hocevar <sam@hocevar.net> | |||
@@ -12,11 +12,6 @@ | |||
#pragma once | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
namespace lol | |||
{ | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Csg: The code belonging to CSG operations | |||
// | |||
// Copyright: (c) 2010-2015 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2015 Cédric Lecacheur <jordx@free.fr> | |||
@@ -10,11 +10,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Cursor: The code belonging to Cursor operations | |||
// | |||
// Copyright: (c) 2010-2015 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2015 Cédric Lecacheur <jordx@free.fr> | |||
@@ -10,11 +10,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Internal: The code belonging to internal operations | |||
// | |||
// Copyright: (c) 2010-2015 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2015 Cédric Lecacheur <jordx@free.fr> | |||
@@ -10,11 +10,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
@@ -0,0 +1,185 @@ | |||
// | |||
// MY CLASS TYPE | |||
// | |||
// Copyright © 2009-2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
// | |||
// This program is free software. It comes without any warranty, to | |||
// the extent permitted by applicable law. You can redistribute it | |||
// and/or modify it under the terms of the Do What the Fuck You Want | |||
// to Public License, Version 2, as published by the WTFPL Task Force. | |||
// See http://www.wtfpl.net/ for more details. | |||
// | |||
#if HAVE_CONFIG_H | |||
# include "config.h" | |||
#endif | |||
#include <cstdio> | |||
#include <lol/engine.h> | |||
#include "loldebug.h" | |||
using namespace lol; | |||
//----------------------------------------------------------------------------- | |||
EasyMeshLuaLoader::EasyMeshLuaLoader() : Lolua::Loader() | |||
{ | |||
Lolua::State* l = GetLuaState(); | |||
//Registering demo object | |||
Lolua::Object::Register<EasyMeshLuaObject>(l); | |||
} | |||
//----------------------------------------------------------------------------- | |||
EasyMeshLuaLoader::~EasyMeshLuaLoader() | |||
{ | |||
} | |||
//----------------------------------------------------------------------------- | |||
EasyMeshLuaObject::EasyMeshLuaObject() : Lolua::ObjectDef() | |||
{ | |||
} | |||
//----------------------------------------------------------------------------- | |||
EasyMeshLuaObject::~EasyMeshLuaObject() | |||
{ | |||
} | |||
//----------------------------------------------------------------------------- | |||
EasyMeshLuaObject* EasyMeshLuaObject::New(Lolua::State* l, int arg_nb) | |||
{ | |||
UNUSED(l); | |||
UNUSED(arg_nb); | |||
return new EasyMeshLuaObject(); | |||
} | |||
//------------------------------------------------------------------------- | |||
const Lolua::ObjectLib* EasyMeshLuaObject::GetLib() | |||
{ | |||
static const Lolua::ObjectLib lib = Lolua::ObjectLib( | |||
"EasyMesh", | |||
{ { nullptr, nullptr } }, | |||
{ { nullptr, nullptr } }, | |||
{ { nullptr, nullptr, nullptr } }); | |||
return &lib; | |||
} | |||
//----------------------------------------------------------------------------- | |||
bool EasyMesh::Compile(char const *command, bool Execute) | |||
{ | |||
bool res = false; | |||
// FIXME: make this work again | |||
#if 0 | |||
EasyMeshCompiler mc(*this); | |||
BD()->Enable(MeshBuildOperation::CommandRecording); | |||
if ((res = mc.ParseString(command))) | |||
{ | |||
BD()->Disable(MeshBuildOperation::CommandRecording); | |||
if (Execute) | |||
ExecuteCmdStack(); | |||
} | |||
#endif | |||
return res; | |||
} | |||
//----------------------------------------------------------------------------- | |||
#define EZSET(M0) BD()->CmdStack().GetValue(M0); | |||
#define EZDEF_1(T0) T0 m0; EZSET(m0) | |||
#define EZDEF_2(T0, T1) EZDEF_1(T0) T1 m1; EZSET(m1) | |||
#define EZDEF_3(T0, T1, T2) EZDEF_2(T0, T1) T2 m2; EZSET(m2) | |||
#define EZDEF_4(T0, T1, T2, T3) EZDEF_3(T0, T1, T2) T3 m3; EZSET(m3) | |||
#define EZDEF_5(T0, T1, T2, T3, T4) EZDEF_4(T0, T1, T2, T3) T4 m4; EZSET(m4) | |||
#define EZDEF_6(T0, T1, T2, T3, T4, T5) EZDEF_5(T0, T1, T2, T3, T4) T5 m5; EZSET(m5) | |||
#define EZDEF_7(T0, T1, T2, T3, T4, T5, T6) EZDEF_6(T0, T1, T2, T3, T4, T5) T6 m6; EZSET(m6) | |||
#define EZDEF_8(T0, T1, T2, T3, T4, T5, T6, T7) EZDEF_7(T0, T1, T2, T3, T4, T5, T6) T7 m7; EZSET(m7) | |||
#define EZDEF_9(T0, T1, T2, T3, T4, T5, T6, T7, T8) EZDEF_8(T0, T1, T2, T3, T4, T5, T6, T7) T8 m8; EZSET(m8) | |||
#define EZDEF_10(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) EZDEF_9(T0, T1, T2, T3, T4, T5, T6, T7, T8) T9 m9; EZSET(m9) | |||
//---- | |||
#define EZCALL_1(F) F(); | |||
#define EZCALL_2(F, T0) EZDEF_1(T0) F(m0); | |||
#define EZCALL_3(F, T0, T1) EZDEF_2(T0, T1) F(m0, m1); | |||
#define EZCALL_4(F, T0, T1, T2) EZDEF_3(T0, T1, T2) F(m0, m1, m2); | |||
#define EZCALL_5(F, T0, T1, T2, T3) EZDEF_4(T0, T1, T2, T3) F(m0, m1, m2, m3); | |||
#define EZCALL_6(F, T0, T1, T2, T3, T4) EZDEF_5(T0, T1, T2, T3, T4) F(m0, m1, m2, m3, m4); | |||
#define EZCALL_7(F, T0, T1, T2, T3, T4, T5) EZDEF_6(T0, T1, T2, T3, T4, T5) F(m0, m1, m2, m3, m4, m5); | |||
#define EZCALL_8(F, T0, T1, T2, T3, T4, T5, T6) EZDEF_7(T0, T1, T2, T3, T4, T5, T6) F(m0, m1, m2, m3, m4, m5, m6); | |||
#define EZCALL_9(F, T0, T1, T2, T3, T4, T5, T6, T7) EZDEF_8(T0, T1, T2, T3, T4, T5, T6, T7) F(m0, m1, m2, m3, m4, m5, m6, m7); | |||
#define EZCALL_10(F, T0, T1, T2, T3, T4, T5, T6, T7, T8) EZDEF_9(T0, T1, T2, T3, T4, T5, T6, T7, T8) F(m0, m1, m2, m3, m4, m5, m6, m7, m8); | |||
#define EZCALL_11(F, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) EZDEF_10(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) F(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9); | |||
//---- | |||
#define EZM_CALL_FUNC(...) \ | |||
LOL_CALL(LOL_CAT(EZCALL_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__)) | |||
//----------------------------------------------------------------------------- | |||
void EasyMesh::ExecuteCmdStack(bool ExecAllStack) | |||
{ | |||
#define DO_EXEC_CMD(MESH_CMD, FUNC_PARAMS) \ | |||
case EasyMeshCmdType::MESH_CMD: \ | |||
{ EZM_CALL_FUNC FUNC_PARAMS; break; } | |||
BD()->Enable(MeshBuildOperation::CommandExecution); | |||
if (ExecAllStack) | |||
BD()->Cmdi() = 0; | |||
for (; BD()->Cmdi() < BD()->CmdStack().GetCmdNb() && BD()->CmdExecNb() != 0; ++BD()->Cmdi()) | |||
{ | |||
if (BD()->CmdExecNb() > 0) | |||
--BD()->CmdExecNb(); | |||
switch (BD()->CmdStack().GetCmd(BD()->Cmdi())) | |||
{ | |||
DO_EXEC_CMD(MeshCsg, (MeshCsg, CSGUsage)) | |||
DO_EXEC_CMD(LoopStart, (LoopStart, int)) | |||
DO_EXEC_CMD(LoopEnd, (LoopEnd)) | |||
DO_EXEC_CMD(OpenBrace, (OpenBrace)) | |||
DO_EXEC_CMD(CloseBrace, (CloseBrace)) | |||
DO_EXEC_CMD(ScaleWinding, (ToggleScaleWinding)) | |||
DO_EXEC_CMD(QuadWeighting, (ToggleQuadWeighting)) | |||
DO_EXEC_CMD(PostBuildNormal, (TogglePostBuildNormal)) | |||
DO_EXEC_CMD(PreventVertCleanup, (ToggleVerticeNoCleanup)) | |||
DO_EXEC_CMD(VerticesMerge, (VerticesMerge)) | |||
DO_EXEC_CMD(VerticesSeparate, (VerticesSeparate)) | |||
DO_EXEC_CMD(SetColorA, (SetCurColorA, vec4)) | |||
DO_EXEC_CMD(SetColorB, (SetCurColorB, vec4)) | |||
DO_EXEC_CMD(SetVertColor, (SetVertColor, vec4)) | |||
DO_EXEC_CMD(Translate, (Translate, vec3)) | |||
DO_EXEC_CMD(Rotate, (Rotate, float, vec3)) | |||
DO_EXEC_CMD(RadialJitter, (RadialJitter, float)) | |||
DO_EXEC_CMD(MeshTranform, (DoMeshTransform, MeshTransform, Axis, Axis, float, float, float, bool)) | |||
DO_EXEC_CMD(Scale, (Scale, vec3)) | |||
DO_EXEC_CMD(DupAndScale, (DupAndScale, vec3, bool)) | |||
DO_EXEC_CMD(Chamfer, (Chamfer, float)) | |||
DO_EXEC_CMD(SplitTriangles, (SplitTriangles, int)) | |||
DO_EXEC_CMD(SmoothMesh, (SmoothMesh, int, int, int)) | |||
DO_EXEC_CMD(AppendCylinder, (AppendCylinder, int, float, float, float, bool, bool, bool)) | |||
DO_EXEC_CMD(AppendCapsule, (AppendCapsule, int, float, float)) | |||
DO_EXEC_CMD(AppendTorus, (AppendTorus, int, float, float)) | |||
DO_EXEC_CMD(AppendBox, (AppendBox, vec3, float, bool)) | |||
DO_EXEC_CMD(AppendStar, (AppendStar, int, float, float, bool, bool)) | |||
DO_EXEC_CMD(AppendExpandedStar, (AppendExpandedStar, int, float, float, float)) | |||
DO_EXEC_CMD(AppendDisc, (AppendDisc, int, float, bool)) | |||
DO_EXEC_CMD(AppendSimpleTriangle, (AppendSimpleTriangle, float, bool)) | |||
DO_EXEC_CMD(AppendSimpleQuad, (AppendSimpleQuad, vec2, vec2, float, bool)) | |||
DO_EXEC_CMD(AppendCog, (AppendCog, int, float, float, float, float, float, float, float, float, bool)) | |||
default: | |||
ASSERT(0, "Unknown command pseudo bytecode"); | |||
} | |||
} | |||
BD()->Disable(MeshBuildOperation::CommandExecution); | |||
if (!BD()->IsEnabled(MeshBuildOperation::PreventVertCleanup)) | |||
VerticesCleanup(); | |||
if (BD()->IsEnabled(MeshBuildOperation::PostBuildComputeNormals)) | |||
ComputeNormals(0, (int)m_indices.Count()); | |||
BD()->Disable(MeshBuildOperation::PostBuildComputeNormals); | |||
BD()->Disable(MeshBuildOperation::PreventVertCleanup); | |||
if (BD()->CmdExecNb() > 0) | |||
BD()->CmdExecNb() = -1; | |||
} | |||
@@ -0,0 +1,144 @@ | |||
// | |||
// MY CLASS TYPE | |||
// | |||
// Copyright © 2009-2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
// | |||
// This program is free software. It comes without any warranty, to | |||
// the extent permitted by applicable law. You can redistribute it | |||
// and/or modify it under the terms of the Do What the Fuck You Want | |||
// to Public License, Version 2, as published by the WTFPL Task Force. | |||
// See http://www.wtfpl.net/ for more details. | |||
// | |||
#pragma once | |||
namespace lol | |||
{ | |||
//----------------------------------------------------------------------------- | |||
class EasyMeshLuaLoader : public Lolua::Loader | |||
{ | |||
public: | |||
EasyMeshLuaLoader(); | |||
virtual ~EasyMeshLuaLoader(); | |||
}; | |||
//----------------------------------------------------------------------------- | |||
class EasyMeshLuaObject : public Lolua::ObjectDef | |||
{ | |||
public: | |||
//------------------------------------------------------------------------- | |||
EasyMeshLuaObject(); | |||
virtual ~EasyMeshLuaObject(); | |||
//------------------------------------------------------------------------- | |||
static EasyMeshLuaObject* New(Lolua::State* l, int arg_nb); | |||
static const Lolua::ObjectLib* GetLib(); | |||
//------------------------------------------------------------------------- | |||
/* | |||
(csgu|csgunion) { return token::T_CSGUNION; } | |||
(csgs|CsgSub) { return token::T_CSGSUBSTRACT; } | |||
(csgsl|CsgSubL) { return token::T_CSGSUBSTRACTLOSS; } | |||
(csga|csgand) { return token::T_CSGAND; } | |||
(csgx|csgxor) { return token::T_CSGXOR; } | |||
(lp|loop) { return token::T_LOOP; } | |||
(sc|setcolor) { return token::T_COLOR; } | |||
(sca|setcolora) { return token::T_ACOLOR; } | |||
(scb|setcolorb) { return token::T_BCOLOR; } | |||
(scv|setcolorv) { return token::T_VCOLOR; } | |||
(tsw|tglscalewind) { return token::T_TOGGLESCALEWINDING; } | |||
(tqw|tglquadweight) { return token::T_TOGGLEQUADWEIGHTING; } | |||
(tpbn|tglpstbuildnormal) { return token::T_TOGGLEPOSTBUILDNORMAL; } | |||
(tvnc|tglvertnocleanup) { return token::T_TOGGLEVERTNOCLEANUP; } | |||
(vm|vertmerge) { return token::T_VERTMERGE; } | |||
(vs|vertseparate) { return token::T_VERTSEPARATE; } | |||
(tx|translatex) { return token::T_TRANSLATEX; } | |||
(ty|translatey) { return token::T_TRANSLATEY; } | |||
(tz|translatez) { return token::T_TRANSLATEZ; } | |||
(t|translate) { return token::T_TRANSLATE; } | |||
(rx|rotatex) { return token::T_ROTATEX; } | |||
(ry|rotatey) { return token::T_ROTATEY; } | |||
(rz|rotatez) { return token::T_ROTATEZ; } | |||
(r|rotate) { return token::T_ROTATE; } | |||
(rj|radialjitter) { return token::T_RADIALJITTER; } | |||
(tax|taperx) { return token::T_TAPERX; } | |||
(tay|tapery) { return token::T_TAPERY; } | |||
(taz|taperz) { return token::T_TAPERZ; } | |||
(twx|twistx) { return token::T_TWISTX; } | |||
(twy|twisty) { return token::T_TWISTY; } | |||
(twz|twistz) { return token::T_TWISTZ; } | |||
(shx|shearx) { return token::T_SHEARX; } | |||
(shy|sheary) { return token::T_SHEARY; } | |||
(shz|shearz) { return token::T_SHEARZ; } | |||
(stx|stretchx) { return token::T_STRETCHX; } | |||
(sty|stretchy) { return token::T_STRETCHY; } | |||
(stz|stretchz) { return token::T_STRETCHZ; } | |||
(bdxy|bendxy) { return token::T_BENDXY; } | |||
(bdxz|bendxz) { return token::T_BENDXZ; } | |||
(bdyx|bendyx) { return token::T_BENDYX; } | |||
(bdyz|bendyz) { return token::T_BENDYZ; } | |||
(bdzx|bendzx) { return token::T_BENDZX; } | |||
(bdzy|bendzy) { return token::T_BENDZY; } | |||
(sx|scalex) { return token::T_SCALEX; } | |||
(sy|scaley) { return token::T_SCALEY; } | |||
(sz|scalez) { return token::T_SCALEZ; } | |||
(s|scale) { return token::T_SCALE; } | |||
(mx|mirrorx) { return token::T_MIRRORX; } | |||
(my|mirrory) { return token::T_MIRRORY; } | |||
(mz|mirrorz) { return token::T_MIRRORZ; } | |||
(ch|chamfer) { return token::T_CHAMFER; } | |||
(splt|splittriangle) { return token::T_SPLITTRIANGLE; } | |||
(smth|smooth) { return token::T_SMOOTHMESH; } | |||
(dup|duplicate) { return token::T_DUPLICATE; } | |||
(ac|addcylinder) { return token::T_CYLINDER; } | |||
(asph|addsphere) { return token::T_SPHERE; } | |||
(acap|addcapsule) { return token::T_CAPSULE; } | |||
(ato|addtorus) { return token::T_TORUS; } | |||
(ab|addbox) { return token::T_BOX; } | |||
(ascb|addsmoothchamfbox) { return token::T_SMOOTHCHAMFBOX; } | |||
(afcb|addflatchamfbox) { return token::T_FLATCHAMFBOX; } | |||
(as|addstar) { return token::T_STAR; } | |||
(aes|addexpandedstar) { return token::T_EXPANDEDSTAR; } | |||
(ad|adddisc) { return token::T_DISC; } | |||
(at|addtriangle) { return token::T_TRIANGLE; } | |||
(aq|addquad) { return token::T_QUAD; } | |||
(acg|addcog) { return token::T_COG; } | |||
*/ | |||
/* | |||
%{ *//* ======= BASE COLOR TYPES ========================================= *//* % | |||
} | |||
%{ *//* COLOR *//* %} | |||
#[0-9a-fA-F]{3} { | |||
uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); | |||
yylval->u32val = 0x11000000u * (tmp >> 8) | |||
| 0x00110000u * ((tmp >> 4) & 0xf) | |||
| 0x00001100u * (tmp & 0xf) | |||
| 0x000000ffu; | |||
return token::COLOR; } | |||
#[0-9a-fA-F]{4} { | |||
uint32_t tmp = std::strtol(yytext + 1, nullptr, 16); | |||
yylval->u32val = 0x11000000u * (tmp >> 12) | |||
| 0x00110000u * ((tmp >> 8) & 0xf) | |||
| 0x00001100u * ((tmp >> 4) & 0xf) | |||
| 0x00000011u * (tmp & 0xf); | |||
return token::COLOR; } | |||
#[0-9a-fA-F]{6} { | |||
yylval->u32val = 0xffu | |||
| 0x100u * (uint32_t)std::strtol(yytext + 1, nullptr, 16); | |||
return token::COLOR; } | |||
#[0-9a-fA-F]{8} { | |||
yylval->u32val = (uint32_t)std::strtol(yytext + 1, nullptr, 16); | |||
return token::COLOR; } | |||
*/ | |||
}; | |||
} /* namespace lol */ |
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Primitive: The code belonging to primitive operations | |||
// | |||
// Copyright: (c) 2010-2015 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2015 Cédric Lecacheur <jordx@free.fr> | |||
@@ -10,11 +10,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Render: The code belonging to render operations | |||
// | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2013 Cédric Lecacheur <jordx@free.fr> | |||
@@ -10,11 +10,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
@@ -28,6 +23,52 @@ LOLFX_RESOURCE_DECLARE(shinydebugnormal); | |||
LOLFX_RESOURCE_DECLARE(shinydebugUV); | |||
LOLFX_RESOURCE_DECLARE(shiny_SK); | |||
//----------------------------------------------------------------------------- | |||
void EasyMesh::MeshConvert() | |||
{ | |||
/* Default material */ | |||
Shader *shader = Shader::Create(LOLFX_RESOURCE_NAME(shiny)); | |||
/* Push index buffer to GPU */ | |||
IndexBuffer *ibo = new IndexBuffer(m_indices.Count() * sizeof(uint16_t)); | |||
uint16_t *indices = (uint16_t *)ibo->Lock(0, 0); | |||
for (int i = 0; i < m_indices.Count(); ++i) | |||
indices[i] = m_indices[i]; | |||
ibo->Unlock(); | |||
/* Push vertex buffer to GPU */ | |||
struct Vertex | |||
{ | |||
vec3 pos, normal; | |||
u8vec4 color; | |||
vec4 texcoord; | |||
}; | |||
VertexDeclaration *vdecl = new VertexDeclaration( | |||
VertexStream<vec3, vec3, u8vec4, vec4>(VertexUsage::Position, | |||
VertexUsage::Normal, | |||
VertexUsage::Color, | |||
VertexUsage::TexCoord)); | |||
VertexBuffer *vbo = new VertexBuffer(m_vert.Count() * sizeof(Vertex)); | |||
Vertex *vert = (Vertex *)vbo->Lock(0, 0); | |||
for (int i = 0; i < m_vert.Count(); ++i) | |||
{ | |||
vert[i].pos = m_vert[i].m_coord, | |||
vert[i].normal = m_vert[i].m_normal, | |||
vert[i].color = (u8vec4)(m_vert[i].m_color * 255.f); | |||
vert[i].texcoord = m_vert[i].m_texcoord; | |||
} | |||
vbo->Unlock(); | |||
/* Reference our new data in our submesh */ | |||
m_submeshes.Push(new SubMesh(shader, vdecl)); | |||
m_submeshes.Last()->SetIndexBuffer(ibo); | |||
m_submeshes.Last()->SetVertexBuffer(0, vbo); | |||
m_state = MeshRender::CanRender; | |||
} | |||
//----------------------------------------------------------------------------- | |||
GpuShaderData::GpuShaderData() | |||
{ | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Render: The code belonging to render operations | |||
// | |||
// Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
// (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
@@ -12,11 +12,6 @@ | |||
#pragma once | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
namespace lol | |||
{ | |||
@@ -1,5 +1,5 @@ | |||
// | |||
// Lol Engine | |||
// EasyMesh-Transform: The code belonging to transform operations | |||
// | |||
// Copyright: (c) 2010-2015 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2015 Cédric Lecacheur <jordx@free.fr> | |||
@@ -10,11 +10,6 @@ | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#include <lol/engine-internal.h> | |||
namespace lol | |||
@@ -107,6 +107,7 @@ | |||
<ClCompile Include="easymesh\easymeshcsg.cpp" /> | |||
<ClCompile Include="easymesh\easymeshcursor.cpp" /> | |||
<ClCompile Include="easymesh\easymeshinternal.cpp" /> | |||
<ClCompile Include="easymesh\easymeshlua.cpp" /> | |||
<ClCompile Include="easymesh\easymeshprimitive.cpp" /> | |||
<ClCompile Include="easymesh\easymeshrender.cpp" /> | |||
<ClCompile Include="easymesh\easymeshtransform.cpp" /> | |||
@@ -243,6 +244,7 @@ | |||
<ClInclude Include="easymesh\csgbsp.h" /> | |||
<ClInclude Include="easymesh\easymesh.h" /> | |||
<ClInclude Include="easymesh\easymeshbuild.h" /> | |||
<ClInclude Include="easymesh\easymeshlua.h" /> | |||
<ClInclude Include="easymesh\easymeshrender.h" /> | |||
<ClInclude Include="eglapp.h" /> | |||
<ClInclude Include="emitter.h" /> | |||
@@ -88,6 +88,9 @@ | |||
<Filter Include="image\filter"> | |||
<UniqueIdentifier>{3f420a7d-0538-463a-925b-3f8968bf628e}</UniqueIdentifier> | |||
</Filter> | |||
<Filter Include="lua"> | |||
<UniqueIdentifier>{25cc0513-ad71-4fbe-bd24-acc88aa66833}</UniqueIdentifier> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="image\crop.cpp"> | |||
@@ -403,8 +406,11 @@ | |||
<ClCompile Include="easymesh\easymeshcursor.cpp"> | |||
<Filter>easymesh</Filter> | |||
</ClCompile> | |||
<ClCompile Include="easymesh\easymeshlua.cpp"> | |||
<Filter>easymesh</Filter> | |||
</ClCompile> | |||
<ClCompile Include="application\baselua.cpp"> | |||
<Filter>application</Filter> | |||
<Filter>lua</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -757,8 +763,11 @@ | |||
<ClInclude Include="lol\algorithm\portal.h"> | |||
<Filter>lol\algorithm</Filter> | |||
</ClInclude> | |||
<ClInclude Include="easymesh\easymeshlua.h"> | |||
<Filter>easymesh</Filter> | |||
</ClInclude> | |||
<ClInclude Include="application\baselua.h"> | |||
<Filter>application</Filter> | |||
<Filter>lua</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
<ItemGroup> | |||