pixijs-scene-mesh
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMeshes render arbitrary 2D (or perspective-projected) geometry with a texture or custom shader. PixiJS ships the base class plus four specialized subclasses for common shapes: , , , and . Pick the subclass that matches your shape; drop to the base when you need full vertex-level control or a custom shader.
MeshMeshSimpleMeshPlaneMeshRopePerspectiveMeshMeshAssumes familiarity with . Meshes are leaf nodes; they cannot have children. Wrap multiple meshes in a to group them.
pixijs-scene-core-conceptsContainer网格(Mesh)可使用纹理或自定义着色器渲染任意2D(或透视投影)几何图形。PixiJS 提供基础的类以及四个针对常见形状的专用子类:、、和。根据你的形状选择对应的子类;当你需要完全的顶点级控制或自定义着色器时,使用基础的类。
MeshMeshSimpleMeshPlaneMeshRopePerspectiveMeshMesh假设你已熟悉。网格是叶子节点,不能拥有子元素。可将多个网格包裹在中进行分组。
pixijs-scene-core-conceptsContainerQuick Start
快速开始
ts
const texture = await Assets.load("pattern.png");
const geometry = new MeshGeometry({
positions: new Float32Array([0, 0, 100, 0, 100, 100, 0, 100]),
uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
indices: new Uint32Array([0, 1, 2, 0, 2, 3]),
topology: "triangle-list",
});
const mesh = new Mesh({
geometry,
texture,
roundPixels: false,
});
app.stage.addChild(mesh);Every subclass takes a single options object. The base requires a ; subclasses (, , , ) build the geometry internally and require a instead. See each variant's reference for the full field list.
MeshMeshgeometryMeshSimpleMeshPlaneMeshRopePerspectiveMeshtexturets
const texture = await Assets.load("pattern.png");
const geometry = new MeshGeometry({
positions: new Float32Array([0, 0, 100, 0, 100, 100, 0, 100]),
uvs: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
indices: new Uint32Array([0, 1, 2, 0, 2, 3]),
topology: "triangle-list",
});
const mesh = new Mesh({
geometry,
texture,
roundPixels: false,
});
app.stage.addChild(mesh);每个子类都接受一个选项对象。基础需要参数;子类(、、、)会在内部构建几何图形,因此需要传入参数。请查看各变体的参考文档获取完整字段列表。
MeshMeshgeometryMeshSimpleMeshPlaneMeshRopePerspectiveMeshtextureVariants
变体对比
| Variant | Use when | Trade-offs | Reference |
|---|---|---|---|
| Full control, custom geometry, custom shaders | You build the | references/mesh.md |
| Quick textured shapes with per-frame vertex animation | Thin wrapper; auto-updates the vertex buffer | references/mesh-simple.md |
| Subdivided textured rectangle for distortion effects | Fixed topology; | references/mesh-plane.md |
| Texture following a polyline path | Bent at each point; needs many points for smooth curves | references/mesh-rope.md |
| 2D plane with perspective corners | Not true 3D; UV-level perspective correction only | references/mesh-perspective.md |
| 变体类型 | 使用场景 | 优缺点对比 | 参考文档链接 |
|---|---|---|---|
| 需要完全控制、自定义几何图形、自定义着色器时使用 | 需自行构建 | references/mesh.md |
| 快速创建带逐帧顶点动画的纹理形状时使用 | 轻量封装;自动更新顶点缓冲区 | references/mesh-simple.md |
| 为实现扭曲效果创建细分纹理矩形时使用 | 拓扑结构固定;通过 | references/mesh-plane.md |
| 实现沿折线路径分布的纹理时使用 | 在每个路径点处弯折;需要大量点来实现平滑曲线 | references/mesh-rope.md |
| 创建带透视边角的2D平面时使用 | 并非真正3D;仅在UV层面实现透视校正 | references/mesh-perspective.md |
When to use what
场景选型指南
- "I need a textured quad" → (see
Sprite), not a mesh. Meshes are for cases Sprite can't express.pixijs-scene-sprite - "I need to deform a textured rectangle" → . Set
MeshPlane/verticesXfor the desired smoothness.verticesY - "I need a rope or trail that follows points" → . Control thickness with
MeshRope; usewidthto stretch ortextureScale: 0to repeat.> 0 - "I need a tilted 2D card or floor" → . Pass four corner positions; not real 3D but good enough for 2.5D effects.
PerspectiveMesh - "I need per-frame animated vertices with a simple shape" → . It handles the buffer-update dance for you.
MeshSimple - "I need a custom shader or unusual geometry" → Base with a hand-built
Mesh. SeeMeshGeometryfor shader authoring.pixijs-custom-rendering - "I need true 3D rendering" → Use a dedicated 3D library. simulates perspective at the UV level but has no depth buffer.
PerspectiveMesh
- 「我需要一个带纹理的四边形」 → 使用(参考
Sprite),而非网格。网格适用于Sprite无法实现的场景。pixijs-scene-sprite - 「我需要扭曲带纹理的矩形」 → 使用。通过设置
MeshPlane/verticesX来调整平滑度。verticesY - 「我需要沿路径分布的绳索或轨迹」 → 使用。通过
MeshRope控制厚度;设置width实现拉伸,设置textureScale: 0实现重复纹理。> 0 - 「我需要带倾斜效果的2D卡片或地板」 → 使用。传入四个边角位置;虽非真正3D,但足以实现2.5D效果。
PerspectiveMesh - 「我需要为简单形状实现逐帧顶点动画」 → 使用。它会自动处理缓冲区更新的相关操作。
MeshSimple - 「我需要自定义着色器或特殊几何图形」 → 使用基础类搭配手动构建的
Mesh。着色器编写可参考MeshGeometry。pixijs-custom-rendering - 「我需要真正的3D渲染」 → 使用专门的3D库。仅在UV层面模拟透视效果,没有深度缓冲区。
PerspectiveMesh
Quick concepts
核心概念
MeshGeometry owns the vertex data
MeshGeometry管理顶点数据
MeshGeometrypositionsuvsindicestopologyMeshMeshGeometrypositionsuvsindicestopologyMeshBatching
批处理
A mesh batches (combines with other draw calls) only if it uses , has no custom shader, no depth or culling state, and the rule ( and ≤100 vertices). Custom shaders always render independently.
MeshGeometry'auto'batchMode = 'auto'只有当网格使用、无自定义着色器、无深度或剔除状态,且符合规则(且顶点数≤100)时,才会进行批处理(与其他绘制调用合并)。自定义着色器始终会独立渲染。
MeshGeometry'auto'batchMode = 'auto'Topology is on the geometry, not the mesh
拓扑属性属于几何图形,而非网格
new MeshGeometry({ topology: 'triangle-strip' })'triangle-list'拓扑是几何图形的属性,例如;默认值为,如果你的数据组织方式不同,请显式设置该属性。
new MeshGeometry({ topology: 'triangle-strip' })'triangle-list'Extra knobs
额外配置项
- — trims GPU buffer storage to the actual vertex count on creation. Use it when feeding large, one-shot geometries.
new MeshGeometry({ shrinkBuffersToFit: true }) - — topology-aware hit test that walks the triangles. Works with any
Mesh.containsPoint(point), including custom layouts.MeshGeometry - — pass a
new Mesh({ geometry, state })object to control blend, depth, and culling. Batching is disabled automatically if depth or culling flags are set. Defaults toStatewhen omitted.State.for2d()
- —— 在创建时将GPU缓冲区存储裁剪至实际顶点数量。当传入大型一次性几何图形时可使用此配置。
new MeshGeometry({ shrinkBuffersToFit: true }) - —— 支持拓扑感知的命中检测,会遍历所有三角形。适用于任何
Mesh.containsPoint(point),包括自定义布局。MeshGeometry - —— 传入
new Mesh({ geometry, state })对象来控制混合、深度和剔除设置。如果设置了深度或剔除标志,批处理会自动禁用。如果省略该参数,默认使用State。State.for2d()
Common Mistakes
常见错误
[HIGH] Using old SimpleMesh
/ SimplePlane
/ SimpleRope
names
SimpleMeshSimplePlaneSimpleRope[高风险] 使用旧版SimpleMesh
/ SimplePlane
/ SimpleRope
类名
SimpleMeshSimplePlaneSimpleRopeWrong:
ts
import { SimpleRope } from "pixi.js";
const rope = new SimpleRope(texture, points);Correct:
ts
import { MeshRope } from "pixi.js";
const rope = new MeshRope({ texture, points });Renamed in v8: → , → , → . All switched to options-object constructors.
SimpleMeshMeshSimpleSimplePlaneMeshPlaneSimpleRopeMeshRope错误示例:
ts
import { SimpleRope } from "pixi.js";
const rope = new SimpleRope(texture, points);正确示例:
ts
import { MeshRope } from "pixi.js";
const rope = new MeshRope({ texture, points });在v8版本中已重命名: → , → , → 。所有类均已切换为选项对象构造函数。
SimpleMeshMeshSimpleSimplePlaneMeshPlaneSimpleRopeMeshRope[HIGH] Positional constructor args for MeshGeometry
MeshGeometry[高风险] 使用位置参数构造MeshGeometry
MeshGeometryWrong:
ts
const geom = new MeshGeometry(vertices, uvs, indices);Correct:
ts
const geom = new MeshGeometry({
positions: vertices,
uvs,
indices,
topology: "triangle-list",
});v8 uses an options object. Note the property is , not ; the name is only used by .
positionsverticesverticesMeshSimple错误示例:
ts
const geom = new MeshGeometry(vertices, uvs, indices);正确示例:
ts
const geom = new MeshGeometry({
positions: vertices,
uvs,
indices,
topology: "triangle-list",
});v8版本使用选项对象。注意属性名为而非;仅在中使用。
positionsverticesverticesMeshSimple[MEDIUM] Adding children to a mesh
[中风险] 为网格添加子元素
Wrong:
ts
mesh.addChild(otherMesh);Correct:
ts
const group = new Container();
group.addChild(mesh, otherMesh);MeshallowChildren = falseContainer错误示例:
ts
mesh.addChild(otherMesh);正确示例:
ts
const group = new Container();
group.addChild(mesh, otherMesh);MeshallowChildren = falseContainer