Thing
大约 3 分钟
Thing
Thing继承自THREE.Object3D,拥有所有THREE.Object3D的方法和属性,同时也是引擎内置所有物体的基类。
属性成员
isThing
- 类型:
{Boolean}是否是物体,不可更改 - 默认值:
true 
uuid
唯一ID,随机生成
- 类型:
{String} 
name
物体名称
- 类型:
{String} - 默认值 :""
 
visible
可见性,当为false时,物体不可见
- 类型:
{Boolean} - 默认值:
undefined 
frustumCulled
渲染时是否剔除,默认剔除
- 类型:
{Boolean} - 默认值:
true 
receiveShadow
材质是否接收阴影
- 类型:
{Boolean} - 默认值:
false 
castShadow
材质是否产生阴影
- 类型:
{Boolean} - 默认值:
false 
renderOrder
渲染顺序,这个值将使得scene graph(场景图)中默认的的渲染顺序被覆盖, 即使不透明对象和透明对象保持独立顺序。 渲染顺序是由低到高来排序的,默认值为0。
- 类型:
{Integer} - 默认值 :0
 
layers
物体的层级关系,物体只有和一个正在使用的Camera至少在同一个层时才可见。
- 类型:
{Integer} - 默认值:0
 
position
位置
- 类型:
{THREE.Vector3} - 默认值:
{x: 0, y: 0, z: 0} 
scale
比例
- 类型:
{THREE.Vector3} - 默认值:
{x: 1, y: 1, z: 1} 
rotation
旋转,欧拉角描述一个旋转变换,通过指定轴顺序和其各个轴向上的指定旋转角度来旋转一个物体。对 Euler 实例进行遍历将按相应的顺序生成它的分量 (x, y, z, order)。
对应的每个分量值单位为弧度。
- 类型:
{THREE.Euler} - 默认值:
new THREE.Euler( 0, 0, 0, 'XYZ' ) 
matrix4
局部变换矩阵。
- 类型:
{THREE.Matrix4} - 默认值:
new THREE.Matrix4() 
children
含有对象的子级的数组。
- 类型:
{Array} - 默认值:
[] 
properties
属性对象,一般将业务属性数据注入此对象
- 类型:
{Object} - 默认值:
{uuid} 
locked
是否锁定,锁定后无法选择
- 类型:
{Boolean} - 默认值:
false 
userData
自定义数据,一般将临时数据注入此对象
- 类型:
{Object} - 默认值:
{} 
style
通用样式对象,通用样式是针对通用物体、通用样式值的设置,方便使用。通过它会更改某些属性对象的值,如修改color会遍历物体所有mesh下的material的color值。
- 类型:
Style - 参数: 
- transparent 
{Boolean}是否透明,默认值 false - opacity 
{Number}透明度,默认值 1.0,值范围:0 ~ 1 - side 
{Integer}面,默认值 0,0:前面,1:背面,2:双面 - color 
{String}颜色,默认值 #ffffff - emissive 
{String}发光颜色,默认值 #000000 - wireframe 
{Boolean}是否显示轮廓线,默认值 false - edge 
{Boolean}是否显示边缘线,默认值 false - edgeColor 
{String}边缘线颜色,默认值 #ffffff - edgeOpacity 
{Number}边缘线透明度,默认值 1.0,值范围:0 ~ 1 - box 
{Boolean}是否显示Box盒子,默认值 false - boxColor 
{String}Box盒子颜色,默认值 #00ff00 - castShadow 
{Boolean}是否显示产生阴影,默认值 false - receiveShadow 
{Boolean}是否显示接收阴影,默认值 false 
 - transparent 
 
const box = new VT.Box();
// 修改box的颜色为红色
box.style.color = "#FF0000";
// 等同于
box.mesh.material.color = new THREE.Color("#FF0000");
// 修改box的透明度
box.style.transparent = true;
box.style.opacity = 0.5;
// 等同于
box.mesh.material.transparent = true;
box.mesh.material.opacity = 0.5;
box.mesh.material.needsUpdate = true;
方法
拥有所有THREE.Object3D的方法
clear
清空子物体
- clear()
 - 类型:
{Function} - 参数:
- - 返回:无
 
const group = new VT.Group();
viewer.scene.add(group);
group.add(new VT.Box());
// 清空子物体
group.clear();
clone
克隆物体
- clone()
 - 类型:
{Function} - 参数:
- - 返回:
THREE.Object3D 
toJSON
序列化对象
- toJSON(meta)
 - 类型:
{Object} - 参数: 
- meta 
{Object}需要额外输出的值 
 - meta 
 - 返回:
{Object} 
const box = new VT.Box({
    position: [0, 0.5, 0]
});
box.toJSON();
将输出:
{
    "isThing": true,
    "name": "Box",
    "type": "Box",
    "config": {
        "position": [
            0,
            0.5,
            0
        ],
        "geometry": {
            "width": 1,
            "height": 1,
            "depth": 1,
            "widthSegments": 1,
            "heightSegments": 1,
            "depthSegments": 1
        },
        "properties": {
            "uuid": "BC07E076-E78F-41E5-8459-6B5161BFB604"
        },
        "material": {
            "type": "MeshStandardMaterial"
        }
    }
}
事件
added
添加时触发事件
thing.addEventListener("added", () => {
    // 代码
});
removed
被移除时触发事件
thing.addEventListener("removed", () => {
    // 代码
});
loaded
从远程加载完成时触发,仅针对 isSync == true 的物体有效
thing.addEventListener("loaded", () => {
    // 代码
});