跳转至

tkintertools.three.engine

字数 1106 个   代码 215 行   阅读时间 6 分钟   访问量

Core codes of 3D

🟢Canvas

class public | Canvas

def __init__(
    self,
    master: tkintertools.core.containers.Tk | tkintertools.core.containers.Canvas,
    *,
    expand: typing.Literal['', 'x', 'y', 'xy'] = 'xy',
    zoom_item: bool = False,
    keep_ratio: typing.Optional[typing.Literal['min', 'max']] = None,
    free_anchor: bool = False,
    **kwargs,
) -> None: ...
Base class of 3D Canvas

🟡space_sort

method public

1
2
3
def space_sort(
    self,
) -> None: ...
Sort the contextual relationship between the spatial positions of the components

🟢Component

class public | ABC

1
2
3
4
def __init__(
    self,
    *coordinates,
) -> _empty: ...
3D 对象基类

🟡_project

method protected

1
2
3
4
5
def _project(
    self,
    distance,
    canvas = None,
) -> _empty: ...
投影对象自身

  • distance: 对象与观察者的距离
  • canvas: 投影到的画布

🟡center

method public

1
2
3
def center(
    self,
) -> _empty: ...
几何中心

🟡rotate

method public

1
2
3
4
5
6
7
8
9
def rotate(
    self,
    dx = 0,
    dy = 0,
    dz = 0,
    *,
    center = (0, 0, 0),
    axis = None,
) -> _empty: ...
旋转对象本身

  • dx: x 方向逆时针旋转弧度,或者绕旋转轴线的旋转弧度
  • dy: y 方向逆时针旋转弧度
  • dz: z 方向逆时针旋转弧度
  • center: 旋转中心,默认为原点
  • axis: 旋转轴线,无默认值

🟡scale

method public

1
2
3
4
5
6
7
8
def scale(
    self,
    kx = 1,
    ky = 1,
    kz = 1,
    *,
    center = None,
) -> _empty: ...
缩放对象本身

  • kx: x 方向缩放比例
  • ky: y 方向缩放比例
  • kz: z 方向缩放比例
  • center: 缩放中心,默认为几何中心

🟡translate

method public

1
2
3
4
5
6
def translate(
    self,
    dx = 0,
    dy = 0,
    dz = 0,
) -> _empty: ...
平移对象本身

  • dx: x 方向位移长度
  • dy: y 方向位移长度
  • dz: z 方向位移长度

🟡update

method public

1
2
3
def update(
    self,
) -> None: ...

🟢Geometry

class public | object

1
2
3
4
5
def __init__(
    self,
    canvas,
    *sides,
) -> _empty: ...
几何体

  • canvas: 父画布
  • sides: 组成几何体的面

🟡append

method public

1
2
3
4
def append(
    self,
    *sides,
) -> _empty: ...
给几何体添加更多新的面

  • sides: Side

🟡center

method public

1
2
3
def center(
    self,
) -> _empty: ...
几何中心

🟡rotate

method public

1
2
3
4
5
6
7
8
9
def rotate(
    self,
    dx = 0,
    dy = 0,
    dz = 0,
    *,
    center = (0, 0, 0),
    axis = None,
) -> _empty: ...
旋转几何体中的所有 3D 对象

  • dx: x 方向逆时针旋转弧度,或者绕旋转轴线的旋转弧度
  • dy: y 方向逆时针旋转弧度
  • dz: z 方向逆时针旋转弧度
  • center: 旋转中心,默认为原点
  • axis: 旋转轴线,无默认值

🟡scale

method public

1
2
3
4
5
6
7
8
def scale(
    self,
    kx = 1,
    ky = 1,
    kz = 1,
    *,
    center = None,
) -> _empty: ...
缩放几何体中的所有 3D 对象

  • kx: x 方向缩放比例
  • ky: y 方向缩放比例
  • kz: z 方向缩放比例
  • center: 缩放中心,默认为几何中心

🟡translate

method public

1
2
3
4
5
6
def translate(
    self,
    dx = 0,
    dy = 0,
    dz = 0,
) -> _empty: ...
平移几何体中的所有 3D 对象

  • dx: x 方向位移长度
  • dy: y 方向位移长度
  • dz: z 方向位移长度

🟡update

method public

1
2
3
def update(
    self,
) -> _empty: ...
更新几何体

🟢Line

class public | Component

1
2
3
4
5
6
7
8
9
def __init__(
    self,
    canvas,
    point_start,
    point_end,
    *,
    width = 1,
    fill = '#000000',
) -> _empty: ...
线

  • canvas: 父画布
  • point_start: 起点坐标
  • point_end: 终点坐标
  • width: 线的宽度
  • fill: 线的颜色

🟡_camera_distance

method protected

1
2
3
def _camera_distance(
    self,
) -> _empty: ...
与相机距离

🟡update

method public

1
2
3
def update(
    self,
) -> _empty: ...
更新对象的显示

🟢Plane

class public | Component

1
2
3
4
5
6
7
8
def __init__(
    self,
    canvas,
    *points,
    width = 1,
    fill = '',
    outline = '#000000',
) -> _empty: ...

  • canvas: 父画布
  • points: 各点的空间坐标
  • width: 面轮廓的宽度
  • fill: 面内部的填充颜色
  • outline: 面轮廓的颜色

🟡_camera_distance

method protected

1
2
3
def _camera_distance(
    self,
) -> _empty: ...
与相机距离

🟡update

method public

1
2
3
def update(
    self,
) -> _empty: ...
更新对象的显示

🟢Point

class public | Component

def __init__(
    self,
    canvas,
    coords,
    *,
    size = 1,
    width = 1,
    fill = '#000000',
    outline = '#000000',
    markuptext = '',
    markupdelta = (0, 0),
    markupfont = ('Microsoft YaHei', -20),
    markupfill = '#000000',
    markupjustify = 'center',
) -> _empty: ...

  • canvas: 父画布
  • coords: 点的空间坐标
  • size: 点的大小
  • width: 点轮廓的宽度
  • fill: 点内部的填充颜色
  • outline: 点轮廓的颜色
  • markuptext: 标记文本
  • markupdelta: 标记文本显示位置的偏移量
  • markupfont: 标记文本字体
  • markupfill: 标记文本颜色
  • markupjustify: 标记文本多行对齐方式

🟡_camera_distance

method protected

1
2
3
def _camera_distance(
    self,
) -> _empty: ...
与相机距离

🟡update

method public

1
2
3
def update(
    self,
) -> _empty: ...
更新对象的显示

🟢Space

class public | Canvas

def __init__(
    self,
    master: tkintertools.core.containers.Tk | tkintertools.core.containers.Canvas,
    *,
    expand: typing.Literal['', 'x', 'y', 'xy'] = 'xy',
    zoom_item: bool = False,
    keep_ratio: typing.Optional[typing.Literal['min', 'max']] = None,
    free_anchor: bool = False,
    **kwargs,
) -> None: ...
A canvas where you can view 3D objects

🟡_initialization

method protected

1
2
3
def _initialization(
    self,
) -> None: ...

🟡_rotate

method protected

1
2
3
4
5
6
def _rotate(
    self,
    event: Event,
    press: bool | None = None,
    _cache: list[float] = [],
) -> None: ...

Triggering of a rotation event

  • event: Event
  • press: True, False, and None represent press, release, and move events, respectively
  • _cache: cache values that record the coordinates of mouse presses

🟡_scale

method protected

1
2
3
4
5
def _scale(
    self,
    event: Event,
    flag: bool | None = None,
) -> None: ...
Triggering of a scaling event

🟡_translate

method protected

1
2
3
4
5
6
def _translate(
    self,
    event: Event,
    press: bool | None = None,
    _cache: list[float] = [],
) -> None: ...

Triggering of a translation event

  • event: Event
  • press: True, False, and None represent press, release, and move events, respectively
  • _cache: cache values that record the coordinates of mouse presses

🟡_zoom_self

method protected

1
2
3
def _zoom_self(
    self,
) -> None: ...

🟢Text3D

class public | Component

def __init__(
    self,
    canvas,
    coords,
    text = '',
    *,
    font = ('Microsoft YaHei', -20),
    justify = 'center',
    fill = '#000000',
) -> _empty: ...
三维文本

  • canvas: 父画布
  • coords: 点的空间坐标
  • text: 显示的文本
  • size: 点的大小
  • font: 点轮廓的宽度
  • justify: 多行文本对齐方式
  • fill: 点内部的填充颜色

🟡_camera_distance

method protected

1
2
3
def _camera_distance(
    self,
) -> _empty: ...
与相机距离

🟡update

method public

1
2
3
def update(
    self,
) -> _empty: ...
更新对象的显示

🔵project

function public

1
2
3
4
def project(
    coordinate,
    distance,
) -> _empty: ...
将一个三维空间中的点投影到指定距离的正向平面上,并返回在该平面上的坐标

  • coordinate: 点的空间坐标
  • distance: 正向平面的距离(平面正对着我们)

🔵rotate

function public

1
2
3
4
5
6
7
8
9
def rotate(
    coordinate,
    dx = 0,
    dy = 0,
    dz = 0,
    *,
    center,
    axis = None,
) -> _empty: ...
将一个三维空间中的点以一个点或线为参照进行旋转(实现方式为欧拉角)

  • coordinate: 点的空间坐标
  • dx: x 方向逆时针旋转弧度,或者绕旋转轴线的旋转弧度
  • dy: y 方向逆时针旋转弧度
  • dz: z 方向逆时针旋转弧度
  • center: 旋转中心的空间坐标
  • axis: 旋转轴线的空间坐标

🔵scale

function public

1
2
3
4
5
6
7
8
def scale(
    coordinate,
    kx = 1,
    ky = 1,
    kz = 1,
    *,
    center,
) -> _empty: ...
将一个三维空间中的点以另一个点为缩放中心进行缩放

  • coordinate: 点的空间坐标
  • kx: x 方向缩放比例
  • ky: y 方向缩放比例
  • kz: z 方向缩放比例
  • center: 缩放中心的空间坐标

🔵translate

function public

1
2
3
4
5
6
def translate(
    coordinate: tuple[float, float, float],
    dx: float = 0,
    dy: float = 0,
    dz: float = 0,
) -> None: ...
将一个三维空间中的点进行平移

  • coordinate: 点的空间坐标
  • dx: x 方向位移长度
  • dy: y 方向位移长度
  • dz: z 方向位移长度