ekiefl / pooltool Goto Github PK
View Code? Open in Web Editor NEWA sandbox billiards game that emphasizes realistic physics
Home Page: https://ekiefl.github.io/projects/pooltool/
License: Apache License 2.0
A sandbox billiards game that emphasizes realistic physics
Home Page: https://ekiefl.github.io/projects/pooltool/
License: Apache License 2.0
Hi, it is a great project, do you have any plan to support Snooker ?
In the last 2 weeks I've discovered just how realistic pooltool graphics could become. Prior to my investment in the graphics
branch, I had assumed graphical capabilities of panda3d were bad (I think this is owed to a lot of amateur projects floating around, and a lack of impressive tech showcases). However, I'm now realizing that pooltool could actually rival or surpass VirtualPool4's graphics, for example. For the most part this is due to simplepbr (simple, physical-based rendering).
Of course, with increased graphics comes increased performance costs. The problem is that I don't actually no what is expensive and what isn't. I need to perform a systematic study on how the following things affect FPS.
Poly count
Normal smoothing (Mesh>Normals>Smooth Vectors>Factor>1)
Normal/roughness mapping (fingerprints, floorboards)
Texture image quality (ambientcg is amazing)
Number of lights
Shadow casting
With all of these ramped up, my macbook (with an CPU-integrated GPU) at times will dip below 15 fps depending on what else I'm doing. Yet being able to use pooltool on weak machines is necessary for my vision. So I think graphics options need to be toggleable.
Here is what I'm imagining:
render.set_shader_off()
)In making this list, it seems like turning off shaders drastically improves performance. I get 120 fps on my macbook with render.set_shader_off()
.
Create a mode to move balls on the table.
The state of the code is becoming more and more complex, and I need to simplify the design for my sanity. At the same time, I have written so many classes and functions that docs have become important, even if for no other reason than for my own personal use. Here are a couple of things I need to do, and I'm pretty sure it should be in this order.
objects
is getting huge, and I think it would be better to move object type, e.g. Ball
along with its child classes BallRender
, BallHistory
, etc., into their own submodules. engine
may be better called system
, and all algorithm stuff may be best put in a shot_algorithm
submodule that contains a class that can select whichever algorithm to use based on keyword.It seems that Pooltool doesn't work with touchpad
Methods related to tracking and calculating the cue stroke are currently housed in CueRender, despite these methods having to do with stroke mechanics, not rendering directly.
def track_stroke(self):
"""Initialize variables for storing cue position during stroke"""
def append_stroke_data(self):
"""Append current cue position and timestamp to the cue tracking data"""
def set_stroke_sequence(self):
"""Initiate a stroke sequence based off of self.stroke_pos and self.stroke_time"""
def get_stroke_times(self, as_index=False):
"""Get key moments in the trajectory of the stroke
def is_shot(self):
in the first article,“Rk x w” the k what does it represent ?
Implement pocket's via https://ekiefl.github.io/2020/12/20/psim-alg/#-ball-pocket-collision-times
Note: this task should really be accomplished after #5
Hi, this is a very nice open source tool. I'm wondering since it's 3D model, does it support jump shot or masse shot? Or any tiny jumps of the cue ball when the cue is not leveled?
Hey hey. As I noticed, there is no deflection on a cue ball, when I try maximum side spin.
I recreated this setup: https://youtu.be/h_x1XPqVBIM?t=90
and got totally different results.
I want to contribute, but I am terrible with physics. Could you give a direction on where to start from?
edit: sorry title is a little bit misleading.
Originally I wanted to ask about this part: https://youtu.be/h_x1XPqVBIM?t=490
Implement cushions using collision plane cushion segments: https://ekiefl.github.io/2020/12/20/psim-alg/#-ball-cushion-collision-times
This will allow for finite cushion segments and pave way for pockets.
version: 0.2.2.1
gist with stacktrace
Currently, pressing esc brings players back to main menu. Instead, in-game option menu should pop up with the ability to modify physics, game rules, etc.
If you raise the cue elevation, then take a shot (either with or in stroke mode), the cue elevation is usually returned to the minimum (not always). Isn't that a fun bug?
I can't figure out how the controls work. It might be helpful to have a Controls
page on the main menu to explain how to adjust all of the parameters and then actually take a shot.
I tried to install the project on two different machines using the pip install method and in both instances the package seemed to not be correctly installed. When trying to run the snippet provided on the readme section, the script failed to import any of the necessary classes, only having access to the constants.
Code example
#! /usr/bin/env python
import pooltool as pt
interface = pt.ShotViewer()
table = pt.PocketTable()
balls = pt.get_nine_ball_rack(table, ordered=True)
cue = pt.Cue(cueing_ball=balls['cue'])
# Aim at the head ball then strike the cue ball
cue.aim_at_ball(balls['1'])
cue.strike(V0=8)
# Evolve the shot
shot = pt.System(cue=cue, table=table, balls=balls)
shot.simulate(continuize=True)
interface.show(shot)
Error
Traceback (most recent call last):
File "...\test.py", line 5, in <module>
interface = pt.ShotViewer()
AttributeError: module 'pooltool' has no attribute 'ShotViewer'
AFAIK, the friction for these balls are responsible for throws and clings/skids are caused when a high-friction spot (where it is a chalk mark) is happened to be at contact point.
However, a paper about Bounce Maps makes me curious because the idea of spatially-varying physical properties are nothing new, can something like this be applied for the friction instead of elasticity and these maps are dynamically changing (every time a cue strikes the ball, it imparts high-friction spot where there is a chalk mark)?
Should you perhaps put up a list of all the issues on Windows, the choice of over 80% of desktop users, to make us aware of what works and what doesn't?
Are you aware of these, for example:
Permission denied for Temp when taking next shot
List index out of range when flicking mouse too quickly
Panda3D 1.10.13's "relative" mouse mode does not work on Windows. I can see from this panda3d issue that @ekiefl is already familiar with the problem and has previously reached out to the maintainers. To date, panda3d 1.11.0 is yet to be released.
Despite being unreleased, Panda3d's install instructions detail a user-friendly way to install the current dev build of 1.11.0 using pip:
pip install --pre --extra-index-url https://archive.panda3d.org/ panda3d
In order to install the dev build of panda3d, I first needed to uninstall the existing version:
pip uninstall panda3d -y
From my (very limited) testing, it seems that "panda3d-1.11.0.dev3179" works as a drop-in replacement for 1.10.13. It solves the relative mouse error, and from what I can tell as a new user, the tool seems to work as intended. It's obviously bad practice to take dependency on pre-release versions of software, but as a workaround that brings usability back to a whole platform I think the install instructions can be updated with the above information. I'd say that the GUI can be considered to support Windows,
with the caveat that the workaround relies on a potentially unstable pre-release version of panda3d.
Obviously this requires further testing to ensure that it doesn't break existing functionality - but at least for me, this allows me to use the tool and hopefully get familiar enough to start modifying & contributing to the codebase 😄.
Is the modulo on your calculation of Phi losing the y direction sign information in this line ?
phi = math.angle(rvw_R[1]) % (2 * np.pi)
is always a +ve quantity
I set up a test case bouncing a ball to two symmetrically equivalent directions and observed that the outcomes were not matching. This led me to remove the modulo in my version of the code.
https://tailuge.github.io/billiards/dist/diagrams/symmetry.html
Let me know if I am wrong about this, thanks in advance.
Luke
Hi,
I'm on MacOS with apple M1 chip. Installation went smooth, but when trying to run (python run_pooltool
) I get the following error:
Traceback (most recent call last):
File "run_pooltool", line 6, in <module>
from pooltool.ani.animate import Play
File "/Users/idodavid/dev/pooltool/pooltool/__init__.py", line 8, in <module>
import pooltool.ani.utils as autils
File "/Users/idodavid/dev/pooltool/pooltool/ani/utils.py", line 7, in <module>
from pandac.PandaModules import NodePath, PGItem, Vec4
File "/Users/idodavid/miniforge3/envs/pooltool/lib/python3.8/site-packages/pandac/PandaModules.py", line 28, in <module>
from panda3d.vision import *
ImportError: dlopen(/Users/idodavid/miniforge3/envs/pooltool/lib/python3.8/site-packages/panda3d/vision.cpython-38-darwin.so, 0x0002): Library not loaded: lib/libopencv_imgproc.2.4.dylib
Some binaries are probably missing, or a path should be set?
Will appreciate any help,
Ido
when is Elastic, instantaneous coming? been waiting for it from long
Currently, camera is centered behind the ball, but when english is applied, it feels more intuitive to center camera behind cue stick
The invisible rails are quite an eyesore. A proper rendering of the table should eventually be undertaken, but since I am going to procedurally render the table, this will be a monumental task. In the mean time, some quick rails represented as lines should be thrown in.
Shot calculation is now close to instantaneous, but animating shots are still slow.
[X] - Add pprofile class to utils (and address discovered problems)
[ ] - Create fast implementation of continuize
[X] - Create less dense LERP intervals
line 183, in center_by_table self.balls[-1].R, AttributeError: 'Ball' object has no attribute 'R'
It looks like line 183 should be self.balls[-1].params.R
. I don't know pooltool well enough yet to know if this is my mistake or a missed refactoring issue.
when I create a new table , the error occured:
pooltool\pooltool\ani\menu.py", line 1019, in func_save_table for dropdown in self.xml.root.findall(".//*[@name='new_table']/dropdown"): AttributeError: 'XMLMenu' object has no attribute 'root'. Did you mean: 'roots'?
In order of importance, here is what needs to be documented.
First of all, (almost) everything that is in the top-level API (aka pooltool/__init__.py
), in order of importance:
Highest level stuff
Balls
Cue
Table
Events
Game
We'll see how long this takes me, and if I have energy for more afterwards. After this, I think pooltool qualifies for having "essential docstring coverage"
Hi
When I started installing pooltool , python does not find panda3d 1.10.10 package, also I could not find required package anywhere to install. So, I can not install pooltool on windows 10, python 3.11
Hi -
There is an error when installing the archive one and as a result I am not able to run_pooltool.bat - I am on windows - can you advise please? thanks
pip install --pre --extra-index-url https://archive.panda3d.org/ panda3d
Found existing installation: Panda3D 1.10.13
Uninstalling Panda3D-1.10.13:
Successfully uninstalled Panda3D-1.10.13
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
Looking in indexes: https://pypi.org/simple, https://archive.panda3d.org/
Collecting panda3d
Downloading https://buildbot.panda3d.org/downloads/78f8e1eaa95071ae21c2f6d8f16768c7330c5f15/panda3d-1.11.0.dev3306-cp39-cp39-win_amd64.whl (61.2 MB)
---------------------------------------- 61.2/61.2 MB 10.1 MB/s eta 0:00:00
WARNING: Ignoring invalid distribution -ip (c:\python39\lib\site-packages)
Installing collected packages: panda3d
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pooltool-billiards 0.2.1 requires panda3d==1.10.13, but you have panda3d 1.11.0.dev3306 which is incompatible.
Successfully installed panda3d-1.11.0.dev3306
Just some quick feedback on my linux install experience of pooltool.
I had to use pipx
to install and the python version was 3.11
However it is tricky to use with a mouse because unlike MacOS when the mouse leaves the window events are no longer forwarded to the app, and after aiming +/-10 degrees the screen flicks straight again. Similarly when hitting the ball pushing mouse forward it travels out of the window and no shot is played. Same story full screen - mouse events stop at border.
As for using the API I am not experienced with Python enough to say. I believe pipx
is not the right method as it is more for executing code. I went on to try python venv
approach but still had issue with import not finding pooltool (it could find PoolTool)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.