-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/__pycache__ | ||
/assets_compiled | ||
/works |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Snooker | ||
|
||
**Snooker** is a game that was programmed in Python using the HARFANG 3D framework. | ||
|
||
*Become a pool player and test out our physics engine.* | ||
|
||
![Snooker Banner](https://github.com/harfang3d/snooker-python-hg2/raw/master/screenshots/scene0.png) | ||
|
||
## How to run Snooker | ||
|
||
### Python | ||
1. Get [Python 3](https://www.python.org/downloads/) | ||
1. Get HARFANG 3D | ||
1. Either download it from the [HARFANG website](https://www.harfang3d.com/releases/3.2.0/) and follow the [install instructions](https://www.harfang3d.com/docs/3.2.0/man.cpython/) | ||
1. Or, using PIP in the command line, type '*pip install -Iv harfang==3.2.0*' | ||
1. Clone/download this repository | ||
1. run *main.py* | ||
|
||
## Credits | ||
* Python programming : François Gutherz, Eric Kernin | ||
* Release : Clément Beudot | ||
|
||
## Screenshots |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Animations | ||
|
||
import harfang as hg | ||
from math import cos, pi | ||
|
||
|
||
class Animations: | ||
animations = [] | ||
|
||
TWEEN_COS = 0 | ||
TWEEN_EASEINQUAD = 1 | ||
|
||
@staticmethod | ||
def interpolation_lineaire(a, b, t): | ||
return a * (1 - t) + b * t | ||
|
||
@staticmethod | ||
def interpolation_cosinusoidale(a, b, t): | ||
return Animations.interpolation_lineaire(a, b, (-cos(pi * t) + 1) / 2) | ||
|
||
@staticmethod | ||
def easeInQuad(t, b, c, d): | ||
t /= d | ||
return c * t * t + b | ||
|
||
@staticmethod | ||
def minimize_angle_delta(angle_strt, angle_dest): | ||
delta = angle_dest - angle_strt | ||
if abs(delta) > pi: | ||
delta_min = 2*pi - abs(delta) | ||
if angle_strt > angle_dest: | ||
return angle_strt + delta_min | ||
else: | ||
return angle_strt - delta_min | ||
return angle_dest | ||
|
||
@classmethod | ||
def minimize_rotation_vec3(cls, rot_start, rot_dest): | ||
rot_dest.x = cls.minimize_angle_delta(rot_start.x, rot_dest.x) | ||
rot_dest.y = cls.minimize_angle_delta(rot_start.y, rot_dest.y) | ||
rot_dest.z = cls.minimize_angle_delta(rot_start.z, rot_dest.z) | ||
|
||
@classmethod | ||
def update_animations(cls, t): | ||
flag_end = True | ||
for anim in cls.animations: | ||
flag_end &= anim.update(t) | ||
return flag_end | ||
|
||
@classmethod | ||
def clear_animations(cls): | ||
cls.animations = [] | ||
|
||
@classmethod | ||
def is_running(cls): | ||
if len(cls.animations) == 0: | ||
return False | ||
return True | ||
|
||
|
||
class Animation: | ||
|
||
def __init__(self, t_start, delay, v_start, v_end, tween_type=Animations.TWEEN_COS): | ||
self.t_start = t_start | ||
self.delay = delay | ||
self.v_start = v_start | ||
self.v_end = v_end | ||
self.v = v_start | ||
self.tween_type = tween_type | ||
self.flag_end = False | ||
Animations.animations.append(self) | ||
|
||
def update(self, t): | ||
if t > self.t_start + self.delay: | ||
self.v = self.v_end | ||
self.flag_end = True | ||
elif t >= self.t_start: | ||
if self.tween_type == Animations.TWEEN_COS: | ||
self.v = Animations.interpolation_cosinusoidale(self.v_start, self.v_end, (t - self.t_start) / self.delay) | ||
elif self.tween_type == Animations.TWEEN_EASEINQUAD: | ||
self.v = Animations.easeInQuad((t - self.t_start), self.v_start, self.v_end-self.v_start, self.delay) | ||
else: | ||
self.v = self.v_start | ||
return self.flag_end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"profiles": { | ||
"default": { | ||
"generate-probe": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"anim_policy":"1" | ||
"anim_simplify_color_tolerance":"0.001000" | ||
"anim_simplify_rotation_tolerance":"0.100000" | ||
"anim_simplify_scale_tolerance":"0.001000" | ||
"anim_simplify_translation_tolerance":"0.001000" | ||
"detect_geometry_instances":"1" | ||
"fbx_file_path":"c:/WORKS/harfang/hg2/website-tutorials_hg2/game-snooker-hg2/works/table_hole.fbx" | ||
"finalizer_script":"" | ||
"fix_geometry_orientation":"1" | ||
"frames_per_second":"24" | ||
"geometry_policy":"1" | ||
"geometry_scale":"1.000000" | ||
"import_animations":"0" | ||
"material_policy":"1" | ||
"max_smoothing_angle":"70.000000" | ||
"output_folder":"pool/table_hole" | ||
"profile":"1" | ||
"recalculate_normals":"0" | ||
"recalculate_tangents":"0" | ||
"scale":"1.000000" | ||
"scene_policy":"1" | ||
"texture_policy":"1" | ||
"use_finalizer_script":"0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"c:/WORKS/harfang/hg2/website-tutorials_hg2/game-snooker-hg2/works/ground_shadow.fbx":"_prod/c292a3f5-4353-6542-9ecf-a69c61add993" | ||
"c:/WORKS/harfang/hg2/website-tutorials_hg2/game-snooker-hg2/works/table_hole.fbx":"_prod/d4a354c6-7ded-864d-9d6f-2d03ac73dd04" | ||
"d:/Movida/gits/eric/website-tutorials_hg2/game-snooker-hg2/work/light_model/light_model_export.fbx":"_prod/5f5e2591-618f-405b-fed5-f7ee56d11a11" | ||
"d:/Movida/gits/eric/website-tutorials_hg2/game-snooker-hg2/work/pool_col_shape.fbx":"_prod/2726ed59-2957-4823-c69d-bfb61e99e2d9" | ||
"d:/Movida/gits/eric/website-tutorials_hg2/game-snooker-hg2/work/pool_v2.fbx":"_prod/c09ff16d-9f46-4aa1-bb6c-b9df1a822a96" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"profiles": { | ||
"default": { | ||
"generate-probe": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"profiles": { | ||
"default": { | ||
"generate-probe": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"profiles": { | ||
"default": { | ||
"generate-probe": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"profiles": { | ||
"default": { | ||
"generate-probe": true, | ||
"max-probe-size": 256, | ||
"radiance-edge-fixup": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <forward_pipeline.sh> | ||
|
||
SAMPLER2D(u_color, 0); | ||
SAMPLER2D(u_attr0, 1); | ||
|
||
uniform vec4 u_dir; | ||
uniform vec4 u_sigma; // x: pos, y: normal, z: depth, w: depth weight cutoff | ||
|
||
void main() { | ||
const float epsilon = 1.e-6; | ||
|
||
ivec2 p0 = ivec2(gl_FragCoord.xy); | ||
ivec2 offset = ivec2(u_dir.xy); | ||
|
||
vec4 c0 = texelFetch(u_color, p0, 0); | ||
vec4 v0 = texelFetch(u_attr0, p0, 0); | ||
|
||
float w = 3.0 / 8.0; | ||
vec4 c = w * c0; | ||
|
||
float falloff = 1.0 / (sqrt(2.0) * u_sigma.x); | ||
|
||
int i; | ||
float ws; | ||
|
||
ws = 1.0 / 4.0; | ||
for(i=1; i<=2; i++) { | ||
ivec2 p1; | ||
vec4 v1; | ||
float wn, dz, wz, wp, w1, d; | ||
|
||
ivec2 delta = offset * i; | ||
float d2 = dot(vec2(delta), vec2(delta)); | ||
wp = exp(-d2 * falloff); | ||
|
||
// right | ||
p1 = p0 + delta; | ||
v1 = texelFetch(u_attr0, p1, 0); | ||
|
||
dz = abs(v1.w - v0.w); | ||
wz = exp(-dz / u_sigma.z); | ||
wz *= step(u_sigma.w, wz); | ||
|
||
wn = pow(max(0.0, dot(v1.xyz, v0.xyz)), u_sigma.y); | ||
w1 = ws * wn * wz * wp; | ||
|
||
w += w1; | ||
c += w1 * texelFetch(u_color, p1, 0); | ||
|
||
// left | ||
p1 = p0 - delta; | ||
v1 = texelFetch(u_attr0, p1, 0); | ||
|
||
dz = abs(v1.w - v0.w); | ||
wz = exp(-dz / u_sigma.z); | ||
wz *= step(u_sigma.w, wz); | ||
|
||
wn = pow(max(0.0, dot(v1.xyz, v0.xyz)), u_sigma.y); | ||
w1 = ws * wn * wz * wp; | ||
|
||
w += w1; | ||
c += w1 * texelFetch(u_color, p1, 0); | ||
|
||
ws *= ws; | ||
} | ||
|
||
gl_FragColor = c / w; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vec3 a_position : POSITION; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$input a_position | ||
|
||
#include <forward_pipeline.sh> | ||
|
||
void main() { | ||
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <forward_pipeline.sh> | ||
|
||
SAMPLER2D(u_color, 0); | ||
SAMPLER2D(u_attr0, 1); | ||
SAMPLER2D(u_depth, 2); | ||
|
||
void main() { | ||
ivec2 pos = ivec2(gl_FragCoord.xy) * 2; | ||
|
||
vec4 v0 = texelFetchOffset(u_attr0, pos, 0, ivec2(0,0)); | ||
vec4 v1 = texelFetchOffset(u_attr0, pos, 0, ivec2(1,0)); | ||
vec4 v2 = texelFetchOffset(u_attr0, pos, 0, ivec2(0,1)); | ||
vec4 v3 = texelFetchOffset(u_attr0, pos, 0, ivec2(1,1)); | ||
|
||
vec4 c0 = texelFetchOffset(u_color, pos, 0, ivec2(0,0)); | ||
vec4 c1 = texelFetchOffset(u_color, pos, 0, ivec2(1,0)); | ||
vec4 c2 = texelFetchOffset(u_color, pos, 0, ivec2(0,1)); | ||
vec4 c3 = texelFetchOffset(u_color, pos, 0, ivec2(1,1)); | ||
|
||
vec4 z0 = texelFetchOffset(u_depth, pos, 0, ivec2(0,0)); | ||
vec4 z1 = texelFetchOffset(u_depth, pos, 0, ivec2(1,0)); | ||
vec4 z2 = texelFetchOffset(u_depth, pos, 0, ivec2(0,1)); | ||
vec4 z3 = texelFetchOffset(u_depth, pos, 0, ivec2(1,1)); | ||
|
||
vec2 tmp = floor(mod(gl_FragCoord.xy, 2.0)); | ||
#if AAA_DOWNSAMPLE_CHECKERBOARD | ||
float checkerboard = tmp.x + tmp.y - 2.0*tmp.x*tmp.y; | ||
|
||
vec4 v_min = (v0.w < v1.w) ? v0 : v1; | ||
vec4 c_min = (v0.w < v1.w) ? c0 : c1; | ||
vec4 z_min = (v0.w < v1.w) ? z0 : z1; | ||
vec4 v_max = (v0.w > v1.w) ? v0 : v1; | ||
vec4 c_max = (v0.w > v1.w) ? c0 : c1; | ||
vec4 z_max = (v0.w > v1.w) ? z0 : z1; | ||
|
||
v_min = (v_min.w < v2.w) ? v_min : v2; | ||
c_min = (v_min.w < v2.w) ? c_min : c2; | ||
z_min = (v_min.w < v2.w) ? z_min : z2; | ||
v_max = (v_max.w > v2.w) ? v_max : v2; | ||
c_max = (v_max.w > v2.w) ? c_max : c2; | ||
z_max = (v_max.w > v2.w) ? z_max : z2; | ||
|
||
v_min = (v_min.w < v3.w) ? v_min : v3; // mix(v_min, v3, step(v_min.w, v3.w)); | ||
c_min = (v_min.w < v3.w) ? c_min : c3; | ||
z_min = (v_min.w < v3.w) ? z_min : z3; | ||
v_max = (v_max.w > v3.w) ? v_max : v3; // mix(v_max, v3, step(v3.w, v_max.w)); | ||
c_max = (v_max.w > v3.w) ? c_max : c3; | ||
z_max = (v_max.w > v3.w) ? z_max : z3; | ||
|
||
gl_FragData[0] = mix(c_min, c_max, checkerboard); | ||
gl_FragData[1] = mix(v_min, v_max, checkerboard); | ||
gl_FragData[2] = mix(z_min, z_max, checkerboard); | ||
#else | ||
vec4 v_min = (v0.w < v1.w) ? v0 : v1; | ||
vec4 c_min = (v0.w < v1.w) ? c0 : c1; | ||
vec4 z_min = (v0.w < v1.w) ? z0 : z1; | ||
|
||
v_min = (v_min.w < v2.w) ? v_min : v2; | ||
c_min = (v_min.w < v2.w) ? c_min : c2; | ||
z_min = (v_min.w < v2.w) ? z_min : z2; | ||
|
||
v_min = (v_min.w < v3.w) ? v_min : v3; | ||
c_min = (v_min.w < v3.w) ? c_min : c3; | ||
z_min = (v_min.w < v3.w) ? z_min : z3; | ||
|
||
gl_FragData[0] = c_min; | ||
gl_FragData[1] = v_min; | ||
gl_FragData[2] = z_min; | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vec3 a_position : POSITION; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$input a_position | ||
|
||
#include <forward_pipeline.sh> | ||
|
||
void main() { | ||
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0)); | ||
} |