Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JujuAdams committed Jul 31, 2022
2 parents 4f52baa + 598cbdd commit aed14d9
Show file tree
Hide file tree
Showing 80 changed files with 504 additions and 88 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align="center">dotobj 5.3.2</h1>
<h1 align="center">dotobj 5.4.0</h1>

<p align="center">.obj/.mtl loader, written in native GML, for GameMaker Studio 2.3 by <b>@jujuadams</b></p>

Expand Down
62 changes: 62 additions & 0 deletions datafiles/cube/cube.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Blender MTL File: 'None'
# Material Count: 6

newmtl Material.001
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.009420 0.800000 0.409103
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl Material.002
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.214308 0.257536 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl Material.003
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.142288 0.090150
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl Material.004
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.173395 0.800000 0.035974
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl Material.005
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.788905 0.058295 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

newmtl Material.006
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.707811 0.001922
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
59 changes: 59 additions & 0 deletions datafiles/cube/cube.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Blender v2.93.1 OBJ File: ''
# www.blender.org
mtllib cube.mtl
o Cube_Cube.001
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vn 0.0000 1.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 -1.0000 0.0000
g Cube_Cube.001_Material.001
usemtl Material.001
s off
f 4/1/1 6/2/1 8/3/1
f 4/1/1 2/4/1 6/2/1
g Cube_Cube.001_Material.002
usemtl Material.002
f 4/1/2 7/5/2 3/6/2
f 4/1/2 8/3/2 7/5/2
g Cube_Cube.001_Material.003
usemtl Material.003
f 8/3/3 5/7/3 7/5/3
f 8/3/3 6/8/3 5/7/3
g Cube_Cube.001_Material.004
usemtl Material.004
f 6/9/4 1/10/4 5/11/4
f 6/9/4 2/12/4 1/10/4
g Cube_Cube.001_Material.005
usemtl Material.005
f 2/12/5 3/13/5 1/10/5
f 2/12/5 4/14/5 3/13/5
g Cube_Cube.001_Material.006
usemtl Material.006
f 7/15/6 1/10/6 3/16/6
f 7/15/6 5/11/6 1/10/6
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
129 changes: 66 additions & 63 deletions dotobj.yyp

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions objects/objCubeTest/Create_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
model = DotobjModelLoadFile("cube\\cube.obj");

//Mouse lock variables (press F3 to lock the mouse and use mouselook)
mouse_lock = false;
mouse_lock_timer = 0;

//Some variables to track the camera
cam_x = 0;
cam_y = 120;
cam_z = 0;
cam_yaw = -60;
cam_pitch = 0;
cam_dx = -dcos(cam_pitch)*dsin(cam_yaw);
cam_dy = -dsin(cam_pitch);
cam_dz = dcos(cam_pitch)*dcos(cam_yaw);

//Smoothed fps_real variable
fps_smoothed = 60;
show_info = true;
40 changes: 40 additions & 0 deletions objects/objCubeTest/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//Turn on z-writing and z-testing so we're ready for 3D rendering
gpu_set_ztestenable(true);
gpu_set_zwriteenable(true);

//Counterclockwise faces are backfaces. We want to cull these so we're drawing less
gpu_set_cullmode(cull_counterclockwise);

//Texture repeating is required to render a lot of .obj files
//For now, all textures are externally imported sprites so they can handle texture
//repeats just fine, though for atlased textures this method may not work
gpu_set_tex_repeat(true);

//Turn on anisotropic filtering because why not, we're showing off
gpu_set_tex_mip_enable(mip_on);
gpu_set_tex_mip_filter(tf_anisotropic);
gpu_set_tex_max_aniso(16);

//Set our view + projection matrices
var _old_world = matrix_get(matrix_world);
var _old_view = matrix_get(matrix_view);
var _old_projection = matrix_get(matrix_projection);

matrix_set(matrix_view, matrix_build_lookat(cam_x, cam_y, cam_z,
cam_x+cam_dx, cam_y+cam_dy, cam_z+cam_dz,
0, 1, 0));
matrix_set(matrix_projection, matrix_build_projection_perspective_fov(90, room_width/room_height, 1, 3000));

//Finally, draw the model
matrix_set(matrix_world, matrix_build(0,0,0, 0,0,0, 100, 100, 100));
model.Submit();

//Reset draw state
matrix_set(matrix_world , _old_world );
matrix_set(matrix_view , _old_view );
matrix_set(matrix_projection, _old_projection);
gpu_set_ztestenable(false);
gpu_set_zwriteenable(false);
gpu_set_cullmode(cull_noculling);
gpu_set_tex_repeat(false);
gpu_set_tex_mip_enable(mip_off);
27 changes: 27 additions & 0 deletions objects/objCubeTest/Draw_64.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
if (show_info)
{
//Display credits
var _string = "dotobj " + __DOTOBJ_VERSION + "\n";
_string += "@jujuadams " + __DOTOBJ_DATE + "\n";
_string += "\n";
_string += "Cube by wynaut\n"
_string += "\n";
_string += "FPS = " + string(fps) + " (" + string(fps_smoothed) + ")\n";
_string += "\n";
_string += "WASD/shift/space to move\n";
_string += "F1 to toggle this panel\n";
_string += "F3 to toggle mouselook\n";
_string += "F4 to toggle fullscreen";

draw_set_colour(c_black);
draw_set_alpha(0.5);
draw_rectangle(10, 10, 20+string_width(_string), 20+string_height(_string), false);
draw_text(15, 16, _string);
draw_set_alpha(1.0);
draw_text(14, 15, _string);
draw_text(16, 15, _string);
draw_text(15, 14, _string);
draw_text(15, 16, _string);
draw_set_colour(c_white);
draw_text(15, 15, _string);
}
57 changes: 57 additions & 0 deletions objects/objCubeTest/Step_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//Toggle the info panel if we press F1
if (keyboard_check_released(vk_f1)) show_info = !show_info;

//Lock the mouse if we press F3
if (keyboard_check_released(vk_f3))
{
mouse_lock = !mouse_lock;
mouse_lock_timer = 0;

//Hide the mouse if we're locked
window_set_cursor(mouse_lock? cr_none : cr_default);
}

//Toggle the fullscreen if we press f4
if (keyboard_check_released(vk_f4)) window_set_fullscreen(!window_get_fullscreen());

//If we've got the mouse locked...
if (mouse_lock)
{
//Figure out where the centre of the window is
var _centre_x = window_get_width()/2;
var _centre_y = window_get_height()/2;

//Increment a timer. Once that timer reaches 5, start pitching/panning the camera
//There's a little bit of lag between pressing F3 and the mouse actually
//centring in the window - this timer stops the camera freaking out!
++mouse_lock_timer;
if (mouse_lock_timer > 4)
{

var _delta_x = window_mouse_get_x() - _centre_x;
var _delta_y = window_mouse_get_y() - _centre_y;
cam_yaw += -0.1*_delta_x;
cam_pitch += 0.1*_delta_y;

cam_pitch = clamp(cam_pitch + 0.1*_delta_y, -89, 89); //Make sure we can't gimbal lock the camera
}

//Now move the mouse
window_mouse_set(_centre_x, _centre_y);
}

//Figure out where the camera is looking
var _cos_pitch = dcos(cam_pitch);
cam_dx = -_cos_pitch*dsin(cam_yaw);
cam_dy = -dsin(cam_pitch);
cam_dz = _cos_pitch*dcos(cam_yaw);

//Move parallel/perpendicular to the camera
var _para = keyboard_check(ord("W")) - keyboard_check(ord("S"));
var _perp = keyboard_check(ord("A")) - keyboard_check(ord("D"));
cam_x += 5*(cam_dx*_para - cam_dz*_perp);
cam_y += 5*(keyboard_check(vk_space) - keyboard_check(vk_shift));
cam_z += 5*(cam_dz*_para + cam_dx*_perp);

//Slightly weird use of lerp() but it works
fps_smoothed = lerp(fps_smoothed, fps_real, 0.1);
36 changes: 36 additions & 0 deletions objects/objCubeTest/objCubeTest.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions objects/objCubeTest/obj_test.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion objects/objSponzaCachedTest/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (!code_is_compiled() && !debug_mode) show_error("It is strongly recommended y
//The script returns a dotobj model (in reality, a struct) that we can draw in the Draw event
//If the model references a material (.mtl) file then that will be loaded as well
DotobjSetFlipTexcoordV(true);
model_sponza = DotobjTryCache("sponza.obj");
model_sponza = DotobjTryCache("sponza\\sponza.obj");
model_sponza.Freeze(); //Wise to freeze your models as well

//Output the materials that this model uses
Expand Down
2 changes: 1 addition & 1 deletion objects/objSponzaTest/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (!code_is_compiled() && !debug_mode) show_error("It is strongly recommended y
//If the model references a material (.mtl) file then that will be loaded as well
DotobjSetFlipTexcoordV(true);

model_sponza = DotobjModelLoadFile("sponza.obj");
model_sponza = DotobjModelLoadFile("sponza\\sponza.obj");
model_sponza.Freeze(); //Wise to freeze your models as well

//Output the materials that this model uses
Expand Down
8 changes: 7 additions & 1 deletion options/main/options_main.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aed14d9

Please sign in to comment.