Skip to content

Commit dabbf5a

Browse files
committed
Merge: Intro gamnit depth, the 3D game framework for Nit
This PR intro the base structure of a framework for portable 3D game development in Nit. This framework is based on a list of `Actor`, in `app::actors`, which are drawn at each frame. Each actor is composed of a model and other information specific to this instance: position in the world, rotation and scaling. Each `Model` is either a composite of models or it is composed of a `Mesh` defining its geometry and a `Material` defining how to draw the model. `Material` can be subclassed to use custom shaders. These main classes are defined in the module `depth_core`. _gamnit depth_ is built upon _app.nit_ and it works well with _gamnit flat_ (renamed from _gamnit simple_2d_). Clients are portable across GNU/Linux and Android, and _gamnit flat_ can still be used for UI elements. This framework is far from complete at this point, however it designed for extensibility. Here's a list of _gamnit depth_ implemented features and todo: ### Mesh - [x] Create 3D simple meshes: cube, plane and UVSphere. - [ ] Create simple debug meshes: axis arrows, etc. ### Material - [x] Simple material with uniform ambient, diffuse and specular colors - [x] Normals visualization materials - [ ] Depth material - [x] Texture material with ambient and diffuse lighting - [ ] Texture material with specular lighting (implement Blinn Phong in GLSL, most attributes are already present) - [ ] Texture material with normals mapping ### Models - [x] Load models from .obj and .mtl files. - [ ] Load models from a binary model format - [x] Fallback on a simple material and mesh on load errors ### Sample programs - [x] Sample minimal graphics-only application: model_viewer - [ ] Merge the globe example with model_viewer - [ ] Simple client game (like Asteronits for `gamnit::flat`) ### Other engine features - [x] Composite pattern to manage simple models (single mesh to single material) and composite models - [ ] Scene framework with a tree-like structure - [ ] Particle emitters. - [ ] Support for multiple light types and instances. - [ ] Optimized GPU side caching with VBO. - [ ] Optimized C side caching of models data. - [ ] VR support (at least Cardboard) - [ ] Hardware key services. - [ ] Line-3D model collision (as in simple model selection from mouse click) ### Known bugs - [ ] TexturedMaterial affects 2D sprites geometry, more data is needed to debug. Pull-Request: #1920 Reviewed-by: Jean Privat <jean@pryen.org>
2 parents 12fb7a6 + 05c6ccf commit dabbf5a

34 files changed

+14341
-43
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Categories:Nit,Games
22
License:Apache2
33
Web Site:http://nitlanguage.org
4-
Source Code:http://nitlanguage.org/nit.git/tree/HEAD:/lib/gamnit/examples/asteronits
4+
Source Code:http://nitlanguage.org/nit.git/tree/HEAD:/contrib/asteronits
55
Issue Tracker:https://github.com/nitlang/nit/issues
66

77
Summary:Destroy asteroids in this simple 2D sample game made with gamnit
88
Description:
9-
Sample portable gamnit game implemented with the simple_2d API.
9+
Sample portable gamnit game implemented with the flat API.
1010
.

contrib/asteronits/package.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ tags=example
44
maintainer=Alexis Laferrière <alexis.laf@xymus.net>
55
license=Apache-2.0
66
[upstream]
7-
browse=https://github.com/nitlang/nit/tree/master/lib/gamnit/examples/asteronits/
7+
browse=https://github.com/nitlang/nit/tree/master/contrib/asteronits/
88
git=https://github.com/nitlang/nit.git
9-
git.directory=lib/gamnit/examples/asteronits/
9+
git.directory=contrib/asteronits/
1010
homepage=http://nitlanguage.org
1111
issues=https://github.com/nitlang/nit/issues
1212
apk=http://nitlanguage.org/fdroid/apk/asteronits.apk

contrib/asteronits/src/asteronits.nit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module asteronits is
2222
android_api_target 15
2323
end
2424
25-
import gamnit::simple_2d
25+
import gamnit::flat
2626
2727
import game_logic
2828
import spritesheet

contrib/model_viewer/Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
NITC=../../bin/nitc
2+
NITLS=../../bin/nitls
3+
4+
all: bin/model_viewer
5+
6+
bin/model_viewer: $(shell ${NITLS} -M src/model_viewer.nit linux) ${NITC}
7+
${NITC} src/model_viewer.nit -m linux -o $@
8+
9+
check: bin/model_viewer
10+
NIT_TESTING=true bin/model_viewer
11+
12+
# ---
13+
# Android
14+
15+
android: bin/model_viewer.apk
16+
bin/model_viewer.apk: $(shell ${NITLS} -M src/model_viewer.nit android) ${NITC} res/drawable-hdpi/icon.png
17+
${NITC} src/model_viewer.nit -m android -o $@
18+
19+
android-release: $(shell ${NITLS} -M src/model_viewer.nit android) ${NITC} res/drawable-hdpi/icon.png
20+
${NITC} src/model_viewer.nit -m android -o bin/model_viewer.apk --release
21+
22+
res/drawable-hdpi/icon.png: art/icon.png
23+
make -C ../inkscape_tools/
24+
mkdir -p res/drawable-ldpi/ res/drawable-mdpi/ res/drawable-hdpi/ \
25+
res/drawable-xhdpi/ res/drawable-xxhdpi/ res/drawable-xxxhdpi/
26+
convert -resize 36x36 art/icon.png res/drawable-ldpi/icon.png
27+
convert -resize 48x48 art/icon.png res/drawable-mdpi/icon.png
28+
convert -resize 72x72 art/icon.png res/drawable-hdpi/icon.png
29+
convert -resize 96x96 art/icon.png res/drawable-xhdpi/icon.png
30+
convert -resize 144x144 art/icon.png res/drawable-xxhdpi/icon.png
31+
convert -resize 192x192 art/icon.png res/drawable-xxxhdpi/icon.png

contrib/model_viewer/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Sample portable 3D app implemented with the gamnit depth framework
2+
3+
# Art
4+
5+
* 3D models `Tree_01` and `Oak_Fall_01` were created by Kenney.nl and published under CC0.
6+
* 3D model `Quandtum_BA-2_v1_1` was created by Quandtum and published under CC0.
7+
* Some textures on the `Quandtum_BA-2_v1_1` model have been created with images from goodtextures.com.
8+
These images can be used in free softwares, some restrictions still applies for modifications and other uses.

contrib/model_viewer/art/icon.png

247 KB
Loading

contrib/model_viewer/art/icon.xcf

449 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
## Alias OBJ Material File
3+
# Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited
4+
5+
newmtl Fall_Leafs
6+
Ka 0.000000 0.000000 0.000000
7+
Kd 0.619608 0.356863 0.235294
8+
Ks 0.330000 0.330000 0.330000
9+
10+
newmtl Wood
11+
Ka 0.000000 0.000000 0.000000
12+
Kd 0.666667 0.545098 0.356863
13+
Ks 0.330000 0.330000 0.330000
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
# Alias OBJ Model File
2+
# Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited
3+
# File units = meters
4+
5+
mtllib Oak_Fall_01.mtl
6+
7+
g Mesh1 Oak_Fall Model
8+
9+
usemtl Fall_Leafs
10+
v 1.57617 1.5335 -1.365
11+
vt -0.310227 0.697045
12+
vn 0.5 0 -0.866025
13+
v 0.788083 1.5335 -1.82
14+
vt 0.103409 0.697045
15+
v 0.788083 2.817 -1.82
16+
vt 0.103409 1.28045
17+
vn 0.497668 0.0964695 -0.861986
18+
v 1.57617 2.817 -1.365
19+
vt -0.310227 1.28045
20+
f 1/1/1 2/2/1 3/3/2 4/4/2
21+
22+
v 0.788083 1.27 -1.4196
23+
vt 0.0124091 0.936811
24+
vn 0.302516 -0.796201 -0.523973
25+
vt 0.103409 1.13477
26+
vt -0.310227 1.13477
27+
v 1.22941 1.27 -1.1648
28+
vt -0.219227 0.936811
29+
f 5/5/3 2/6/3 1/7/3 6/8/3
30+
31+
v 0.346757 1.27 -1.1648
32+
vt -0.401227 0.651596
33+
vn -0.302516 -0.796201 -0.523973
34+
v 1.80478e-015 1.5335 -1.365
35+
vt -0.310227 0.849557
36+
vt -0.723864 0.849557
37+
vt -0.632864 0.651596
38+
f 7/9/4 8/10/4 2/11/4 5/12/4
39+
40+
v 0 1.5335 -0.455
41+
vt -0.206818 0.421735
42+
vn -0.605032 -0.796201 -3.68114e-016
43+
vt -0.620455 0.421735
44+
vt -0.529455 0.223774
45+
v 0.346757 1.27 -0.6552
46+
vt -0.297818 0.223774
47+
f 9/13/5 8/14/5 7/15/5 10/16/5
48+
49+
vt -0.620455 0.697045
50+
vn -1 0 -7.93309e-016
51+
vt -0.206818 0.697045
52+
v 0 2.817 -0.455
53+
vt -0.206818 1.28045
54+
vn -0.995336 0.0964695 -6.93437e-016
55+
v 1.80478e-015 2.817 -1.365
56+
vt -0.620455 1.28045
57+
f 8/17/6 9/18/6 11/19/7 12/20/7
58+
59+
vt -0.103409 0.697045
60+
vn -0.5 0 0.866025
61+
v 0.788083 1.5335 -0
62+
vt 0.310227 0.697045
63+
v 0.788083 2.817 -0
64+
vt 0.310227 1.28045
65+
vn -0.497668 0.0964695 0.861986
66+
vt -0.103409 1.28045
67+
f 9/21/8 13/22/8 14/23/9 11/24/9
68+
69+
v 0.788083 1.27 -0.4004
70+
vt 0.219227 0.0811668
71+
vn -0.302516 -0.796201 0.523973
72+
vt 0.310227 0.279128
73+
vt -0.103409 0.279128
74+
vt -0.0124091 0.0811668
75+
f 15/25/10 13/26/10 9/27/10 10/28/10
76+
77+
v 1.22941 1.27 -0.6552
78+
vt 0.632864 0.366382
79+
vn 0.302516 -0.796201 0.523973
80+
v 1.57617 1.5335 -0.455
81+
vt 0.723864 0.564342
82+
vt 0.310227 0.564342
83+
vt 0.401227 0.366382
84+
f 16/29/11 17/30/11 13/31/11 15/32/11
85+
86+
vt 0.297818 0.794204
87+
vn 0.605032 -0.796201 4.38273e-018
88+
vt 0.529455 0.794204
89+
vt 0.620455 0.992165
90+
vt 0.206818 0.992165
91+
f 16/33/12 6/34/12 1/35/12 17/36/12
92+
93+
vt -0.558823 0.297818
94+
vn 0 -1 -0
95+
v 0.902339 1.27 -0.795744
96+
vt -0.410154 0.361702
97+
vt -0.558823 0.529455
98+
f 16/37/13 18/38/13 6/39/13
99+
100+
vt -0.35822 0.182
101+
f 15/40/13 18/38/13 16/37/13
102+
103+
v 0.673827 1.27 -0.795744
104+
vt -0.306285 0.361702
105+
f 15/40/13 19/41/13 18/38/13
106+
107+
vt -0.157617 0.297818
108+
f 10/42/13 19/41/13 15/40/13
109+
110+
v 0.673827 1.27 -1.02426
111+
vt -0.306285 0.465571
112+
f 19/41/13 10/42/13 20/43/13
113+
114+
vt -0.35822 0.645273
115+
f 10/42/13 5/44/13 20/43/13
116+
117+
vt -0.157617 0.529455
118+
f 5/44/13 10/42/13 7/45/13
119+
120+
v 0.902339 1.27 -1.02426
121+
vt -0.410154 0.465571
122+
f 20/43/13 5/44/13 21/46/13
123+
124+
f 21/46/13 5/44/13 6/39/13
125+
126+
f 21/46/13 6/39/13 18/38/13
127+
128+
usemtl Wood
129+
v 0.968014 0 -0.73007
130+
vt 0.33185 -0.0227234
131+
vn 0.998666 0.0516433 -0
132+
v 0.968014 0 -1.08993
133+
vt 0.495423 -0.0227234
134+
vt 0.465571 0.555321
135+
vt 0.361702 0.555321
136+
f 22/47/14 23/48/14 21/49/14 18/50/14
137+
138+
v 0.608153 0 -0.73007
139+
vt -0.276433 0.33185
140+
v 0.608153 0 -1.08993
141+
vt -0.276433 0.495423
142+
vt -0.440006 0.495423
143+
vt -0.440006 0.33185
144+
f 24/51/13 25/52/13 23/53/13 22/54/13
145+
146+
vt -0.33185 0.0142759
147+
vn -0.998666 0.0516433 -0
148+
vt -0.361702 0.59232
149+
vt -0.465571 0.59232
150+
vt -0.495423 0.0142759
151+
f 24/55/15 19/56/15 20/57/15 25/58/15
152+
153+
vt 0.440006 0.0171378
154+
vn -1.52886e-017 0.0516433 0.998666
155+
vt 0.410154 0.595182
156+
vt 0.306285 0.595182
157+
vt 0.276433 0.0171378
158+
f 22/59/16 18/60/16 19/61/16 24/62/16
159+
160+
vt -0.276433 -0.0255853
161+
vn -1.52886e-017 0.0516433 -0.998666
162+
vt -0.306285 0.552459
163+
vt -0.410154 0.552459
164+
vt -0.440006 -0.0255853
165+
f 25/63/17 20/64/17 21/65/17 23/66/17
166+
167+
usemtl Fall_Leafs
168+
vt 0.206818 0.697045
169+
vn 1 0 -0
170+
vt 0.620455 0.697045
171+
vt 0.620455 1.28045
172+
vn 0.995336 0.0964695 3.71398e-018
173+
v 1.57617 2.817 -0.455
174+
vt 0.206818 1.28045
175+
f 17/67/18 1/68/18 4/69/19 26/70/19
176+
177+
vt 0.206818 1.11904
178+
vt 0.620455 1.11904
179+
v 1.24517 4.5085 -1.1739
180+
vt 0.533591 1.90248
181+
vn 0.981387 0.192039 7.39332e-018
182+
v 1.24517 4.5085 -0.6461
183+
vt 0.293682 1.90248
184+
f 26/71/19 4/72/19 27/73/20 28/74/20
185+
186+
vt 0.103409 1.08464
187+
v 0.788083 4.5085 -1.4378
188+
vt 0.0165455 1.86809
189+
vn 0.490694 0.192039 -0.849906
190+
vt -0.223364 1.86809
191+
vt -0.310227 1.08464
192+
f 3/75/2 29/76/21 27/77/21 4/78/2
193+
194+
vt -0.310227 1.15343
195+
vn -0.497668 0.0964695 -0.861986
196+
v 0.330995 4.5085 -1.1739
197+
vt -0.397091 1.93688
198+
vn -0.490694 0.192039 -0.849906
199+
vt -0.637 1.93688
200+
vt -0.723864 1.15343
201+
f 12/79/22 30/80/23 29/81/23 3/82/22
202+
203+
v 0.330995 4.5085 -0.6461
204+
vt -0.293682 2.04007
205+
vn -0.981387 0.192039 -5.87097e-016
206+
vt -0.533591 2.04007
207+
vt -0.620455 1.25662
208+
vt -0.206818 1.25662
209+
f 31/83/24 30/84/24 12/85/7 11/86/7
210+
211+
vt -0.293682 1.50563
212+
vn -0.680934 0.732345 -5.13467e-017
213+
v 0.788083 4.9335 -0.91
214+
vt -0.413636 1.78933
215+
vt -0.533591 1.50563
216+
f 31/87/25 32/88/25 30/89/25
217+
218+
v 0.788083 4.5085 -0.3822
219+
vt 0.223364 1.6368
220+
vn -0.340467 0.732345 0.589706
221+
vt 0.103409 1.9205
222+
vt -0.0165455 1.6368
223+
f 33/90/26 32/91/26 31/92/26
224+
225+
vt 0.517045 1.65816
226+
vn 0.340467 0.732345 0.589706
227+
vt 0.397091 1.37446
228+
vt 0.637 1.37446
229+
f 32/93/27 33/94/27 28/95/27
230+
231+
vt 0.723864 1.22223
232+
vn 0.497668 0.0964695 0.861986
233+
vt 0.637 2.00567
234+
vn 0.490694 0.192039 0.849906
235+
vt 0.397091 2.00567
236+
vt 0.310227 1.22223
237+
f 26/96/28 28/97/29 33/98/29 14/99/28
238+
239+
vt 0.310227 1.29102
240+
vt 0.223364 2.07446
241+
vn -0.490694 0.192039 0.849906
242+
vt -0.0165455 2.07446
243+
vt -0.103409 1.29102
244+
f 14/100/9 33/101/30 31/102/30 11/103/9
245+
246+
vn 0.5 0 0.866025
247+
vt 0.723864 0.697045
248+
vt 0.723864 1.28045
249+
f 13/22/31 17/104/31 26/105/28 14/23/28
250+
251+
vt 0.533591 0.980952
252+
vn 0.680934 0.732345 -5.13467e-017
253+
vt 0.413636 1.26465
254+
vt 0.293682 0.980952
255+
f 27/106/32 32/107/32 28/108/32
256+
257+
vt 0.0165455 0.849782
258+
vn 0.340467 0.732345 -0.589706
259+
vt -0.103409 1.13348
260+
vt -0.223364 0.849782
261+
f 29/109/33 32/110/33 27/111/33
262+
263+
vt -0.397091 1.11212
264+
vn -0.340467 0.732345 -0.589706
265+
vt -0.517045 1.39582
266+
vt -0.637 1.11212
267+
f 30/112/34 32/113/34 29/114/34
268+
269+
vt -0.723864 0.697045
270+
vn -0.5 0 -0.866025
271+
vt -0.723864 1.28045
272+
f 2/115/35 8/1/35 12/4/22 3/116/22
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Blender MTL File: 'Quandtum_BA-2_v1_1.blend'
2+
# Material Count: 1
3+
4+
newmtl Bot
5+
Ns 96.078431
6+
Ka 0.000000 0.000000 0.000000
7+
Kd 0.640000 0.640000 0.640000
8+
Ks 1.000000 1.000000 1.000000
9+
Ni 1.000000
10+
d 1.000000
11+
illum 2
12+
map_Ka textures/Turret-Emission.jpg
13+
map_Kd textures/Turret-Diffuse.jpg
14+
map_Bump textures/Turret-Normal.jpg
15+
map_Ks textures/Turret-Specular.jpg
16+
map_Ns textures/Turret-Specular.jpg

0 commit comments

Comments
 (0)