Skip to content

模型方法

以下为模型常用的相关方法,是为了在场景中精准的找到模型,从而对模型进行一系列操作。

getObjectByProperty

依据对象的属性值来查找场景中的特定对象。该方法定义于 Object3D 类,所以场景里的任何对象都能使用它。

js
TO.scene.getObjectByProperty(name, value, recursive);
参数名说明类型必填默认值
name查找的属性名称string
value该属性所对应的值string
recursive为 true,就会递归查找所有的子对象; 为 false,则只会在直接子对象中进行查找booleantrue

实际使用案例

已导入ABB机械臂为例,具体代码请参考 导入模型章节

  1. 通过 name 属性查找对象
js
let model = TO.scene.getObjectByProperty("name", "WS30-1"); //找到名称为“WS30-1”的模型对象
console.log(model);
  1. 通过自定义属性查找对象
js
let model = TO.scene.getObjectByProperty("userData.by", "ThingOrigin"); //找到userData.by 为 ThingOrigin的模型对象
console.log(model);

getModelCenter

场景中获取模型中心点位置。

js
TO.tool.getModelCenter(model);
参数名说明类型必填默认值
model模型any

实际使用案例

已导入ABB机械臂为例,具体代码请参考 导入模型章节

js
let model = TO.scene.getObjectByProperty("name", "fileModel-abb"); //找到模型
let center = TO.tool.getModelCenter(model);//获取模型中心点
console.log(center);

getModelInfo

获取模型信息。

js
TO.tool.getModelInfo(model);
参数名说明类型必填默认值
model模型any

实际使用案例

已导入ABB机械臂为例,具体代码请参考 导入模型章节

js
let model = TO.scene.getObjectByProperty("name", "fileModel-abb"); //找到模型
let modelInfo = TO.tool.getModelInfo(model);//获取模型信息
console.log(modelInfo);

getChildrenInfo

获取模型的子模型信息。

js
TO.tool.getChildrenInfo(model);
参数名说明类型必填默认值
model模型any

实际使用案例

已导入ABB机械臂为例,具体代码请参考 导入模型章节

js
let model = TO.scene.getObjectByProperty("name", "fileModel-abb"); //找到模型
let child = TO.tool.getChildrenInfo(model);//获取模型的子模型信息
console.log(child);

getWorldPosition

获取模型世界坐标位置。

js
TO.tool.getWorldPosition(model);
参数名说明类型必填默认值
model模型any

实际使用案例

已导入ABB机械臂为例,具体代码请参考 导入模型章节

js
let model = TO.scene.getObjectByProperty("name", "fileModel-abb"); //找到模型
let position = TO.tool.getWorldPosition(model);//获取模型世界坐标位置
console.log(position);