Git Product home page Git Product logo

ursina's Introduction

ursina ʕ •ᴥ•ʔゝ□

An easy to use game engine/framework for python.

Banner

Trailer

Getting Started

  1. Install Python 3.6 or newer. https://www.python.org/downloads/
  2. Open cmd/terminal and type:
pip install ursina

If you want to install the newest version from git, you can install like this:

pip install git+https://github.com/pokepetter/ursina.git

If you want to easily edit the source, it's recommended to clone the git repo and install as develop like this. Make sure you have git installed. https://git-scm.com/

git clone https://github.com/pokepetter/ursina.git
python setup.py develop

Also install any of the optional dependencies you want from the list below, or install them all with:

pip install ursina[extras]

On some systems you might have to use pip3 instead of pip in order to use Python 3 and not the old Python 2.

Dependencies

  • python 3.6+
  • panda3d
  • pillow, for texture manipulation
  • psd-tools, for converting .psd files
  • blender, for converting .blend files
  • pyperclip, for copy/pasting

Examples

from ursina import *            # this will import everything we need from ursina with just one line.

app = Ursina()
ground = Entity(
    model = 'cube',
    color = color.magenta,
    z = -.1,
    y = -3,
    origin = (0, .5),
    scale = (50, 1, 10),
    collider = 'box',
    )

app.run()                       # opens a window and starts the game.

How do I make a game?

Ursina games are made by writing Python code. You can use any text editor you want, but personally I like to use Atom.

  1. Create an empty .py file called ursina_game.py
  2. Copy this text into your new file:
from ursina import *           # this will import everything we need from ursina with just one line.

app = Ursina()

player = Entity(
    model = 'cube' ,           # finds a 3d model by name
    color = color.orange,
    scale_y = 2
    )

def update():                  # update gets automatically called by the engine.
    player.x += held_keys['d'] * .1
    player.x -= held_keys['a'] * .1


app.run()                     # opens a window and starts the game.
  1. Type this in the terminal to start the game:

    python ursina_game.py
    

    If you use Atom, I recommend installing the package atom-python-run to run your scripts with the press of a button.

  2. You can now move the orange box around with 'a' and 'd'!

    To close the window, you can by default, press shift+q or press the red x. to disable this, write window.exit_button.enabled = False somewhere in your code.

Project Structure

## Project Structure

📁docs
    📃index.txt
    📃documentation.txt
    📃inventory_tutorial.txt
    ...
        # text files for the website. gets turned into .html files with sswg.

    📃cheat_sheet.html
        # auto generated documentation made with documentation_generator.py.

    📃tutorial_generator.py
        # turns specific .py files into .txt files, which can then be turned into .html by sswg.
        # this extracts the comments from the source files into description for that step and the code after into code blocks.
        # see platformer_tutorial.py for an example.

📁samples               # small example games.

📁ursina                # the actual ursina module.
    📁audio                 # built-in audio clips.
    📁editor                # the 3d level editor for ursina.
    📁fonts                 # built-in fonts.
    📁models                # .blend files, source files, for built-in 3d models.
        📁procedural            # classes for generating 3d models, like Cylinder, Quad and Terrain.
    📁models_compressed     # .blend files converted to .ursinamesh.
    📁prefabs               # higher level classes like Draggable, Slider, Sprite, etc.

    📃__init__.py
    📃application.py
    📃audio.py
    ...
        # ursina base modules, like code for Entity, input_handler, Text, window and so on.

ursina's People

Contributors

a2cy avatar ahmad-a0 avatar albfan avatar binary-sequence avatar bt530 avatar carlsonmark avatar cclauss avatar clayboone avatar dandiez avatar diamondsbattle avatar jakeroggenbuck avatar konvay avatar luengor avatar makiyu-py avatar mozzo1000 avatar mxp2095onetechguy avatar petteramland avatar philipcander avatar philippeitis avatar pokepetter avatar ryancollingwood avatar snoroz avatar sorendeveloppement avatar squigglecito avatar tanay-errorcode avatar tannnxr avatar tech-helper503 avatar tom-fredricksondm avatar werxzy avatar whutch 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  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

ursina's Issues

How to compile game?

Hi!
I have a problem with compiling a game.Its nothing fancy, just wanted to try it out. In the FAQ on the ursinaengine.org i found how to do it. I tried it and in just copied python. Nothing else. Can someone tell me what am i doing wrong? Thanks!

Axis orientation

Is there a way to use custom axis orientation? Like in Blender for example.

Official pronunciation?

Some FOSS projects with odd names have a pronunciation in the readme. Either using IPA or sounding it out like err-seen-a

Ursina for dummies

Hi,

I wrote this for my son but also tried to make it so that it might be used by other people trying to learn the engine. This is completely draft but I have tested each step and verified working. Please read and add to your code base, maybe format it a bit.

Regards,
Guimo

ursina_for_dummiestxt.txt

get_mouse_position() not working

So I'm trying to create a simple world editor using Ursina Engine, but when I looked on the documentation I couldn't find anything that would help me with the mouse position. I did already tried doing mouse.position, but the output wasn't an integer. And when I tried get_mouse_position() it wasn't there. So by any chance would you help me by either telling me if my code is wrong, or maybe showing me where in your code you have the Cursor() function or any other function that uses the position of the mouse. Thanks love your engine. if held_keys['left mouse down']: player.x = mouse.position

Error in compilation with Nuitka

Hi !

Very interested in the ursina project, I wanted to test a little puzzle coding to test the game engine.
However, once finished, I tried to compile it with nuitka simply using:
python -m nuitka --standalone --mingw64 --show-progress --show-scons --follow-imports khun-pan.py
(the code : here)

I ended up with this error, which seems to be related to panda3d.

Warning: unable to auto-locate config files in directory named by "<auto>etc".
package_folder: D:\Ursina\Test_Project\khun_pan\khun-pan.dist\ursina
asset_folder: D:\Ursina\Test_Project\khun_pan\khun-pan.dist
blender_paths:
{}
psd-tools not installed
missing model: quad
Known pipe types:
(all display modules loaded.)
Traceback (most recent call last):
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\khun-pan.py", line 150, in <module>
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\ursina\main.py", line 9, in __init__
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\direct\showbase\ShowBase.py", line 289, in __init__
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\direct\showbase\ShowBase.py", line 959, in openDefaultWindow
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\direct\showbase\ShowBase.py", line 995, in openMainWindow
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\direct\showbase\ShowBase.py", line 707, in openWindow
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\direct\showbase\ShowBase.py", line 687, in <lambda>
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\direct\showbase\ShowBase.py", line 759, in _doOpenWindow
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\direct\showbase\ShowBase.py", line 597, in makeDefaultPipe
  File "D:\Ursina\Test_Project\khun_pan\khun-pan.dist\direct\directnotify\Notifier.py", line 130, in error
Exception: No graphics pipe is available!
Your Config.prc file must name at least one valid panda display
library via load-display or aux-display.

Any idea how to fix it?

Thanks a lot.

Wrong rotations

This is the bug:
Entity.rotation_z rotates on the y-axis
Entity.rotation_y rotates on the z-axis.

Vertical line is z-axis.

on panda3D, setHpr signature is this:
z = heading/yaw
x = pitch
y = roll
setHpr(z, x, y)

Mouse Velocity Issues - macOS [10.15.6]

Here I am with another macOS related issue.

I have 2 computers, one running Windows, and one running macOS. I wanted to make a first-person game, so I locked the mouse and took the velocity as the input for how the camera is rotated. It works fine on Windows - buttery smooth. On macOS, it is far more jittery, and some times the view just "jumps" to a completely different orientation. Are there any workarounds for this? Or is there a simple fix I'm not aware of?

EDIT:
I found that the velocity just spikes, even though it should be a semi-constant movement. While moving, mouse.velocity is nearly always 0 on every axis. Without mouse locking, it behaves the same - except the mouse is obviously not locked.

EDIT 2:
I don't understand why it's even happening - mouse.py looks fine to me. The only reason it would return 0 is if the mouse wasn't moving.

EDIT 3:
If more than one instance of update() is running at the same time, it could just be constantly setting the mouse to 0 before any script has a chance to read a value???? I'm not good at Python, but I do want this to work. I hope someone has a solution...

Move game window

Hey I had try some tutorials for minutes, and the game window cannot moving to another screen is bothering me a lot, it block my vscode window for "real-time".

Is there any solution to make a "move bar"(Window title) ?

numpy not among dependencies but is required to create Terrain.

Bug Description

numpy appears to be a required dependency to run Ursina but was not included in the installation process. This was discovered per the steps below. Installing the latest numpy build resolved the issue, so I suspect this was just a simple oversight.

Steps to Reproduce

Follow the ursina_for_dummies tutorial and attempt to load a Terrain, as shown in the cheat_sheet:

    Entity(model=Terrain('heightmap_1', skip=4), scale=(20,5,20), texture='heightmap_1')

Converting ui cordinates into entity cordinates

Is there a function or some easy way to do this ? I tried to get the ratio between the mouse ui cords and an entity's cords but the resulting ratio was never consistent.

Any help is appreciated

Guide on how to texture an object

This game engine is amazing! Unfortunately, especially to those not so experienced with 3d modelling / game development in general, it's quite hard to understand how to apply textures to the models.

A guide on that would be great. Just two examples which I don't know how to realize:

  • I have a cube entity. The default one. How can I create a cube map texture (so not the same texture for every side of the cube) for it through the official Ursina engine? What does my texture need to look like? What methods do I need to call? Maybe I would like to texture your Minecraft code sample.

  • I have modelled some basic stuff in blender. Let's say it's a low-poly car. I just switched to edit mode, pulled around some corners and then exported to a .obj file. How would I texture that one? Would I have to apply textures in Blender and somehow export them? I'm lost.

Thank you for your great work so far!

Procedural Primitives not working

I was looking around at the prefabs and tried to test out the VideoRcorder, and noticed I was getting an error at the procedural primitive call "RedCube()". Here's the error log:

File "ursina_game.py", line 6, in <module> cube = primitives.RedCube() File "<string>", line 4, in __init__ File "C:\Users\Kai\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ursina\entity.py", line 80, in __init__ if len(_stack)>2 and 'super().__init__()' in _stack[1].code_context[0]: TypeError: 'NoneType' object is not subscriptable

No window opened on macOS

Hi! I would like to look in to ursina but I can't seem to get the basic examples working. Maybe I'm doing something stupid. I followed the instructions in Ursina Game Engine Tutorial for Dummies to set up a virtualenv:

(venv) $ python3 -m venv venv
(venv) $ . venv/bin/activate
(venv) $ pip install cython
Collecting cython
  Using cached https://files.pythonhosted.org/packages/21/17/135ed3c0b9d4c877af3efed6d5968dd05852aeea84923ce0aa89c045f60f/Cython-0.29.16-cp38-cp38-macosx_10_9_x86_64.whl
Installing collected packages: cython
Successfully installed cython-0.29.16
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) $ pip install git+https://github.com/pokepetter/ursina.git
Collecting git+https://github.com/pokepetter/ursina.git
  Cloning https://github.com/pokepetter/ursina.git to /private/var/folders/zh/qmj7vwqn4ql302y46nl7dp4m0000gn/T/pip-req-build-af1rp9cu
  Running command git clone -q https://github.com/pokepetter/ursina.git /private/var/folders/zh/qmj7vwqn4ql302y46nl7dp4m0000gn/T/pip-req-build-af1rp9cu
Collecting panda3d (from ursina==0.1)
  Using cached https://files.pythonhosted.org/packages/8a/9d/d5a639b31653d85500e82876f146f82f44ded07e7e224daad5cefe82da7e/panda3d-1.10.6.post2-cp38-cp38-macosx_10_9_x86_64.whl
Collecting pillow (from ursina==0.1)
  Using cached https://files.pythonhosted.org/packages/f3/c7/6aac64d950363a017ef8216f86d19ea29872e078f0607231a6b00849b7ad/Pillow-7.1.1-cp38-cp38-macosx_10_10_x86_64.whl
Collecting screeninfo (from ursina==0.1)
  Using cached https://files.pythonhosted.org/packages/d1/1d/d9861700fa0692d39f4aaf7233ee3dd9cbebd514546fec9344a824f63af4/screeninfo-0.6.5.tar.gz
Collecting dataclasses (from screeninfo->ursina==0.1)
  Using cached https://files.pythonhosted.org/packages/26/2f/1095cdc2868052dd1e64520f7c0d5c8c550ad297e944e641dbf1ffbb9a5d/dataclasses-0.6-py3-none-any.whl
Requirement already satisfied: Cython in ./venv/lib/python3.8/site-packages (from screeninfo->ursina==0.1) (0.29.16)
Collecting pyobjus (from screeninfo->ursina==0.1)
  Using cached https://files.pythonhosted.org/packages/cb/9e/6425d66cf66892ee99ebdc86204c825d6817458328b6cdc3a6c51ad152d1/pyobjus-1.1.0.tar.gz
Installing collected packages: panda3d, pillow, dataclasses, pyobjus, screeninfo, ursina
  Running setup.py install for pyobjus ... done
  Running setup.py install for screeninfo ... done
  Running setup.py install for ursina ... done
Successfully installed dataclasses-0.6 panda3d-1.10.6.post2 pillow-7.1.1 pyobjus-1.1.0 screeninfo-0.6.5 ursina-0.1
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Then, when I try to run any of the examples, no window opens, no app shows up in the Dock and the Python process does not respond to ctrl-c, which may be a separate issue:

(venv) $ cat example.py 
from ursina import *                    # Import the ursina engine

app = Ursina()                          # Initialise your Ursina app
app.run()                               # Run the app
(venv) $ python example.py 
package_folder: /Users/michi/Documents/Projects/mygame/venv/lib/python3.8/site-packages/ursina
asset_folder: /Users/michi/Documents/Projects/mygame
dev mode: True
blender_paths:
{}
psd-tools not installed

I'm running macOS 10.13.6. Here is the setup of the virtualenv:

(venv) $ pip list
Package     Version     
----------- ------------
Cython      0.29.16     
dataclasses 0.6         
panda3d     1.10.6.post2
Pillow      7.1.1       
pip         19.2.3      
pyobjus     1.1.0       
screeninfo  0.6.5       
setuptools  41.2.0      
ursina      0.1         
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Panda3d 1.10.6.post2 doesn't have windows wheels

Latest version of Ursina has panda3d 1.10.6.post2 as a dependency. That version doesn't have Windows wheels and thus Ursin installation fails.

According to documentation Ursina should work on Windows.

Distance function from Ursinamath not imported

For the trigger example to be able to run, i had to import the distance function from ursinamath again with the line:

from ursina.ursinamath import distance

I don't exactly see why this was necessary as you already import everything from ursinamath in the second line of your init.py. But maybe i'm doing something wrong here.

Hope this is helping and thank you for your exceptional effort!

Shader files are missing

Currently it's impossible to import ursina due to the fact that rim_shader.py and height_shader.py are missing from the repository.

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from ursina.shaders import colored_lights_shader
  File "/home/rdb/.local/lib/python3.7/site-packages/ursina/shaders/__init__.py", line 5, in <module>
    from ursina.shaders.height_shader import height_shader
ModuleNotFoundError: No module named 'ursina.shaders.height_shader'

Glitch on sphere.py

if __name__ == '__main__':
    app = Ursina()
    Entity(model=Sphere(subdivisions=5), color=color.color(60, 1, 1, .5), x=0)
    Entity(model=Sphere(radius=0.15, subdivisions=6),
           color=color.color(1, 60, 1, .5), x=4)
    origin = Entity(model='quad', color=color.orange, scale=(.05, .05))
    ed = EditorCamera(rotation_speed=200, panning_speed=200)
    Entity(model=Sphere(radius=2), color=color.color(1, 1, 1, .5))
    app.run()

is this normal ?
all other examples working fine except this, something about subdivisions
imagen
with "subdivisions" set, got those rays, without it, i got the sphere without all the faces

  • ryzen 3 3200g
  • igpu
  • 16gb ram
  • b450 aorus mini itx
  • corsair cx 450w

Help on Importing .blend animations

Is there a way to import 3D animations of an object in a .blend file? I was trying it with the Animation and Animator Classes but can't seem to succeed. Is this only for 2D animations?

Screen Tearing [macOS 10.15.6]

I've followed the default example (And tweaked the window settings a bit), but I noticed some screen tearing.

I thought Vsync would fix the issue, so I enabled it (Even though it looks like it's on by default) and it didn't work. Just for kicks, I turned off Vsync, and it still was the same.

Could anyone help me? (I can't get screenshots of the screen tearing, it's a bit hard to do that), but I can give you my code.

Incorrect content of held_keys

I've just dived into code and found some strange thing.

held_keys contains incorrect key events. Just an example of code I used in main function of ursina/input_handler.py:

    hk = None
    def update():
        # Print held_keys on its change
        global hk
        if hk != held_keys:
            hk = held_keys.copy()
            print(held_keys)

Then I pressed some keys and got the following output(with my comments):

defaultdict(<function <lambda> at 0x039CCF60>, {'left mouse down': 1, 'shift': 0})   # Press LMB
defaultdict(<function <lambda> at 0x039CCF60>, {'left mouse down': 1, 'shift': 0, 'left mouse': 0})  # Release LMB
defaultdict(<function <lambda> at 0x039CCF60>, {'left mouse down': 1, 'shift': 0, 'left mouse': 0, 'a': 1}) # Press 'a'
defaultdict(<function <lambda> at 0x039CCF60>, {'left mouse down': 1, 'shift': 0, 'left mouse': 0, 'a': 1, 'a hold': 1}) # Holding 'a'
defaultdict(<function <lambda> at 0x039CCF60>, {'left mouse down': 1, 'shift': 0, 'left mouse': 0, 'a': 0, 'a hold': 1})` # Release 'a'

How can I see mouse release wasn't detected at all. The 'a' button determined as always hold - looks not good.
Is it expected behavior or it is a bug? If bug - please tell wht behavior is expeted

NameError: name 'Ursina' is not defined

Hello,

I installed Ursina using pip (pip install ursina) and checked that it was there using pip list, however when running the example code on this page, I get this error:

Traceback (most recent call last):
File "[redacted]", line 1, in
from ursina import * # Import the ursina engine
File "[redacted]", line 3, in
app = Ursina() # Initialise your Ursina app
NameError: name 'Ursina' is not defined

Code:
from ursina import * # Import the ursina engine

app = Ursina() # Initialise your Ursina app
app.run() # Run the app

I don't know where I have gone wrong. Any help appreciated, cheers.

edit: removed code formatting as it isn't exactly working as i hoped it would.

Clearer representations of rotations

Ursina seems like a nice way to get started with animations and 3D, but the way representations of bodies are stored gave me so much headache today honestly.

First off, the de-facto standard of having the angular positive direction as counter-clockwise positive around each axis is violated. Compare https://www.ursinaengine.org/coordinate_system.html to https://en.wikipedia.org/wiki/Right-hand_rule
Is there a particular reason for that?

Also, I see that the coordinate systems are flipped compared to Panda3D, which makes it even harder to use documentation for Panda3D when documentation is lacking for Ursina:
https://docs.panda3d.org/1.10/python/programming/scene-graph/common-state-changes

I assumed that the Entity.rotation() would return some sort of Euler sequence. So I did a bruteforce search along all possible Euler angles combinations without any match. I didn't reverse engineer the whole thing yet, but I think the root cause lies around here:

self.setHpr(Vec3(value[1], value[0], value[2]) * Entity.rotation_directions)

As an attempted constructive feedback, use the same coordinate systems and rotation interfaces as Panda3D instead. There is no use re-inventing the wheel and all that documentation, is there? Or at least create an interface that can return the orientation of each body as a quaternion, or something else that is clearly and uniquely defined.

EDIT: Now I see that the coordinate system is not only flipped axis-wise compared to Panda3D, but the coordinate system is changed from a right-handed to a left-handed one! This explains a lot. I have a background in engineering/applied physics and I have never ever come across a left-handed coordinate in any textbook or any paper before. https://en.wikipedia.org/wiki/Cartesian_coordinate_system#Orientation_and_handedness

connecting through Websockets

Hello,
I'd like to use my Ursina project with Websockets, but it seems impossible to implement WS:

  • Threading crash the Engine
  • Threading the Websocket connection don't work at all.

Is it possible to implement a Websocket thread inside the Engine ?
Thomas

rotation_y=180 makes sprite disappear

I was trying to flip a slime sprite around the y-axis:

areg

This is the goal:
Screen Shot 2020-03-08 at 12 51 24 PM

But I can't use any combinations of .scale and .rotation. Is there any programmatic solution or do I need to make a new texture?

Also, on an unrelated note - doing entity.shake() returns an error since random isn't imported in entity.py.

mouse.normal always returns None

i tried running the minecraft example. I had to change the mouse.normal line to mouse.collisions[0].normal which did work. but no matter where i click, mouse.normal always returns None

Syntax Error

Hello,

I wanted to try ursina, but when trying to get any ursina game running, I get this :

File "/Users/tmd/Library/Python/2.7/lib/python/site-packages/ursina/sequence.py", line 132
Func(print, 'one'),
^
SyntaxError: invalid syntax

(the caret is actually under the "t" of print)
I just saw this file was corrected for a typo 4 days ago, could there be another bug in it ?

Thanks a lot anyway for this very cool project.

Text position incorrect when origin is set

When the Text class's origin is set, the text is no longer aligned correctly, and the background is not lined up with the text.

text_box = Text(
    z=-999,
    eternal=True,
    origin=(-1, 1),
    color=color.red.tint(-.2),
    text=text)

Bug?
Screenshot from 2020-05-09 14-02-36

What I expect:
Screenshot from 2020-05-09 14-03-03

I have a potential fix and will create a PR

Bug in `ursina.audio` prevents loading audio files when in a different directory than root.

Bug Description

I understand there is some logic to try to help the user of ursina.audio.Audio to load audio without having to specify an extension. The logic that detects the desired file appears to have a bug when the file is not in a simple location (like placing the audio file in the project working directory along with the code that's running). In my case, I have audio resources separated into a different directory named resources. Using ursina.audio.Audio fails to load audio files from this directory, even though I've confirmed that the path is correct and reachable by other parts of my code.

Expected Behaviour

Take a look at the steps to reproduce to find the exact output. I would expect this to result in the audio file being played, but this is not the case. Further, I would expect such a failure to result in an exception being thrown, which was not the case here. This causes silent failures, which is unreliable in practice.

As a developer, being unable to simply pass in a filepath to a loader without it getting mangled behind the scenes is a significant hindrance, and was a poor introduction to an otherwise promising library.

For others encountering this issue, a workaround.

To mitigate this issue, I had to recreate a bit of the ursina.audio.Audio class myself, pasting below to help anyone else who has been bit by this. If you are one such dev trying to resolve this issue, you'll find the solution simple, to just use the ShowBase loader directly:

app = Ursina()

def load_audio(filepath: str) -> audio.Audio:
    a = audio.Audio(sound_file_name=None, loop=False)
    loaded_sound = app.loader.loadSfx(filepath)
    a.clip = loaded_sound
    return a

# Test:
load_audio(os.path.join('..', 'resources', 'select-long.wav')).play()

Steps to Reproduce

Create a directory with the following structure:

+---project
    \---venv
    \---resources
    |   \---select-long.wav
    \---src
        \---__init__.py
        +---main.py

Follow the ursina_for_dummies tutorial up until loading sounds is mentioned, with your code being housed in the src package. At this point, add the following code:

a = audio.Audio(sound_file_name=os.path.join('..', 'resources', 'select-long'), loop=False)
a.play()

Run this code with your current working directory as project/src/.

Observe the following error output, and observe no exception was thrown:

:audio(error): Cannot open file: urces\select-long.wav
:audio(error): Could not open audio urces\select-long.wav

The process should not crash in this state, but also should not play the audio file.

Performance issues for a larger amount of Entities

Unfortunately, I'm unable to create a Voxel-game, because there are so many cube entities (13,000) that the game gets really slow.

Generating Entities is generally slow (due to the fact that you use inspect.[...] functions in entity.py which make the code slow).

But we can live with longer loading times. However, the rendering speed is generally quite slow. I suppose this is due to Panda3d. It can handle few meshes with many polygons much better than many meshes with few polygons. For that reason, there is the RigidBodyCombiner which intelligently combines meshes just before they're being rendered.

I've written this Ursina Binding:

from panda3d.core import RigidBodyCombiner, NodePath, Vec3
import random

class EntityCombiner(Entity):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.rbc = RigidBodyCombiner("rbc")
        self.rbcnp = NodePath(self.rbc)
        self.rbcnp.reparentTo(self)

        self.rbc.collect()
    
    def add(self, entity):
        entity.reparentTo(self.rbcnp)
    
    def update_items(self):
        self.rbc.collect()

It does improve the framerate, drastically indeed. But at the same time, removing Entities or setting their shaders doesn't show on the screen anymore, because I suppose that we'd have to call self.rbc.collect() in that case, which, in turn, is slow again and not desirable for regular view updates.

I think, a good performance for screens filled with thousands of similar objects, is quite important! Any idea on how to improve the performance?

Sphere texturing / generating problems

Trying to set up a little planet, i quickly ran into issues to texture the standard sphere that you provide in the library. Loading a texture on it with texture='myTex' results into just covering the sphere in the most dominant color of the texture. So even loading your texture 'brick' ends up as a greyish ball, where if i load it onto the cube i can clearly see the brick pattern.

I then tried the same with your procedural sphere object, which ended in the same result. In addition, the subdivision doesent seem to work for me. With subdivision=0 i see the Icosahedron, just with 3 missing triangles (i can see through the object). But as soon as i increase the subdivision, the object absolutely deforms with faces shooting out of the window.

Chances are high im doing something wrong here, but i thought this needed to be pointed out.

Environment:
Windows 10
Python 3.7.6 64-Bit
Panda3D 1.10.5
Ursina 0.1 obv.

Normal cube:
cube
Normal sphere:
shpere_model
Subdivision 0 sphere:
subdivision0
Subdivision 3 sphere:
subdivision3

BTW: Thank you for your awesome work in giving panda3d the overhaul it so urgently needs :->

Shaders

Life is much more interesting with shaders. I will now go and make a small demo with shaders.
This might be hard because I can't remember my shader math and I only used DirectX HLSL years ago and I see ursina uses some kind of python-GLSL hybrid. Lets see.

Unable to Install with Python 3.7.2

Get the following when running pip install git+https://github.com/pokepetter/ursina.git :

...
Requirement already satisfied: dataclasses in /usr/local/lib/python3.7/site-packages/dataclasses-0.7-py3.7.egg (from screeninfo->ursina==0.1) (0.7)
dataclasses requires Python '>=3.6, <3.7' but the running Python is 3.7.2

Readme says Ursina is compatible with Python 3.6+, but error reports differently. Will try with Windows later.

Python 3.7.2
MacOS Mojave

Publish to PyPI

Looks like a cool project. How about publishing to PyPI before someone else squats that name?
Edit:
Also until it gets published to PyPI, you can update the install instructions to:

pip install https://github.com/pokepetter/ursina/archive/master.zip

Not only it skips the git system dependency but also installs faster as it skips the cloning

Some questions on lights and uvs

Hi,

I'm teaching my 12yo son a bit of graphics using python and found this project to be fantastic. I'm writing a tutorial for him that maybe I can provide to your project once cleaned up. The tutorial takes you step by step through multiple concepts like window creation, object creation, object movement, camera manipulation, hierarchies, textures and more.

However I have found problems with how to alter a vertices or UV coords in a mesh model (i.e. I create an entity with a cube model, then I want to alter the UVs for texture animations). If not possible, then how do I define a shader so I can programatically change the UVs on shader computation (so model is not affected). I can see a shader object but no references how to use it.

Another thing I can't find is a rendering mode. I would like to render the wireframe to explain how the meshes are built but can't find the option.

Finally, I can't find how to define the environment light, directional light, spot light, etc. I can see the entities have reflectiveness and all but can't find light info.

Help please?

Regards
Guimo

Partially transparent texture bug?

I'm working on a simple vertical shooter game to try some ideas. However, I have noticed that if a texture has a partially transparent part it will apply the background color again resulting in a weird frame effect.

image

isolated case:

image

Any way around this problem of partially transparent textures?

script to reproduce the showcase problem

from ursina import *
from pathlib import Path

class Bullet(Entity):
    def __init__(self,texture=None,x=0.,y=0.):
        super().__init__()
        self.model = 'quad'
        self.texture = texture
        self.scale = 1/8
        self.x = x
        self.x = y

app = Ursina()
tex_bullet = Texture(Path('./bullet.png'))
b1 = Bullet(texture=tex_bullet)
b2 = Bullet(texture=tex_bullet,x=0.05,y=0.05)

camera.orthographic = True
camera.fov = 1
app.run()     

the texture I use: ./bullet.png:
bullet

Dungeon Generator

This thread is to discuss the dungeon generator and see its progress. When finished the player should be able to walk around a dungeon as a FPS. We can later improve the same example to provide a bit of flavour like in the old Eye Of The Beholder or Dungeon Master rogue like games, or fly a top camera in Diablo style.

help on making player controller

Is there a simple way to add in gravity and block collisions?
something like unity's rigidbody
im getting tired of trying and failing to do that

Package resources are accessed from path

Accesing package resources from filesystem is considered bad practice as it won't allow the package to be zip_safe (unable to use the package in compressed mode), breaking application 'freeze' functionality (heavily used by python commercial applications) as provided by nuitka standalone, cx_freeze, py2exe/py2app, etc.

Those calls could be either be replaced by importlib.resources/importlib_resources or, alternatively, implementing a configurable resource loader whith appropriate hooks to do so.

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.