Libs3D Library Shapes: Difference between revisions
wip |
|||
| Line 50: | Line 50: | ||
We are going to use the Plane shape (helper file ''3DShapes.lua''), this will be our ground. | We are going to use the Plane shape (helper file ''3DShapes.lua''), this will be our ground. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- a | -- our first shape, a plane for the ground | ||
local ground = D3.Plane.new(1*8, 1*8) -- (width,depth) | local ground = D3.Plane.new(1*8, 1*8) -- (width,depth) | ||
-- a color | -- a color | ||
ground:mapColor( | ground:mapColor(0x9d7878) -- (color,[alpha=1]) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Let's texture our plane, I picked this one: https://polyhaven.com/a/forrest_ground_01, '''Diffuse | Let's texture our plane, I picked this one: https://polyhaven.com/a/forrest_ground_01, '''Diffuse''', '''1K''', '''JPG''' | ||
[[File:3d_plane_polyhaven_forrest_ground.png|480px]] | [[File:3d_plane_polyhaven_forrest_ground.png|480px]] | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- a | -- our first shape, a plane for the ground | ||
local ground = D3.Plane.new(1*8, 1*8) -- (width,depth) | local ground = D3.Plane.new(1*8, 1*8) -- (width,depth) | ||
-- a color | -- a color | ||
ground:mapColor(0x9d7878) -- (color,[alpha=1]) | |||
-- a texture (diffuse | -- a texture (diffuse) | ||
local tex = Texture.new(" | local tex = Texture.new("textures/forrest_ground_01_diff_1k.jpg", nil, { wrap=Texture.REPEAT, } ) | ||
local texsx, texsy = 0.1*8, 0.1*8 -- texture scaling | |||
local texsx, texsy = 0. | ground:mapTexture(tex, texsx, texsy) -- (texture,sw,sh) | ||
ground:mapTexture(tex, texsx, texsy, | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 86: | Line 85: | ||
'''...TO BE CONTINUED...''' | '''...TO BE CONTINUED...''' | ||
== I am out 2 == | == I am out 2 == | ||
Revision as of 03:50, 31 July 2026
Please note: there is a Shapes Library V2. We only keep this one for backward compatibility 🤷♂️
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)
- some common 3D shapes (plane, cube, ...)
- light and shadows
- playground
Copy the following two Library folders in your project 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.25*8,0.5*8,0.5*8, 0*8,0*8,0*8) -- (eyex,eyey,eyez, targetx,targety,targetz[, upx,upy,upz])
In order to display the content of the Viewport (camera) to the screen, we add it to Gideros stage.
-- we add the view (camera) to Gideros stage
stage:addChild(view)
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.
-- our first shape, a plane for the ground
local ground = D3.Plane.new(1*8, 1*8) -- (width,depth)
-- a color
ground:mapColor(0x9d7878) -- (color,[alpha=1])
Let's texture our plane, I picked this one: https://polyhaven.com/a/forrest_ground_01, Diffuse, 1K, JPG
-- our first shape, a plane for the ground
local ground = D3.Plane.new(1*8, 1*8) -- (width,depth)
-- a color
ground:mapColor(0x9d7878) -- (color,[alpha=1])
-- a texture (diffuse)
local tex = Texture.new("textures/forrest_ground_01_diff_1k.jpg", nil, { wrap=Texture.REPEAT, } )
local texsx, texsy = 0.1*8, 0.1*8 -- texture scaling
ground:mapTexture(tex, texsx, texsy) -- (texture,sw,sh)
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)
And we add the ground to the world (scene).
-- we add the shape to the scene (world)
scene:addChild(ground)
...TO BE CONTINUED...
I am out 2
...
You are strongly encouraged to mess with the code.
Bye for now!