VectorFields
Scripts to create vector fields and flowmaps that can be used in game engines like Unreal Engine 4 and Unity 3D.
Have a look at UE4's documentation.
Installation
via Python Package Index
pip install vectorfields
Bleeding Edge
- To install using development mode:
pip install -e git+https://github.com/OlafHaag/vectorfields.git@master#egg=vectorfields - To install using regular mode (building the package):
pip install https://github.com/OlafHaag/vectorfields/archive/master.zip
Usage
You have to know a bit of python and math.
The abstract base classes VectorField and VectorField2D can't be instantiated.
Instantiate a specific vector field, like ElectricDipole2D.
You can use the save method to write the vector field to disk in FGA or VF format. To be able to save in vf format, you have to turn instances of VectorField2D subclasses into 3D vector fields with the to_3d method. If I'm not mistaken Unity expects cubic vector fields with resolution x=y=z.
You can also save instances of Vectorfield2D's sub classes to flow maps (e.g. png).
It's best to preview your vector field directly in engine. Saving to disk usually reloads the file in Unity.
For other purposes you can use the plot-method of the Vectorfield2D class to get a preview.
Special classes
Vortex2D
Has parameters radius and pull.
TwirlFlow2D
ElectricDipole2D
ElectricDipole2D has 2 special methods to either normalize the vectors and lose all information on field strength or to clamp the field strength to a maximum value. This was necessary, because the physical properties of this field aren't visually pleasing.
Belt2D
With this you can place rotating areas in the field that more or less merge together, hence creating the impression of a belt running over pulleys.
Besides their x and y coordinates each pulley has a radius, thickness and speed (negative speed to change direction).
As a flowmap:
CustomUVW
This is a class for quick prototyping and generation of vector fields.
You provide custom functions to the constructor for creating the U, V and W vector components.
These functions must take 3 parameters that will be substituted for the class' data members grid_x, grid_y, grid_z.
The return value must be an array of the same shape as grid_x, grid_y or grid_z respectively.
CustomUV2D
This is a class for quick prototyping and generation of 2D vectorfields.
You provide custom functions to the constructor for creating the U and V vector components.
These functions must take 2 parameters that will be substituted for the class' data members grid_x and grid_y.
The return value must be an array of the same shape as grid_x or grid_y respectively.
2D Examples:
non-square sine vector field
import numpy as np
from vectorfields import CustomUV2D
ufunc = lambda x,y: np.ones(x.shape) # Flow in one direction.
vfunc = lambda x,y: np.sin(x)
vf = CustomUV2D(ufunc, vfunc, size=[8,2], resolution=[32,8])
square example:
regular cosine whirls
import numpy as np
from vectorfields import CustomUV2D
ufunc = lambda x,y: np.cos(y)
vfunc = lambda x,y: np.cos(x)
vf = CustomUV2D(ufunc, vfunc, size=16)
"flowers"
import numpy as np
from vectorfields import CustomUV2D
ufunc = lambda x,y: np.sin(y + x)
vfunc = lambda x,y: np.cos(x - y)
vf = CustomUV2D(ufunc, vfunc, size=12, resolution=48)
some diagonal flow thingy
import numpy as np
from vectorfields import CustomUV2D
ufunc = lambda x,y: np.cos(np.sqrt(np.abs(x)))
vfunc = lambda x,y: np.cos(np.sqrt(np.abs(y)))
vf = CustomUV2D(ufunc, vfunc)
anvaka's square flow tiles (seriously, it's hard to find names for this stuff)
import numpy as np
from vectorfields import CustomUV2D
ufunc = lambda x,y: 2.0 * np.mod(np.floor(-y), 2.0) - 1.0
vfunc = lambda x,y: 2.0 * np.mod(np.floor(-x), -2.0) + 1.0
vf = CustomUV2D(ufunc, vfunc, size=5.9, resolution=24)
beautiful twirls
import numpy as np
from vectorfields import CustomUV2D
ufunc = lambda x,y: np.cos(np.linalg.norm(np.dstack((x, y)), axis=2))[:,:,np.newaxis]
vfunc = lambda x,y: np.cos(x-y)
vf = CustomUV2D(ufunc, vfunc, size=16)
twirl column
import numpy as np
from vectorfields import CustomUV2D
ufunc = lambda x,y: np.sin(y)
vfunc = lambda x,y: x
vf = CustomUV2D(ufunc, vfunc, size=[12, 16], resolution=[24, 32])
One last thingy...
import numpy as np
from vectorfields import CustomUV2D
ufunc = lambda x,y: np.cos(y**2)
vfunc = lambda x,y: np.cos(y*x)
vf = CustomUV2D(ufunc, vfunc, size=[24, 16], resolution=[48,32])
History
This little project started at a little game jam with the topic "electricity". I wanted to do something with particles and controlling their flow with formulas, but the available methods for creating vector fields at the time where either too complicated for this small task, or too time consuming or bound to purchasing a software license. Of course, this cannot compete with GUI software like VectorayGen, but it's free and open source.
Development
Since it did what I needed it got stuck in early development stage. For example, there's a lack of three-dimensional vector field examples and there are no unit-tests.
I'd like to see people creating other vector fields with this and improve and advance the code.
Metadata
Release files for vectorfields 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| vectorfields-0.1.2.tar.gz | 12.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vectorfields-0.1.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 22.5 kB
Release files / vectorfields-0.1.2.tar.gz
| Download URL | vectorfields-0.1.2.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b6a406c4630559893ce81cdab8d25c658457c2e5ede568c01568e4316fec0e3
|
|
BLAKE2b-256 checksum How to use checksums |
c2fa9187050e852c20d655249e3aaa14ffdce561d42ca85ec86eae148a054377
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.1
|
Release files / vectorfields-0.1.2-py2.py3-none-any.whl
| Download URL | vectorfields-0.1.2-py2.py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c35f4278bb08559fe3387e4d90558b50608dda3d6a5f9064fd156a5acac480a5
|
|
BLAKE2b-256 checksum How to use checksums |
ab8e183a3ccf2e8bbcd0d48697b42489e45f4bd23fee658cabb0b8a3b81b4cdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.1
|
Security for vectorfields 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.