scripting updates and new sample scripts
This commit is contained in:
@@ -429,6 +429,7 @@ The scene holds components. Entity handles can be used to retrieve associated co
|
||||
- Clear() -- deletes every entity and component inside the scene
|
||||
- Merge(Scene other) -- moves contents from an other scene into this one. The other scene will be empty after this operation (contents are moved, not copied)
|
||||
|
||||
- CreateEntity() : int entity -- creates an empty entity and returns it
|
||||
- Entity_FindByName(string value) : int entity -- returns an entity ID if it exists, and 0 otherwise
|
||||
- Entity_Remove(Entity entity) -- removes an entity and deletes all its components if it exists
|
||||
- Entity_Duplicate(Entity entity) : int entity -- duplicates all of an entity's components and creates a new entity with them. Returns the clone entity handle
|
||||
@@ -527,6 +528,9 @@ Describes an orientation in 3D space.
|
||||
- GetInvView() : Matrix result
|
||||
- GetInvProjection() : Matrix result
|
||||
- GetInvViewProjection() : Matrix result
|
||||
- GetPosition() : Vector result
|
||||
- GetLookDirection() : Vector result
|
||||
- GetUpDirection() : Vector result
|
||||
|
||||
#### AnimationComponent
|
||||
- Play()
|
||||
@@ -565,9 +569,11 @@ Describes an orientation in 3D space.
|
||||
- [outer]DIRECTIONAL : int
|
||||
- [outer]POINT : int
|
||||
- [outer]SPOT : int
|
||||
- SetRange(float value)
|
||||
- SetEnergy(float value)
|
||||
- SetColor(Vector value)
|
||||
- SetCastShadow(bool value)
|
||||
- SetFOV(float value)
|
||||
- GetType() : int result
|
||||
|
||||
#### ObjectComponent
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
-- This script will add a point light fixed to camera
|
||||
|
||||
backlog_post("---> START SCRIPT: camera_pointlight.lua")
|
||||
|
||||
scene = GetScene()
|
||||
|
||||
runProcess(function()
|
||||
|
||||
local light_entity = CreateEntity()
|
||||
scene.Component_CreateLight(light_entity)
|
||||
|
||||
local light = scene.Component_GetLight(light_entity)
|
||||
light.SetType(POINT)
|
||||
light.SetRange(20)
|
||||
light.SetEnergy(4)
|
||||
light.SetColor(Vector(1,0.9,0.8))
|
||||
|
||||
scene.Component_CreateTransform(light_entity)
|
||||
|
||||
while true do
|
||||
|
||||
local camera = GetCamera()
|
||||
local campos = camera.GetPosition()
|
||||
local transform = scene.Component_GetTransform(light_entity)
|
||||
if transform == nil then
|
||||
backlog_post("light no longer exists, exiting script")
|
||||
return
|
||||
else
|
||||
transform.ClearTransform()
|
||||
transform.Translate(campos)
|
||||
end
|
||||
|
||||
update()
|
||||
end
|
||||
end)
|
||||
|
||||
backlog_post("---> END SCRIPT: camera_pointlight.lua")
|
||||
@@ -0,0 +1,42 @@
|
||||
-- This script will add a spot light fixed to camera
|
||||
|
||||
backlog_post("---> START SCRIPT: camera_spotlight.lua")
|
||||
|
||||
scene = GetScene()
|
||||
|
||||
runProcess(function()
|
||||
|
||||
local light_entity = CreateEntity()
|
||||
scene.Component_CreateLight(light_entity)
|
||||
|
||||
local light = scene.Component_GetLight(light_entity)
|
||||
light.SetType(SPOT)
|
||||
light.SetRange(100)
|
||||
light.SetEnergy(8)
|
||||
light.SetFOV(math.pi / 3.0)
|
||||
light.SetColor(Vector(1,0.7,0.8))
|
||||
|
||||
scene.Component_CreateTransform(light_entity)
|
||||
|
||||
while true do
|
||||
|
||||
local camera = GetCamera()
|
||||
local campos = camera.GetPosition()
|
||||
local camlook = camera.GetLookDirection()
|
||||
local camup = camera.GetUpDirection()
|
||||
local transform = scene.Component_GetTransform(light_entity)
|
||||
if transform == nil then
|
||||
backlog_post("light no longer exists, exiting script")
|
||||
return
|
||||
else
|
||||
transform.ClearTransform()
|
||||
transform.Rotate(Vector(-math.pi / 2.0, 0, 0)) -- spot light was facing downwards by default, rotate it to face +Z like camera default
|
||||
--transform.MatrixTransform(camera.GetInvView())
|
||||
transform.MatrixTransform(matrix.Inverse(matrix.LookTo(campos, camlook, camup))) -- This is similar to camera.GetInvView()
|
||||
end
|
||||
|
||||
update()
|
||||
end
|
||||
end)
|
||||
|
||||
backlog_post("---> END SCRIPT: camera_spotlight.lua")
|
||||
@@ -1487,6 +1487,9 @@ Luna<CameraComponent_BindLua>::FunctionType CameraComponent_BindLua::methods[] =
|
||||
lunamethod(CameraComponent_BindLua, GetInvView),
|
||||
lunamethod(CameraComponent_BindLua, GetInvProjection),
|
||||
lunamethod(CameraComponent_BindLua, GetInvViewProjection),
|
||||
lunamethod(CameraComponent_BindLua, GetPosition),
|
||||
lunamethod(CameraComponent_BindLua, GetLookDirection),
|
||||
lunamethod(CameraComponent_BindLua, GetUpDirection),
|
||||
{ NULL, NULL }
|
||||
};
|
||||
Luna<CameraComponent_BindLua>::PropertyType CameraComponent_BindLua::properties[] = {
|
||||
@@ -1675,6 +1678,21 @@ int CameraComponent_BindLua::GetInvViewProjection(lua_State* L)
|
||||
Luna<Matrix_BindLua>::push(L, new Matrix_BindLua(component->GetInvViewProjection()));
|
||||
return 1;
|
||||
}
|
||||
int CameraComponent_BindLua::GetPosition(lua_State* L)
|
||||
{
|
||||
Luna<Vector_BindLua>::push(L, new Vector_BindLua(component->GetEye()));
|
||||
return 1;
|
||||
}
|
||||
int CameraComponent_BindLua::GetLookDirection(lua_State* L)
|
||||
{
|
||||
Luna<Vector_BindLua>::push(L, new Vector_BindLua(component->GetAt()));
|
||||
return 1;
|
||||
}
|
||||
int CameraComponent_BindLua::GetUpDirection(lua_State* L)
|
||||
{
|
||||
Luna<Vector_BindLua>::push(L, new Vector_BindLua(component->GetUp()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2135,6 +2153,7 @@ Luna<LightComponent_BindLua>::FunctionType LightComponent_BindLua::methods[] = {
|
||||
lunamethod(LightComponent_BindLua, SetColor),
|
||||
lunamethod(LightComponent_BindLua, SetCastShadow),
|
||||
lunamethod(LightComponent_BindLua, GetType),
|
||||
lunamethod(LightComponent_BindLua, SetFOV),
|
||||
{ NULL, NULL }
|
||||
};
|
||||
Luna<LightComponent_BindLua>::PropertyType LightComponent_BindLua::properties[] = {
|
||||
@@ -2235,6 +2254,21 @@ int LightComponent_BindLua::SetCastShadow(lua_State* L)
|
||||
|
||||
return 0;
|
||||
}
|
||||
int LightComponent_BindLua::SetFOV(lua_State* L)
|
||||
{
|
||||
int argc = wi::lua::SGetArgCount(L);
|
||||
if (argc > 0)
|
||||
{
|
||||
float value = wi::lua::SGetFloat(L, 1);
|
||||
component->fov = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
wi::lua::SError(L, "SetFOV(float value) not enough arguments!");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LightComponent_BindLua::GetType(lua_State* L)
|
||||
{
|
||||
|
||||
@@ -179,6 +179,9 @@ namespace wi::lua::scene
|
||||
int GetInvView(lua_State* L);
|
||||
int GetInvProjection(lua_State* L);
|
||||
int GetInvViewProjection(lua_State* L);
|
||||
int GetPosition(lua_State* L);
|
||||
int GetLookDirection(lua_State* L);
|
||||
int GetUpDirection(lua_State* L);
|
||||
};
|
||||
|
||||
class AnimationComponent_BindLua
|
||||
@@ -275,6 +278,7 @@ namespace wi::lua::scene
|
||||
int SetEnergy(lua_State* L);
|
||||
int SetColor(lua_State* L);
|
||||
int SetCastShadow(lua_State* L);
|
||||
int SetFOV(lua_State* L);
|
||||
|
||||
int GetType(lua_State* L);
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wi::version
|
||||
// minor features, major updates, breaking compatibility changes
|
||||
const int minor = 60;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 14;
|
||||
const int revision = 15;
|
||||
|
||||
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user