[英]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.