Löve 3D

Löve3D engine (forked from g3d) simplifies LÖVE's 2D capabilities for 3D games to be as simple to use as possible. We recommend to use Blender (open source software ) to build the 3D models for using inside Löve3D games.


Löve3D has full interoperability with Löve2D source code. You can add pieces of code from Löve2D into Löve3D with no working problems.

Camera movimentation keys: W,A,S,D, Left Shift, Left Control, Space bar and ESC to quit.

Free Lua courses on YouTube

Free Löve2D courses on YouTube

Download



Basic Löve3D program

These are the basics, see more about gamestates and conf.lua file.
You can also see the Löve2D's keycodes table.

love3d = require 'love3d'

function love3d.load()
      ...
end
function love3d.mousemoved(x,y, dx,dy)
      ...
end
function love3d.update(dt)
      ...
end
function love3d.draw()
      ...
end


Getting current screen dimensions

It returns current display/screen dimensions: width (x) and height (y).

local screen_width = love3d.display.width
local screen_height = love3d.display.height


Creating a Timer

It creates a timer passsing dt argument from love3d.update(dt) as average speed in physics: V = Δs/Δt

local MyTimer = 0
MyTimer = love3d.engine.newTimer(MyTimer,dt)


Example

love3d = require 'love3d'
local MyTimer = 0


function love3d.load()

      ...
end

function love3d.mousemoved(x,y, dx,dy)

      ...
end

function love3d.update(dt)
      ...
      MyTimer = love3d.engine.newTimer(MyTimer,dt)
end

function love3d.draw()

      ...
end


Creating Entities

Create new entity (object) in the world, it should be modeled in an external software, such as, Blender.

local moon = love3d.newModel(BlenderFile, PngFile, WorldCoordinates, Rotation, EntityScale)

moon:draw()


Example I

local moon = love3d.newModel("assets/sphere.obj", "assets/moon.png", {5,0,4}, nil, {1,1,1})

moon:draw()




Example II

love3d = require 'love3d'
local MyTimer = 0
local moon = love3d.newModel("assets/sphere.obj", "assets/moon.png", {5,0,4}, nil, {1,1,1})


function love3d.load()

end

function love3d.mousemoved(x,y, dx,dy)

end

function love3d.update(dt)
      MyTimer = love3d.engine.newTimer(MyTimer,dt)

      ...
end

function love3d.draw()
      moon:draw()
end





Set entity translation

Set created entity translation in the world

moon:setTranslation(x,y,z)



Set entity rotation

Set entity's rotation at its own axis (using Euler angles)

moon:setEulerRotation(x,y,z)


Set entity's rotation at its own axis (using degrees)

moon:setDegreeRotation(x,y,z)


Set entity's rotation at its own axis (using Quartenions)

moon:setQuaternionRotation(x,y,z,w)


Set entity scale in the world

This is the size of the modeled object in the world at axes: {x,y,z}

moon:setScale(x,y,z)


Set entity upside down in the world

Set the modeled object upside down or not in the world: true (upside down) or false (normal).

moon:upsideDown(isUpsideDown)


Examples:

moon:upsideDown(true)

moon:upsideDown(false)


Set entities collision field

Detect camera collision into an entity or the entity's collision into another entity, using a 3D implementation of AABB formula.

Parameters (they can be numbers or variables):

Inspect tables

Returns the inspected table name.

local MyTable = {0,5,0}
local inspected_table = love3d.inspect.table(MyTable)



1. You can print the inspected table on the console.

print(inspected_table)



2. Or you can also display on the game screen.

love.graphics.print(inspected_table,10,20)




Spectator Camera

1. Get camera position in the world, returns a three value table

local camera_position = love3d.camera.position


2. The point where your camera is looking in the world, returns a three value table.

local looking_world = love3d.camera.target


3. Which way up is, returns a three value table, this is used for matrix math calculations.

local looking_up = love3d.camera.up


Sets the camera at a position, looking towards the target point.



The x coordinate of the position where the camera look:

xAt

The y coordinate of the position where the camera look:

yAt

The z coordinate of the position where the camera look:

zAt

love3d.camera.lookAt(x, y, z, xAt, yAt, zAt)




Example

Setting the camera coordinates to:

x=10, y=0, z=10
And camera looking at coordinates to:
x=10, y=0, z=10

love3d.camera.lookAt(10,0,40, 10,0,40)





Licensed under BSD 2-clause license
Forked from g3d by Gabriel Margarido