Engee 文档

网格;网格

该页面正在翻译中。

mesh(x, y, z)
mesh(mesh_object)
mesh(x, y, z, faces)
mesh(xyz, faces)

绘制3D或2D网格。 支持 网格_对象s包括 网格;网格 类型从https://github.com/JuliaGeometry/GeometryBasics.jl[GeometryBasics.jl]。

地块类型

绘图类型别名 网格;网格 功能是 网格;网格.

例子:

简单网格图

网格可以从一组顶点坐标和面构造。 </无翻译>

using GLMakie
vertices = [
    0.0 0.0;
    1.0 0.0;
    1.0 1.0;
    0.0 1.0;
]

faces = [
    1 2 3;
    3 4 1;
]

colors = [:red, :green, :blue, :orange]

mesh(vertices, faces, color = colors, shading = NoShading)
a076fb3

请注意,面内顶点的顺序对于3d中正常生成很重要,因此会影响着色。 法线遵循右手规则,这意味着如果面顶点按逆时针顺序,法线将朝外。 </无翻译>

using GLMakie
vertices = Point3f[(1,0,0), (1,1,0), (0,1,0)]
faces1 = [1 2 3]
faces2 = [1 3 2]
colors = [:red, :green, :blue]

f = Figure(size = (800, 400))
ax = LScene(f[1,1], show_axis = false)
p = mesh!(ax, vertices, faces1, color = colors)
arrows!(ax, vertices, p.converted[1][].normal, lengthscale = 0.1, arrowsize = Vec3f(0.05, 0.05, 0.1), color = :orange)
text!(ax, vertices[faces1[:]], text = ["1", "2", "3"], align = (:center, :center), fontsize = 20, strokecolor = :white, strokewidth = 2, overdraw = true)

ax = LScene(f[1,2], show_axis = false)
p = mesh!(ax, vertices, faces2, color = colors)
arrows!(ax, vertices, p.converted[1][].normal, lengthscale = 0.1, arrowsize = Vec3f(0.05, 0.05, 0.1), color = :orange)
text!(ax, vertices[faces2[:]], text = ["1", "2", "3"], align = (:center, :center), fontsize = 20, strokecolor = :white, strokewidth = 2, overdraw = true)

f
1ba6d88

创建网格图的另一种快速方法是使用FileIO(依赖于MeshIO)导入网格: </无翻译>

using GLMakie
using FileIO

brain = load(assetpath("brain.stl"))

mesh(
    brain,
    color = [tri[1][2] for tri in brain for i in 1:3],
    colormap = Reverse(:Spectral)
)
b1830ca

脸部颜色和法线

</无翻译>

using GLMakie
using GeometryBasics

# Reduce quality of sphere
s = Tessellation(Sphere(Point3f(0), 1f0), 12)
ps = coordinates(s)
fs = faces(s)

#使用一个面观来处理一组新的面,每个面指一种颜色。
#每个面必须与fs中各自的面具有相同的长度。
#(使用相同的脸型保证了这一点)
FT=eltype(fs);N=长度(fs)
cs=FaceView(rand(RGBf,N),[FT(i)for i in1:N])

#每张脸生成法线(这也会创建一个视图)
ns=face_normals(ps,fs)

#创建网格
m=GeometryBasics。网格(ps,fs,normal=ns,color=cs)

网格(m)
bb52943

使用GeometryBasics。网格和缓冲器/采样器类型

我们还可以创建一个网格来指定法线,uv坐标:

using GeometryBasics, LinearAlgebra, GLMakie, FileIO


# Create vertices for a Sphere
r = 0.5f0
n = 30
θ = LinRange(0, pi, n)
φ2 = LinRange(0, 2pi, 2 * n)
x2 = [r * cos(φv) * sin(θv) for θv in θ, φv in φ2]
y2 = [r * sin(φv) * sin(θv) for θv in θ, φv in φ2]
z2 = [r * cos(θv) for θv in θ, φv in 2φ2]
points = vec([Point3f(xv, yv, zv) for (xv, yv, zv) in zip(x2, y2, z2)])

# The coordinates form a matrix, so to connect neighboring vertices with a face
# we can just use the faces of a rectangle with the same dimension as the matrix:
_faces = decompose(QuadFace{GLIndex}, Tessellation(Rect(0, 0, 1, 1), size(z2)))
# Normals of a centered sphere are easy, they're just the vertices normalized.
_normals = normalize.(points)

# Now we generate UV coordinates, which map the image (texture) to the vertices.
# (0, 0) means lower left edge of the image, while (1, 1) means upper right corner.
function gen_uv(shift)
    return vec(map(CartesianIndices(size(z2))) do ci
        tup = ((ci[1], ci[2]) .- 1) ./ ((size(z2) .* shift) .- 1)
        return Vec2f(reverse(tup))
    end)
end

# We add some shift to demonstrate how UVs work:
uv = gen_uv(0.0)
# We can use a Buffer to update single elements in an array directly on the GPU
# with GLMakie. They work just like normal arrays, but forward any updates written to them directly to the GPU
uv_buff = Buffer(uv)
gb_mesh = GeometryBasics.Mesh(points, _faces; uv = uv_buff, normal = _normals)

f, ax, pl = mesh(gb_mesh,  color = rand(100, 100), colormap=:blues)
wireframe!(ax, gb_mesh, color=(:black, 0.2), linewidth=2, transparency=true)
record(f, "uv_mesh.mp4", LinRange(0, 1, 100)) do shift
    uv_buff[1:end] = gen_uv(shift)
end

超出边界的uv坐标将在默认情况下重复。 人们可以使用一个 取样器 反对改变这种行为:

#=
Possible values:
:clamp_to_edge (default)
:mirrored_repeat
:repeat
=#
data = load(Makie.assetpath("earth.png"))
color = Sampler(rotl90(data'), x_repeat=:mirrored_repeat,y_repeat=:repeat)
f, ax, pl = mesh(gb_mesh,  color = color)
wireframe!(ax, gb_mesh, color=(:black, 0.2), linewidth=2, transparency=true)

record(f, "uv_mesh_mirror.mp4", LinRange(0, 1, 100)) do shift
    uv_buff[1:end] = gen_uv(shift)
end

体积纹理

可以将3d数组传递给 `网格(args…​;颜色=体积),并通过uvw坐标索引体积。 下面是一个交互式卷切片查看器的示例:

using GLMakie, GeometryBasics, NIfTI
brain = Float32.(niread(Makie.assetpath("brain.nii.gz")).raw)
# Define the positions
positions = Observable([Point3f(0.5, 0, 0), Point3f(0.5, 1, 0), Point3f(0.5, 1, 1), Point3f(0.5, 0, 1)])
triangles = GLTriangleFace[(1, 2, 3), (3, 4, 1)]

# We will stay in the unit cube, so the uv coordinates are just the positions.
uv_mesh = map((p) -> GeometryBasics.Mesh(p, triangles; uv=Vec3f.(p)), positions)
# Pass the volume plot to the color
f, ax, pl = mesh(uv_mesh, color=brain, shading=NoShading, axis=(; show_axis=false))
# Visualize the unit cube in which the volume lives
wireframe!(ax, Rect3f(Vec3f(0), Vec3f(1)), transparency=true, color=(:gray, 0.5))
cam = cameracontrols(ax.scene)
# Only rotate when left + alt buttons are pressed, so we can better interact with the slice
cam.controls.rotation_button = Mouse.left & Keyboard.left_alt
# Have colors for each point, so we can highlight it on hover
colors = Observable(fill(:black, 4))
ms = meshscatter!(ax, positions, markersize=0.05, color=colors)
# Also plot the volume next to it with a maximum intensity projection.
Makie.volume(f[1, 2], brain)

# Use mouseevents for drag events etc.
m_events = addmouseevents!(ax.scene)
point_idx = Ref(0)
point_start = Ref(Point3f(0))
clear_color() = if any(x -> x == :red, colors[])
    colors[] .= :black
    notify(colors)
end
# Define the handler for handling drag events to move the slice and
# highlight hovered points.
onany(ax.scene.events.mouseposition, m_events.obs) do mp, event
    if event.type == Makie.MouseEventTypes.leftdragstart
        p, idx = Makie.pick(ax.scene)
        if p == ms
            point_idx[] = idx
            colors[][idx] = :red
            point_start[] = positions[][idx]
            notify(colors)
        else
            point_idx[] = 0
        end
    elseif event.type == Makie.MouseEventTypes.leftdrag
        if point_idx[] != 0
            ray = Makie.ray_at_cursor(ax.scene)
            p = point_start[]
            line_start = Point3f(0, p[2], p[3])
            line_end = Point3f(1, p[2], p[3])
            new_point = Makie.closest_point_on_line(line_start, line_end, ray)
            positions[][point_idx[]] = new_point
            notify(positions)
        end
    elseif event.type == Makie.MouseEventTypes.leftdragstop
        point_idx[] = 0
        clear_color()
    elseif event.type == Makie.MouseEventTypes.over
        p, idx = Makie.pick(ax.scene)
        if p == ms
            if colors[][idx] != :red
                colors[][idx] = :red
                notify(colors)
            end
        else
            clear_color()
            point_idx[] = 0
        end
    end
end
f
qwertyu

复杂网格(实验)

</无翻译>

using GLMakie
using FileIO

# Load a mesh with material information. This will produce a GeometryBasics.MetaMesh
sponza = load(assetpath("sponza/sponza.obj"))

# The MetaMesh contains a standard GeometryBasics.Mesh in `sponza.mesh` with
# `mesh.views` defining the different sub-meshes, and material metadata in the
# `sponza.meta` Dict. The metadata includes:
# - meta[:material_names] which maps each view in `mesh.views` to a material name
# - meta[:materials] which maps a material name to a nested Dict of the loaded properties
# When a MetaMesh is given to Makie.mesh(), it will look for these entries and
# try to build a plot accordingly.
f, a, p = mesh(sponza)

# Set up camera
update_cam!(a.scene, Vec3f(-15, 7, 1), Vec3f(3, 5, 0), Vec3f(0,1,0))
cameracontrols(a).settings.center[] = false # don't recenter on display
cameracontrols(a).settings.fixed_axis[] = false # rotate freely
f
51fb17b

属性

阿尔法

默认值为 1.0

Colormap或color属性的alpha值。 多个阿尔法像在 图(alpha=0.2,颜色=(:红色,0.5),会成倍增加。

背光源

默认值为 0.0

为具有倒法线的二次光计算设置权重。

夹式飞机

默认值为 自动的

剪辑平面提供了一种在3D空间中进行剪辑的方法。 您可以设置最多8个向量 平面3f 飞机在这里,后面的情节将被裁剪(即变得不可见)。 默认情况下,剪辑平面继承自父绘图或场景。 您可以删除父 夹式飞机 通过传递 平面3f[].

颜色

默认值为 @继承patchcolor

设置网格的颜色。 可以是一个 向量资料{<:Colorant} 对于每个顶点颜色或单个 着色剂. A 矩阵{<:Colorant} 可用于用纹理为网格着色,该纹理要求网格包含纹理坐标。 A <:抽象模式 可用于将重复的像素采样图案应用于网格,例如用于阴影。

颜色表

默认值为 @继承colormap:viridis

设置为数字采样的颜色表 颜色s. PlotUtils.cgrad(。..), 麦琪反向(any_colormap) 也可以使用,或者来自ColorBrewer或PlotUtils的任何符号。 要查看所有可用的颜色渐变,您可以调用 麦琪可用_gradients().

颜色变化

默认值为 自动的

表示的开始点和结束点的值 颜色表.

色阶;色阶

默认值为 身份认同

的颜色变换功能。 可以是任何函数,但只能与 颜色栏身份认同, 日志, 日志2, 日志10, sqrt,sqrt, 罗吉特, 麦琪伪科学10麦琪符号10.

周期

默认值为 [:颜色=>:补丁颜色]

没有可用的文档。

depth_换档

默认值为 0.0

在所有其他变换之后(即在剪辑空间中)调整绘图的深度值,其中 0<=深度<=1. 这仅适用于GLMakie和WGLMakie,可用于调整渲染顺序(如可调谐透绘)。

弥漫性;弥漫性

默认值为 1.0

设置红色、绿色和蓝色通道对漫射(散射)光的反应强度。

外汇管理局

默认值为 真的

调整绘图是否使用fxaa渲染(仅限消除锯齿、GLMakie)。

[医]高

默认值为 自动的

Colorrange上方任何值的颜色。

可检查的

默认值为 @继承inspectable

设置此图是否应由 数据探测仪. 默认值取决于父场景的主题。

检查员-检查员

默认值为 自动的

设置回调函数 (检查员,情节)->。.. 用于清理DataInspector中的自定义指标。

检查员-检查员

默认值为 自动的

设置回调函数 (检查员,情节,索引)->。.. 它取代了默认值 显示_数据 方法。

检查器_label

默认值为 自动的

设置回调函数 (绘图、索引、位置)->字符串 它替换了DataInspector生成的默认标签。

插值,插值

默认值为 真的

设置是否应插值颜色

低频,低频

默认值为 自动的

Colorrange以下任何值的颜色。

[医]马特卡

默认值为 什么都没有

没有可用的文档。

材料

默认值为 什么都没有

RPRMakie只属性设置复杂的RadeonProRender材料. Warning,如何设置RPR材质可能会发生变化,其他后端会忽略此属性

模型

默认值为 自动的

为绘图设置模型矩阵。 这将复盖使用 翻译!, 旋转!规模!.

纳米色

默认值为 :透明

NaN值的颜色。

透支

默认值为 错误

控制绘图是否将绘制在其他绘图上。 这具体意味着忽略GL后端中的深度检查

底纹/底纹

默认值为 自动的

设置使用的照明算法。 选项是 NoShading (无照明), 快装,快装 (AmbientLight+PointLight)或 MultiLightShading (多个灯,仅GLMakie)。 请注意,这不会影响RPRMakie。

光泽,光泽

默认值为 32.0

设置反射的锐度。

空间

默认值为 :数据

设置包含情节的盒子的变换空间。 见 麦琪空间() 供可能的输入。

镜面,镜面

默认值为 0.2

设置对象在红色、绿色和蓝色通道中反射光线的强度。

ssao

默认值为 错误

调整是否使用ssao(屏幕空间环境光遮蔽)渲染绘图。 请注意,这仅在3D绘图中有意义,并且仅适用于 fxaa=真.

转型

默认值为 :自动

没有可用的文档。

透明度

默认值为 错误

调整情节处理透明度的方式。 在GLMakie 透明度=真 导致使用顺序独立的透明度。

uv_翻译

默认值为 自动的

设置uv坐标的变换,用于控制纹理映射到网格的方式。 属性可以是 , 比例::向量类型{2}, (翻译::VecTypes{2},比例::向量类型{2}),任何:rotr90,:rotl90,:rot180,:swap_xy/:transpose,:flip_x,:flip_y,:flip_xy,或最一般的a 麦琪垫子{2, 3, Float32}麦琪Mat3f 返回的 麦琪uv_transform(). 它们也可以通过传递元组来改变 (op3,op2,op1).

可见

默认值为 真的

控制是否渲染绘图。