groverburger's 3D engine (g3d) simplifies LÖVE's 3d capabilities to be as simple as possible.
- 3D Model rendering
- .obj file loading
- Basic first person movement and camera controls
- Perspective and orthographic projections
- Simple, commented, and organized
Add the g3d
subfolder folder to your project, and require it in main.lua
.
The entire main.lua
file for the demo shown is under 30 lines, as shown here:
-- written by groverbuger for g3d
-- october 2020
-- MIT license
require "g3d"
function love.load()
Earth = Model:new("assets/sphere.obj", "assets/earth.png", {0,0,4}, nil, {-1,1,1})
Moon = Model:new("assets/sphere.obj", "assets/moon.png", {5,0,4}, nil, {-0.5,0.5,0.5})
Background = Model:new("assets/sphere.obj", "assets/starfield.png", {0,0,0}, nil, {500,500,500})
Timer = 0
end
function love.mousemoved(x,y, dx,dy)
FirstPersonCameraLook(dx,dy)
end
function love.update(dt)
Timer = Timer + dt
Moon:setTranslation(math.cos(Timer)*5, 0, math.sin(Timer)*5 +4)
Moon:setRotation(0,-1*Timer,0)
FirstPersonCameraMovement(dt)
end
function love.draw()
Earth:draw()
Moon:draw()
Background:draw()
end
- Create
Model
s withModel:new(obj, texture)
passing in a path to a .obj file and a LÖVE image file - Translate and rotate the
Model
withModel:setTranslation(x,y,z)
andModel:setRotation(x,y,z)
- Move and rotate the
Camera
withSetCamera(x,y,z, direction,pitch)
orSetCameraAndLookAt(x,y,z, xAt,yAt,zAt)
- Use basic first person movement with
FirstPersonCameraMovement(dt)
andFirstPersonCameraLook(dx,dy)
For more information, check out the model.lua
and camera.lua
files.
Please use the CPML library or refer to 3DreamEngine for their 3D collision code. Mozilla also has a nice article on basic 3D collision detection. g3d no longer offers collision detection, instead focusing only on making 3D rendering as simple as possible.