## groverburger's Super Simple 3D Engine

groverburger
Prole
Posts: 5
Joined: Tue Oct 30, 2018 9:27 pm

### groverburger's Super Simple 3D Engine

Hello everyone!
groverburger's Super Simple 3D Engine (SS3D) is my take on simplifying love 11's new 3D capabilities into a ready-to-use library for simple 3D games.

Here's a gif from the attached demo:

Here's the entire main.lua file for the demo shown above:

Code: Select all

-- store global reference to the Engine for use in calling functions
Engine = require "engine"

-- make the mouse cursor locked to the screen
love.mouse.setRelativeMode(true)
love.window.setTitle("ss3d 1.1 demo")

-- create a Scene object which stores and renders Models
-- arguments refer to the Scene's camera's canvas output size in pixels
Scene = Engine.newScene(love.graphics.getWidth(), love.graphics.getHeight())
DefaultTexture = love.graphics.newImage("texture.png")
Timer = 0

-- define vertices to be used in the creation of a new Model object for the Scene
local cubeVerts = {}
-- front
cubeVerts[#cubeVerts+1] = {0,0,0, 0,0}
cubeVerts[#cubeVerts+1] = {1,0,0, 1,0}
cubeVerts[#cubeVerts+1] = {0,1,0, 0,1}
cubeVerts[#cubeVerts+1] = {1,1,0, 1,1}
cubeVerts[#cubeVerts+1] = {0,1,0, 0,1}
cubeVerts[#cubeVerts+1] = {1,0,0, 1,0}

-- back
cubeVerts[#cubeVerts+1] = {1,0,1, 1,0}
cubeVerts[#cubeVerts+1] = {0,0,1, 0,0}
cubeVerts[#cubeVerts+1] = {0,1,1, 0,1}
cubeVerts[#cubeVerts+1] = {0,1,1, 0,1}
cubeVerts[#cubeVerts+1] = {1,1,1, 1,1}
cubeVerts[#cubeVerts+1] = {1,0,1, 1,0}

-- right side
cubeVerts[#cubeVerts+1] = {0,0,1, 1,0}
cubeVerts[#cubeVerts+1] = {0,0,0, 0,0}
cubeVerts[#cubeVerts+1] = {0,1,0, 0,1}
cubeVerts[#cubeVerts+1] = {0,1,0, 0,1}
cubeVerts[#cubeVerts+1] = {0,1,1, 1,1}
cubeVerts[#cubeVerts+1] = {0,0,1, 1,0}

-- left side
cubeVerts[#cubeVerts+1] = {1,0,0, 0,0}
cubeVerts[#cubeVerts+1] = {1,0,1, 1,0}
cubeVerts[#cubeVerts+1] = {1,1,0, 0,1}
cubeVerts[#cubeVerts+1] = {1,1,1, 1,1}
cubeVerts[#cubeVerts+1] = {1,1,0, 0,1}
cubeVerts[#cubeVerts+1] = {1,0,1, 1,0}

-- top side
cubeVerts[#cubeVerts+1] = {0,1,0}
cubeVerts[#cubeVerts+1] = {1,1,0}
cubeVerts[#cubeVerts+1] = {0,1,1}
cubeVerts[#cubeVerts+1] = {1,1,1}
cubeVerts[#cubeVerts+1] = {0,1,1}
cubeVerts[#cubeVerts+1] = {1,1,0}

-- bottom side
cubeVerts[#cubeVerts+1] = {1,0,0}
cubeVerts[#cubeVerts+1] = {0,0,0}
cubeVerts[#cubeVerts+1] = {0,0,1}
cubeVerts[#cubeVerts+1] = {0,0,1}
cubeVerts[#cubeVerts+1] = {1,0,1}
cubeVerts[#cubeVerts+1] = {1,0,0}

-- turn the vertices into a Model with a texture
CubeModel = Engine.newModel(cubeVerts, DefaultTexture)

-- add the CubeModel to the Scene
Scene.modelList[1] = CubeModel
end

function love.update(dt)
-- make the CubeModel go in circles and rotate
Timer = Timer + dt/2
CubeModel:setTransform({math.cos(Timer)*3 -1, -1, math.sin(Timer)*3 -1}, {Timer, cpml.vec3.unit_y, Timer, cpml.vec3.unit_z, Timer, cpml.vec3.unit_x})

Scene:update()
end

function love.mousemoved(x,y, dx,dy)
-- basic first person mouselook, built into Scene object
Scene:mouseLook(x,y, dx,dy)
end

function love.draw()
-- render all Models in the Scene
Scene:render()

-- render a HUD
Scene:renderFunction(
function ()
love.graphics.print("groverburger's super simple 3d engine v1.1")
end
)
end


Features:
- Built in first person camera controls
- Engine encapsulated into a single file
- 2D rendering / HUD support
- Rotatable and translatable models
- UV mapping
- Backface culling (enabled on a per-model basis)
- Wireframe rendering (enabled on a per-model basis)

To Dos
- Simple lighting
- Obj file format import
- Simple collision handling

Installation
Just drag the engine.lua file into your project directory to install. SS3D does require CPML, which can be found here.

Here's an example of what can be done with this engine.
This is a Minecraft clone I've beem working on. I abstracted the engine I used for this project and that is what became SS3D.
https://github.com/groverburger/lovecraft

Feedback and suggestions are greatly appreciated!
Feel free to use SS3D for whatever no permission necessary. MIT License.
Attachments
ss3d_demo.zip
engine.lua
Last edited by groverburger on Fri Feb 15, 2019 10:45 pm, edited 1 time in total.

St. Cosmo
Prole
Posts: 8
Joined: Wed Nov 07, 2018 6:53 pm

### Re: groverburger's Super Simple 3D Engine

Impressive work m8

pgimeno
Party member
Posts: 1531
Joined: Sun Oct 18, 2015 2:58 pm

### Re: groverburger's Super Simple 3D Engine

Wow and wow. That's a very impressive work. Map generator including strata and trees, collision handling, very decent lighting with light propagation. Great job.

The FOV is a bit wide, which can cause a bit of dizziness. But that's an easy adjustment

The name was already used for a 2D game (also here but that's just an early test). As hinted in that thread, that name suggests darker contents, which is a bit of a problem.

Another problem is the lack of any license text and copyright statement in the repository. Legal stuff is damn boring to handle, but needs to be sorted out correctly if you want it to be of any use to others. Also, are the assets yours? Are they under the same license? Unless they are yours or public domain, that is a problem as well, because there are no credits or license statement for them in the repo. In case they are not free, note there are free assets in the Minetest repo (CC BY-SA, see license for details).
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

groverburger
Prole
Posts: 5
Joined: Tue Oct 30, 2018 9:27 pm

### Re: groverburger's Super Simple 3D Engine

St. Cosmo wrote:
Mon Feb 11, 2019 2:59 pm
Impressive work m8
pgimeno wrote:
Mon Feb 11, 2019 6:54 pm
Wow and wow. That's a very impressive work. Map generator including strata and trees, collision handling, very decent lighting with light propagation. Great job.

The FOV is a bit wide, which can cause a bit of dizziness. But that's an easy adjustment

The name was already used for a 2D game (also here but that's just an early test). As hinted in that thread, that name suggests darker contents, which is a bit of a problem.

Another problem is the lack of any license text and copyright statement in the repository. Legal stuff is damn boring to handle, but needs to be sorted out correctly if you want it to be of any use to others. Also, are the assets yours? Are they under the same license? Unless they are yours or public domain, that is a problem as well, because there are no credits or license statement for them in the repo. In case they are not free, note there are free assets in the Minetest repo (CC BY-SA, see license for details).
Thanks for the compliments and feedback!
I was sure the name Lovecraft was already taken. If that causes too many problems, I may change it in the future.

I'll be upfront that I currently know very little about legal stuff and licensing or how to apply it to my creations. I want SS3D to be free for anyone to use in their creations and even sell without problems. The engine.lua file was created entirely by me so that shouldn't be too much of an issue.

In Lovecraft, the things I used but didn't create myself are all the textures and gui sprites (all stolen from Minecraft directly), and CPML. I should give credit to CPML and I could change the textures to Minetest textures as you said, but Lovecraft is intended to be an open-source hobby project so I don't think Microsoft would cause me any problems regardless.
I'll do some research on the topic. Thanks again for your feedback.

pgimeno
Party member
Posts: 1531
Joined: Sun Oct 18, 2015 2:58 pm

### Re: groverburger's Super Simple 3D Engine

It's not really hard, a quick way is to just include a LICENSE.md or .txt in the repository with the copyright and the license text, and mention in every file that the license can be found there.

In the CPML directory you already include one: https://github.com/groverburger/lovecra ... LICENSE.md but that's the CPML license only, obviously. You can use it as a guide, but note that the authors have forgotten to comply with the BSD 2-clause license: https://github.com/Nition/UnityOctree/b ... er/LICENCE which also requires the license text to be reproduced. I've filed an issue about that in the CPML tracker.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

drikdrok
Prole
Posts: 35
Joined: Sun Mar 15, 2015 9:53 am
Contact:

### Re: groverburger's Super Simple 3D Engine

Awesome stuff! This will be my goto library if I ever want to make a 3D game with Löve!

Can't wait for lighting and .obj import. Perhaps you could add collision handling too!

groverburger
Prole
Posts: 5
Joined: Tue Oct 30, 2018 9:27 pm

### Re: groverburger's Super Simple 3D Engine

pgimeno wrote:
Tue Feb 12, 2019 12:44 am
It's not really hard, a quick way is to just include a LICENSE.md or .txt in the repository with the copyright and the license text, and mention in every file that the license can be found there.

In the CPML directory you already include one: https://github.com/groverburger/lovecra ... LICENSE.md but that's the CPML license only, obviously. You can use it as a guide, but note that the authors have forgotten to comply with the BSD 2-clause license: https://github.com/Nition/UnityOctree/b ... er/LICENCE which also requires the license text to be reproduced. I've filed an issue about that in the CPML tracker.
Thanks for the support! I'll make sure to do that when I migrate SS3D to github.
drikdrok wrote:
Fri Feb 15, 2019 9:09 pm
Awesome stuff! This will be my goto library if I ever want to make a 3D game with Löve!

Can't wait for lighting and .obj import. Perhaps you could add collision handling too!
Thanks for the compliments and feedback! I have some simple diffuse lighting working but it's not polished yet, it should be making its way into SS3D sometime soon. CPML has some really handy 3d line to triangle intersection functions that work well for collisions. I'll put collision handling on the todo list, but in the meantime here's a simple collision function I was testing using CPML.

The ray.direction represents where the object will be next frame, and the function tests if the line from where the object is now to where it is next frame intersects with any model in the CollisionList. It may still have some bugs.

Code: Select all

-- check for collisions, put add models you want to have collisions to the CollisionList
for i=1, #CollisionList do
local pos = cpml.vec3.new(self.x,self.y,self.z)
local ray = {}
ray.position = cpml.vec3.new(0,0,0)
ray.direction = cpml.vec3.new(0,self.ySpeed,0)

local triangle = {}
triangle[1] = cpml.vec3.new(CollisionList[i].verts[1]) - pos
triangle[2] = cpml.vec3.new(CollisionList[i].verts[2]) - pos
triangle[3] = cpml.vec3.new(CollisionList[i].verts[3]) - pos

local intersection, distance = cpml.intersect.ray_triangle(ray, triangle)

if intersection ~= false then
print(intersection)

if intersection:len() <= ray.direction:len() then
-- COLLISION DETECTED!
end
end
end


ingsoc451
Citizen
Posts: 71
Joined: Sat Feb 06, 2016 9:42 pm
Location: Oceania

### Re: groverburger's Super Simple 3D Engine

You can use this free texture pack:
https://opengameart.org/node/91360
eom

### Who is online

Users browsing this forum: No registered users and 4 guests