Libs3D Library Shapes
I am ready
As we have seen, to make more advanced 3D, Gideros has a bunch of helper files packed in the Library folder.
Here is the plan:
- start with a camera
- a world to populate (scene)
- add some primitive shapes (plane, cube, ...)
- load some .obj models
- and some animations (bones)
Please create a new Gideros project and copy the two following Library folders in the assets folder:
- 3dbase
- luashader
The Camera
The camera is a Viewport with a perspective projection Matrix (helper file 3DView.lua). Let's add one:
application:setBackgroundColor(0x454545)
-- we set up a fullscreen 3D viewport (fov: consoles 60, pc 90)
local sw, sh = application:getContentWidth(), application:getContentHeight()
local view = D3.View.new(sw,sh, 90, 0.1,1*1024) -- (screen w,screen h, fov, near plane,far plane)
You can position the view (camera) and set its target using the Viewport:lookAt function.
-- we position the view (camera) and set its target
view:lookAt(0*8,0.3*8,0.8*8, 0*8,0*8,0*8) -- (eyex,eyey,eyez, targetx,targety,targetz[, upx,upy,upz])
The World (scene)
We will add all our 3D models to a scene. The scene is a simple Sprite and is part of the camera.
-- we will add 3D shapes and models to a scene
local scene = view:getScene()
Our first shape: a Plane
We are going to use the Plane shape (helper file 3DShapes.lua), this will be our ground.
-- a shape
local ground = D3.Plane.new(1*8, 1*8) -- (width,depth)
-- a color
ground:mapColor(0x554333, 0.5) -- (color,[alpha=1])
Let's texture our plane, I picked this one: https://polyhaven.com/a/forrest_ground_01, Diffuse + Normal (GL), 1K, JPG
-- a shape
local ground = D3.Plane.new(1*8, 1*8) -- (width,depth)
-- a color
--ground:mapColor(0x554333, 0.5) -- (color,[alpha=1])
-- a texture (diffuse + normal)
local tex = Texture.new("models/textures/forrest_ground_01_diff_1k.jpg", nil, { wrap=Texture.REPEAT, } )
local normal = Texture.new("models/textures/forrest_ground_01_nor_gl_1k.jpg", nil, { wrap=Texture.REPEAT, } )
local texsx, texsy = 0.15*8, 0.15*8 -- texture scaling
ground:mapTexture(tex, texsx, texsy, normal)
We tell the shape to receive light and shadows.
-- we tell the shape to receive light and shadows
ground:updateMode(D3.Mesh.MODE_LIGHTING + D3.Mesh.MODE_SHADOW)
We add the ground to the scene.
-- we add the shape to the scene (world)
scene:addChild(ground)
Finally, we add the view (camera) to Gideros stage.
-- and the scene to stage
stage:addChild(view)
.obj Rulez
When you work with 3D, you need to follow some "engine" rulez. In Gideros, for the .obj file format, those are:
- currently Gideros supports .png and .jpg image formats
- currently Gideros supports Base Color, Texture map and Normal Map
- the textures shouldn't be embedded in the models. In Blender, use unpack resources:
- your Blender BSDF shaders should look something like:
- Gideros will import the position of the models, so make sure your models are at location 0, 0, 0
- I believe Gideros also imports the origin of the models, so place the origins accordingly
I personally use this Blender add-on: https://extensions.blender.org/add-ons/act-game-asset-creation-toolset/
Please note, you can still have the Metallic, Roughness and other textures attached in your Blender BSDF shaders, Gideros will just ignore them.
The assets: .obj
I have chosen this cc0 asset pack: https://roadtovostok.itch.io/road-to-vostok-assets-vol1.
In 3D, the assets you download from the internet, often need some adjustement to follow your "engine" rulez 🤷♂️. I already made those adjustements and you can find the adjusted asset pack here: https://mokatunprod.itch.io/3dpixel-obj-packs.
Please copy the roadtovostok asset pack (or your own models) in the objs folder:
- models
- objs
- roadtovostok
- objs
- models
I am out 2
To do.
You are strongly encouraged to mess with the code.
Bye for now!