This commit is contained in:
Mikulas Florek 2023-10-06 20:15:01 +02:00
parent 7d44effd32
commit b1db4d2932
5 changed files with 16 additions and 1 deletions

View File

@ -98,6 +98,7 @@ declare class SweepHit
position : Vec3
normal : Vec3
entity : Entity
distance : number
end
declare class GUISystem

View File

@ -7,6 +7,7 @@
#include "lua_wrapper.h"
#include "plugin.h"
#include "prefab.h"
#include "profiler.h"
#include "reflection.h"
#include "string.h"
#include "world.h"
@ -1005,6 +1006,10 @@ void registerEngineAPI(lua_State* L, Engine* engine)
LuaWrapper::createSystemFunction(L, "LumixReflection", "getStructMemberName", &LuaWrapper::wrap<LUA_getStructMemberName>);
LuaWrapper::createSystemFunction(L, "LumixReflection", "getStructMemberType", &LuaWrapper::wrap<LUA_getStructMemberType>);
LuaWrapper::createSystemFunction(L, "LumixAPI", "beginProfilerBlock", LuaWrapper::wrap<&profiler::endBlock>);
LuaWrapper::createSystemFunction(L, "LumixAPI", "endProfilerBlock", LuaWrapper::wrap<&profiler::beginBlock>);
LuaWrapper::createSystemFunction(L, "LumixAPI", "createProfilerCounter", LuaWrapper::wrap<&profiler::createCounter>);
LuaWrapper::createSystemFunction(L, "LumixAPI", "pushProfilerCounter", LuaWrapper::wrap<&profiler::pushCounter>);
LuaWrapper::createSystemFunction(L, "LumixAPI", "networkRead", &LUA_networkRead);
LuaWrapper::createSystemFunction(L, "LumixAPI", "packU32", &LUA_packU32);
LuaWrapper::createSystemFunction(L, "LumixAPI", "unpackU32", &LUA_unpackU32);
@ -1158,6 +1163,11 @@ void registerEngineAPI(lua_State* L, Engine* engine)
end
end
end
Lumix.Entity.__eq = function(a, b)
return a._entity == b._entity and a._world == b._world
end
Lumix.Entity.__newindex = function(table, key, value)
if key == "position" then
LumixAPI.setEntityPosition(table._world, table._entity, value)

View File

@ -2407,6 +2407,7 @@ struct PhysicsModuleImpl final : PhysicsModule
result.entity = EntityPtr{(int)(intptr_t)hit.block.actor->userData};
result.position = fromPhysx(hit.block.position);
result.normal = fromPhysx(hit.block.normal);
result.distance = hit.block.distance;
return true;
}
@ -3972,6 +3973,7 @@ void PhysicsModule::reflect() {
reflection::structure<SweepHit>("SweepHit")
.member<&SweepHit::position>("position")
.member<&SweepHit::normal>("normal")
.member<&SweepHit::distance>("distance")
.member<&SweepHit::entity>("entity");
LUMIX_MODULE(PhysicsModuleImpl, "physics")

View File

@ -50,6 +50,7 @@ struct SweepHit {
Vec3 position;
Vec3 normal;
EntityPtr entity;
float distance;
};
struct LUMIX_PHYSICS_API PhysicsModule : IModule

View File

@ -2027,8 +2027,9 @@ struct RenderModuleImpl final : RenderModule {
RayCastModelHit hit = module->castRay(origin, dir, INVALID_ENTITY);
LuaWrapper::push(L, hit.is_hit);
LuaWrapper::push(L, hit.is_hit ? hit.origin + hit.dir * hit.t : DVec3(0));
LuaWrapper::pushEntity(L, hit.is_hit ? hit.entity : INVALID_ENTITY, &module->getWorld());
return 2;
return 3;
}