apply-conventions
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEngine conventions
引擎约定
Read and the installed source before relying on version-sensitive API
details. Apply these stable conventions throughout the project.
package.jsonplaycanvas在依赖版本敏感的API细节之前,请先阅读和已安装的源代码。在整个项目中遵循这些稳定的约定。
package.jsonplaycanvasCoordinates and angles
坐标与角度
- Use the right-handed coordinate system: +Y is up and the gameplay ground plane is XZ.
- Treat and the camera viewing direction as -Z;
entity.forwardis +X andentity.rightis +Y.entity.uppoints -Z at the target.lookAt - Expect glTF models authored toward +Z to need a yaw correction. Inspect and calibrate each directional model instead of applying one global correction.
- Pass degrees in XYZ order to high-level angle APIs.
- Keep pitch, yaw, and roll as application state. Do not repeatedly read and feed its decomposition back into
getEulerAngles().setEulerAngles() - Interpolate periodic angles with or rotations with
math.lerpAngle(), not scalar lerp across the 0/360 seam.Quat.slerp()
- 使用右手坐标系:+Y轴向上,游戏地面平面为XZ平面。
- 将和相机视角方向视为-Z方向;
entity.forward为+X方向,entity.right为+Y方向。entity.up方法会将-Z方向指向目标。lookAt - 注意面向+Z方向制作的glTF模型可能需要偏航角修正。请检查并校准每个定向模型,而非应用全局统一修正。
- 向高层角度API传递角度时,采用XYZ顺序的度数。
- 将俯仰角(pitch)、偏航角(yaw)和滚转角(roll)作为应用状态保存。不要反复读取并将分解结果重新传入
getEulerAngles()。setEulerAngles() - 使用对周期性角度进行插值,或使用
math.lerpAngle()对旋转进行插值,不要在0/360度接缝处使用标量插值。Quat.slerp()
Transforms and units
变换与单位
- Use ,
setPosition, andsetRotationfor world transforms.setEulerAngles - Use the variants below a parent.
setLocal* - Treat units as metres. Physics gravity defaults to .
(0, -9.81, 0) - Keep gameplay transforms on a semantic root and asset-authoring corrections on a child.
- Do not scale rigid-body roots or skinned bones.
- 使用、
setPosition和setRotation设置世界变换。setEulerAngles - 在父实体下使用系列方法设置局部变换。
setLocal* - 将单位视为米。物理重力默认值为。
(0, -9.81, 0) - 将游戏玩法变换放在语义根实体上,将资源制作修正放在子实体上。
- 不要缩放刚体根实体或蒙皮骨骼。
Cameras, materials, and bounds
相机、材质与边界
- Perspective camera FOV is vertical and defaults to 45 degrees.
- Smooth an orbit camera's focus, yaw, pitch, and distance, then derive its position. Do not
between orbit positions on opposite sides of the focus; the chord crosses the subject.
Vec3.lerp() - Before writing custom camera input, inspect the installed controller script and its matching Engine example. Preserve their gesture mapping and damping unless the product explicitly asks for different behavior; do not derive signs from memory.
- Define the input contract in screen space, then verify positive and negative movement on both axes with real input after a rendered frame. Judge the camera basis or a projected fixed landmark, not world-space camera coordinates or internal angle signs; both can approve inverted behavior.
- Materials cull back faces by default; counter-clockwise winding defines the front face.
- Clone a material before per-instance tinting or edits, and assign the clone; never mutate one shared by other instances, including default and asset-imported materials.
- Entities do not have an . Union descendant
aabbvalues after transforms have synchronized.meshInstance.aabb - Let calculate local bounds. If passing
Mesh.update()forfalse, assign an explicitupdateBoundingBoxbefore the mesh can be culled.mesh.aabb - Expand custom-mesh bounds by the maximum vertex-shader displacement; CPU bounds do not observe shader deformation.
- Treat offline skinned-mesh bounds as bind-pose estimates and confirm animated poses at runtime.
- 透视相机的视野(FOV)为垂直方向,默认值为45度。
- 对轨道相机的焦点、偏航角、俯仰角和距离进行平滑处理,然后推导其位置。不要在焦点两侧的轨道位置之间使用;这样的插值路径会穿过目标对象。
Vec3.lerp() - 在编写自定义相机输入逻辑之前,请检查已安装的控制器脚本及其对应的引擎示例。除非产品明确要求不同行为,否则保留它们的手势映射和阻尼效果;不要凭记忆推导符号。
- 在屏幕空间中定义输入协议,然后在渲染帧后通过实际输入验证两个轴上的正负移动。判断相机基准或投影的固定地标,而非世界空间中的相机坐标或内部角度符号;这两者都可能认可反向行为。
- 材质默认剔除背面;逆时针缠绕顺序定义正面。
- 在进行逐实例着色或编辑之前克隆材质,并分配克隆后的材质;永远不要修改其他实例共享的材质,包括默认材质和导入的资源材质。
- 实体没有属性。在变换同步后,合并子实体的
aabb值。meshInstance.aabb - 让计算局部边界。如果在调用时传入
Mesh.update()作为false参数,请在网格可能被剔除前显式分配updateBoundingBox。mesh.aabb - 将自定义网格的边界扩展至顶点着色器的最大位移量;CPU端的边界不会考虑着色器变形。
- 将离线蒙皮网格的边界视为绑定姿势的估计值,并在运行时确认动画姿势。
Imports
导入
Use named ESM imports from . Import production scripts only from
; legacy sibling script directories depend on a global Engine namespace.
playcanvasplaycanvas/scripts/esm/**使用来自的命名ESM导入。仅从导入生产脚本;旧的同级脚本目录依赖全局引擎命名空间。
playcanvasplaycanvas/scripts/esm/**Runtime confirmation
运行时确认
Offline measurements cannot prove facing, animated poses, or final placement. Confirm each one in the
running application:
- Start the project's own dev server or build; do not construct a separate harness.
- Log the value from inside the Engine, using ,
getPosition(), agetEulerAngles(), or an anim component's active state, from ameshInstance.aabbor an update callback.Script - For large or vertex-displaced meshes, inspect their runtime AABB and after a rendered frame from at least two representative camera angles.
visibleThisFrame - Confirm a directional model's visible front aligns with its semantic root's ; a stored yaw or runtime transform alone cannot prove mesh facing.
forward - Read that logged value from the browser console. Screenshots judge composition and orientation; numeric claims require logged values.
- Record the confirmed value in application state or an asset tuning record, then remove the logging.
离线测量无法验证朝向、动画姿势或最终位置。请在运行中的应用程序中逐一确认:
- 启动项目自身的开发服务器或构建版本;不要构建单独的测试环境。
- 在引擎内部记录值,例如从或更新回调中调用
Script、getPosition()、getEulerAngles()或动画组件的活动状态。meshInstance.aabb - 对于大型或顶点位移的网格,在渲染帧后从至少两个代表性相机角度检查其运行时AABB和属性。
visibleThisFrame - 确认定向模型的可见正面与其语义根实体的方向对齐;仅存储的偏航角或运行时变换无法证明网格朝向正确。
forward - 从浏览器控制台读取记录的值。截图用于判断构图和方向;数值结论需要记录的数值支持。
- 将确认的值记录到应用状态或资源调优记录中,然后移除日志代码。