taichi.ui.scene
#
- class taichi.ui.scene.Scene#
The old 3D scene class, which can contain meshes, lines and particles, and can be rendered on a canvas. This scene class is to be instantiated directly and is deprecated. Use the new SceneV2 class instead, which can be retrieved using the get_scene() function of a taichi.ui.Window.
- ambient_light(self, color)#
Set the ambient color of this scene.
Example:
>>> scene = ti.ui.Scene()
>>> scene.ambient_light([0.2, 0.2, 0.2])
- lines(self, vertices, width, indices=None, color=(0.5, 0.5, 0.5), per_vertex_color=None, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, index_count: int = None)#
Declare multi-lines inside the scene.
Note that under current situation, for example, there you have 4 vertices, vertices.shape[0] is 4. So there will be 2 lines, the first line’s two points are vertices[0] and vertices[1], and the second line’s two points are vertices[2] and vertices[3].
- Parameters:
vertices – a taichi 3D Vector field, where each element indicate the 3D location of points of lines.
width – the line width (maybe different on different systems).
indices – a taichi int field of shape (2 * #points), which indicate the points indices of the lines. If this is None, then it is assumed that the points are already arranged in lines order.
color – a global color of the mesh as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.
per_vertex_color (Tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of the line.
vertex_offset (int, optional) – if ‘indices’ is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the index of the first vertex to draw.
vertex_count (int, optional) – only available when indices is not provided, which is the number of vertices to draw. There are 2 cases that we will change your vertex_count. [1] If the vertex_count is an odd number, then we will change it to vertex_count - 1. [2] If vertex_offset plus vertex_count greater than vertices.shape[0], then we will reduce vertex_count to no more than vertices.shape[0].
index_offset (int, optional) – Only available when indices is provided, which is the base index within the index buffer.
index_count (int, optional) – Only available when indices is provided, which is the number of vertices to draw.
- mesh(self, vertices, indices=None, normals=None, color=(0.5, 0.5, 0.5), per_vertex_color=None, two_sided=False, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, index_count: int = None, show_wireframe: bool = False)#
Declare a mesh inside the scene.
if you indicate the index_offset and index_count, the normals will also be sliced by the args, and the shading resultes will not be affected. (It is equal to make a part of the mesh visible)
- Parameters:
vertices – a taichi 3D Vector field, where each element indicate the 3D location of a vertex.
indices – a taichi int field of shape (3 * #triangles), which indicate the vertex indices of the triangles. If this is None, then it is assumed that the vertices are already arranged in triangles order.
normals – a taichi 3D Vector field, where each element indicate the normal of a vertex. If this is none, normals will be automatically inferred from vertex positions.
color – a global color of the mesh as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.
per_vertex_color (Tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of a vertex.
two_sided (bool) – whether or not the triangles should be able to be seen from both sides.
vertex_offset (int, optional) – if ‘indices’ is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the index of the first vertex to draw.
vertex_count (int, optional) – only available when indices is not provided, which is the number of vertices to draw.
index_offset (int, optional) – only available when indices is provided, which is the base index within the index buffer.
index_count (int, optional) – only available when indices is provided, which is the the number of vertices to draw.
show_wireframe (bool, optional) – turn on/off WareFrame mode.
- mesh_instance(self, vertices, indices=None, normals=None, color=(0.5, 0.5, 0.5), per_vertex_color=None, two_sided=False, transforms=None, instance_offset: int = 0, instance_count: int = None, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, index_count: int = None, show_wireframe: bool = False)#
Declare mesh instances inside the scene.
If transforms is given, then according to the shape of transforms, it will draw mesh instances based on the transforms, and you can indicate which instance to draw first. If you indicate the index_offset and index_count, the normals will also be sliced by the args, and the shading resultes will not be affected. (It is equal to make a part of the mesh visible)
- Parameters:
vertices – a taichi 3D Vector field, where each element indicate the 3D location of a vertex.
indices – a taichi int field of shape (3 * #triangles), which indicate the vertex indices of the triangles. If this is None, then it is assumed that the vertices are already arranged in triangles order.
normals – a taichi 3D Vector field, where each element indicate the normal of a vertex. If this is none, normals will be automatically inferred from vertex positions.
color – a global color of the mesh as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.
per_vertex_color (Tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of a vertex.
two_sided (bool) – whether or not the triangles should be able to be seen from both sides.
transforms (ti.Matrix.field, optional) – The Matrix must be 4x4 size with N instances, and data type should be ti.f32, ti.i32, ti.u32. If None, then it behaves like raw mesh (no copy).
instance_offset (int, optional) – Default value is 0 which means no offset to show mesh instances. Otherwise, the mesh instances will show from the instance_offset.
instance_count (int, optional) – The default value is None. If this parameter is not provided, instance_count = transforms.shape[0] - instance_offset.
vertex_offset (int, optional) – if ‘indices’ is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the index of the first vertex to draw.
vertex_count (int, optional) – only available when indices is not provided, which is the number of vertices to draw.
index_offset (int, optional) – only available when indices is provided, which is the base index within the index buffer.
index_count (int, optional) – only available when indices is provided, which is the the number of indices to draw.
show_wireframe (bool, optional) – turn on/off WareFrame mode.
- particles(self, centers, radius, color=(0.5, 0.5, 0.5), per_vertex_color=None, per_vertex_radius=None, index_offset: int = 0, index_count: int = None)#
Declare a set of particles within the scene.
- Parameters:
centers – a taichi 3D Vector field, where each element indicate the 3D location of the center of a particle.
color – a global color for the particles as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.
radius – a global radius for the particles as a float. If ‘per_vertex_radius’ is provided, this is ignored.
per_vertex_color – a taichi 3D vector field, where each element indicates the RGB color of a particle.
per_vertex_radius – a taichi float field, where each element indicates the radius of a particle.
index_offset (int, optional) – the index of the first vertex to draw.
index_count (int, optional) – the number of vertices to draw.
- point_light(self, pos, color)#
Set a point light in this scene.
- Parameters:
pos (list, tuple,
vector(3, float)
) – 3D vector for light position.color (list, tuple,
vector(3, float)
) – (r, g, b) triple for the color of the light, in the range [0, 1].
- class taichi.ui.scene.SceneV2(scene)#
The new 3D scene class, which can contain meshes, lines and particles, and can be rendered on a canvas. An instance of this class can be retrieved using the get_scene() function of a taichi.ui.Window.
- ambient_light(self, color)#
Set the ambient color of this scene.
- Example::
>>> scene.ambient_light([0.2, 0.2, 0.2])
- lines(self, vertices, width, indices=None, color=(0.5, 0.5, 0.5), per_vertex_color=None, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, index_count: int = None)#
Declare multi-lines inside the scene.
Note that under current situation, for example, there you have 4 vertices, vertices.shape[0] is 4. So there will be 2 lines, the first line’s two points are vertices[0] and vertices[1], and the second line’s two points are vertices[2] and vertices[3].
- Parameters:
vertices – a taichi 3D Vector field, where each element indicate the 3D location of points of lines.
width – the line width (maybe different on different systems).
indices – a taichi int field of shape (2 * #points), which indicate the points indices of the lines. If this is None, then it is assumed that the points are already arranged in lines order.
color – a global color of the mesh as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.
per_vertex_color (Tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of the line.
vertex_offset (int, optional) – if ‘indices’ is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the index of the first vertex to draw.
vertex_count (int, optional) – only available when indices is not provided, which is the number of vertices to draw. There are 2 cases that we will change your vertex_count. [1] If the vertex_count is an odd number, then we will change it to vertex_count - 1. [2] If vertex_offset plus vertex_count greater than vertices.shape[0], then we will reduce vertex_count to no more than vertices.shape[0].
index_offset (int, optional) – Only available when indices is provided, which is the base index within the index buffer.
index_count (int, optional) – Only available when indices is provided, which is the number of vertices to draw.
- mesh(self, vertices, indices=None, normals=None, color=(0.5, 0.5, 0.5), per_vertex_color=None, two_sided=False, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, index_count: int = None, show_wireframe: bool = False)#
Declare a mesh inside the scene.
if you indicate the index_offset and index_count, the normals will also be sliced by the args, and the shading resultes will not be affected. (It is equal to make a part of the mesh visible)
- Parameters:
vertices – a taichi 3D Vector field, where each element indicate the 3D location of a vertex.
indices – a taichi int field of shape (3 * #triangles), which indicate the vertex indices of the triangles. If this is None, then it is assumed that the vertices are already arranged in triangles order.
normals – a taichi 3D Vector field, where each element indicate the normal of a vertex. If this is none, normals will be automatically inferred from vertex positions.
color – a global color of the mesh as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.
per_vertex_color (Tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of a vertex.
two_sided (bool) – whether or not the triangles should be able to be seen from both sides.
vertex_offset (int, optional) – if ‘indices’ is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the index of the first vertex to draw.
vertex_count (int, optional) – only available when indices is not provided, which is the number of vertices to draw.
index_offset (int, optional) – only available when indices is provided, which is the base index within the index buffer.
index_count (int, optional) – only available when indices is provided, which is the the number of vertices to draw.
show_wireframe (bool, optional) – turn on/off WareFrame mode.
- mesh_instance(self, vertices, indices=None, normals=None, color=(0.5, 0.5, 0.5), per_vertex_color=None, two_sided=False, transforms=None, instance_offset: int = 0, instance_count: int = None, vertex_offset: int = 0, vertex_count: int = None, index_offset: int = 0, index_count: int = None, show_wireframe: bool = False)#
Declare mesh instances inside the scene.
If transforms is given, then according to the shape of transforms, it will draw mesh instances based on the transforms, and you can indicate which instance to draw first. If you indicate the index_offset and index_count, the normals will also be sliced by the args, and the shading resultes will not be affected. (It is equal to make a part of the mesh visible)
- Parameters:
vertices – a taichi 3D Vector field, where each element indicate the 3D location of a vertex.
indices – a taichi int field of shape (3 * #triangles), which indicate the vertex indices of the triangles. If this is None, then it is assumed that the vertices are already arranged in triangles order.
normals – a taichi 3D Vector field, where each element indicate the normal of a vertex. If this is none, normals will be automatically inferred from vertex positions.
color – a global color of the mesh as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.
per_vertex_color (Tuple[float]) – a taichi 3D vector field, where each element indicate the RGB color of a vertex.
two_sided (bool) – whether or not the triangles should be able to be seen from both sides.
transforms (ti.Matrix.field, optional) – The Matrix must be 4x4 size with N instances, and data type should be ti.f32, ti.i32, ti.u32. If None, then it behaves like raw mesh (no copy).
instance_offset (int, optional) – Default value is 0 which means no offset to show mesh instances. Otherwise, the mesh instances will show from the instance_offset.
instance_count (int, optional) – The default value is None. If this parameter is not provided, instance_count = transforms.shape[0] - instance_offset.
vertex_offset (int, optional) – if ‘indices’ is provided, this refers to the value added to the vertex index before indexing into the vertex buffer, else this refers to the index of the first vertex to draw.
vertex_count (int, optional) – only available when indices is not provided, which is the number of vertices to draw.
index_offset (int, optional) – only available when indices is provided, which is the base index within the index buffer.
index_count (int, optional) – only available when indices is provided, which is the the number of indices to draw.
show_wireframe (bool, optional) – turn on/off WareFrame mode.
- particles(self, centers, radius, color=(0.5, 0.5, 0.5), per_vertex_color=None, per_vertex_radius=None, index_offset: int = 0, index_count: int = None)#
Declare a set of particles within the scene.
- Parameters:
centers – a taichi 3D Vector field, where each element indicate the 3D location of the center of a particle.
color – a global color for the particles as 3 floats representing RGB values. If per_vertex_color is provided, this is ignored.
radius – a global radius for the particles as a float. If ‘per_vertex_radius’ is provided, this is ignored.
per_vertex_color – a taichi 3D vector field, where each element indicates the RGB color of a particle.
per_vertex_radius – a taichi float field, where each element indicates the radius of a particle.
index_offset (int, optional) – the index of the first vertex to draw.
index_count (int, optional) – the number of vertices to draw.
- point_light(self, pos, color)#
Set a point light in this scene.
- Parameters:
pos (list, tuple,
vector(3, float)
) – 3D vector for light position.color (list, tuple,
vector(3, float)
) – (r, g, b) triple for the color of the light, in the range [0, 1].
- taichi.ui.scene.gen_normals(vertices, indices)#
- taichi.ui.scene.gen_normals_kernel(vertices: template(), normals: template())#
- taichi.ui.scene.gen_normals_kernel_indexed(vertices: template(), indices: template(), normals: template(), weights: template())#
- taichi.ui.scene.get_normals_field(vertices)#
- taichi.ui.scene.normals_field_cache#