tresjs-core-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTresjs/tres @tresjs/core
@tresjs/coreTresjs/tres @tresjs/core
@tresjs/coreVersion: 5.5.0 (Feb 2026)
Deps: @pmndrs/pointer-events@^6.6.17, @vue/devtools-api@^7.7.2, @vueuse/core@^13.9.0, radashi@^12.6.2
Tags: beta: 2.0.0-beta.13 (Apr 2023), next: 5.0.0-next.6 (Jun 2025), alpha: 5.0.0-alpha.2 (Sep 2025), rc: 5.0.0-rc.0 (Sep 2025), latest: 5.5.0 (Feb 2026)
References: Docs — API reference, guides • GitHub Issues — bugs, workarounds, edge cases • GitHub Discussions — Q&A, patterns, recipes • Releases — changelog, breaking changes, new APIs
**版本:**5.5.0(2026年2月)
依赖:@pmndrs/pointer-events@^6.6.17、@vue/devtools-api@^7.7.2、@vueuse/core@^13.9.0、radashi@^12.6.2
**版本标签:**beta: 2.0.0-beta.13(2023年4月)、next: 5.0.0-next.6(2025年6月)、alpha: 5.0.0-alpha.2(2025年9月)、rc:5.0.0-rc.0(2025年9月)、latest:5.5.0(2026年2月)
参考资源:文档——API参考、使用指南 • GitHub问题——bug报告、解决方案、边缘案例 • GitHub讨论——问答、模式、实践方案 • 版本发布记录——更新日志、破坏性变更、新API
API Changes
API变更
This section documents version-specific API changes — prioritize recent major/minor releases.
-
BREAKING:— returns reactive state
useLoadersince v5, no longer returns a Promise source{ state, isLoading, error, progress } -
BREAKING: Pointer Events — renamed to native DOM names (e.g.,instead of
@pointerdown) in v5 source@pointer-down -
BREAKING:— removed from core in v5, moved to
useTexturepackage source@tresjs/cientos -
BREAKING: ESM-only — TresJS v5 is ESM-only; UMD build and CommonJSare no longer supported source
require() -
BREAKING:Props — WebGL context props like
TresCanvas,alpha,antialias, andstencilare now readonly and non-reactive in v5 sourcedepth -
BREAKING:— returns a state object in v5; use
useTresContext().camerafor the active camera instance sourceuseTres().camera -
BREAKING: Renderer Context —is now readonly in
renderer;useTresContext()state was removed from context in v5 sourceperformance -
BREAKING: Event Bubbling — only the first intersected element triggers pointer events since v5 to align with standard behavior source
-
NEW:Component — exported in v5.5.0 (as
Context) for advanced scene and state management sourceTresCanvasContext -
NEW: Kebab-case Support — support for components written in kebab-case (e.g.,) added in v5.1.0 source
<tres-mesh> -
NEW:Prefix — added
primitiveoption for primitives in v5.3.0 to avoid name collisions sourceprefix -
NEW:/
TresCanvasProps— explicitly exported types added in v5.2.0 for better TypeScript integration sourceTresCanvasEmits -
REMOVED: Legacy Composables —,
useRenderLoop,useCamera,useTresReady,useSeek, anduseRaycasterremoved in v5 sourceuseLogger -
NEW:— integrated into
useForwardPropsEmitsin v5.3.0 for streamlined event and prop handling sourceTresCanvas
Also changed: replaces · replaces · event replaces · replaces common usage · supports prop (deprecated) · supports and reactive paths.
useLoopuseRenderLoopuseGraphuseSeek@readyuseTresReadyuseTres()useTresContext()TresCanvasuseLegacyLightsuseLoaderextensions本节记录特定版本的API变更——优先参考近期的主版本/次版本更新。
-
破坏性变更:——从v5版本开始返回响应式状态
useLoader,不再返回Promise 来源{ state, isLoading, error, progress } -
破坏性变更:Pointer Events——v5版本中重命名为原生DOM名称(例如使用替代
@pointerdown)来源@pointer-down -
破坏性变更:——v5版本中从核心库移除,迁移至
useTexture包 来源@tresjs/cientos -
破坏性变更:仅支持ESM——TresJS v5仅支持ESM;不再支持UMD构建和CommonJS的语法 来源
require() -
破坏性变更:属性——v5版本中,WebGL上下文属性如
TresCanvas、alpha、antialias和stencil变为只读且非响应式 来源depth -
破坏性变更:——v5版本中返回状态对象;如需获取活跃相机实例,请使用
useTresContext().camera来源useTres().camera -
破坏性变更:渲染器上下文——v5版本中中的
useTresContext()变为只读;上下文移除了renderer状态 来源performance -
破坏性变更:事件冒泡——v5版本中仅第一个被交叉检测到的元素触发指针事件,以对齐标准行为 来源
-
新增功能:组件——v5.5.0版本中导出(别名
Context),用于高级场景和状态管理 来源TresCanvasContext -
新增功能:短横线命名支持——v5.1.0版本中支持短横线命名的组件(例如)来源
<tres-mesh> -
新增功能:前缀——v5.3.0版本中为primitive添加
primitive选项,避免名称冲突 来源prefix -
新增功能:/
TresCanvasProps——v5.2.0版本中显式导出类型,提升TypeScript集成体验 来源TresCanvasEmits -
移除功能:遗留组合式函数——v5版本中移除、
useRenderLoop、useCamera、useTresReady、useSeek和useRaycaster来源useLogger -
新增功能:——v5.3.0版本中集成到
useForwardPropsEmits,简化事件和属性处理 来源TresCanvas
其他变更:替代 · 替代 · 事件替代 · 替代的常见用法 · 支持属性(已废弃) · 支持和响应式路径。
useLoopuseRenderLoopuseGraphuseSeek@readyuseTresReadyuseTres()useTresContext()TresCanvasuseLegacyLightsuseLoaderextensionsBest Practices
最佳实践
- Use with template refs to access Three.js instances directly in high-frequency render loops. This avoids Vue's deep proxy overhead, which can be significantly slower than direct property access source
shallowRef
vue
<script setup lang="ts">
const meshRef = shallowRef<TresInstance | null>(null)
const { onBeforeRender } = useLoop()
onBeforeRender(({ elapsed }) => {
if (meshRef.value) meshRef.value.rotation.y = elapsed
})
</script>
<template>
<TresMesh ref="meshRef" />
</template>-
Preferand
shallowRefovershallowReactiveorreffor Three.js objects. This maintains reactivity for the reference itself while preventing expensive deep tracking of complex internal Three.js properties sourcereactive -
Seton
renderMode="on-demand"for non-game applications to reduce CPU/GPU usage. The scene will only re-render when props change or when manual invalidation is explicitly triggered source<TresCanvas> -
Manually trigger a render usingfrom
invalidate()oruseLoopwhen modifying instances via template refs or direct mutations inuseTresmode, as these changes are invisible to Vue's reactivity system sourceon-demand -
Ensure animations are frame-rate independent by using theparameter in
deltacallbacks. This guarantees consistent movement speed across different display refresh rates (e.g., 60Hz vs 144Hz) sourceuseLoop
ts
onBeforeRender(({ delta }) => {
// Moves 2 units per second regardless of frame rate
mesh.position.x += delta * 2
})-
Use theprop for values required at Three.js instantiation (like geometry dimensions). Note that changing these reactive values at runtime forces TresJS to recreate the entire instance, which is performance-heavy source
args -
Take complete control of the render process usingfrom
renderfor custom post-processing or multi-pass setups. You must calluseLoopat the end of the function to maintain the loop state sourcenotifySuccess() -
Orchestrate complex update sequences using theargument in
priority(default 0). Higher priority numbers ensure a callback runs after those with lower priorities within the same frame sourceonBeforeRender -
Explicitly callfrom
dispose()for Three.js objects created programmatically and used via@tresjs/core. TresJS automatically disposes of template-defined components but cannot track lifecycle for raw objects source<primitive /> -
Useto generate a reactive map of named meshes, materials, and nodes from a complex hierarchy (like a loaded GLTF). This enables direct, named access without manually traversing the object tree source
useGraph
- 在高频渲染循环中,使用配合模板引用直接访问Three.js实例。这能避免Vue深度代理带来的性能开销,因为深度代理的速度远慢于直接属性访问 来源
shallowRef
vue
<script setup lang="ts">
const meshRef = shallowRef<TresInstance | null>(null)
const { onBeforeRender } = useLoop()
onBeforeRender(({ elapsed }) => {
if (meshRef.value) meshRef.value.rotation.y = elapsed
})
</script>
<template>
<TresMesh ref="meshRef" />
</template>-
对于Three.js对象,优先使用和
shallowRef而非shallowReactive或ref。这可以保持引用本身的响应式,同时避免对Three.js复杂内部属性进行昂贵的深度追踪 来源reactive -
对于非游戏类应用,在上设置
<TresCanvas>以降低CPU/GPU占用。场景仅会在属性变更或手动触发失效时重新渲染 来源renderMode="on-demand" -
在模式下,通过模板引用或直接修改实例时,需使用
on-demand或useLoop中的useTres手动触发渲染,因为这些变更无法被Vue的响应式系统检测到 来源invalidate() -
使用回调中的
useLoop参数确保动画帧率无关。这可以保证在不同刷新率的显示器(如60Hz vs 144Hz)上移动速度一致 来源delta
ts
onBeforeRender(({ delta }) => {
// 无论帧率如何,每秒移动2个单位
mesh.position.x += delta * 2
})-
使用属性传递Three.js实例化所需的值(如几何体尺寸)。注意:运行时修改这些响应式值会强制TresJS重新创建整个实例,性能开销较大 来源
args -
如需自定义后期处理或多通道渲染设置,使用中的
useLoop完全控制渲染流程。必须在函数末尾调用render以维持循环状态 来源notifySuccess() -
使用中的
onBeforeRender参数(默认值0)编排复杂的更新序列。优先级数值越高,回调在同一帧中执行的顺序越靠后 来源priority -
对于通过使用的、以编程方式创建的Three.js对象,需显式调用
<primitive />中的@tresjs/core方法。TresJS会自动处理模板定义组件的生命周期,但无法追踪原生对象的生命周期 来源dispose() -
使用从复杂层级结构(如加载的GLTF)生成响应式的网格、材质和节点映射。无需手动遍历对象树即可直接通过名称访问目标元素 来源
useGraph