feat(physics): Enhance physics bridge service with new functionalities

- Added SetGravity method to adjust the gravity in the physics world.
- Introduced AddSphereRigidBody method for creating sphere rigid bodies.
- Implemented RemoveRigidBody method to delete existing rigid bodies.
- Added SetRigidBodyTransform method to update the position and rotation of rigid bodies.
- Included ApplyForce and ApplyImpulse methods for applying forces and impulses to rigid bodies.
- Added SetLinearVelocity method to set the linear velocity of rigid bodies.
- Enhanced StepSimulation method to accept a maxSubSteps parameter.
- Implemented GetBodyCount method to retrieve the number of rigid bodies in the world.
- Added Clear method to remove all rigid bodies from the physics world.
- Updated the script engine service to bind new physics methods to Lua.
- Enhanced material configuration handling in shader script service.
- Introduced MaterialXMaterialConfig structure for better material management.
- Added texture binding support in ShaderPaths structure.
- Included stb_image implementation for image loading support.
This commit is contained in:
2026-01-07 00:20:19 +00:00
parent ffeba6c142
commit cb5b58ca9e
42 changed files with 3168 additions and 226 deletions

View File

@@ -1,5 +1,22 @@
local math3d = {}
local function require_glm(name)
local fn = _G[name]
if type(fn) ~= "function" then
error("math3d requires missing binding: " .. name)
end
return fn
end
local glm_identity = require_glm("glm_matrix_identity")
local glm_multiply = require_glm("glm_matrix_multiply")
local glm_translation = require_glm("glm_matrix_translation")
local glm_rotation_x = require_glm("glm_matrix_rotation_x")
local glm_rotation_y = require_glm("glm_matrix_rotation_y")
local glm_from_transform = require_glm("glm_matrix_from_transform")
local glm_look_at = require_glm("glm_matrix_look_at")
local glm_perspective = require_glm("glm_matrix_perspective")
local function normalize(vec)
local x, y, z = vec[1], vec[2], vec[3]
local len = math.sqrt(x * x + y * y + z * z)
@@ -31,89 +48,35 @@ local function identity_matrix()
end
function math3d.identity()
return identity_matrix()
return glm_identity()
end
function math3d.multiply(a, b)
local result = {}
for row = 1, 4 do
for col = 1, 4 do
local sum = 0.0
for idx = 1, 4 do
sum = sum + a[(idx - 1) * 4 + row] * b[(col - 1) * 4 + idx]
end
result[(col - 1) * 4 + row] = sum
end
end
return result
return glm_multiply(a, b)
end
function math3d.translation(x, y, z)
return {
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
x, y, z, 1.0,
}
return glm_translation(x, y, z)
end
function math3d.rotation_x(radians)
local c = math.cos(radians)
local s = math.sin(radians)
return {
1.0, 0.0, 0.0, 0.0,
0.0, c, s, 0.0,
0.0, -s, c, 0.0,
0.0, 0.0, 0.0, 1.0,
}
return glm_rotation_x(radians)
end
function math3d.rotation_y(radians)
local c = math.cos(radians)
local s = math.sin(radians)
return {
c, 0.0, -s, 0.0,
0.0, 1.0, 0.0, 0.0,
s, 0.0, c, 0.0,
0.0, 0.0, 0.0, 1.0,
}
return glm_rotation_y(radians)
end
function math3d.from_transform(translation, rotation)
return glm_from_transform(translation, rotation)
end
function math3d.look_at(eye, center, up)
local f = normalize({center[1] - eye[1], center[2] - eye[2], center[3] - eye[3]})
local s = normalize(cross(f, up))
local u = cross(s, f)
local result = identity_matrix()
result[1] = s[1]
result[2] = u[1]
result[3] = -f[1]
result[5] = s[2]
result[6] = u[2]
result[7] = -f[2]
result[9] = s[3]
result[10] = u[3]
result[11] = -f[3]
result[13] = -dot(s, eye)
result[14] = -dot(u, eye)
result[15] = dot(f, eye)
return result
return glm_look_at(eye, center, up)
end
function math3d.perspective(fov, aspect, zNear, zFar)
local tanHalf = math.tan(fov / 2.0)
local result = {
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
}
result[1] = 1.0 / (aspect * tanHalf)
result[6] = -1.0 / tanHalf
result[11] = zFar / (zNear - zFar)
result[12] = -1.0
result[15] = (zNear * zFar) / (zNear - zFar)
return result
return glm_perspective(fov, aspect, zNear, zFar)
end
return math3d