Files
rk_pve/pve/mesh.py
2025-10-21 13:18:23 +02:00

62 lines
1.8 KiB
Python

# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
#TODO: split channels
from .shape import Vertex, Shape
from array import array
class Mesh:
__slots__ = '_array', '_view', '_size'
def __init__(self, shape):
#TODO: cpp
if shape.cutouts:
raise NotImplementedError
if shape.size > 4:
raise NotImplementedError
self._array = array(Vertex.Type, 2 * 3 * Vertex.Channels)
self._view = memoryview(self._array)
self._size = self.view.nbytes
tl = shape[0]
tr = shape[1]
br = shape[2]
bl = shape[3]
self.set(0, 0, tl)
self.set(0, 1, tr)
self.set(0, 2, br)
self.set(1, 0, br)
self.set(1, 1, bl)
self.set(1, 2, tl)
def __del__(self):
del self._view
del self._array
def set(self, triangle, index, vertex):
index = (triangle * 3 + index) * Vertex.Channels
self._view[index:(index + Vertex.Channels)] = vertex
@property
def size(self):
return self._size
@property
def view(self):
return self._view