Attention

You are viewing PyUnity docs under the develop branch. As such, they are only applicable if you installed from source. Go to https://docs.pyunity.x10.bz/en/latest/ for the most recent release.

pyunity.meshes module


Module for meshes created at runtime and their various attributes.

class pyunity.meshes.Mesh[source]

Bases: Asset

Class to create a mesh for rendering with a MeshRenderer

Parameters:
  • verts (list) – List of Vector3’s containing each vertex

  • triangles (list) – List of ints containing triangles joining up the vertices. Each int is the index of a vertex above.

  • normals (list) – List of Vector3’s containing the normal of each vertex.

verts

List of Vector3’s containing each vertex

Type:

list

triangles

List of lists containing triangles joining up the vertices. Each int is the index of a vertex above. The list is two-dimesional, meaning that each item in the list is a list of three ints.

Type:

list

normals

List of Vector3’s containing the normal of each vertex.

Type:

list

texcoords

List of lists containing the texture coordinate of each vertex. The list is two-dimesional, meaning that each item in the list is a list of two floats.

Type:

list (optional)

Notes

When any of the mesh attributes are updated while a scene is running, you must use compile(force=True) to update the mesh so that it is displayed correctly.

>>> mesh = Mesh.cube(2)
>>> mesh.vertices[1] = Vector3(2, 0, 0)
>>> mesh.compile(force=True)
compile(force=False)[source]
draw()[source]
copy()[source]

Create a copy of the current Mesh.

Returns:

Copy of the mesh

Return type:

Mesh

GetAssetFile(gameObject)[source]
SaveAsset(ctx)[source]
static quad(size)[source]

Creates a quadrilateral mesh.

Parameters:

size (float) – Side length of quad

Returns:

A quad centered at Vector3(0, 0, 0) with side length of size facing in the direction of the positive z axis.

Return type:

Mesh

static doubleQuad(size)[source]

Creates a two-sided quadrilateral mesh.

Parameters:

size (float) – Side length of quad

Returns:

A double-sided quad centered at Vector3(0, 0) with side length of size.

Return type:

Mesh

static cylinder(radius, height, detail=32)[source]
static sphere(size, detail=16)[source]
static capsule(radius, height, detail=16)[source]
static cube(size)[source]

Creates a cube mesh.

Parameters:

size (float) – Side length of cube

Returns:

A cube centered at Vector3(0, 0, 0) that has a side length of size

Return type:

Mesh

class pyunity.meshes.Material[source]

Bases: Asset

Class to hold data on a material.

color

An albedo tint.

Type:

Color

texture

A texture to map onto the mesh provided by a MeshRenderer

Type:

Texture2D

GetAssetFile(gameObject)[source]
SaveAsset(ctx)[source]
class pyunity.meshes.Color[source]

Bases: object

toString()[source]
static fromString(string)[source]
class pyunity.meshes.RGB[source]

Bases: Color

A class to represent an RGB color.

Parameters:
  • r (int) – Red value (0-255)

  • g (int) – Green value (0-255)

  • b (int) – Blue value (0-255)

toRGB()[source]
toHSV()[source]
static fromHSV(h, s, v)[source]
class pyunity.meshes.HSV[source]

Bases: Color

A class to represent a HSV color.

Parameters:
  • h (int) – Hue (0-360)

  • s (int) – Saturation (0-100)

  • v (int) – Value (0-100)

toRGB()[source]
toHSV()[source]
static fromRGB(r, g, b)[source]
class pyunity.meshes.MeshRenderer[source]

Bases: SingleComponent

Component to render a mesh at the position of a transform.

mesh = None

Mesh that the MeshRenderer will render.

Type:

Mesh

mat = <pyunity.meshes.Material object at 0x7fc4aa68eb50>

Material to use for the mesh

Type:

Material

DefaultMaterial = <pyunity.meshes.Material object>

Type:    Material

Render()[source]

Render the mesh that the MeshRenderer has.