Hello everyone!
I'm not a very frequent member, but I try to keep up with things.
Anyhow, I have been working for the last few days to create a 3d engine for Love2d!
Description:
This is a REAL 3d library. It's not pseudo. Objects can be rotated in every single way and .obj files can be loaded and displayed. The engine is very basic and minimal at the moment, but if you want to download it and add some functions in, go for it!
The engine is very basic so far and definitely far from finished, but I thought I would show some of it's functions.
Here's a list of functions:
There is functions that are only used by the library, namely "to2d()" and "toinds()" which are used to convert a 3d vertex to a 2d vertex and convert an array of faces to indices, respectively.-nil L3DSetup(Width, Height, FOV)
To be run when L3D is first started.
Define the screen width, height and field of view here.
-Vertices, Indices, Material L3DLoadObj(Path to Object)
Loads a .obj wavefront file and returns three arrays, Vertices, indices and material
-nil L3DSetClipping(Min X, Max X, Min Y, Max Y)
Set's the clipping to these arguments
-nil L3DLoadIdentity()
Resets the pointer to the origin (0, 0, 0)
Resets all rotations (Won't effect already drawn objects)
-nil L3DTranslate(Position X, Position Y, Position Z)
Moves the Pointer (Objects are drawn at the pointer)
-nil L3DRotate(Rotation X, Rotation Y, Rotation Z)
Rotates an object prior to drawing it.
-nil L3DDraw(Vertice Array, Indice Array, [Material])
Draws a element to the screen at the current pointer
position with the current rotation
The library is attached and here is an example script:
Code: Select all
--Load our Library :)
local L3D = require('/libs/L3D/l3d')
--Some tables to store our model in
Verts = {}
Indcs = {}
Mat = {}
--The Rotation is stored here
rot_y = 0
function love.load()
--Let's set the mode (Mainly so I know how big the screen is
love.graphics.setMode(640, 480, false, true, 0)
--Set the screen width, height and field of view
L3DSetup(640, 480, 256)
--Load an object into the tables Verts, Indcs and Mat (Vertices, Indices, and material)
Verts, Indcs, Mat = L3DLoadObj("Road.obj")
end
function love.update(dt)
--Let's see the FPS
love.graphics.setCaption("FPS: " .. tostring(love.timer.getFPS()))
end
function love.draw()
--Reset Rotations and Translations
L3DLoadIdentity()
--Rotate the Y axis by rot_y
L3DRotate(rot_y, 0, 0)
--Translate on the Z axis by 20 units
L3DTranslate(0, 0, 20)
--Draw the .obj we loaded
L3DDraw(Verts, Indcs, Mat, L3DDiffuse)
--This will get how many materials are loaded
love.graphics.print(#Mat .. " Materials", 0, 0)
--This will show the names of all the materials that are loaded
for a = 1, #Mat do
love.graphics.print(Mat[a].ID, 0, a * 12)
end
rot_y = rot_y + 0.01
end
http://sience.schattenkind.net/love2d/l3d/
Thank you to SiENCe
Tell me what you think and if you'd like to analyze the code and suggest optimizations, I would be grateful!
Things you should NOT suggest:
• Adding texture and material support for OBJ loader.
• Frustum Culling
• Fog support
• Lookat function (There never will be one unless someone else wants to do it)
• Lighting support (Unless you want to help me with this one )
What I plan to do before I quit (In order of priority):
• Error handling
•
•
• Fog Support
• Lighting
For kicks and giggles, I rendered 100 cubes (Each contains 8 vertices and 6 faces (quads), so 800 faces) with an average fps of about 10. That translates to around 50-60 on a normal computer (Mine has the worst video card....).
Here's the Library: This is an example demonstrating that color's are being successfully set (:D )
This is showing a whole bunch of cubes falling from the heavons