You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Wikitude插件做图像跟踪绘制物体时push属性未定义报错求助

错误原因

报错Cannot read property 'push' of undefined触发在World.drawables.push(this.imgOne)这行代码,核心原因是你没有提前初始化World.drawables属性,此时该属性的值为undefined,不具备数组的push方法。

解决方案

在创建AR实例前先将World.drawables初始化为空数组即可,修正后的完整代码如下:

// 提前初始化drawables为空数组
World.drawables = [];

var imgOneScale = 0.04;
var imgOnePositionX = -0.52;
var imgOnePositionY = 0.24

this.imgOne = new AR.Model("https://www.docummedia.com/WikitudePlugin/01_ImageTracking_3_Interactivity/assets/ruption.wt3", {
    scale: {
        x: imgOneScale,
        y: imgOneScale,
        z: imgOneScale
    },
    translate: {
        x: imgOnePositionX,
        y: imgOnePositionY
    },
    rotate: {
        y: 180
    },
    enabled: false
});

World.drawables.push(this.imgOne);

this.pageOne = new AR.ImageTrackable(this.tracker, "CircleRuption_Black_MagentaFont_Large", {
     drawables: {
         cam: World.drawables
     },
     onImageRecognized: World.hideInfoBar,
     onError: World.onError
});
额外注意项
  • 确保执行初始化代码时,World对象已经在当前作用域中被正确创建,避免出现World本身未定义的问题
  • 若你的项目预设了World对象的结构,可检查是否存在drawables拼写错误、大小写不匹配的问题

内容的提问来源于stack exchange,提问作者Andi Luis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 19:27:03