How to use the payton.scene.geometry.Mesh function in Payton

To help you get started, we’ve selected a few Payton examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sinanislekdemir / payton / payton / tools / mesh / geometry.py View on Github external
def merge_mesh(mesh1: Mesh, mesh2: Mesh) -> Mesh:
    m1_vertices = list(mesh1.absolute_vertices())
    m2_vertices = list(mesh2.absolute_vertices())
    mesh = Mesh()
    mesh.material = deepcopy(mesh1.material)
    mesh._vertices = m1_vertices + m2_vertices
    mesh._vertex_colors = mesh1._vertex_colors + mesh2._vertex_colors
    mesh._vertex_count = len(mesh._vertices)
    mesh._texcoords = mesh1._texcoords + mesh2._texcoords
    mesh._normals = mesh1._normals + mesh2._normals
    len_v = len(mesh1._vertices)
    m2_indices = [[i[0] + len_v, i[1] + len_v, i[2] + len_v] for i in mesh2._indices]
    mesh._indices = mesh1._indices + m2_indices
    mesh.material._indices = mesh._indices
    mesh._calc_bounds()
    mesh.refresh()
    return mesh
github sinanislekdemir / payton / examples / basics / 25_materials.py View on Github external
import os

from payton.scene import Scene
from payton.scene.geometry import Mesh
from payton.scene.material import DEFAULT, Material

scene = Scene()
mesh = Mesh()

yellow_material = Material(lights=False, color=[1.0, 1.0, 0.0, 1.0])
mesh.add_material("yellow", yellow_material)

# Regular add_triangle will add it with DEFAULT material
mesh.add_triangle([[0, 0, 0], [2, 0, 0], [2, 2, 0]], texcoords=[[0, 0], [1, 0], [1, 1]])

# Explicit material definition
mesh.add_triangle(
    [[0, 0, 0], [2, 2, 0], [0, 2, 0]], texcoords=[[0, 0], [1, 1], [0, 1]], material="yellow",
)

texture_file = os.path.join(os.path.dirname(__file__), "cube.png")
mesh.materials[DEFAULT].texture = texture_file
# mesh.material.texture = texture_file  # implicit declaration
scene.add_object("mesh", mesh)
github sinanislekdemir / payton / examples / basics / 09_mesh.py View on Github external
import os

from payton.scene import Scene
from payton.scene.geometry import Mesh

scene = Scene()
mesh = Mesh()
mesh.add_triangle([[0, 0, 0], [2, 0, 0], [2, 2, 0]], texcoords=[[0, 0], [1, 0], [1, 1]])
mesh.add_triangle([[0, 0, 0], [2, 2, 0], [0, 2, 0]], texcoords=[[0, 0], [1, 1], [0, 1]])
texture_file = os.path.join(os.path.dirname(__file__), "cube.png")
mesh.material.texture = texture_file
scene.add_object("mesh", mesh)
scene.run()
github sinanislekdemir / payton / payton / tools / mesh / line.py View on Github external
def lines_to_mesh(lines: List[Line]) -> Mesh:
    lens = [len(l._vertices) for l in lines]
    lmin = min(lens)
    lmax = max(lens)
    mesh = Mesh()
    if lmin != lmax:
        raise BaseException("Number of vertices for each line must be equal")
    if len(lines) == 0:
        raise BaseException("You must specify more than one line object")
    for i in range(len(lines) - 1):
        fvlist = lines[i]._vertices
        tvlist = lines[i + 1]._vertices
        for j in range(lmin - 1):
            mesh.add_triangle(vertices=[fvlist[j], fvlist[j + 1], tvlist[j]])
            mesh.add_triangle(vertices=[fvlist[j + 1], tvlist[j + 1], tvlist[j]])
    mesh.fix_normals()
    mesh.fix_texcoords()
    return mesh
github sinanislekdemir / payton / payton / tools / mesh / line.py View on Github external
def extrude_line(line: Line, direction: List[float], distance: float) -> Mesh:
    vertices = line._vertices
    diff_vector = scale_vector(direction, distance)
    mirror_vertices = [add_vectors(v, diff_vector) for v in vertices]

    mesh = Mesh()
    for i in range(len(vertices) - 1):
        mesh.add_triangle(
            vertices=[vertices[i], vertices[i + 1], mirror_vertices[i]], texcoords=[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]],
        )
        mesh.add_triangle(
            vertices=[vertices[i + 1], mirror_vertices[i + 1], mirror_vertices[i]],
            texcoords=[[1.0, 0.0], [1.0, 1.0], [0.0, 1.0]],
        )
    return mesh
github sinanislekdemir / payton / payton / tools / mesh / line.py View on Github external
def rotate_line(line: Line, axis: List[float], angle: float, steps: int = 10) -> Mesh:
    step_angle = angle / steps
    vertices = line._vertices
    step_u = 1.0 / steps
    step_v = 1.0 / len(vertices)
    mesh = Mesh()

    for i in range(steps):
        matrix = create_rotation_matrix_raw(axis, step_angle)
        mirror_vertices = [vector_transform(v, matrix) for v in vertices]
        for j in range(len(vertices) - 1):
            mesh.add_triangle(
                vertices=[vertices[j], vertices[j + 1], mirror_vertices[j]],
                texcoords=[[step_u * i, step_v * j], [step_u * (i + 1), step_v * j], [step_u * i, step_v * (j + 1)]],
            )
            mesh.add_triangle(
                vertices=[vertices[j + 1], mirror_vertices[j + 1], mirror_vertices[j]],
                texcoords=[
                    [step_u * (i + 1), step_v * j],
                    [step_u * (i + 1), step_v * (j + 1)],
                    [step_u * i, step_v * (j + 1)],
                ],
github sinanislekdemir / payton / examples / mid-level / engrave.py View on Github external
import os

from PIL import Image

from payton.scene import Scene
from payton.scene.geometry import Mesh
from payton.scene.gui import info_box

scene = Scene()
mesh = Mesh()

texture = os.path.join(os.path.dirname(__file__), "engraved.jpg")

img = Image.open(texture)
pix = img.load()

aspect = img.size[0] / img.size[1]

pixel_size_x = 5 / img.size[0]
pixel_size_y = 5 / (img.size[1] * aspect)

print("Building the engraving")
x, y = img.size
count = 0
for j in range(y - 1):
    for i in range(x - 1):
github sinanislekdemir / payton / examples / basics / 10_vertex_colors.py View on Github external
from payton.scene import Scene
from payton.scene.geometry import Mesh

scene = Scene()
mesh = Mesh()
mesh.add_triangle(
    [[-2, 0, 0], [2, 0, 0], [0, 2, 0]], texcoords=[[0, 0], [1, 0], [1, 1]], colors=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
)

scene.add_object("mesh", mesh)
scene.run()