Giter Site home page Giter Site logo

ekiefl / pooltool Goto Github PK

View Code? Open in Web Editor NEW
107.0 107.0 28.0 390.64 MB

A sandbox billiards game that emphasizes realistic physics

Home Page: https://ekiefl.github.io/projects/pooltool/

License: Apache License 2.0

Python 93.23% PLSQL 0.03% Batchfile 0.01% TeX 6.73%
billiards eight-ball panda3d physics pool python simulation snooker

pooltool's Introduction

pooltool's People

Contributors

chaochaodev avatar edoson avatar ekiefl avatar kerby2000 avatar zhaodong-wang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pooltool's Issues

Animation performance issues

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

Can not install panda3d 1.10.10

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

Pip installation not working correctly

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'

Essential docstring coverage is missing

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

  • System
  • MultiSystem
  • simulate
  • continuize
  • ShotViewer
  • PhysicsEngine

Balls

  • Ball
  • BallState
  • BallParams
  • BallHistory
  • BallSet
  • BallOrientation
  • get_ball_set

Cue

  • Cue
  • CueSpecs

Table

  • Table
  • TableType
  • PocketTableSpecs
  • BilliardTableSpecs
  • SnookerTableSpecs
  • CushionSegments
  • LinearCushionSegment
  • CircularCushionSegment
  • Pocket
  • CushionDirection
  • TableModelDescr

Events

  • Event
  • EventType
  • AgentType
  • Agent
  • filter_ball
  • filter_time
  • filter_type
  • filter_events
  • by_type
  • by_ball
  • by_time
  • null_event
  • ball_ball_collision
  • ball_linear_cushion_collision
  • ball_circular_cushion_collision
  • ball_pocket_collision
  • stick_ball_collision
  • spinning_stationary_transition
  • rolling_stationary_transition
  • rolling_spinning_transition
  • sliding_rolling_transition

Game

  • GameType
  • ThreeCushion
  • EightBall
  • NineBall
  • Ruleset
  • Player
  • SumToThree
  • Snooker
  • get_ruleset
  • get_rack
  • get_eight_ball_rack
  • get_nine_ball_rack
  • get_three_cushion_rack
  • get_snooker_rack

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"

ImportError when trying to load the app (M1 mac)

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

error re-installing panda3d

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

Render primitive rails

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.

Panda3d 1.10.13 relative mouse mode workaround

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 😄.

Redo cue stick trajectory calculations

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):

Windows issue list?

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

Toggleable graphics options

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:

  1. Choose fps (30/60)
  2. Hide room (y/n)
  3. Shadow casting (y/n)
  4. Shaders (y/n) (can turn off with render.set_shader_off())
  5. Audio (y/n)

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().

Clings/skids

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)?

Asymmetrical behaviour in Han cushion code

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

phi = math.angle(rvw_R[1]) % (2 * np.pi)

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

https://github.com/tailuge/billiards/blob/c5aa067cc4caf444cc2057d72ae69b3349a3e1bc/src/model/physics/physics.ts#L108

Let me know if I am wrong about this, thanks in advance.
Luke

xml error when save new table

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'?

Create in-game options menu

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.

Implement 3D ball trajectories

  • Trajectories
  • Airborne ball state
  • Ball-slate collisions
  • Ball-ball collisions with 3D
  • Ball-pocket collisions with 3D
  • Ball-cushion collisions with 3D

Jump or masse shots?

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?

Installing on linux

Just some quick feedback on my linux install experience of pooltool.

  • Debian 12 installs ok, crashes when run
  • Arch installs ok, runs ok. Works in both Gnome and Xfce desktops and looks fantastic with solid framerate.

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)

Undo shot does not store cue elevation

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?

Roadmap #1

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.

get_eight_ball_rack is broken

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.

Instructions

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.

Milestones for v0.2

  • settings available in menu
  • installer for mac
  • screen size
  • fix mouse locking

Rk x w

in the first article,“Rk x w” the k what does it represent ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.