简体   繁体   English

每当我尝试从 UserData 获取值时,ThreeJS 返回 undefined

[英]ThreeJS returning undefined whenever I try to get a value from UserData

Ive spent so long trying to figure out why I can't get a value from UserData.我花了很长时间试图弄清楚为什么我无法从 UserData 中获取值。 I think my code works fine, but I'm just lost.我认为我的代码工作正常,但我只是迷路了。

The raycast code is pretty simple.光线投射代码非常简单。

const interactIntersects = raycaster.intersectObjects( flags, true );

if (interactIntersects.length > 0)
{
  console.log(interactIntersects[0].object.userData.id);
}

I can't figure out why it keeps giving me the undefined value.我不明白为什么它一直给我未定义的价值。 I was thinking it mightve been the insertion of the data itself, but when I checked it returned the values.我在想它可能是数据本身的插入,但是当我检查它时它返回了值。 (Checking in the place where its being created) (检查创建它的地方)

export function createFlag(flag_id, web, desc, x, y, z, orx, ory, orz)
{
  const fbxLoader = new FBXLoader()
  fbxLoader.load('flag.fbx', (object) => 
  {
    object.scale.set(.003, .003, .005);
    scene.add(object)
    object.position.set(x, y, z)
    object.rotation.set(orx, ory, orz);
    object.userData = { id: flag_id };
    console.log(object.userData.id);
    flags.push(object);
  }); 

  createModal(flag_id, web, desc);
}

Can anyone help?任何人都可以帮忙吗? Thanks in advance.提前致谢。

Found out you cannot set userData to Imported objects.发现您无法将 userData 设置为 Imported 对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每当我尝试从服务中调用方法时,服务的状态都未定义 - Service s undefined whenever I try to call a method from it 尝试从标签获取数据时获取未定义的值 - Getting an undefined value when I try to get data from a label 每当我尝试编译 javascript 代码时,都会出现语法错误 - Whenever I try to compile javascript code I get a syntax error userData未定义 - userData is undefined 每当我尝试访问 record.username 时,我都会收到“TypeError: Cannot read property 'username' of undefined” - I am getting "TypeError: Cannot read property 'username' of undefined" whenever I try to access record.username javascript,每当我尝试计算参数的平均值时,当它为假时返回真 - javascript, returning true when it's false whenever I would try to calculate the average of parameters Mongoose 无法将“”的属性设置为未定义,每当我尝试创建新条目时。即使模式被声明为正确 - Mongoose cannot set property of “ ” to undefined,Whenever i try to create a new entry.Eventhough the schema is declared right 每当我更改日期时,如何从 React 日期选择器中获取价值? - How do i get value from a React date picker whenever i change the dates? Promise 在函数 firebase 中尝试获取图像链接时返回未定义 - Promise returning undefined when try to get link of image in functions firebase 我尝试访问数组元素但未定义 - I try to access the array elements but get undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM