From 018f5d003dc2ad149bd4d5a038322cb90b5341d5 Mon Sep 17 00:00:00 2001 From: Megumumpkin Date: Sun, 4 Sep 2022 00:06:56 +0700 Subject: [PATCH] Add HairParticleSystem and Small Enhancements for Lua Bindings (#553) * Update Lua * Update Lua Bindings * HairComponent Lua Binding Fix * Adding Documentation --- .vscode/launch.json | 16 + .../ScriptingAPI-Documentation.md | 74 ++++ WickedEngine/wiPrimitive_BindLua.cpp | 92 ++++ WickedEngine/wiPrimitive_BindLua.h | 4 + WickedEngine/wiScene_BindLua.cpp | 418 ++++++++++++++++++ WickedEngine/wiScene_BindLua.h | 218 ++++++++- 6 files changed, 820 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..08a74cb2b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Editor", + "type": "gdb", + "request": "launch", + "target": "./WickedEngineEditor", + "cwd": "${workspaceRoot}/build/Editor", + "valuesFormatting": "parseText" + } + ] +} \ No newline at end of file diff --git a/Content/Documentation/ScriptingAPI-Documentation.md b/Content/Documentation/ScriptingAPI-Documentation.md index 1e3174611..b3bdda712 100644 --- a/Content/Documentation/ScriptingAPI-Documentation.md +++ b/Content/Documentation/ScriptingAPI-Documentation.md @@ -32,6 +32,7 @@ This is a reference and explanation of Lua scripting features in Wicked Engine. 7. [AnimationComponent](#animationcomponent) 8. [MaterialComponent](#materialcomponent) 9. [EmitterComponent](#emittercomponent) + 9. [HairParticleSystem](#hairparticlesystem) 10. [LightComponent](#lightcomponent) 11. [ObjectComponent](#objectcomponent) 12. [InverseKinematicsComponent](#inversekinematicscomponent) @@ -657,6 +658,7 @@ Describes an orientation in 3D space. - GetAmount() : float result #### MaterialComponent +- _flags : int - BaseColor : Vector - EmissiveColor : Vector - EngineStencilRef : int @@ -692,8 +694,30 @@ Describes an orientation in 3D space. - SetEngineStencilRef(int value) - SetUserStencilRef(int value) - GetStencilRef() : int result +- SetTexture(int textureindex, string texturefile) +- SetTextureUVSet(int textureindex, int uvset) +- GetTexture(int textureindex) : string texturefile +- GetTextureUVSet(int textureindex) : int uvset + +#### MeshComponent +- _flags : int +- TessellationFactor : float +- ArmatureID : int +- SubsetsPerLOD : int + +
+ +- SetMeshSubsetMaterialID(int subsetindex, Entity materialID) +- GetMeshSubsetMaterialID(int subsetindex) #### EmitterComponent +- _flags : int +- ShaderType : int +- Mass : float +- Velocity : Vector +- Gravity : Vector +- Drag : float +- Restitution : float - EmitCount : float -- emitted particle count per second - Size : float -- particle starting size - Life : float -- particle lifetime @@ -704,6 +728,15 @@ Describes an orientation in 3D space. - ScaleY : float -- scaling along lifetime in Y axis - Rotation : float -- rotation speed - MotionBlurAmount : float -- set the motion elongation factor +- SPH_h : float +- SPH_K : float +- SPH_p0 : float +- SPH_e : float +- SpriteSheet_Frames_X : int +- SpriteSheet_Frames_Y : int +- SpriteSheet_Frame_Count : int +- SpriteSheet_Frame_Start : int +- SpriteSheet_Framerate : float
@@ -719,6 +752,20 @@ Describes an orientation in 3D space. - SetRotation(float value) -- set rotation speed - SetMotionBlurAmount(float value) -- set the motion elongation factor +#### HairParticleSystem +- _flags : int +- StrandCount : int +- SegmentCount : int +- RandomSeed : int +- Length : float +- Stiffness : float +- Randomness : float +- ViewDistance : float +- SpriteSheet_Frames_X : int +- SpriteSheet_Frames_Y : int +- SpriteSheet_Frame_Count : int +- SpriteSheet_Frame_Start : int + #### LightComponent - Type : int -- light type, see accepted values below (by default it is a point light) - [outer]DIRECTIONAL : int @@ -800,9 +847,22 @@ Describes an Inverse Kinematics effector. #### SpringComponent Enables jiggle effect on transforms such as bones for example. +- Stiffness : float +- Damping : float +- WindAffection : float +- DragForce : float +- HitRadius : float +- GravityPower : float +- GravityDirection : Vector + +
+ - SetStiffness(float value) - SetDamping(float value) - SetWindAffection(float value) +- GetStiffness() : float result +- GetDamping() : float result +- GetWindAffection() : float result #### ScriptComponent A lua script bound to an entity @@ -995,15 +1055,27 @@ It inherits functions from RenderPath2D. #### Ray A ray is defined by an origin Vector and a normalized direction Vector. It can be used to intersect with other primitives or the scene +- Origin : Vector +- Direction : Vector + +
+ - [constructor]Ray(Vector origin,direction) - Intersects(AABB aabb) : bool result - Intersects(Sphere sphere) : bool result - Intersects(Capsule capsule) : bool result - GetOrigin() : Vector result - GetDirection() : Vector result +- SetOrigin(Vector vector) +- SetDirection(Vector vector) #### AABB Axis Aligned Bounding Box. Can be intersected with other primitives. +- Min : Vector +- Max : Vector + +
+ - [constructor]AABB(opt Vector min,max) -- if no argument is given, it will be infinitely inverse that can't intersect - Intersects2D(AABB aabb) : bool result -- omit the z component for intersection check for more precise 2D intersection - Intersects(AABB aabb) : bool result @@ -1011,6 +1083,8 @@ Axis Aligned Bounding Box. Can be intersected with other primitives. - Intersects(Ray ray) : bool result - GetMin() : Vector result - GetMax() : Vector result +- SetMin(Vector vector) +- SetMax(Vector vector) - GetCenter() : Vector result - GetHalfExtents() : Vector result - Transform(Matrix matrix) : AABB result -- transforms the AABB with a matrix and returns the resulting conservative AABB diff --git a/WickedEngine/wiPrimitive_BindLua.cpp b/WickedEngine/wiPrimitive_BindLua.cpp index 5978dc4e3..205d0e113 100644 --- a/WickedEngine/wiPrimitive_BindLua.cpp +++ b/WickedEngine/wiPrimitive_BindLua.cpp @@ -30,9 +30,13 @@ namespace wi::lua::primitive lunamethod(Ray_BindLua, Intersects), lunamethod(Ray_BindLua, GetOrigin), lunamethod(Ray_BindLua, GetDirection), + lunamethod(Ray_BindLua, SetOrigin), + lunamethod(Ray_BindLua, SetDirection), { NULL, NULL } }; Luna::PropertyType Ray_BindLua::properties[] = { + lunaproperty(Ray_BindLua, Origin), + lunaproperty(Ray_BindLua, Direction), { NULL, NULL } }; @@ -104,11 +108,53 @@ namespace wi::lua::primitive Luna::push(L, new Vector_BindLua(XMLoadFloat3(&ray.origin))); return 1; } + int Ray_BindLua::SetOrigin(lua_State *L) + { + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* v = Luna::lightcheck(L, 1); + if (v != nullptr) + { + XMStoreFloat3(&ray.origin, XMLoadFloat4(v)); + } + else + { + wi::lua::SError(L, "SetOrigin(Vector vector) argument is not a vector!"); + } + } + else + { + wi::lua::SError(L, "SetOrigin(Vector vector) not enough arguments!"); + } + return 0; + } int Ray_BindLua::GetDirection(lua_State* L) { Luna::push(L, new Vector_BindLua(XMLoadFloat3(&ray.direction))); return 1; } + int Ray_BindLua::SetDirection(lua_State *L) + { + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* v = Luna::lightcheck(L, 1); + if (v != nullptr) + { + XMStoreFloat3(&ray.direction, XMLoadFloat4(v)); + } + else + { + wi::lua::SError(L, "SetDirection(Vector vector) argument is not a vector!"); + } + } + else + { + wi::lua::SError(L, "SetDirection(Vector vector) not enough arguments!"); + } + return 0; + } @@ -119,6 +165,8 @@ namespace wi::lua::primitive lunamethod(AABB_BindLua, Intersects2D), lunamethod(AABB_BindLua, GetMin), lunamethod(AABB_BindLua, GetMax), + lunamethod(AABB_BindLua, SetMin), + lunamethod(AABB_BindLua, SetMax), lunamethod(AABB_BindLua, GetCenter), lunamethod(AABB_BindLua, GetHalfExtents), lunamethod(AABB_BindLua, Transform), @@ -126,6 +174,8 @@ namespace wi::lua::primitive { NULL, NULL } }; Luna::PropertyType AABB_BindLua::properties[] = { + lunaproperty(AABB_BindLua, Min), + lunaproperty(AABB_BindLua, Max), { NULL, NULL } }; @@ -220,12 +270,54 @@ namespace wi::lua::primitive Luna::push(L, new Vector_BindLua(XMLoadFloat3(&M))); return 1; } + int AABB_BindLua::SetMin(lua_State *L) + { + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* v = Luna::lightcheck(L, 1); + if (v != nullptr) + { + XMStoreFloat3(&aabb._min, XMLoadFloat4(v)); + } + else + { + wi::lua::SError(L, "SetMin(Vector vector) argument is not a vector!"); + } + } + else + { + wi::lua::SError(L, "SetMin(Vector vector) not enough arguments!"); + } + return 0; + } int AABB_BindLua::GetMax(lua_State* L) { XMFLOAT3 M = aabb.getMax(); Luna::push(L, new Vector_BindLua(XMLoadFloat3(&M))); return 1; } + int AABB_BindLua::SetMax(lua_State *L) + { + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* v = Luna::lightcheck(L, 1); + if (v != nullptr) + { + XMStoreFloat3(&aabb._max, XMLoadFloat4(v)); + } + else + { + wi::lua::SError(L, "SetMax(Vector vector) argument is not a vector!"); + } + } + else + { + wi::lua::SError(L, "SetMax(Vector vector) not enough arguments!"); + } + return 0; + } int AABB_BindLua::GetCenter(lua_State* L) { XMFLOAT3 C = aabb.getCenter(); diff --git a/WickedEngine/wiPrimitive_BindLua.h b/WickedEngine/wiPrimitive_BindLua.h index 45e6b82b6..83b2cfb3e 100644 --- a/WickedEngine/wiPrimitive_BindLua.h +++ b/WickedEngine/wiPrimitive_BindLua.h @@ -23,6 +23,8 @@ namespace wi::lua::primitive int Intersects(lua_State* L); int GetOrigin(lua_State* L); int GetDirection(lua_State* L); + int SetOrigin(lua_State* L); + int SetDirection(lua_State* L); }; class AABB_BindLua @@ -41,6 +43,8 @@ namespace wi::lua::primitive int Intersects2D(lua_State* L); int GetMin(lua_State* L); int GetMax(lua_State* L); + int SetMin(lua_State* L); + int SetMax(lua_State* L); int GetCenter(lua_State* L); int GetHalfExtents(lua_State* L); int Transform(lua_State* L); diff --git a/WickedEngine/wiScene_BindLua.cpp b/WickedEngine/wiScene_BindLua.cpp index d5632d575..52d570c2a 100644 --- a/WickedEngine/wiScene_BindLua.cpp +++ b/WickedEngine/wiScene_BindLua.cpp @@ -314,7 +314,9 @@ void Bind() Luna::Register(L); Luna::Register(L); Luna::Register(L); + Luna::Register(L); Luna::Register(L); + Luna::Register(L); Luna::Register(L); Luna::Register(L); Luna::Register(L); @@ -346,6 +348,8 @@ Luna::FunctionType Scene_BindLua::methods[] = { lunamethod(Scene_BindLua, Component_CreateName), lunamethod(Scene_BindLua, Component_CreateLayer), lunamethod(Scene_BindLua, Component_CreateTransform), + lunamethod(Scene_BindLua, Component_CreateEmitter), + lunamethod(Scene_BindLua, Component_CreateHairParticleSystem), lunamethod(Scene_BindLua, Component_CreateLight), lunamethod(Scene_BindLua, Component_CreateObject), lunamethod(Scene_BindLua, Component_CreateMaterial), @@ -365,7 +369,9 @@ Luna::FunctionType Scene_BindLua::methods[] = { lunamethod(Scene_BindLua, Component_GetCamera), lunamethod(Scene_BindLua, Component_GetAnimation), lunamethod(Scene_BindLua, Component_GetMaterial), + lunamethod(Scene_BindLua, Component_GetMesh), lunamethod(Scene_BindLua, Component_GetEmitter), + lunamethod(Scene_BindLua, Component_GetHairParticleSystem), lunamethod(Scene_BindLua, Component_GetLight), lunamethod(Scene_BindLua, Component_GetObject), lunamethod(Scene_BindLua, Component_GetInverseKinematics), @@ -384,7 +390,9 @@ Luna::FunctionType Scene_BindLua::methods[] = { lunamethod(Scene_BindLua, Component_GetCameraArray), lunamethod(Scene_BindLua, Component_GetAnimationArray), lunamethod(Scene_BindLua, Component_GetMaterialArray), + lunamethod(Scene_BindLua, Component_GetMeshArray), lunamethod(Scene_BindLua, Component_GetEmitterArray), + lunamethod(Scene_BindLua, Component_GetHairParticleSystemArray), lunamethod(Scene_BindLua, Component_GetLightArray), lunamethod(Scene_BindLua, Component_GetObjectArray), lunamethod(Scene_BindLua, Component_GetInverseKinematicsArray), @@ -403,7 +411,9 @@ Luna::FunctionType Scene_BindLua::methods[] = { lunamethod(Scene_BindLua, Entity_GetCameraArray), lunamethod(Scene_BindLua, Entity_GetAnimationArray), lunamethod(Scene_BindLua, Entity_GetMaterialArray), + lunamethod(Scene_BindLua, Entity_GetMeshArray), lunamethod(Scene_BindLua, Entity_GetEmitterArray), + lunamethod(Scene_BindLua, Entity_GetHairParticleSystemArray), lunamethod(Scene_BindLua, Entity_GetLightArray), lunamethod(Scene_BindLua, Entity_GetObjectArray), lunamethod(Scene_BindLua, Entity_GetInverseKinematicsArray), @@ -591,6 +601,40 @@ int Scene_BindLua::Component_CreateLight(lua_State* L) } return 0; } +int Scene_BindLua::Component_CreateEmitter(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wi::lua::SGetLongLong(L, 1); + + EmittedParticleSystem& component = scene->emitters.Create(entity); + Luna::push(L, new EmitterComponent_BindLua(&component)); + return 1; + } + else + { + wi::lua::SError(L, "Scene::Component_CreateEmitter(Entity entity) not enough arguments!"); + } + return 0; +} +int Scene_BindLua::Component_CreateHairParticleSystem(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wi::lua::SGetLongLong(L, 1); + + HairParticleSystem& component = scene->hairs.Create(entity); + Luna::push(L, new HairParticleSystem_BindLua(&component)); + return 1; + } + else + { + wi::lua::SError(L, "Scene::Component_CreateHairParticle(Entity entity) not enough arguments!"); + } + return 0; +} int Scene_BindLua::Component_CreateObject(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -913,6 +957,28 @@ int Scene_BindLua::Component_GetMaterial(lua_State* L) } return 0; } +int Scene_BindLua::Component_GetMesh(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wi::lua::SGetLongLong(L, 1); + + MeshComponent* component = scene->meshes.GetComponent(entity); + if (component == nullptr) + { + return 0; + } + + Luna::push(L, new MeshComponent_BindLua(component)); + return 1; + } + else + { + wi::lua::SError(L, "Scene::Component_GetMesh(Entity entity) not enough arguments!"); + } + return 0; +} int Scene_BindLua::Component_GetEmitter(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -935,6 +1001,28 @@ int Scene_BindLua::Component_GetEmitter(lua_State* L) } return 0; } +int Scene_BindLua::Component_GetHairParticleSystem(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + Entity entity = (Entity)wi::lua::SGetLongLong(L, 1); + + wi::HairParticleSystem* component = scene->hairs.GetComponent(entity); + if (component == nullptr) + { + return 0; + } + + Luna::push(L, new HairParticleSystem_BindLua(component)); + return 1; + } + else + { + wi::lua::SError(L, "Scene::Component_GetHairParticle(Entity entity) not enough arguments!"); + } + return 0; +} int Scene_BindLua::Component_GetLight(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -1244,6 +1332,17 @@ int Scene_BindLua::Component_GetMaterialArray(lua_State* L) } return 1; } +int Scene_BindLua::Component_GetMeshArray(lua_State* L) +{ + lua_createtable(L, (int)scene->meshes.GetCount(), 0); + int newTable = lua_gettop(L); + for (size_t i = 0; i < scene->meshes.GetCount(); ++i) + { + Luna::push(L, new MeshComponent_BindLua(&scene->meshes[i])); + lua_rawseti(L, newTable, lua_Integer(i + 1)); + } + return 1; +} int Scene_BindLua::Component_GetEmitterArray(lua_State* L) { lua_createtable(L, (int)scene->emitters.GetCount(), 0); @@ -1255,6 +1354,17 @@ int Scene_BindLua::Component_GetEmitterArray(lua_State* L) } return 1; } +int Scene_BindLua::Component_GetHairParticleSystemArray(lua_State* L) +{ + lua_createtable(L, (int)scene->hairs.GetCount(), 0); + int newTable = lua_gettop(L); + for (size_t i = 0; i < scene->hairs.GetCount(); ++i) + { + Luna::push(L, new HairParticleSystem_BindLua(&scene->hairs[i])); + lua_rawseti(L, newTable, lua_Integer(i + 1)); + } + return 1; +} int Scene_BindLua::Component_GetLightArray(lua_State* L) { lua_createtable(L, (int)scene->lights.GetCount(), 0); @@ -1443,6 +1553,17 @@ int Scene_BindLua::Entity_GetMaterialArray(lua_State* L) } return 1; } +int Scene_BindLua::Entity_GetMeshArray(lua_State* L) +{ + lua_createtable(L, (int)scene->meshes.GetCount(), 0); + int newTable = lua_gettop(L); + for (size_t i = 0; i < scene->meshes.GetCount(); ++i) + { + wi::lua::SSetLongLong(L, scene->meshes.GetEntity(i)); + lua_rawseti(L, newTable, lua_Integer(i + 1)); + } + return 1; +} int Scene_BindLua::Entity_GetEmitterArray(lua_State* L) { lua_createtable(L, (int)scene->emitters.GetCount(), 0); @@ -1454,6 +1575,17 @@ int Scene_BindLua::Entity_GetEmitterArray(lua_State* L) } return 1; } +int Scene_BindLua::Entity_GetHairParticleSystemArray(lua_State* L) +{ + lua_createtable(L, (int)scene->hairs.GetCount(), 0); + int newTable = lua_gettop(L); + for (size_t i = 0; i < scene->hairs.GetCount(); ++i) + { + wi::lua::SSetLongLong(L, scene->hairs.GetEntity(i)); + lua_rawseti(L, newTable, lua_Integer(i + 1)); + } + return 1; +} int Scene_BindLua::Entity_GetLightArray(lua_State* L) { lua_createtable(L, (int)scene->lights.GetCount(), 0); @@ -2415,9 +2547,16 @@ Luna::FunctionType MaterialComponent_BindLua::methods lunamethod(MaterialComponent_BindLua, SetEngineStencilRef), lunamethod(MaterialComponent_BindLua, SetUserStencilRef), lunamethod(MaterialComponent_BindLua, GetStencilRef), + + lunamethod(MaterialComponent_BindLua, SetTexture), + lunamethod(MaterialComponent_BindLua, SetTextureUVSet), + lunamethod(MaterialComponent_BindLua, GetTexture), + lunamethod(MaterialComponent_BindLua, GetTextureUVSet), { NULL, NULL } }; Luna::PropertyType MaterialComponent_BindLua::properties[] = { + lunaproperty(MaterialComponent_BindLua, _flags), + lunaproperty(MaterialComponent_BindLua, BaseColor), lunaproperty(MaterialComponent_BindLua, EmissiveColor), lunaproperty(MaterialComponent_BindLua, EngineStencilRef), @@ -2565,6 +2704,195 @@ int MaterialComponent_BindLua::GetStencilRef(lua_State* L) wi::lua::SSetInt(L, (int)component->GetStencilRef()); return 1; } +int MaterialComponent_BindLua::SetTexture(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc >= 2) + { + uint32_t textureindex = wi::lua::SGetLongLong(L, 1); + std::string resourcename = wi::lua::SGetString(L, 2); + + if(textureindex < MaterialComponent::TEXTURESLOT_COUNT) + { + auto& texturedata = component->textures[textureindex]; + texturedata.name = resourcename; + texturedata.resource = wi::resourcemanager::Load(resourcename); + component->SetDirty(); + } + else + { + wi::lua::SError(L, "SetTexture(int textureindex, string resourcename) index out of range!"); + } + } + else + { + wi::lua::SError(L, "SetTexture(int textureindex, string resourcename) not enough arguments!"); + } + + return 0; +} +int MaterialComponent_BindLua::GetTexture(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + uint32_t textureindex = wi::lua::SGetLongLong(L, 1); + + if(textureindex < MaterialComponent::TEXTURESLOT_COUNT) + { + auto& texturedata = component->textures[textureindex]; + wi::lua::SSetString(L, texturedata.name); + return 1; + } + else + { + wi::lua::SError(L, "GetTexture(int textureindex) index out of range!"); + } + } + else + { + wi::lua::SError(L, "GetTexture(int textureindex) not enough arguments!"); + } + return 0; +} +int MaterialComponent_BindLua::SetTextureUVSet(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc >= 2) + { + uint32_t textureindex = wi::lua::SGetLongLong(L, 1); + uint32_t uvset = wi::lua::SGetLongLong(L, 2); + + if(textureindex < MaterialComponent::TEXTURESLOT_COUNT) + { + auto& texturedata = component->textures[textureindex]; + texturedata.uvset = uvset; + component->SetDirty(); + } + else + { + wi::lua::SError(L, "SetTextureUVSet(int textureindex, int uvset) index out of range!"); + } + } + else + { + wi::lua::SError(L, "SetTextureUVSet(int textureindex, int uvset) not enough arguments!"); + } + + return 0; +} +int MaterialComponent_BindLua::GetTextureUVSet(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + uint32_t textureindex = wi::lua::SGetLongLong(L, 1); + + if(textureindex < MaterialComponent::TEXTURESLOT_COUNT) + { + auto& texturedata = component->textures[textureindex]; + wi::lua::SSetLongLong(L, texturedata.uvset); + return 1; + } + else + { + wi::lua::SError(L, "GetTextureUVSet(int textureindex) index out of range!"); + } + } + else + { + wi::lua::SError(L, "GetTextureUVSet(int textureindex) not enough arguments!"); + } + return 0; +} + + + + + + + + + + +const char MeshComponent_BindLua::className[] = "MeshComponent"; + +Luna::FunctionType MeshComponent_BindLua::methods[] = { + lunamethod(MeshComponent_BindLua, SetMeshSubsetMaterialID), + lunamethod(MeshComponent_BindLua, GetMeshSubsetMaterialID), + { NULL, NULL } +}; +Luna::PropertyType MeshComponent_BindLua::properties[] = { + lunaproperty(MeshComponent_BindLua, _flags), + lunaproperty(MeshComponent_BindLua, TessellationFactor), + lunaproperty(MeshComponent_BindLua, ArmatureID), + lunaproperty(MeshComponent_BindLua, SubsetsPerLOD), + { NULL, NULL } +}; + +MeshComponent_BindLua::MeshComponent_BindLua(lua_State *L) +{ + owning = true; + component = new MeshComponent; + BuildBindings(); +} +MeshComponent_BindLua::~MeshComponent_BindLua() +{ + if (owning) + { + delete component; + } +} + +int MeshComponent_BindLua::SetMeshSubsetMaterialID(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc >= 2) + { + size_t subsetindex = wi::lua::SGetLongLong(L, 1); + uint32_t uvset = wi::lua::SGetLongLong(L, 2); + + if(subsetindex < component->subsets.size()) + { + auto& subsetdata = component->subsets[subsetindex]; + subsetdata.materialID = uvset; + } + else + { + wi::lua::SError(L, "SetMeshSubsetMaterialID(int subsetindex, Entity materialID) index out of range!"); + } + } + else + { + wi::lua::SError(L, "SetMeshSubsetMaterialID(int subsetindex, Entity materialID) not enough arguments!"); + } + + return 0; +} +int MeshComponent_BindLua::GetMeshSubsetMaterialID(lua_State* L) +{ + int argc = wi::lua::SGetArgCount(L); + if (argc > 0) + { + size_t subsetindex = wi::lua::SGetLongLong(L, 1); + + if(subsetindex < component->subsets.size()) + { + auto& subsetdata = component->subsets[subsetindex]; + wi::lua::SSetLongLong(L, subsetdata.materialID); + return 1; + } + else + { + wi::lua::SError(L, "GetMeshSubsetMaterialID(int subsetindex) index out of range!"); + } + } + else + { + wi::lua::SError(L, "GetMeshSubsetMaterialID(int subsetindex) not enough arguments!"); + } + return 0; +} @@ -2592,6 +2920,15 @@ Luna::FunctionType EmitterComponent_BindLua::methods[] { NULL, NULL } }; Luna::PropertyType EmitterComponent_BindLua::properties[] = { + lunaproperty(EmitterComponent_BindLua, _flags), + + lunaproperty(EmitterComponent_BindLua, ShaderType), + + lunaproperty(EmitterComponent_BindLua, Mass), + lunaproperty(EmitterComponent_BindLua, Velocity), + lunaproperty(EmitterComponent_BindLua, Gravity), + lunaproperty(EmitterComponent_BindLua, Drag), + lunaproperty(EmitterComponent_BindLua, Restitution), lunaproperty(EmitterComponent_BindLua, EmitCount), lunaproperty(EmitterComponent_BindLua, Size), lunaproperty(EmitterComponent_BindLua, Life), @@ -2602,6 +2939,17 @@ Luna::PropertyType EmitterComponent_BindLua::propertie lunaproperty(EmitterComponent_BindLua, ScaleY), lunaproperty(EmitterComponent_BindLua, Rotation), lunaproperty(EmitterComponent_BindLua, MotionBlurAmount), + + lunaproperty(EmitterComponent_BindLua, SPH_h), + lunaproperty(EmitterComponent_BindLua, SPH_K), + lunaproperty(EmitterComponent_BindLua, SPH_p0), + lunaproperty(EmitterComponent_BindLua, SPH_e), + + lunaproperty(EmitterComponent_BindLua, SpriteSheet_Frames_X), + lunaproperty(EmitterComponent_BindLua, SpriteSheet_Frames_Y), + lunaproperty(EmitterComponent_BindLua, SpriteSheet_Frame_Count), + lunaproperty(EmitterComponent_BindLua, SpriteSheet_Frame_Start), + lunaproperty(EmitterComponent_BindLua, SpriteSheet_Framerate), { NULL, NULL } }; @@ -2609,6 +2957,7 @@ EmitterComponent_BindLua::EmitterComponent_BindLua(lua_State *L) { owning = true; component = new wi::EmittedParticleSystem; + BuildBindings(); } EmitterComponent_BindLua::~EmitterComponent_BindLua() { @@ -2832,6 +3181,52 @@ int EmitterComponent_BindLua::SetMotionBlurAmount(lua_State* L) +const char HairParticleSystem_BindLua::className[] = "HairParticleSystem"; + +Luna::FunctionType HairParticleSystem_BindLua::methods[] = { + { NULL, NULL } +}; +Luna::PropertyType HairParticleSystem_BindLua::properties[] = { + lunaproperty(HairParticleSystem_BindLua, _flags), + + lunaproperty(HairParticleSystem_BindLua, StrandCount), + lunaproperty(HairParticleSystem_BindLua, SegmentCount), + lunaproperty(HairParticleSystem_BindLua, RandomSeed), + lunaproperty(HairParticleSystem_BindLua, Length), + lunaproperty(HairParticleSystem_BindLua, Stiffness), + lunaproperty(HairParticleSystem_BindLua, Randomness), + lunaproperty(HairParticleSystem_BindLua, ViewDistance), + + lunaproperty(HairParticleSystem_BindLua, SpriteSheet_Frames_X), + lunaproperty(HairParticleSystem_BindLua, SpriteSheet_Frames_Y), + lunaproperty(HairParticleSystem_BindLua, SpriteSheet_Frame_Count), + lunaproperty(HairParticleSystem_BindLua, SpriteSheet_Frame_Start), + { NULL, NULL } +}; + +HairParticleSystem_BindLua::HairParticleSystem_BindLua(lua_State *L) +{ + owning = true; + component = new wi::HairParticleSystem; + BuildBindings(); +} +HairParticleSystem_BindLua::~HairParticleSystem_BindLua() +{ + if (owning) + { + delete component; + } +} + + + + + + + + + + const char LightComponent_BindLua::className[] = "LightComponent"; Luna::FunctionType LightComponent_BindLua::methods[] = { @@ -3428,6 +3823,13 @@ Luna::FunctionType SpringComponent_BindLua::methods[] = { NULL, NULL } }; Luna::PropertyType SpringComponent_BindLua::properties[] = { + lunaproperty(SpringComponent_BindLua, Stiffness), + lunaproperty(SpringComponent_BindLua, Damping), + lunaproperty(SpringComponent_BindLua, WindAffection), + lunaproperty(SpringComponent_BindLua, DragForce), + lunaproperty(SpringComponent_BindLua, HitRadius), + lunaproperty(SpringComponent_BindLua, GravityPower), + lunaproperty(SpringComponent_BindLua, GravityDirection), { NULL, NULL } }; @@ -3435,6 +3837,7 @@ SpringComponent_BindLua::SpringComponent_BindLua(lua_State* L) { owning = true; component = new SpringComponent; + BuildBindings(); } SpringComponent_BindLua::~SpringComponent_BindLua() { @@ -3444,6 +3847,11 @@ SpringComponent_BindLua::~SpringComponent_BindLua() } } +int SpringComponent_BindLua::GetStiffness(lua_State *L) +{ + wi::lua::SSetFloat(L, component->stiffnessForce); + return 1; +} int SpringComponent_BindLua::SetStiffness(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -3458,6 +3866,11 @@ int SpringComponent_BindLua::SetStiffness(lua_State* L) } return 0; } +int SpringComponent_BindLua::GetDamping(lua_State *L) +{ + wi::lua::SSetFloat(L, component->dragForce); + return 1; +} int SpringComponent_BindLua::SetDamping(lua_State* L) { int argc = wi::lua::SGetArgCount(L); @@ -3486,6 +3899,11 @@ int SpringComponent_BindLua::SetWindAffection(lua_State* L) } return 0; } +int SpringComponent_BindLua::GetWindAffection(lua_State* L) +{ + wi::lua::SSetFloat(L, component->windForce); + return 0; +} diff --git a/WickedEngine/wiScene_BindLua.h b/WickedEngine/wiScene_BindLua.h index 2310b4f2b..0c541ff8a 100644 --- a/WickedEngine/wiScene_BindLua.h +++ b/WickedEngine/wiScene_BindLua.h @@ -46,6 +46,8 @@ namespace wi::lua::scene int Component_CreateName(lua_State* L); int Component_CreateLayer(lua_State* L); int Component_CreateTransform(lua_State* L); + int Component_CreateEmitter(lua_State* L); + int Component_CreateHairParticleSystem(lua_State* L); int Component_CreateLight(lua_State* L); int Component_CreateObject(lua_State* L); int Component_CreateMaterial(lua_State* L); @@ -65,7 +67,9 @@ namespace wi::lua::scene int Component_GetCamera(lua_State* L); int Component_GetAnimation(lua_State* L); int Component_GetMaterial(lua_State* L); + int Component_GetMesh(lua_State* L); int Component_GetEmitter(lua_State* L); + int Component_GetHairParticleSystem(lua_State* L); int Component_GetLight(lua_State* L); int Component_GetObject(lua_State* L); int Component_GetInverseKinematics(lua_State* L); @@ -84,7 +88,9 @@ namespace wi::lua::scene int Component_GetCameraArray(lua_State* L); int Component_GetAnimationArray(lua_State* L); int Component_GetMaterialArray(lua_State* L); + int Component_GetMeshArray(lua_State* L); int Component_GetEmitterArray(lua_State* L); + int Component_GetHairParticleSystemArray(lua_State* L); int Component_GetLightArray(lua_State* L); int Component_GetObjectArray(lua_State* L); int Component_GetInverseKinematicsArray(lua_State* L); @@ -103,7 +109,9 @@ namespace wi::lua::scene int Entity_GetCameraArray(lua_State* L); int Entity_GetAnimationArray(lua_State* L); int Entity_GetMaterialArray(lua_State* L); + int Entity_GetMeshArray(lua_State* L); int Entity_GetEmitterArray(lua_State* L); + int Entity_GetHairParticleSystemArray(lua_State* L); int Entity_GetLightArray(lua_State* L); int Entity_GetObjectArray(lua_State* L); int Entity_GetInverseKinematicsArray(lua_State* L); @@ -285,6 +293,7 @@ namespace wi::lua::scene inline void BuildBindings() { + _flags = LongLongProperty(reinterpret_cast(&component->_flags)); ShaderType = IntProperty(reinterpret_cast(&component->shaderType)); UserBlendMode = IntProperty(reinterpret_cast(&component->roughness)); SpecularColor = VectorProperty(&component->specularColor); @@ -314,6 +323,7 @@ namespace wi::lua::scene MaterialComponent_BindLua(lua_State *L); ~MaterialComponent_BindLua(); + LongLongProperty _flags; IntProperty ShaderType; IntProperty UserBlendMode; VectorProperty SpecularColor; @@ -338,6 +348,7 @@ namespace wi::lua::scene FloatProperty texAnimElapsedTime; IntProperty customShaderID; + PropertyFunction(_flags) PropertyFunction(ShaderType) PropertyFunction(UserBlendMode) PropertyFunction(SpecularColor) @@ -371,6 +382,47 @@ namespace wi::lua::scene int SetUserStencilRef(lua_State* L); int GetUserStencilRef(lua_State* L); int GetStencilRef(lua_State* L); + + int SetTexture(lua_State* L); + int SetTextureUVSet(lua_State* L); + int GetTexture(lua_State* L); + int GetTextureUVSet(lua_State* L); + }; + + class MeshComponent_BindLua + { + public: + bool owning = false; + wi::scene::MeshComponent* component = nullptr; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + inline void BuildBindings() + { + _flags = LongLongProperty(reinterpret_cast(&component->_flags)); + TessellationFactor = FloatProperty(&component->tessellationFactor); + ArmatureID = LongLongProperty(reinterpret_cast(&component->armatureID)); + SubsetsPerLOD = LongLongProperty(reinterpret_cast(&component->subsets_per_lod)); + } + + MeshComponent_BindLua(wi::scene::MeshComponent* component) :component(component) { BuildBindings(); } + MeshComponent_BindLua(lua_State *L); + ~MeshComponent_BindLua(); + + LongLongProperty _flags; + FloatProperty TessellationFactor; + LongLongProperty ArmatureID; + LongLongProperty SubsetsPerLOD; + + PropertyFunction(_flags) + PropertyFunction(TessellationFactor) + PropertyFunction(ArmatureID) + PropertyFunction(SubsetsPerLOD) + + int SetMeshSubsetMaterialID(lua_State* L); + int GetMeshSubsetMaterialID(lua_State* L); }; class EmitterComponent_BindLua @@ -383,10 +435,76 @@ namespace wi::lua::scene static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; - EmitterComponent_BindLua(wi::EmittedParticleSystem* component) :component(component) {} + inline void BuildBindings() + { + _flags = LongLongProperty(reinterpret_cast(&component->_flags)); + + ShaderType = IntProperty(reinterpret_cast(&component->shaderType)); + + Mass = FloatProperty(&component->mass); + Velocity = VectorProperty(&component->velocity); + Gravity = VectorProperty(&component->gravity); + Drag = FloatProperty(&component->drag); + Restitution = FloatProperty(&component->restitution); + + SPH_h = FloatProperty(&component->SPH_h); + SPH_K = FloatProperty(&component->SPH_K); + SPH_p0 = FloatProperty(&component->SPH_p0); + SPH_e = FloatProperty(&component->SPH_e); + + SpriteSheet_Frames_X = LongLongProperty(reinterpret_cast(&component->framesX)); + SpriteSheet_Frames_Y = LongLongProperty(reinterpret_cast(&component->framesY)); + SpriteSheet_Frame_Count = LongLongProperty(reinterpret_cast(&component->frameCount)); + SpriteSheet_Frame_Start = LongLongProperty(reinterpret_cast(&component->frameStart)); + SpriteSheet_Framerate = FloatProperty(&component->frameRate); + } + + EmitterComponent_BindLua(wi::EmittedParticleSystem* component) :component(component) { BuildBindings(); } EmitterComponent_BindLua(lua_State *L); ~EmitterComponent_BindLua(); + LongLongProperty _flags; + + IntProperty ShaderType; + + FloatProperty Mass; + VectorProperty Velocity; + VectorProperty Gravity; + FloatProperty Drag; + FloatProperty Restitution; + + FloatProperty SPH_h; + FloatProperty SPH_K; + FloatProperty SPH_p0; + FloatProperty SPH_e; + + LongLongProperty SpriteSheet_Frames_X; + LongLongProperty SpriteSheet_Frames_Y; + LongLongProperty SpriteSheet_Frame_Count; + LongLongProperty SpriteSheet_Frame_Start; + FloatProperty SpriteSheet_Framerate; + + PropertyFunction(_flags) + + PropertyFunction(ShaderType) + + PropertyFunction(Mass) + PropertyFunction(Velocity) + PropertyFunction(Gravity) + PropertyFunction(Drag) + PropertyFunction(Restitution) + + PropertyFunction(SPH_h) + PropertyFunction(SPH_K) + PropertyFunction(SPH_p0) + PropertyFunction(SPH_e) + + PropertyFunction(SpriteSheet_Frames_X) + PropertyFunction(SpriteSheet_Frames_Y) + PropertyFunction(SpriteSheet_Frame_Count) + PropertyFunction(SpriteSheet_Frame_Start) + PropertyFunction(SpriteSheet_Framerate) + int Burst(lua_State* L); int SetEmitCount(lua_State* L); int SetSize(lua_State* L); @@ -411,6 +529,69 @@ namespace wi::lua::scene int GetMotionBlurAmount(lua_State* L); }; + class HairParticleSystem_BindLua + { + public: + bool owning = false; + HairParticleSystem* component = nullptr; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + inline void BuildBindings() + { + _flags = LongLongProperty(reinterpret_cast(&component->_flags)); + + StrandCount = LongLongProperty(reinterpret_cast(&component->strandCount)); + SegmentCount = LongLongProperty(reinterpret_cast(&component->segmentCount)); + RandomSeed = LongLongProperty(reinterpret_cast(&component->randomSeed)); + Length = FloatProperty(&component->length); + Stiffness = FloatProperty(&component->stiffness); + Randomness = FloatProperty(&component->randomness); + ViewDistance = FloatProperty(&component->viewDistance); + + SpriteSheet_Frames_X = LongLongProperty(reinterpret_cast(&component->framesX)); + SpriteSheet_Frames_Y = LongLongProperty(reinterpret_cast(&component->framesY)); + SpriteSheet_Frame_Count = LongLongProperty(reinterpret_cast(&component->frameCount)); + SpriteSheet_Frame_Start = LongLongProperty(reinterpret_cast(&component->frameStart)); + } + + HairParticleSystem_BindLua(HairParticleSystem* component) :component(component) { BuildBindings(); } + HairParticleSystem_BindLua(lua_State *L); + ~HairParticleSystem_BindLua(); + + LongLongProperty _flags; + + LongLongProperty StrandCount; + LongLongProperty SegmentCount; + LongLongProperty RandomSeed; + FloatProperty Length; + FloatProperty Stiffness; + FloatProperty Randomness; + FloatProperty ViewDistance; + + LongLongProperty SpriteSheet_Frames_X; + LongLongProperty SpriteSheet_Frames_Y; + LongLongProperty SpriteSheet_Frame_Count; + LongLongProperty SpriteSheet_Frame_Start; + + PropertyFunction(_flags) + + PropertyFunction(StrandCount) + PropertyFunction(SegmentCount) + PropertyFunction(RandomSeed) + PropertyFunction(Length) + PropertyFunction(Stiffness) + PropertyFunction(Randomness) + PropertyFunction(ViewDistance) + + PropertyFunction(SpriteSheet_Frames_X) + PropertyFunction(SpriteSheet_Frames_Y) + PropertyFunction(SpriteSheet_Frame_Count) + PropertyFunction(SpriteSheet_Frame_Start) + }; + class LightComponent_BindLua { public: @@ -517,13 +698,34 @@ namespace wi::lua::scene static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; - SpringComponent_BindLua(wi::scene::SpringComponent* component) :component(component) {} + inline void BuildBindings() + { + DragForce = FloatProperty(&component->dragForce); + HitRadius = FloatProperty(&component->hitRadius); + GravityPower = FloatProperty(&component->gravityPower); + GravityDirection = VectorProperty(&component->gravityDir); + } + + SpringComponent_BindLua(wi::scene::SpringComponent* component) :component(component) { BuildBindings(); } SpringComponent_BindLua(lua_State* L); ~SpringComponent_BindLua(); + FloatProperty DragForce; + FloatProperty HitRadius; + FloatProperty GravityPower; + VectorProperty GravityDirection; + + PropertyFunction(DragForce) + PropertyFunction(HitRadius) + PropertyFunction(GravityPower) + PropertyFunction(GravityDirection) + int SetStiffness(lua_State* L); int SetDamping(lua_State* L); int SetWindAffection(lua_State* L); + int GetStiffness(lua_State* L); + int GetDamping(lua_State* L); + int GetWindAffection(lua_State* L); }; class ScriptComponent_BindLua @@ -986,6 +1188,10 @@ namespace wi::lua::scene OceanParameters = Weather_OceanParams_Property(&component->oceanParameters); AtmosphereParameters = Weather_AtmosphereParams_Property(&component->atmosphereParameters); VolumetricCloudParameters = Weather_VolumetricCloudParams_Property(&component->volumetricCloudParameters); + + skyMapName = StringProperty(&component->skyMapName); + colorGradingMapName = StringProperty(&component->colorGradingMapName); + volumetricCloudsWeatherMapName = StringProperty(&component->volumetricCloudsWeatherMapName); } WeatherComponent_BindLua(wi::scene::WeatherComponent* component) :component(component) { BuildBindings(); } @@ -1046,6 +1252,14 @@ namespace wi::lua::scene PropertyFunction(AtmosphereParameters) PropertyFunction(VolumetricCloudParameters) + StringProperty skyMapName; + StringProperty colorGradingMapName; + StringProperty volumetricCloudsWeatherMapName; + + PropertyFunction(skyMapName) + PropertyFunction(colorGradingMapName) + PropertyFunction(volumetricCloudsWeatherMapName) + int IsOceanEnabled(lua_State* L); int IsSimpleSky(lua_State* L); int IsRealisticSky(lua_State* L);